Skip to content
Draft
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
22 changes: 22 additions & 0 deletions .changeset/37767-reconciler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@objectstack/plugin-approvals': patch
---

feat(approvals): the reconciler, and the door reads every run of an approval (ADR-0162 Execution item 8)

Clause-②: yes (widening)
Metadata-protocol: none

Widened: `ApprovalService` gains `reconcileMarkedApprovals(options?)`, which the plugin runs on the sweep clock beside the escalation, dead-run and stranded-request sweeps; the `getRun` member of the automation surface the plugin declares types the step log's `childRunIds`.

Only for an approval the check stamped when it opened (one with a step that can act on an object that declares `closedStates`):

- **The door reads every run of the approval.** Where it read the run that carries the record and the latest request's own run, it now walks the tree from the run that carries the record, following the child runs each delegating step records: every `subflow` child, and a `map` item run where it is the run of one of the approval's own requests. One run decides for the whole approval: one that cannot be read or that another process is advancing makes it cannot tell; one parked at a node a step can follow, in progress; one that ended between two steps, abandoned. So a sibling child whose failure the flow routed, a middle run two levels down that failed, and a run between two others that is being advanced are no longer read as finished. A tree of more than 200 runs is cannot tell.
- **The reconciler.** It scans the marked requests (`unjudged_since`), oldest first, at most 200 a pass, and judges each approval among them once, as the door would have: it writes the outcome in the name of the request's recorded decider, abandons the approval, or, where nothing was held back, clears the mark and writes nothing. It ends what no door saw: a run that was cancelled, a parent run cancelled while its child's request was pending, a process that died after a decision. Once every mark of an approval has stood for an hour (the age bound), it also reads as stopped where it stood a run that reports paused while its pause is gone, and a run parked at a `subflow` or a `map` whose child run has ended.
- **A refused write is tried again.** A refused outcome or put-back leaves the marks, and the next pass tries it again. The timeline line and the administrators' notice (keyed per request and status) are left once for one refusal; the same holds for the line an abandoned approval leaves.
- **A deleted record.** Where the approval's record was deleted, the reconciler clears the marks of its requests and writes nothing: no retry and no notice.
- **The stranded-request report** (`inspectStrandedRequests`) leaves a request the check stamped to the reconciler.

- **A refusing end is an end.** The door reads a run that reached an end of the flow as having ended there, a refusing end (`outcome: 'refused'`) included, as it already did for a completed run.

Unchanged: an object that declares no `closedStates`; an approval that opened before its object declared the key.
15 changes: 15 additions & 0 deletions .changeset/37767-step-child-runs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/service-automation': patch
---

feat(automation): a delegating step records the child runs it started (ADR-0162 Execution item 8)

Clause-②: yes (widening)
Metadata-protocol: none

Widened: `AutomationEngine` gains the public read `runStartedFor(context)`, and a node executor's result (`NodeExecutionResult`) the optional `childRunIds`, which the engine copies onto the step's log entry (`ExecutionStepLogSchema.childRunIds`, in `@objectstack/spec`).

- **`childRunIds` on a step.** A `subflow` step names the one run it started, on every exit: paused on its child, completed, failed or refused. A `map` step names the item runs that execution of the step started. Absent on a step that started none. `getRun` serves it with the rest of the step log, so a reader can walk a run's tree from its root; before this, a parent's link to its child lived only on the parent's pause (`correlation: 'subflow:<id>'`), and only while the parent was parked.
- **`runStartedFor(context)`.** A run that ends inside `execute` answers no `runId` (the contract sets it on a paused run only). The engine now answers the id of the run the last `execute` call started for that very context object, whatever it ended in; `undefined` where no run started. Under `errorHandling.strategy: 'retry'` it is the last attempt's run. The `subflow` and `map` nodes read it for a child that ended inside the call.

Unchanged: what a run does, the `runId` the contract returns, and every existing step field.
10 changes: 10 additions & 0 deletions .changeset/37767-step-log-child-runs-spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/spec': minor
---

feat(spec): a run's step log names the child runs a step started (`ExecutionStepLogSchema.childRunIds`, ADR-0162 Execution item 8)

Clause-②: yes (widening)
Metadata-protocol: added

Widened: `ExecutionStepLogSchema` gains the optional `childRunIds: string[]`: the run ids of the child runs the step started, the one run of a `subflow` and, for a `map`, the item runs that execution of the step started. Absent for a step that started none. The engine writes it (`@objectstack/service-automation`); a reader of `getRun` can walk a run's tree from its root with it. Nothing an author writes in a flow changes.
56 changes: 52 additions & 4 deletions content/docs/automation/approvals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,8 @@ not swallowed:
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.
The sweeps are what release a record held by a dead run, and what judge an
approval that no action judged, below.

### An approval that does not mirror onto the closing field

