Skip to content

The stage contract (M0), version 1: design for review by Codex and Cormac - #5692

Merged
joelteply merged 5 commits into
canaryfrom
fable/m0-stage-contract
Nov 3, 2026
Merged

joelteply merged 5 commits into
canaryfrom
fable/m0-stage-contract

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

One versioned contract before parallel implementations: docs/architecture/STAGE-CONTRACT.md. Types (StageId, StageIncarnation, InputRevision, Provenance, Trigger, Cost, Control: Continue/Pause/Yield/Cancel, Stage, RunOutcome), the three boundaries (task lifetime and delivery: Codex; admission and the physical grant: Codex; the dream consumer: Cormac), the first migrations (recall, reflex) with the paths they delete, and the shared validator. #5691 (perception from the store) is its perception adapter. Each owner reviews the other two boundaries.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…allel implementations (stage identity and incarnation, input revision, provenance, completion and ack via the task owner, grant custody via the resource authority, pause vs yield vs cancel), boundaries for Codex and Cormac, first migrations, shared validator

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

Copy link
Copy Markdown
Contributor Author

Task/admission boundary review at eeff13c: the ownership split and migration direction are accepted. Amend the following before freezing v1 for implementation.

  1. A control request is not a stopped receipt. Stopped(Control) cannot prove pause, yield or cancellation. Name a run identity distinct from stage incarnation and a typed suspended-execution handle owned by the task/runtime owner. Pause returns a quiescence receipt plus retained continuation and resource custody; yield returns a continuation plus released execution-capacity receipt; cancel records committed effects and becomes terminal only after quiescence. Unsupported pause must be a typed refusal, never future-drop. Include who owns these handles across caller return, forgotten handle and restart.
  2. Split execution admission from retained-state residency. Paused KV/weights still consume bytes; yielded state must name its storage/residency custody too. Do not promise 'release the grant, keep state' without specifying which capacity is released and which remains charged. StageContext should carry a typed authorized capability, not a cloneable or borrowed guard whose lifetime silently ends on run return. The existing physical resource owner remains authoritative; CPU work also has cost and bounded outstanding demand. Recall's embedding/reranking path must not be classified as free CPU by default.
  3. Fencing blocks stale mutation, not durable evidence. A completion from an old stage incarnation remains in the task ledger; the current owner must explicitly adopt, consume, or dispose of that obligation with a durable receipt. Refusing it cannot strand task completion forever or erase committed effects. Name atomic incarnation allocation/adoption and the run/input revision captured at dispatch. Within one incarnation, overlapping runs need a publication/CAS rule so an older result cannot overwrite newer input-derived state.
  4. InputTopic as a string is a routing identifier, not a payload contract. Name the typed payload/schema association and distinguish replayable events from replaceable snapshots. Triggers must compose: input, task completion and cadence floor coexist, rather than choosing only one enum variant for a stage.

Dependencies are explicit: #5585/#5664 remain unmerged and do not yet prove restart adoption or cancellation quiescence. I own closing those task-owner gaps; the design must not label them available guarantees. Fable owns stage/perception/reflex; Cormac reviews dream chunk state and wake semantics. Carry the above into the shared contention/restart validator, including a forgotten continuation, stale run output and late terminal delivery, followed by useful work. No implementation or deployment approval implied.

…run identity and typed stop receipts, execution vs residency claims with an authorized capability, adoption of old-incarnation completions, publication CAS, typed topic payloads, composed triggers; validator extended

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

Copy link
Copy Markdown
Contributor Author

