Skip to content

feat(recipe): a recipe run is a durable record; an invocation whose outcome is unknown is never repeated (PR-A) - #5008

Merged
joelteply merged 5 commits into
canaryfrom
durable-recipe-run
Oct 13, 2026
Merged

joelteply merged 5 commits into
canaryfrom
durable-recipe-run

Conversation

@joelteply

@joelteply joelteply commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

PR-A of three. It implements Astra's durable-recipe contract and her review of this PR (6140170884: per-run ownership, merged pending saves, unrecorded commit means RecoveryRequired, fail closed with no store) (powwow review, relayed by Codex root in #cambriantech, e=2db93dd3) and Codex root's outcome rule (e=35d992dc): only refusals before dispatch are NotCommitted, and every handler error is Uncertain. It is the precondition for moving academy and training workflows onto recipe::PipelineExecutor.

What a run is now

One RecipeRunRecord per run, in the node's recipe_runs ORM collection (recipe/run_record.rs). The record is the truth about the run; the room's wall bundle is a projection of it. It holds:

  • an immutable snapshot of the steps;
  • args, seed, the room, and the origin (recipe id and version);
  • caller provenance: peer and source only. It never rebuilds a CallerIdentity, because granted capabilities are never stored;
  • phase, cursor, bindings, and frozen each arrays;
  • every invocation, with a stable id (v5 of run, step and item), its resolved params and its state.

The safety rule

  • Write-ahead: an invocation is written as Dispatching before it is sent. Its result, its binding and the cursor past it commit in one row write.
  • Classification: CommandExecutor::execute_classified (runtime/command_executor.rs) classifies a failure where it happens, never by parsing the message.
    • NotCommitted: the AuthPolicy gate refused it (Forbidden or Deferred), or there was no route.
    • Uncertain: any handler, interceptor or transport error, whatever its CommandError category, and every timeout.
  • Retries and skips: retry_count and on_error: skip apply to NotCommitted only. An Uncertain invocation stops the run in RecoveryRequired, naming it.
  • Callers: execute_with_caller keeps its signature and messages; it wraps the new call.
  • Shipped recipes are unaffected. Every step in benchmark-round.json and coursework-round.json is on_error: fail with no retries and no timeout.

Boot, cancel, verbs

  • Boot: the new RecipeModule (modules/recipe.rs, registered after DataModule) owns the store and the verbs. At startup it exposes every run the last process left Running:

    • a run with an invocation in flight becomes RecoveryRequired, because its outcome is unknown;
    • a run stopped between invocations becomes Interrupted.

    Nothing is re-dispatched; continuing an interrupted run is PR-B.

  • Cancel: recipe/cancel writes only cancelRequested. The owner writes every field except that one, so neither can overwrite the other. A running run stops at its next step or item boundary, and a dispatch already sent is never undone. A held or interrupted run is cancelled at once. A RecoveryRequired run stays there, with the cancel recorded.

  • Verbs: recipe/run, recipe/status, recipe/list and recipe/cancel share one {runId, phase, …receipt} envelope. All are Privileged. recipe/run moved from the work module to the recipe module.

  • Activity birth:

    • records its recipe and room on the run;
    • returns runId and phase;
    • archives the room only for a Failed run, never for a held or recoverable one.
  • Executor: PipelineExecutor::new finds the store through the executor's registry (RecipeModule::runs_in), so every existing caller gets durable runs without carrying a new handle. A registry with no recipe module probes recipe.run.unrecorded.

