feat(statestore): step_executions, StartStep/FinishStep under the run credential

Plan item 3 of docs/prds/execution-tree-state-machine.md (archie-core-1220), on
top of the transition tables and ErrIllegalTransition enforcement (1214/1215,
archie-core-qdbo.5):

- Migration 0017 adds step_executions -- id, org_id, workspace_id, execution_id,
  attempt, parent_id, depth, kind, name, called_execution_id, status, detail,
  tokens_used, started_at, finished_at, indexed on (execution_id, attempt, id).
  Ownership fields are stamped from the execution's row; depth is derived from
  the parent, never supplied by a caller. Existing rows gain no backfilled
  steps.
- task.Store (the workflow engine's mid-run facade) gains StartStep/FinishStep
  (5 methods, within the 8 cap), with storecontract.StepRecorder fronting them
  on the server; deadlineStore wraps both with its per-call timeout.
- The store enforces each write as one transaction: the guarded row write
  under the shared step transition table plus the transition's own
  stage_start/stage_finish event row. Staleness is decided before legality,
  the way guardTransition decides it, and the store returns the persisted
  event for the caller's post-commit publish -- the EmitDurable convention
  (the daemon's event sink skips already-persisted rows by assigned ID), which
  is why workflow.Run stops emitting stage events beside the store and no
  longer discards step-write errors: a failed start or finish parks the
  execution, and the stage does not run unrecorded. An interrupted stage
  records interrupted rather than failed; a recording failure on that
  shutdown path is logged and left to RecoverStale, which owns the
  interrupted-execution sweep in plan item 6.
- The run credential of docs/prds/orgs-and-access.md authorises StartStep and
  FinishStep on its own execution only: both requests carry the execution ID
  the grant check verifies (FinishStep carries it because the interceptor
  never reads the database), and FinishStep verifies handler-side that the
  step really is that execution's. authorizesTaskScopedCall's sanctioned
  widenings are now held as a lookup table so the next one stops growing a
  switch.
- The PRD's wire contract is StartStep(execution, attempt, parent, kind, name)
  -> step id; the responses also carry the persisted event (needed for the
  post-commit publish) and FinishStep's request carries execution_id (needed
  for the grant check) -- both noted here as deliberate additions to the PRD's
  shorthand. called_execution_id exists in the table but not yet on the wire:
  its named consumer is the workflow-call recording of plan item 4 (#1216).

Conformance drives both adapters; grant tests pin the own-execution scoping;
the wire sentinel set gains ErrInvalidStep (InvalidArgument, "step execution
invalid") for a step kind no consumer names.
This commit is contained in:
sam committed 2026-09-27 05:42:32 +10:00
1 parent c07c04e45a
commit 3f0071e27b
29 files changed
+2637 -937

No files matched your search

+14 -7
View File
@@ -266,13 +266,14 @@ _view_, not new RPCs — `Update`/`Transition`/`InsertEvent` are shared with
| Dispatch | `ArmedBindingsForSource`, `RecordDispatch`, `ListUndispatchedCaptures` |
| Playbook | `RecordPlaybookDispatch`, `DeletePlaybookDispatches` |
| WorkflowCaller | `EnqueueCallTask`, `WorkflowCallStatus` |
| Step executions | `StartStep`, `FinishStep` |
| BindingTaskCreator | `EnqueueBindingTask` |
| Config snapshot | `PutConfigSnapshot`, `GetConfigSnapshot` |
| Apply status | `PutApplyStatus`, `ListApplyStatus` |
| Channel status | `PutChannelStatus`, `ListChannelStatus` |
| Task log | `ReadTaskLog`, `StreamTaskLogContent` |
That is **53 unique contract RPCs** across one service (the `TaskEvents.Close` method is dropped).
That is **55 unique contract RPCs** across one service (the `TaskEvents.Close` method is dropped).
`Close()` is **excluded** from the wire (it is server lifecycle, not a client call) — see §11.
The channel-status pair follows the config snapshot's split for the same reason: the writer is the process that HOSTS the channels -- the Messaging Service, which alone observes whether a channel is starting, running or failed -- and the reader is the UI process. Both RPCs are administrative, so a task-scoped grant reaches neither. A channel's state is runtime state rather than a settings document, which is why it is not a `ControlPlaneService` resource kind: a failed channel is not a document anybody edits. Asking for a reload travels on its own surface rather than through this one; see `docs/architecture/migration-decisions.md`, "Channel state to the dashboard".
@@ -307,12 +308,18 @@ condition, and the panel that collapsed them told operators task logging was swi
it was not. The Go facade is `storecontract.TaskLogStore` (2 methods), carried by
`*staterpc.Client` alongside the rest.
The workflow-caller pair was added by `archie-core-t2db.41` (see
`docs/prds/workflow-calls.md`). It is the one surface a task-scoped grant
reaches beyond the three task.Store RPCs: a `workflow.call` step must start
its callee and, with `wait: true`, read it back, and the callee is the
caller's child. Both requests carry the caller's task ID, which the grant
check verifies; `EnqueueCallTask` derives everything else from the caller's
The step-execution pair was added by the execution tree's plan item 3 (see
`docs/prds/execution-tree-state-machine.md`), the surface a task-scoped grant reaches for
its own execution beyond the three `task.Store` RPCs and the workflow-caller pair: the
container records its stages and its own agent calls with the run credential. Both requests
carry the caller's execution ID, which the grant check verifies; `FinishStep` additionally
verifies, handler-side, that the step really is that execution's. The store writes each
transition's `stage_start`/`stage_finish` event row in the same transaction and returns it
for the caller's post-commit bus publish. `called_execution_id` is stored for the `call`
kind but not yet carried on the wire: the named consumer is the workflow-call recording
that will set it.
The workflow-caller pair was added by `archie-core-t2db.41` (see everything else from the caller's
row and refuses a caller that is not running or a call past the depth limit
(`ErrCallCallerNotRunning` / `ErrCallDepthExceeded`), and `WorkflowCallStatus`
re-checks the parent-child relation against the row before answering