Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions content/docs/automation/queues-and-assignment-rules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,19 @@ Content-Type: application/json

There is no claim endpoint and no claim hook. The ownership gate admits this one update when the record is **unowned**, the payload names **you** as a single value, the request addresses **one record by id**, and the sharing model positively admits you to the record — a member of its queue, a holder of an `edit` share, or `modifyAllRecords`. A bulk update carrying `owner_id` stays refused.

**Only one person wins.** The write is conditional on the owner still being empty, so two people claiming at once produce exactly one owner. The loser gets **`409 CONCURRENT_UPDATE`** — "The record was taken: another user changed it first. Reload it to see who has it now." Treat it as an answer, not an error: reload and move on. Any other refusal is `403 PERMISSION_DENIED`, and its message names the condition that failed.
**Only one person wins.** The write is conditional on the owner still being empty, so however many people claim a record at once, it ends with exactly one owner. That is the promise. What a claimant who did not get the record is told depends on when the server judged their request, and it is one of three answers:

- **`409 CONCURRENT_UPDATE`** — "The record was taken: another user changed it first. Reload it to see who has it now." You get this when your claim was checked while the record was still unowned, and your write then found an owner already set.
- **`404 RECORD_NOT_FOUND`** — when your claim is checked after the owner is set and you can no longer read the record. On an object whose [`sharingModel`](/docs/permissions/sharing-rules#organization-wide-defaults-owd) is `private` this is what a late claim gets when the queue was your only way to the record: the moment a claim lands, the queue stops giving the other members access, and a record you cannot read answers exactly as one that does not exist.
- **`403 PERMISSION_DENIED`** — when your claim is checked after the owner is set and you can still read the record (a `public_read` object, a share, `viewAllRecords`): you are now asking to change the owner of a record that has one.

Which of the three arrives is a matter of timing you do not control, so treat all three, straight after a claim, as one answer and not as an error: the record is no longer there to claim, so reload and move on. Do not write code or a test that expects `409` in particular. And neither `404` nor `403` says a colleague took the record: a deleted record, or one you were never admitted to, answers the same way.

The line between `404` and `403` is not sharp either. The server checks a claim in several steps, and if the owner is set while those steps are running, you can get `403` for a record you can no longer read, and that `403` may carry the code `FORBIDDEN` in place of `PERMISSION_DENIED`. Read the status, not the code.

One caller is outside this: someone who can edit the record and holds the transfer grant (`allowTransfer` or `modifyAllRecords`) is not claiming once the record has an owner. For them the same update is a transfer, and it succeeds.

A claim of a record that is still unowned can be refused as well. If you cannot read the record, the answer is `404`, as for any record you cannot read. If you can read it and the sharing model gives you no edit on it, or the update is not a single-record claim of your own, the answer is `403 PERMISSION_DENIED`; a refusal from the ownership gate names the condition that failed in its message.

The Console's **Claim** button on a record sends exactly this update. It appears only on a record that sits in a queue, and only after the server's explain answer says your claim would be admitted; when someone beats you to it, it says so.

Expand Down Expand Up @@ -163,7 +175,7 @@ A queue routes **records** to people. It is not an address for **messages**: a f
- A declared queue's members are positions; organizations add users, teams and units through `sys_queue_member`.
- An organization's own `sys_assignment_rule` records are tried before the stack's rules, lowest `sort_order` first; a `user` target is an active member of the organization.
- Every `least_loaded` entry has a `load` your filter compiler can lower; no other entry has one.
- Code that claims a record sends `{ owner_id: <self> }` by id and handles `409` as "someone else took it".
- Code that claims a record sends `{ owner_id: <self> }` by id and treats `409`, `404` or `403` straight after the claim as "no longer available": it reloads. A test of two claims at once, by users without the transfer grant, asserts exactly one owner and a refusal from that set, never `409` alone.
- Alerts about new work address a team or a position, not the queue.

## See also
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ADR-0142: An ownership queue is a platform primitive — a queue entity, membership through the existing recipient kinds, claim through the ownership-transfer gate, and declarative assignment rules evaluated on insert

**Status**: Proposed (2026-10-25) · **Amended** (2026-10-28, ruling [`6457475657`](https://github.com/objectstack-ai/objectstack/issues/25769#issuecomment-6457475657) on #25769, letter A) — D3's `current_user.queues` producer is `@objectstack/plugin-security`, kernel-side, under the reserved key `queues`; see the note in D3 · **Amended** (2026-11-03, ruling records [`6594432222`](https://github.com/objectstack-ai/objectstack/issues/29604#issuecomment-6594432222) and [`6599731698`](https://github.com/objectstack-ai/objectstack/issues/29604#issuecomment-6599731698) on #29604, letter B in both) — D2 tells an empty expansion (a fact) from a failed read behind the queue (a fault): the admission consumers (D3, D4, D5) keep "nobody" on a failed read, the D7 grant recompute refuses it, and the D6 approver slate refuses it with the approval node refusing to open; see the notes in D2, D6 and D7 · **Amended** (2026-11-05, ruling A on [#30066](https://github.com/objectstack-ai/objectstack/issues/30066) (record [`6631036940`](https://github.com/objectstack-ai/objectstack/issues/30066#issuecomment-6631036940), with the execution parameters of [`6670178869`](https://github.com/objectstack-ai/objectstack/issues/30066#issuecomment-6670178869), agreed 「同意」)) — D5 gains its second source: an organization authors its own assignment rules as `sys_assignment_rule` rows, evaluated before the declared rules, and merge question 11 is answered; see the note in D5 · **Amended** (2026-11-10, ruling of record [`6755714726`](https://github.com/objectstack-ai/objectstack/issues/32004#issuecomment-6755714726) on #32004) — explain's `transfer` and the `/me/permissions` `allowTransfer` hint answer edit and the transfer grant together; enforcement and server-evaluated `current_user.can()` are unchanged, and a Console-evaluated predicate reads the hint; see the note in Context §1. `docs/adr/**` is Tier H (Prime Directive #14): this record becomes **Accepted** by the
**Status**: Proposed (2026-10-25) · **Amended** (2026-10-28, ruling [`6457475657`](https://github.com/objectstack-ai/objectstack/issues/25769#issuecomment-6457475657) on #25769, letter A) — D3's `current_user.queues` producer is `@objectstack/plugin-security`, kernel-side, under the reserved key `queues`; see the note in D3 · **Amended** (2026-11-03, ruling records [`6594432222`](https://github.com/objectstack-ai/objectstack/issues/29604#issuecomment-6594432222) and [`6599731698`](https://github.com/objectstack-ai/objectstack/issues/29604#issuecomment-6599731698) on #29604, letter B in both) — D2 tells an empty expansion (a fact) from a failed read behind the queue (a fault): the admission consumers (D3, D4, D5) keep "nobody" on a failed read, the D7 grant recompute refuses it, and the D6 approver slate refuses it with the approval node refusing to open; see the notes in D2, D6 and D7 · **Amended** (2026-11-05, ruling A on [#30066](https://github.com/objectstack-ai/objectstack/issues/30066) (record [`6631036940`](https://github.com/objectstack-ai/objectstack/issues/30066#issuecomment-6631036940), with the execution parameters of [`6670178869`](https://github.com/objectstack-ai/objectstack/issues/30066#issuecomment-6670178869), agreed 「同意」)) — D5 gains its second source: an organization authors its own assignment rules as `sys_assignment_rule` rows, evaluated before the declared rules, and merge question 11 is answered; see the note in D5 · **Amended** (2026-11-10, ruling of record [`6755714726`](https://github.com/objectstack-ai/objectstack/issues/32004#issuecomment-6755714726) on #32004) — explain's `transfer` and the `/me/permissions` `allowTransfer` hint answer edit and the transfer grant together; enforcement and server-evaluated `current_user.can()` are unchanged, and a Console-evaluated predicate reads the hint; see the note in Context §1 · **Amended** (2026-12-03, ruling record [`7363773549`](https://github.com/objectstack-ai/objectstack/issues/39065#issuecomment-7363773549) on #39065, letter B) — D4 says which claimant hears which answer: 409 `CONCURRENT_UPDATE` goes to a claim whose check read the record unowned and whose write then found it taken; a claim whose check runs after the owner is set is answered as any request is at that moment, 404 where the caller cannot read the record and 403 where it can; "exactly one owner" is the invariant; see the notes in D4 and D9. `docs/adr/**` is Tier H (Prime Directive #14): this record becomes **Accepted** by the
maintainer's merge, and ⛔ the one PR under [Execution plan](#execution-plan-after-acceptance) is cut after that merge,
never before it. Until a published `@objectstack/*` release carries that PR, HotCRM keeps the STOPGAP module this record
exists to retire. **This record declares; it implements nothing** — no schema, no code, no changeset.
Expand Down Expand Up @@ -447,6 +447,48 @@ untouched by the PR (merge question 16). Where the
driver has no `updateMany`, the precondition degrades to the pre-image check and the write goes through unconditionally,
logged once per process at `warn`; every shipped driver has it (Context §1).

**Amended** (2026-12-03, ruling record [`7363773549`](https://github.com/objectstack-ai/objectstack/issues/39065#issuecomment-7363773549)
on #39065, letter B) — **which claimant hears which answer.** "Exactly one owner" is the invariant: however many callers
without the transfer grant claim one sitting record at once, and in whatever order their requests are served, one claim
lands. What a claimant
whose claim did not land is told follows from what the record looked like to that caller when its request was judged,
and there are three answers:

- **409 `CONCURRENT_UPDATE`** — to a claim the gate admitted: its check, under the caller's own sight, read the record
unowned and the precondition was set, and the write then matched nothing because an owner had been set in between.
This is the zero-rows answer of the paragraph above, and it is owed to that claimant alone.
- **404 `RECORD_NOT_FOUND`** — to a claim judged after the owner is set, where the caller cannot read the record. A
member whose only basis was the queue loses it the moment a claim lands (D3), so on a `private` object this is what
such a member is told. It is the answer a by-id write gives for every row the caller cannot read, the one a
nonexistent id gets (ruling record
[`5985885287`](https://github.com/objectstack-ai/objectstack/issues/21771#issuecomment-5985885287)); that rule stands
whole.
- **403 `PERMISSION_DENIED`** — to a claim judged after the owner is set, where the caller can still read the record: a
`public_read` object, a share, `viewAllRecords`. It is the refusal any write of `owner_id` on an owned record gets
without the grant, or, where the caller may read the row and not edit it, the record-level refusal ahead of this
step.

The bullets sort a claim by one moment, and a request has several: it reads the record at the row check, again in the
ownership step and again in the sharing gate, and only then writes. A claim that passes an earlier check while the
record is unowned can be overtaken before a later one, and a later check that then refuses it answers **403** — the
ownership step with `PERMISSION_DENIED`, the sharing gate with `FORBIDDEN`, the wire synonym the ledger keeps for it —
also where the caller can by then no longer read the record. The write does not run, so no 409 follows. The split of 404
from 403 above is therefore exact for a claim whose every check runs after the owner is set; in every other order the
answer is still one of the three statuses, and a client and a test read the status, not the code.

A claim judged after the owner is set is not a lost race the platform reports as one: that caller is answered as any
request for the record is answered at that moment — which, for a caller who can edit the record and holds the transfer
grant, is the transfer this section already admits, not a refusal. Which of the three answers a claimant receives is a
matter of timing it does not control, so a client reads all three, straight after a claim, as "this record is no longer
there to claim" and reloads, and a test of claimants without that grant asserts one owner and an answer from this set,
never 409 alone. Neither 404 nor 403 says that someone claimed the record: 404 is also what a deleted record answers,
and one the caller could never read; 403 is also what a record the caller can read and was never admitted to claim
answers. This narrows the reading the section was given before, that every loser hears 409,
which cannot hold beside the rule above: to a claimant who can no longer read the record, "taken" would confirm a row
that does not exist for them. ⛔ The gate does not admit a claim by its arrival time, and it does not look again at who owns the record
after refusing one (options A and C of the ruling, not taken). Status codes, messages and the gate are unchanged by this
note; no schema, context field or column is added.

**Release** is an update of `owner_id` to null by the current owner on a record whose `queue` is set: admitted when the
pre-image's `owner_id` is the caller and `queue` is unchanged — whether or not the owner is still a member of that queue,
because ownership is not membership and the released record then becomes visible to the queue's current members. The
Expand Down Expand Up @@ -690,6 +732,14 @@ at merge (the card's own words; HotCRM `AGENTS.md` rule 2: *merged is not availa
(D5). D3's registration refusal is thrown at `registerObject`, a door Studio and the metadata API reach at request
time, so it carries the ADR-0112 envelope the registry's other field refusals carry — `INVALID_METADATA`, 422, as
`ObjectFieldTypeRefusedError` does; D1's boot refusal is reached by no request and stays a startup report.
**Amended** (2026-12-03, ruling record [`7363773549`](https://github.com/objectstack-ai/objectstack/issues/39065#issuecomment-7363773549)
on #39065, letter B) — "a lost claim race" is the case D4's note defines: a claim the gate admitted on an unowned
record, whose write then found an owner set. A claim judged after the owner is set carries neither that code nor a
code of its own: it answers what any request for the record answers at that moment, the existing `RECORD_NOT_FOUND`
404 where the caller cannot read the record and `PERMISSION_DENIED` 403 where it can. A claim overtaken between two
of its own checks (D4's note) is refused 403 by the check that finds the owner set: `PERMISSION_DENIED` from the
ownership step, `FORBIDDEN` — the ledger's wire synonym for it — from the sharing gate, so a reader of the answer
keys on the status. No code is added, renamed or re-registered, and no message changes.
- **Unchanged.** The owner anchor's type and every reader of it; the gate's existing arms; the insert pipeline's order
(one step is added, none moved); `ownership` tiers; teams never carry capability (ADR-0090 D8 — a queue is a sharing
and distribution set, bindable to no permission set); the approval node's other types; the `field` recipient; the
Expand Down
Loading