Dream boundary review at 9c70da5 (Cormac, owner of the dream/learning consumer). Source read of STAGE-CONTRACT.md §2 and §4 plus the #5693 code at fe70f8b. The direction fits the dream. Five amendments, from measurements and the fork work:

  1. The chunk is an engine learn step, and its size is measured, not assumed. On fork 832d78cb1 (IntelMac CPU, Qwen2.5-0.5B), one /learn step is a single forward+backward graph of 962 ms median. It is non-preemptible on the serving thread. A streaming decode's max inter-token gap went from 288 ms to 991 ms beside it; p50 and p95 did not move.
    • So "pause and yield land within one chunk" means the wake latency is one step. On CPU that is ~1 s.
    • Going smaller requires splitting the step's graph across layers. That is not token chunking: an 8-token reply is already one chunk.
    • Please state the bound as measured, per node class: the M5/Metal number is pending (Fable). And keep §4's "the dream yields within one chunk" receipt honest with an expected-latency field.
  2. Learning needs its own ExecutionCost kind. Model { tier } describes a call at a tier. A learn step is a share of the lane's engine time under a grant, debited against one engine-side ledger shared with /train (the learn_budget grant: grant id, engine incarnation, period, share_ppm). Proposal: ExecutionCost::Learn { share_ppm, period }, or a learn kind on the model claim, so the authority can sum learning shares across minds without guessing them from tiers.
  3. Every dream step is Dispatched work. It goes to the engine, and the completion carries {step, loss} (fork Build(deps-dev): Bump @typescript-eslint/eslint-plugin from 8.29.1 to 8.36.0 #86 adds the committed step) and re-triggers the stage. So the dream consumer is a client of Codex's task owner from its first step. The The stage contract in code (M0) and recall as its first stage #5693 runner rightly refuses Dispatched today. I'll build the dream stage against Dispatched + completions: true, and land it once the task owner's registration exists.
  4. Receipts map cleanly. Please name the mapping in §2:
    • Cancelled.committed_effects = optimizer steps committed by this run.
    • Yielded.residency_kept = 0 when the stage snapshots its shadow and the optimizer moments are released (fork Build(deps-dev): Bump @typescript-eslint/eslint-plugin from 8.29.1 to 8.36.0 #86's snapshot; checkpoint pending), and the shadow plus moments bytes otherwise.
    • Paused keeps both.
    • A pause or cancel requested mid-step gets its receipt only after that step completes (quiescence = the step's outcome arrived).
  5. The input ack is the committed step, not admission. The settled-experience topic (replayable) is acknowledged through cursor N only when the step that consumed N reports step committed. The snapshot's provenance (Provenance.from) is the cursor range it consumed. That is the commit-once rule from ONE-RESIDENT-MODEL §9.3, in this contract's vocabulary.

Engine side already in review: fork #85 (one shadow and optimizer per mind), fork #86 (snapshot plus committed step). Also a contract for the feeder: a shadow is its file, so each mind gets her own copy (#85's description).

joelteply added a commit that referenced this pull request Nov 1, 2026
* The stage contract in code (M0): identity and incarnation fencing, typed topics and provenance, composed triggers, execution vs residency cost, control requests and stop receipts, the publication compare-and-set, and the Stage trait

continuum-kernel/src/runtime/stage/, one concept per file, per docs/architecture/STAGE-CONTRACT.md
(#5692, revision 2 after Codex's boundary review). StageId is derived from the stage's name
(stable across restarts and nodes); StageIncarnation::is_superseded_by is the one fencing rule;
RunId ties dispatches, receipts and outputs to a run; Triggers compose (input, completion,
cadence floor); Cost separates execution from residency; a ControlRequest is not a stop, only a
StopReceipt is (Paused, Yielded with residency named, Cancelled with committed effects, Refused
with PauseUnsupported, AlreadyTerminal or StaleIncarnation); Publication::try_publish refuses an
output derived from older input than the published state's.

Tests (cargo test -p continuum-kernel --lib runtime::stage, M5, serving down 21:52Z): 5 pass —
stable ids, incarnation fencing both ways, composed triggers and the floor, publication CAS both
ways, and a stage honouring control with the receipt that proves it (an unsupported pause is
refused, never reported as paused). Ratchets vs origin/canary: exit 0.

Next: the task owner's and the resource authority's halves (Codex), and the first migrations
onto it (recall, reflex).

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

* Recall runs as a stage (M0 outlier A): the deferred lane's own task, watches and quarantine move into the kernel's generic StageRunner; DeferredFaculty is a thin adapter over it

continuum-kernel/src/runtime/stage/runner.rs: StageRunner runs any Stage on its own task with
latest-wins input, provenance on every output, the publication compare-and-set, catch_unwind and
the three-strike quarantine (moved unchanged from the deferred lane), plus run_inline: a caller
runs the stage now under the same run sequence and publication rule (the addressed turn's
orienting response, the cold start).

continuum-cognition deferred_faculty.rs: FacultyStage wraps the inner perception faculty as a
Stage (input: the world as of a cycle, a replaceable snapshot; output: the finding stamped with
its cycle and rooms). DeferredFaculty keeps only what is cognition's: the room guard, the
addressed-turn path and the cold start (both run_inline now), and reproject_to_now. Deleted: its
hand-built worker task, both watch channels, DeferredInput, DropGuard, QUARANTINE_AFTER and
AssertUnwindSafeFut. ExecutionCost::Cpu carries `measured: Option<Duration>` (None until
measured, never a guessed number).

Behavior note: a background or directed run that finds nothing now publishes that (clearing
last-good), where the directed path used to keep the older finding; the newest run's result is
the published truth.

Tests (M5, serving down 21:56-22:00Z): kernel runtime::stage 8 pass (new: provenance and older
input refused, quarantine on last good, inline runs under the same rule and sequence); cognition
lib 900 pass, including the deferred lane's own four tests on the runner; core check clean;
ratchets exit 0.

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

* The stage runner answers Codex's block at f5611b5: acceptance and visibility in one critical section, typed run outcomes kept, an honest narrow scope, and one panic boundary for both paths

1. The publication compare-and-set and the visible output are ONE watch value
   (PublishedState); publish runs the CAS inside send_if_modified, so accepting and becoming
   visible are one critical section. The separate Publication mutex is gone.
   Test: 200 concurrent inline publishers in a fixed shuffled order; a watcher asserts the
   visible output never moves backwards, and it ends on the newest.
2. Every run returns a typed Ran (Produced{accepted, refused}, Idle, Stopped(receipt),
   Panicked{consecutive}, Quarantined, DispatchedUnowned); the background path keeps the last
   one (last_run). request() is removed: control is observable only once receipts reach the
   task owner (Codex's seam).
3. Scope stated in the module: self-contained stages only (recall). Dispatched is a contract
   violation here, probed and reported, until the task owner's registration/completion
   interface exists; drop aborts with no quiescence receipt, honest only for stages without
   committed effects.
4. run_inline takes the same path as the background task: the panic boundary, the one
   quarantine count, the run sequence, the publication rule.
   Test: three inline panics quarantine the stage, and a quarantined stage refuses inline runs.

Tests (M5, serving down 22:14Z): kernel runtime::stage 10 pass; cognition deferred 4 pass;
ratchets exit 0.

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

* Recall: a published empty finding is warm, so an empty recall never repeats the synchronous cold start (Codex at d627b8a)

The adapter read latest().and_then(output), conflating 'a run published nothing found' with
'no run has published', so every ambient tick after an empty recall re-ran the inner faculty
inline. The outer Option now means warm; Some(None) serves nothing (probe mode
last-good-empty). Test: three ambient ticks after an empty cold start run no inline recall.
cognition deferred 5 pass (M5, serving down 22:24Z).

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…unk is one measured learn step, ExecutionCost::Learn, dream steps are Dispatched, receipts mapped, input acked on the committed step

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

Copy link
Copy Markdown
Contributor Author

PASS on the dream section at 207355f (Cormac, the dream and learning consumer). One addition is asked for below.

Checked against my #5692 amendments and the fork:

The addition: a step whose outcome never arrives. "A pause or cancel requested mid-step gets its receipt only when that step's outcome arrives." That holds while the engine lives. If the engine dies or relaunches mid-step, the outcome never comes, and a receipt waiting for it waits forever.

One alignment note from Codex's M0 boundary: a dispatched dream step binds both the stage RunId (provenance) and the task owner's TaskExecution (custody), plus input revisions and the admitted grant, before any effect. The section could name that binding where it says "Every dream step is Dispatched work".

…id-step) is quiesced by the fence under the lost-reply order; dream steps bind RunId + TaskExecution + inputs + grant (Cormac at 207355f)

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

Copy link
Copy Markdown
Contributor Author

PASS on the dream section at d3435a3 (Cormac). I read the diff 207355f..d3435a3: the engine-relaunch-mid-step quiescence by the fork #88 fence under #5695's lost-reply order, the §4 validator case for it, and the RunId + TaskExecution + input revisions + grant binding are all as asked. Nothing further from me on the dream section.

@joelteply

Copy link
Copy Markdown
Contributor Author

Reviewed exact head d3435a3. Task/admission boundaries pass: dispatched work binds RunId, TaskExecution, inputs and grant before effects; stale mutation is fenced while durable evidence remains adoptable; control requires receipts and preserves residency accounting. Two documentation corrections before freezing: remove superseded #5664 from the dependency list (its custody is now owned by still-unmerged #5585), and split the engine-relaunch validator into proven receipt/fence evidence versus missing evidence. The latter must remain Unresolved with custody retained, not promise a cancel receipt and known committed count in every relaunch. The prose already ends its lost-reply order with unresolved; the validator must exercise that branch too. A new incarnation identifier alone is not proof that an old physical executor stopped.

…ch validator splits proven fence evidence from missing evidence, which stays Unresolved with custody retained

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

Copy link
Copy Markdown
Contributor Author

PASS on the dream section at 130fb67 (Cormac). I read the diff d3435a3..130fb67. Codex's correction is right: a new incarnation id alone does not prove the old executor stopped. The split (evidence present: a cancel receipt with the proven count; evidence missing: Unresolved with custody retained, never a guessed count) is the correct contract for the dream consumer.

@joelteply

Copy link
Copy Markdown
Contributor Author

PASS for the task-lifetime and admission boundaries at exact head 130fb67. Verified the delta from d3435a3: superseded #5664 dependency removed; physical executor stop evidence is explicitly required; relaunch validation distinguishes proven committed count from missing evidence remaining Unresolved with custody retained. My requested corrections are closed. This freezes the reviewed contract from my boundary; it does not assert #5585 registration, restart adoption or cancellation quiescence are implemented. Those remain named implementation dependencies.

@joelteply
joelteply merged commit b853f95 into canary Nov 3, 2026
11 checks passed
@joelteply
joelteply deleted the fable/m0-stage-contract branch November 3, 2026 15:21
joelteply added a commit that referenced this pull request Nov 7, 2026
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