Shared fixture

  • runtime::module_harness::CannedModule is now the canned ServiceModule (task Add genome visualization to root README with live video #155): answering(result) or scripted(closure), and it counts the dispatches it receives.
  • command_executor's private copy is deleted, and its five tests use the shared one.
  • OrmStore::find_matching(query) is new; find_all now delegates to it.

Coverage

recipe::executor::tests::durable: six tests, each against a real SQLite recipe_runs store (orm::store::fresh_adapter) through the real dispatch chain:

  • the invocation is Dispatching on the row while its handler runs, then is committed together with its binding and the cursor past it;
  • a handler error is dispatched ONCE despite retry_count: 2 and on_error: skip; the run is RecoveryRequired naming it, and the next step never runs;
  • a timeout is Uncertain and never retried;
  • a gate refusal is retried as declared (3 gate calls, 0 handler calls), then fails the run;
  • boot exposure: mid-dispatch becomes RecoveryRequired, between invocations becomes Interrupted, and held stays held;
  • cancel stops an each at the next item (1 dispatch of 3), survives on the row, and leaves a RecoveryRequired run waiting.

#5007's caller test (recipe_run_presents_its_caller_at_every_steps_gate) is kept unchanged.

Measured

  • CI at 347459d (2026-10-13): all checks green. That includes cargo test -p continuum-core --lib (8844 passed, 0 failed, 139 s) and the ts-rs drift detector, which accepted the hand-written bindings.
  • Every new test ran and passed:
    • 10 in recipe::executor::tests::durable: write-ahead, handler error, timeout, gate retry, boot exposure, cancel, refused projection, unrecorded commit, no store;
    • 2 in commands::recipe_run::tests: caller propagation and two-persona ownership;
    • orm::derive_test::round_trip_through_orm_store with the new review_approved field.
  • Local guarded cargo check -p continuum-core --lib --tests (-j2): clean on every push, about 10 min each.
  • CI found a shared ORM defect, fixed here. sqlite looked declared column types up by the snake column name while they are keyed by camelCase field name. Every multi-word column lost its declared type: a bool read back as 0, and JSON or String columns fell back to shape-sniffing. My first regression used a one-word name, which passes either way; it now uses review_approved.

Not in this PR (PR-B / PR-C)

  • PR-B: continuing an Interrupted run; settling RecoveryRequired by reconcile or recipe/resolve; approval resume, where the approver authorises once and the step runs as the original caller, revalidated.
  • PR-C: projecting run status into the room's ViewState, and retrying pendingSaves at boot.
  • Run retention: card 089f21ad, owner me. This PR deletes no rows. Retention must keep active, held, recovery and unresolved runs, and any run still referenced.
  • The node is implicit: recipe_runs lives in the node's own database, so the record has no explicit node field.
  • recipe/run is still synchronous: it returns when the run ends or stops. An async start that returns the runId first comes with PR-B's resume.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

…utcome is unknown is never repeated

Astra's durable-recipe contract (powwow review, relayed by Codex root e=2db93dd3)
and the outcome rule (Codex root e=35d992dc), PR-A of three.

- recipe::run_record: one RecipeRunRecord per run in the node's `recipe_runs`.
  It holds an immutable snapshot of the steps, args, seed, caller provenance
  (never a restorable CallerIdentity), room, phase, cursor, bindings, frozen
  `each` arrays and invocations with stable ids (v5 of run, step, item).
- The executor writes each invocation as Dispatching BEFORE it is sent. Its
  result, its binding and the cursor past it commit in one row write.
  CommandExecutor::execute_classified says where a failure happened:
  NotCommitted (gate refusal, no route) or Uncertain (any handler, interceptor
  or transport failure, and every timeout). retry_count and on_error: skip apply
  to NotCommitted only. An Uncertain invocation stops the run in
  RecoveryRequired naming it.
- recipe/cancel records a durable flag that the owner's writes never clear. The
  run stops at its next step or item boundary. A run in RecoveryRequired keeps
  waiting, with the cancel recorded.
- Boot: RecipeModule (new; owns the store and the recipe/* verbs) exposes every
  run the last process left Running. One with an in-flight invocation becomes
  RecoveryRequired; one stopped between invocations becomes Interrupted.
  Nothing is re-dispatched.
- recipe/run, recipe/status, recipe/list and recipe/cancel share one
  {runId, phase, receipt} envelope. Activity birth records its room on the run,
  returns runId and phase, and archives the room only for a FAILED run, never
  for a held or recoverable one.
- runtime::module_harness::CannedModule is the one canned ServiceModule (task
  #155), scriptable and counting dispatches. command_executor's tests move onto
  it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
@joelteply

Copy link
Copy Markdown
Contributor Author

Astra review of draft5008 exact0c15de208c98ee0dd3a8232a02de764784288dc2: request changes. Journal/immutable steps/frozen items/conservative dispatch outcome direction is sound. Four gaps:

  1. recipe/status/list/cancel ignore Ctx. Privileged is not per-run ownership. Scope to originating caller or explicitly authorized operator; prevent private binding disclosure and cross-persona cancellation.
  2. complete_step overwrites pending_saves with each new patch, even None. A failed wall projection disappears on next step. Merge pending key updates or retain ordered projection intents; deferred retries must retain their input.
  3. Handler commit followed by result-row storage failure returns Err; activity birth archives the room while durable invocation remains Dispatching/unknown. Preserve run ID and room on persistence uncertainty; archive only confirmed Failed.
  4. PipelineExecutor::new turns absent or uninitialized recipe store into None, and persist silently succeeds. Fail closed before production side effects without journal storage; any nondurable fixture must be explicit.
    Acceptance: two callers under production authorization; failed projection followed by another step; committed handler followed by failed ledger write. Linux lib and binding-drift checks failed at inspection, not diagnosed by this review.
    Relayed by Codex root from user-requested Astra review.

joelteply and others added 3 commits October 13, 2026 02:18
…no store never starts; an unrecorded commit waits for recovery

Astra's review of #5008 (6140170884), all four gaps:

1. recipe/status, list and cancel check the run itself (may_access): its own
   caller, the substrate's own code, or the node's operator and agent identities.
   Anyone else is told it does not exist. AccessLevel::Privileged is not enforced
   by the gate (sdk_codegen::AccessLevel), so the module doc no longer implies it.
2. complete_step MERGES a step's saves patch into the still-unsaved one instead
   of replacing it, so a refused projection is retried with its input.
3. A record write refused after an invocation was sent leaves the run
   RecoveryRequired naming that invocation and returns Ok, so an activity keeps
   its room and run id. Only a run that dispatched nothing can fail on a write.
4. No recipe module, or an unopened store, refuses the run before any dispatch
   (Journal::Missing). A walk with no record is PipelineExecutor::unrecorded,
   behind test-fixtures. recipe/run passes its own store explicitly.

Tests: two personas (one cannot read or cancel the other's run); a refused
projection carried into the next save; a committed handler whose result write
fails; a run with no store refused with zero dispatches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
…ot its name; a run with no args stores none

CI's first run of #5008's tests (all failed against the real recipe_runs store)
found two defects:

- orm/sqlite.rs read an INTEGER column back as bool only when its NAME matched
  is_/has_/_active/_enabled/_visible/_deleted. The TEXT branch beside it already
  decodes by the declared FieldType. A `bool` named cancel_requested came back as
  0, and the entity refused the row. Integers now decode by the declared type
  too; the name sniff stays only for undeclared collections. The existing
  derive_test round-trip gains `approved: bool`, a name no sniff knows.
- RecipeRunRecord.args was a non-null JSON column, and Value::Null stores as SQL
  NULL. It is Option<Value> now: None means the run was given no args.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
1f49e5a appended the unwrap_or note between the call and the `;`, so the
line comment swallowed the terminator (CI: expected `;`, found `for`,
executor.rs:216). Checked locally this time: cargo check lib+tests clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
… camelCase name

ensure_schema keys declared types by the entity's field names (camelCase);
row_to_record looked them up by the snake_case column name. Every multi-word
column missed its declared type: cancel_requested read back as 0, and any
multi-word JSON or String column fell back to the shape sniff the declared types
exist to replace. Both the INTEGER and TEXT branches now look up the camel name.
The round-trip test field is review_approved: my first regression used
'approved', a name that is spelled the same both ways, so it passed either way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
@joelteply
joelteply marked this pull request as ready for review October 13, 2026 09:29
@joelteply
joelteply merged commit 68e5a91 into canary Oct 13, 2026
6 checks passed
@joelteply
joelteply deleted the durable-recipe-run branch October 13, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant