From aae6cb05836c6d0700ff7c8f38c36333ef75e538 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Nov 2026 09:33:32 +0000 Subject: [PATCH] docs(approvals): approvals on an object that declares closedStates What the check at an approval's first request asks of the mirror field and the flow, what a refused opening is for the submitter, what an abandoned approval leaves, and how an approval that does not mirror onto the closing field and an approval per map item behave. Read against the trunk's approvals plugin and ADR-0162 as revised. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5phEgfPTCgvPqh4ER2 --- content/docs/automation/approvals.mdx | 190 +++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 1 deletion(-) diff --git a/content/docs/automation/approvals.mdx b/content/docs/automation/approvals.mdx index 9adaf844c92..e12d0d4f765 100644 --- a/content/docs/automation/approvals.mdx +++ b/content/docs/automation/approvals.mdx @@ -1410,6 +1410,194 @@ in-flight request, `reassign` hands one slot to another user directly. - Forget rejection paths - Hard-code approvers +## Approvals on an object that declares `closedStates` [#closed-states] + +An object can declare [`closedStates`](/docs/references/data/object) (ADR-0162): +values of its own `select` fields on which a record and its direct +`master_detail` lines are closed to every caller that is not a system context, +who is refused `409 RECORD_LOCKED`. The approval status mirror writes in a system +context, so it can move such a record: the `pending` of a new approval takes a +document off a closed `approved`. That is why the platform asks more of an +approval on such an object, and what this section describes. In an application +where no object declares `closedStates`, none of it applies and nothing is read. + +### Which approvals are judged, and when + +An approval here is one passage of a record through its approval flow, taken +whole: the run started for the record and every child run under it, a `subflow` +body or an item of a `map`, to any depth. It holds one request for each step it +reaches, and one more each time a returned request is resubmitted. ADR-0044 +numbers those resubmissions as the rounds of a request, and the word means +nothing else on this page. + +The platform judges an approval once, at its first request, before anything is +written. It reads every approval step of the flow the record's run was started +on and of every flow a `subflow` or a `map` in it names, to any depth, each with +its own `approvalStatusField` and every object it can act on: the record's +object, and under a `map` the object the node names for its items as well. A +later request of the same approval is not judged again, since refusing it would +end the approval between two steps that were already decided. Nor is a request +the platform cannot place as first or later, which is a request of an approval +whose earlier requests were opened before requests recorded the run they +belong to. So an approval that was in flight when its object first declared +`closedStates` is not held to what follows. + +A step is **concerned** where the object closes on its mirror field at a status +the mirror writes for a request that is not abandoned: `pending`, `returned`, +`approved` or `rejected`. An object that closes on that field only on values of +its own, such as `paid` or `void`, is asked none of the field and flow +conditions below. + +### What the mirror field owes + +For every concerned step, the step's mirror field: + +- **declares `pending`**, and the object closes on **neither `pending` nor + `returned`**. Those are the statuses of a request in flight, and the revise + window of a returned request opens on `returned` (ADR-0044). +- has **`pending` among the moves out of a closed `approved` or `rejected`**, + wherever a `state_machine` rule on the field declares those moves. A new + approval of a decided document opens it by writing `pending`. +- carries **no `readonlyWhen`**, and **no `visibleWhen` on its options for a + request's status** (`pending`, `returned`, `approved`, `rejected`, + `recalled`). The platform does not evaluate those predicates ahead, and on a + record where one holds it takes away a write the mirror needs. Keep callers + off a mirror field with `readonly`, which the mirror passes. + +The field's other rules and hooks cannot be read ahead, and they meet every +write of the mirror. A `state_machine` rule on the field owes the mirror its +other moves as well: from `pending` to each outcome, and out of `pending` and +`returned` when a request is abandoned. Where the object closes on the field at +`approved` or `rejected`, a write of the mirror that a rule or a hook refuses is +not swallowed: + +- **The `pending` of an approval's first request.** The approval does not open. + The request just written is voided as `cancelled`, its timeline carries the + refusal, no lock is taken, and the run fails at that step with the refusal's + own message. The record keeps the value it held. +- **Any other write.** The field keeps the value it holds, and the refusal is + reported three ways: an `error` line in the server log, a line with no actor on + the request's timeline that carries the refusal's message, and a notice to the + organization's administrators, who can change the rule. + +### What the flow owes + +- **One mirror field for every step.** Every approval step that can act on a + record of the object names the same mirror field as the concerned step. A + step that names another field, or none, refuses the approval, whether it comes + ahead of the concerned step or after it. A step in a `map` body counts as one + that can act on the parent's record, unless the node writes its items out and + every one of them is a record. +- **No pause between two steps.** *Between two steps* means after a step is + decided, either way, and before the next step opens. The next step can be the + same step opened again, so in a `map` or a `loop` body that holds a step, a + node after the body's last step stands between two steps too. No node that can + pause the run of itself may stand there, in a flow that runs as the user or in + one that runs as system: a `wait` or a `screen` there would hold the document + in approval with nobody asked to decide. The platform reads this off the node + type's descriptor (`supportsPause`), and reads a `subflow` or a `map` through + the body it calls. The revise window of a returned request (`approval_revise`) + is not such a pause. +- **A node type without a descriptor.** A node whose type publishes no + descriptor counts as one that can pause, and so does a node whose type the + platform cannot read: such a node between two approval steps refuses the + approval. The structural types `start` and `end` have no executor and never + pause, so the `end` of a `map` body or of a `subflow` body refuses nothing. +- **No `map` of approvals on the parent's record.** Where a concerned step can + act on the parent's record, the approval holds no `map` with an approval step + in its body, at any depth, unless the node writes its items out and none of + them is a record. An item that is a record has its request filed on the item, + and the parent's run waits on it as it would on a pause. A parent run that + carries no record, such as a batch sign-off that hands a `map` its items, is + not refused on this ground. +- **Readable whole.** Every flow a `subflow` or a `map` names is one the + platform can read. An approval it cannot read whole cannot be judged, and is + refused. + +One more ground is the host's, not the author's. An approval any step of which +can act on an object that declares `closedStates`, concerned or not, opens only +on a host that runs the approvals plugin's sweeps, which needs a `job` service. +The sweeps are what release a record held by a dead run, below. + +### An approval that does not mirror onto the closing field + +An approval none of whose steps mirrors onto a field the object closes on is +asked none of the field and flow conditions, only the host's. It moves nothing on +the closing field, so it does not open a closed document: a record that is closed +stays closed through it, on the value its last writer left, and every caller's +edit of it is refused, in the revise window after a send-back as well. Such an +approval is not a way out of the closed state. Where a closed document should +not be sent for approval at all, gate the flow's start on the state. + +### Each item under a `map` is an approval of its own record + +Under a `map` whose items are records, each item's request is filed on that +item, on the object the node names for its items, and what follows is judged for +that record alone: + +- the item object's closed values and mirror field are judged, with the rest of + the approval, at the approval's first request; +- the submitter is told an item's outcome without waiting for the items after it; +- when an item's request is abandoned, only the requests on that item's record + count, never another item's (below). + +### What a refused opening is for the person who submitted + +When the check refuses, the approval does not open: no request is written, +nothing is mirrored, no lock is taken, and nobody is asked to decide. The +approval node fails the run with a `VALIDATION_FAILED` error, and that failed run +is what the person who submitted sees. Its message names the record whose +approval was not started, and then, for each gap, the flow, the step, the object, +the field and what is missing. Its lead says that the object closes on its +approval field only where a gap concerns that field; where the only gaps are the +host's or a flow that could not be read, the lead says instead that the approval +can act on an object that declares `closedStates`. The message is in the run's +locale where the plugin carries it, and in English otherwise. The record keeps the +value it held, and the server log carries a warning that names the gaps. + +Nothing in the message is the submitter's to fix: every gap is the app's +configuration or the host's. Whoever maintains the app fixes the field, the flow +or the host, and the submitter then submits again. + +### What an abandoned approval leaves + +Three writers abandon a request: its submitter's recall, of a pending request or +of a returned one in its revise window; an administrator's override of a pending +request, the override arm of the same recall; and the sweep that releases a +record held by a dead run. Each records `recalled` on the request. Where the +object closes on the mirror field at any value, one of its own or a status, an +abandoned request never writes a closed value of that field: + +1. **A closed value the approval did not write is left alone.** Where the field + holds a closed value that no request of this approval on this record had as + its status, another writer put it there, and the mirror writes nothing. A + request of the same approval on another record, another item of a `map`, does + not count. +2. **Otherwise `recalled`**, where the field declares it, or declares no options, + and the object does not close on it. +3. **Otherwise the first usable value in this order:** the value the field held + at submit, the field's declared default, empty. A closed value is passed over + at each step, and so is a value the field does not declare. On a required + field an empty value at submit is passed over for the default. + +So listing `recalled` among the field's closed values closes nothing through the +mirror: a withdrawn approval leaves the record open. A record that was closed +when it was submitted, and that the approval opened, is left open on the value a +never-submitted record carries, its default or empty. To close a withdrawn +document, use an action or a flow of the app's own. To show a withdrawn approval +on the record, declare `recalled` among the field's options and do not close on +it. + +Where the platform cannot tell whether the approval wrote the closed value the +field holds, because the abandoned request, or one opened on the record since the +approval's run started, does not record the run it belongs to, it goes down the +order. The server log says when the mirror withholds a declared `recalled` (a +warning) and when it passes over a closed value or leaves one alone. On a +required field that is not `readonly`, with no default the mirror can use, the +write of empty is refused: the field keeps the value it holds, and the refusal is +logged, and reported as above where the object closes on the field at `approved` +or `rejected`. + ## Why Separating *who configures* from *who approves* from *as whom it runs* is the same capability/assignment/requirement decoupling as the rest of authorization (ADR-0066). The `runAs` default of `user` means an approval flow can't silently grant the submitter cross-tenant or cross-owner reach — elevation is opt-in and auditable. That is the safe-by-default posture: the common case respects RLS; the elevated case is explicit. @@ -1427,6 +1615,6 @@ Separating *who configures* from *who approves* from *as whom it runs* is the sa ## See also -- Decision records: **ADR-0049** (`runAs`), **ADR-0066** (unified authorization). +- Decision records: **ADR-0049** (`runAs`), **ADR-0066** (unified authorization), **ADR-0044** (send-back and resubmission), **ADR-0162** (closed states and the approvals on them). - Guide: [Hooks](/docs/automation/hooks) and [Flows](/docs/automation/flows); [Who can see data / automation / interface](/docs/permissions/access-recipes). - Reference: [Flow](/docs/references/automation/flow), [Approval](/docs/references/automation/approval).