Skip to content

Commit 97f9f1f

Browse files
committed
Merge the approvals guide's closed-states section into the closed-state trunk (ADR-0162)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5phEgfPTCgvPqh4ER2
2 parents 978bb2b + dc3081f commit 97f9f1f

1 file changed

Lines changed: 189 additions & 1 deletion

File tree

‎content/docs/automation/approvals.mdx‎

Lines changed: 189 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,194 @@ in-flight request, `reassign` hands one slot to another user directly.
14101410
- Forget rejection paths
14111411
- Hard-code approvers
14121412

1413+
## Approvals on an object that declares `closedStates` [#closed-states]
1414+
1415+
An object can declare [`closedStates`](/docs/references/data/object) (ADR-0162):
1416+
values of its own `select` fields on which a record and its direct
1417+
`master_detail` lines are closed to every caller that is not a system context,
1418+
who is refused `409 RECORD_LOCKED`. The approval status mirror writes in a system
1419+
context, so it can move such a record: the `pending` of a new approval takes a
1420+
document off a closed `approved`. That is why the platform asks more of an
1421+
approval on such an object, and what this section describes. In an application
1422+
where no object declares `closedStates`, none of it applies and nothing is read.
1423+
1424+
### Which approvals are judged, and when
1425+
1426+
An approval here is one passage of a record through its approval flow, taken
1427+
whole: the run started for the record and every child run under it, a `subflow`
1428+
body or an item of a `map`, to any depth. It holds one request for each step it
1429+
reaches, and one more each time a returned request is resubmitted. ADR-0044
1430+
numbers those resubmissions as the rounds of a request, and the word means
1431+
nothing else on this page.
1432+
1433+
The platform judges an approval once, at its first request, before anything is
1434+
written. It reads every approval step of the flow the record's run was started
1435+
on and of every flow a `subflow` or a `map` in it names, to any depth, each with
1436+
its own `approvalStatusField` and every object it can act on: the record's
1437+
object, and under a `map` the object the node names for its items as well. A
1438+
later request of the same approval is not judged again, since refusing it would
1439+
end the approval between two steps that were already decided. Nor is a request
1440+
the platform cannot place as first or later, which is a request of an approval
1441+
whose earlier requests were opened before requests recorded the run they
1442+
belong to. So an approval that was in flight when its object first declared
1443+
`closedStates` is not held to what follows.
1444+
1445+
A step is **concerned** where the object closes on its mirror field at a status
1446+
the mirror writes for a request that is not abandoned: `pending`, `returned`,
1447+
`approved` or `rejected`. An object that closes on that field only on values of
1448+
its own, such as `paid` or `void`, is asked none of the field and flow
1449+
conditions below.
1450+
1451+
### What the mirror field owes
1452+
1453+
For every concerned step, the step's mirror field:
1454+
1455+
- **declares `pending`**, and the object closes on **neither `pending` nor
1456+
`returned`**. Those are the statuses of a request in flight, and the revise
1457+
window of a returned request opens on `returned` (ADR-0044).
1458+
- has **`pending` among the moves out of a closed `approved` or `rejected`**,
1459+
wherever a `state_machine` rule on the field declares those moves. A new
1460+
approval of a decided document opens it by writing `pending`.
1461+
- carries **no `readonlyWhen`**, and **no `visibleWhen` on its options for a
1462+
request's status** (`pending`, `returned`, `approved`, `rejected`,
1463+
`recalled`). The platform does not evaluate those predicates ahead, and on a
1464+
record where one holds it takes away a write the mirror needs. Keep callers
1465+
off a mirror field with `readonly`, which the mirror passes.
1466+
1467+
The field's other rules and hooks cannot be read ahead, and they meet every
1468+
write of the mirror. A `state_machine` rule on the field owes the mirror its
1469+
other moves as well: from `pending` to each outcome, and out of `pending` and
1470+
`returned` when a request is abandoned. Where the object closes on the field at
1471+
`approved` or `rejected`, a write of the mirror that a rule or a hook refuses is
1472+
not swallowed:
1473+
1474+
- **The `pending` of an approval's first request.** The approval does not open.
1475+
The request just written is voided as `cancelled`, its timeline carries the
1476+
refusal, no lock is taken, and the run fails at that step with the refusal's
1477+
own message. The record keeps the value it held.
1478+
- **Any other write.** The field keeps the value it holds, and the refusal is
1479+
reported three ways: an `error` line in the server log, a line with no actor on
1480+
the request's timeline that carries the refusal's message, and a notice to the
1481+
organization's administrators, who can change the rule.
1482+
1483+
### What the flow owes
1484+
1485+
- **One mirror field for every step.** Every approval step that can act on a
1486+
record of the object names the same mirror field as the concerned step. A
1487+
step that names another field, or none, refuses the approval, whether it comes
1488+
ahead of the concerned step or after it. A step in a `map` body counts as one
1489+
that can act on the parent's record, unless the node writes its items out and
1490+
every one of them is a record.
1491+
- **No pause between two steps.** *Between two steps* means after a step is
1492+
decided, either way, and before the next step opens. The next step can be the
1493+
same step opened again, so in a `map` or a `loop` body that holds a step, a
1494+
node after the body's last step stands between two steps too. No node that can
1495+
pause the run of itself may stand there, in a flow that runs as the user or in
1496+
one that runs as system: a `wait` or a `screen` there would hold the document
1497+
in approval with nobody asked to decide. The platform reads this off the node
1498+
type's descriptor (`supportsPause`), and reads a `subflow` or a `map` through
1499+
the body it calls. The revise window of a returned request (`approval_revise`)
1500+
is not such a pause.
1501+
- **A node type without a descriptor.** A node whose type publishes no
1502+
descriptor counts as one that can pause, and so does a node whose type the
1503+
platform cannot read: such a node between two approval steps refuses the
1504+
approval. The structural types `start` and `end` have no executor and never
1505+
pause, so the `end` of a `map` body or of a `subflow` body refuses nothing.
1506+
- **No `map` of approvals on the parent's record.** Where a concerned step can
1507+
act on the parent's record, the approval holds no `map` with an approval step
1508+
in its body, at any depth, unless the node writes its items out and none of
1509+
them is a record. An item that is a record has its request filed on the item,
1510+
and the parent's run waits on it as it would on a pause. A parent run that
1511+
carries no record, such as a batch sign-off that hands a `map` its items, is
1512+
not refused on this ground.
1513+
- **Readable whole.** Every flow a `subflow` or a `map` names is one the
1514+
platform can read. An approval it cannot read whole cannot be judged, and is
1515+
refused.
1516+
1517+
One more ground is the host's, not the author's. An approval any step of which
1518+
can act on an object that declares `closedStates`, concerned or not, opens only
1519+
on a host that runs the approvals plugin's sweeps, which needs a `job` service.
1520+
The sweeps are what release a record held by a dead run, below.
1521+
1522+
### An approval that does not mirror onto the closing field
1523+
1524+
An approval none of whose steps mirrors onto a field the object closes on is
1525+
asked none of the field and flow conditions, only the host's. It moves nothing on
1526+
the closing field, so it does not open a closed document: a record that is closed
1527+
stays closed through it, on the value its last writer left, and every caller's
1528+
edit of it is refused, in the revise window after a send-back as well. Such an
1529+
approval is not a way out of the closed state. Where a closed document should
1530+
not be sent for approval at all, gate the flow's start on the state.
1531+
1532+
### Each item under a `map` is an approval of its own record
1533+
1534+
Under a `map` whose items are records, each item's request is filed on that
1535+
item, on the object the node names for its items, and what follows is judged for
1536+
that record alone:
1537+
1538+
- the item object's closed values and mirror field are judged, with the rest of
1539+
the approval, at the approval's first request;
1540+
- the submitter is told an item's outcome without waiting for the items after it;
1541+
- when an item's request is abandoned, only the requests on that item's record
1542+
count, never another item's (below).
1543+
1544+
### What a refused opening is for the person who submitted
1545+
1546+
When the check refuses, the approval does not open: no request is written,
1547+
nothing is mirrored, no lock is taken, and nobody is asked to decide. The
1548+
approval node fails the run with a `VALIDATION_FAILED` error, and that failed run
1549+
is what the person who submitted sees. Its message names the record whose
1550+
approval was not started, and then, for each gap, the flow, the step, the object,
1551+
the field and what is missing. Its lead says that the object closes on its
1552+
approval field only where a gap concerns that field; where the only gaps are the
1553+
host's or a flow that could not be read, the lead says instead that the approval
1554+
can act on an object that declares `closedStates`. The message is in the run's
1555+
locale where the plugin carries it, and in English otherwise. The record keeps the
1556+
value it held, and the server log carries a warning that names the gaps.
1557+
1558+
Nothing in the message is the submitter's to fix: every gap is the app's
1559+
configuration or the host's. Whoever maintains the app fixes the field, the flow
1560+
or the host, and the submitter then submits again.
1561+
1562+
### What an abandoned approval leaves
1563+
1564+
Three writers abandon a request: its submitter's recall, of a pending request or
1565+
of a returned one in its revise window; an administrator's override of a pending
1566+
request, the override arm of the same recall; and the sweep that releases a
1567+
record held by a dead run. Each records `recalled` on the request. Where the
1568+
object closes on the mirror field at any value, one of its own or a status, an
1569+
abandoned request never writes a closed value of that field:
1570+
1571+
1. **A closed value the approval did not write is left alone.** Where the field
1572+
holds a closed value that no request of this approval on this record had as
1573+
its status, another writer put it there, and the mirror writes nothing. A
1574+
request of the same approval on another record, another item of a `map`, does
1575+
not count.
1576+
2. **Otherwise `recalled`**, where the field declares it, or declares no options,
1577+
and the object does not close on it.
1578+
3. **Otherwise the first usable value in this order:** the value the field held
1579+
at submit, the field's declared default, empty. A closed value is passed over
1580+
at each step, and so is a value the field does not declare. On a required
1581+
field an empty value at submit is passed over for the default.
1582+
1583+
So listing `recalled` among the field's closed values closes nothing through the
1584+
mirror: a withdrawn approval leaves the record open. A record that was closed
1585+
when it was submitted, and that the approval opened, is left open on the value a
1586+
never-submitted record carries, its default or empty. To close a withdrawn
1587+
document, use an action or a flow of the app's own. To show a withdrawn approval
1588+
on the record, declare `recalled` among the field's options and do not close on
1589+
it.
1590+
1591+
Where the platform cannot tell whether the approval wrote the closed value the
1592+
field holds, because the abandoned request, or one opened on the record since the
1593+
approval's run started, does not record the run it belongs to, it goes down the
1594+
order. The server log says when the mirror withholds a declared `recalled` (a
1595+
warning) and when it passes over a closed value or leaves one alone. On a
1596+
required field that is not `readonly`, with no default the mirror can use, the
1597+
write of empty is refused: the field keeps the value it holds, and the refusal is
1598+
logged, and reported as above where the object closes on the field at `approved`
1599+
or `rejected`.
1600+
14131601
## Why
14141602

14151603
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
14271615

14281616
## See also
14291617

1430-
- Decision records: **ADR-0049** (`runAs`), **ADR-0066** (unified authorization).
1618+
- Decision records: **ADR-0049** (`runAs`), **ADR-0066** (unified authorization), **ADR-0044** (send-back and resubmission), **ADR-0162** (closed states and the approvals on them).
14311619
- Guide: [Hooks](/docs/automation/hooks) and [Flows](/docs/automation/flows); [Who can see data / automation / interface](/docs/permissions/access-recipes).
14321620
- Reference: [Flow](/docs/references/automation/flow), [Approval](/docs/references/automation/approval).

0 commit comments

Comments
 (0)