Expand Down Expand Up @@ -1564,9 +1565,14 @@ or the host, and the submitter then submits again.
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:
record held by a dead run. Each records `recalled` on the request. The platform
also abandons an approval whose run ended between two steps, below, at the
action that found it or in the reconciler: the requests keep the decisions
already made, a line with no actor on the latest request's timeline says that
the approval did not go on, why, and what the record was put back to, and the
submitter is told, and submits again. 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
Expand Down Expand Up @@ -1598,6 +1604,48 @@ write of empty is refused: the field keeps the value it holds, and the refusal i
logged, and reported as above where the object closes on the field at `approved`
or `rejected`.

### When the outcome lands on the record

Where the object closes on a step's mirror field at `approved` or `rejected`,
the step's decision is held back: the request records it, and the field keeps
`pending` until the approval is over for the record. Every other status is
written as before: `pending` as a request opens, `returned` at a send-back, and
what an abandoned request leaves.

After each action that moves a run of the approval on (a decision, by a person
or by the escalation clock, a send-back, a resubmission, a recall, and the
continuation of a restored run), the platform reads the approval's requests on
the record and every run of the approval: the run that carries the record and,
through the steps that started them, every `subflow` child under it, and every
`map` item run that holds a request of the approval. It answers one of:

- **In progress.** A request is pending or returned on the record, or a run is
parked at a node between two steps. Nothing is written.
- **Ended between two steps.** A run stopped on a node a step could still follow
(it failed or was cancelled there), a failure the flow routed at the top level
of a run ended it, or a later step could not open. The approval is abandoned,
above.
- **Cannot tell.** A run is being advanced by another process, or a run or the
requests cannot be read. Nothing is written.
- **Finished**, otherwise: every run reached an end of the flow, a refusing end
included, stopped after the last step, or is parked at a pause no step can
follow. The latest request's decision is written, in the name of the person
who decided it.

Every decision on an approval any step of which can act on an object that
declares `closedStates` leaves a mark on its request (`unjudged_since`), also
where nothing is held back. The mark is cleared once the approval is judged, or
when its next request opens. The plugin's sweeps run a reconciler that judges
every approval whose mark still stands, oldest first, as the action would have:
after a process that died, a run that was cancelled, or a parent run cancelled
while its child's request was pending. Once the mark has stood for an hour, it
also reads as stopped where it stood a run that reports paused while its pause
is gone, and a run parked at a `subflow` or a `map` whose child run has ended.
Where nothing was held back it clears the mark and writes nothing. A write that
a rule or a hook refuses is reported as above, once, and tried again on each
sweep while the mark stands. Where the record was deleted, the reconciler clears
the mark and writes nothing.

## 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.
Expand Down
2 changes: 2 additions & 0 deletions content/docs/references/automation/execution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const result = CheckpointSchema.parse(data);
| **skippedBy** | `{ nodeId: string; edgeId?: string; label?: string }` | optional | The gate that closed, when `status` is `skipped` |
| **warnings** | `string[]` | optional | Advisory warnings from the node executor. A `success` step may carry them — e.g. a write whose requested fields the data engine legally stripped — so a step that partially did not land never reads as a clean success. Absent when the executor raised none |
| **droppedFields** | `{ object: string; fields: string[]; reason: Enum<'readonly' \| 'readonly_when' \| 'primary_key' \| 'computed' \| 'stored_expression'> }[]` | optional | The data engine's own drop events behind those warnings: which caller-supplied fields of which object the write did not store, and why. Absent when the step dropped nothing |
| **childRunIds** | `string[]` | optional | Run ids of the child runs this step started: the one run of a `subflow`, and for a `map` the item runs this execution of the step started. Absent for a step that started none |

### Nested Shape: `ExecutionLog.summary`

Expand Down Expand Up @@ -210,6 +211,7 @@ const result = CheckpointSchema.parse(data);
| **skippedBy** | `{ nodeId: string; edgeId?: string; label?: string }` | optional | The gate that closed, when `status` is `skipped` |
| **warnings** | `string[]` | optional | Advisory warnings from the node executor. A `success` step may carry them — e.g. a write whose requested fields the data engine legally stripped — so a step that partially did not land never reads as a clean success. Absent when the executor raised none |
| **droppedFields** | `{ object: string; fields: string[]; reason: Enum<'readonly' \| 'readonly_when' \| 'primary_key' \| 'computed' \| 'stored_expression'> }[]` | optional | The data engine's own drop events behind those warnings: which caller-supplied fields of which object the write did not store, and why. Absent when the step dropped nothing |
| **childRunIds** | `string[]` | optional | Run ids of the child runs this step started: the one run of a `subflow`, and for a `map` the item runs this execution of the step started. Absent for a step that started none |

### Nested Shape: `ExecutionStepLog.error`

Expand Down
Loading
Loading