ADR-181 — Exact runs are born behind a compiled capability, and the v8 cut is the drain
- Status: Proposed — the operator arbitrated the Windows platform, the legacy lineage and the storage layout on 2026-12-01 (see Operator arbitrations); the record becomes Accepted when the operator accepts it.
- Date: 2026-12-01
- Deciders: jo (the arbitrations), Claude (the design, the measurements)
- Relates to: ADR-153 (its decision (a) files #2939–#2944; #3013 is their durable-values dependency) · the v8 pruning plan (#3533, §8.4 and §9; this record amends its decision L6-D9)
- Serves: #3013 · epic #3527 · couples with #3573 (migration runner, L6-01), #3574 (census, L6-02), #3866 (engine floor over the live fleet) and plan L8-03 (Windows CI)
Context
#3013 asks that exact structured values survive every durable and transport boundary without approximation: a json.Number("9007199254740993") read back from a run must not become 9007199254740992.
R54 slices 1–7 landed on main in #3507 (a47e4e988, v7.26.0). They brought the exact record codec, the format and protocol headers, and origin-bound stores and streams.
Activation was never part of that work, and no branch contains it. The storage layer is inactive at runtime (docs/agents/engine/run-value-formats.md, first paragraph). Four switches keep it off:
| Where | What it refuses |
|---|---|
pkg/store/run_invocation.go:120-129 | An Exact birth: "exact invocation birth is not connected". |
pkg/store/value_format.go:150-153 | A SaveRun that births Exact. This one stays, because a birth is an insert. |
pkg/store/run_data_storage.go:11-20 | Protocol 1 (IncarnationRunData), with ErrRunDataCapability. |
pkg/store/run.go:389 | It sets RunFormatVersion = 1. |
Every old writer must be upgraded and drained before the first format-2 birth (run-value-formats.md). The existing writer fence already sits before durable effects:
- FS:
RequireRunDataStoragethroughloadRunRawContext(pkg/store/store_run.go:290). - Mongo:
RequireRunDataStoragethroughdecodeRunFormatObservation(pkg/store/mongo/run_metadata_format.go:125).
Today, 28 test files in 8 packages skip their incarnation cases while admission is off.
On 2026-11-23 the operator decided that v8 waits for this activation. On 2026-12-01 the operator named its carrier.
How this design was reached:
- Two independent drafts, birth-first and barrier-first, were written and judged.
- A cross-family plan review (codex gpt-6-astra, 15 findings) attacked the result.
- Five verifiers re-checked every finding against the code.
The disposition is at the end.
Decision
D1 — A compiled capability with a versioned token, not a runtime switch
What the tag compiles in. Protocol 1 and Exact births are compiled in only under the build tag iterion_exact. Every v7.x production binary is built without it.
The token. The capability that the ledger, the census and the boot floor compare is a versioned token (exact-births/1), not the bare tag bit. A tagged binary from mid-series (for example a qualification-lane build) does not carry the token. Only P17 mints it. Such a build therefore can never satisfy a store where exact-births is applied.
The test grant. Before P17 the D9 lane still has to reach the Exact arm of BirthPolicyOf, the genesis row and the Applied row, or P3–P15a would be qualified against Legacy births only. P1 therefore ships one test-only seam, storetest.GrantExactBirths(t):
- it compiles only under
iterion_exact, so the release guards already keep it out of every artifact; - it refuses unless
testing.Testing()reports a test binary, so a taggediterionor server build never carries the token; - it scopes the grant to the test and revokes it in
t.Cleanup.
The Exact birth path therefore runs in process on every Exact PR. A built binary reaches it only from P17, which the rehearsals R1 and R2 cover.
Two release guards:
- A source
ciguardcovers every workflow that uploads or pushes a binary or an image:release.yml;image.ymland_build-image.ymlwith their Dockerfiles, includingENV GOFLAGSand the buildARGs;desktop-release.ymland the Taskfile build tasks it calls;scripts/build.sh.
- An artifact probe reads each built binary's
buildinfobefore upload, push or promotion, and fails if-tagscontainsiterion_exact. For darwin universal binaries, it probes each architecture slice beforelipo.
Why not reader-first. Opening protocol 1 in v7 production would have v7 binaries execute Exact runs before they carry the numeric contract and the transports (P9–P13). It would also defeat the capability-subset boot floor. The field-loss argument is minor: Mongo SaveRun keeps unknown fields (pkg/store/mongo/runs.go:491).
The cost of this choice is that production never executes Exact code before the v8 window. The rehearsals R1 and R2 on the promoted digests (plan A3) carry that risk.
D2 — One birth policy, read at the creation boundary
The policy is BirthPolicyOf(store) = token ∧ ledger state ∧ platform capability.
- Its zero value is Legacy.
- It is read inside the birth's lock or transaction, never cached at the constructor. That covers
store.New,store.Open,mongo.Newand handles that are already open. - Exact is born only as Exact × Incarnation. The pair format 2 × protocol 0 is never created.
Ledger state → birth behaviour:
| Ledger state | Before P17 | From P17 |
|---|---|---|
| Absent, store empty | Legacy | Genesis. The first writer creates the ledger with exact-births applied on a vacuous census. On FS this is an O_EXCL create under the store lock; on Mongo, a unique insert into schema_migrations. It is atomic with the first birth, so concurrent processes produce one ledger. |
| Absent, store has runs | Legacy | Typed refusal naming iterion migrate epoch --census/--apply |
| Censused or applying | Births refused (typed), reads allowed | Same |
| Applied | Built binaries: not reachable without the token. Tests under the D1 grant: Exact × Incarnation | Exact × Incarnation |
| Unreadable, or a state the binary does not know | Births refused | Births refused (same verdict as the boot floor) |
Platform capability. On FS this means atomic birth publication. Today that holds on Linux and macOS only (pkg/store/run_birth_fs_unsupported.go). The operator decided that Windows gets the capability before the flip (PW below), so v8 runs a single regime.
D3 — A birth is a phased insert of a frozen preimage
Birth runs in four phases. Each phase states the effects it is allowed to have.
Phase 0 — freeze.
- Copy the caller-supplied values: vars, overrides, contract, source, retry, routing and LLM policies.
- Validate them with the exact codec.
- This is the only refusal that may claim "before any effect".
Phase 1 — admission.
- This phase covers: credential resolution (which persists a sealed bundle,
pkg/server/cloudpublisher/publisher.go:1909), pool and door grants, cred-slot admission, andExecutionContextresolution. - Each effect keeps the compensation it already has:
- grants use
ReleaseGrantwhen the launch did not happen; - slots use
releaseCredSlotswhen nothing was persisted; - the sealed bundle is left to its TTL.
- grants use
- The admission outputs join the preimage: credential-derived stamps, pinned providers, and inputs injected at
publisher.go:4271and:4319.
Phase 2 — the single insert.
- The
RunLaunchPreimageis encoded once, here. - The store adds the fields it mints:
BirthID, epoch, timestamps,FormatVersion,DataProtocol. - Only the admission park (
SaveParkedLaunchRun) shares the insert. - A refusal runs Phase 1's compensations.
Phase 3 — post-birth.
- This phase covers attachment promotion, retry arming, the pickup claim, the pod's effective budget snapshot and the reconciliation of
ExecutionContext.Workspace. - Each is persisted by its existing granular writer, never by saving the preimage again.
- The engine's post-birth stamp compares only the immutable launch projection, and finds it equal: zero saves.
Field classification. A reflection test classifies every store.Run field, down to sub-fields where a field mixes phases:
ExecutionContext.Workspaceis execution; the rest ofExecutionContextis launch.Budgetis split the same way.
Replay invariant (Mongo LaunchPersistenceGuard). The guard's callbacks are replayable (pkg/store/launch_persistence.go:31). Therefore:
- identity and encoding are minted once, before the guard;
- the callback replays only database operations, on the same bytes;
- the caller adopts the receipt only after the guard returns nil.
The states that follow:
- After an abort: no row, and the caller's state is unchanged.
- After an uncertain commit: the launch is reported as not persisted, as today.
PrepareRunInvocation refuses a reserved sub-bot birth under a guard, because Publish consumes the reservation on entry (pkg/store/mongo/run_birth.go:85).
A completion never mints. A cloud submission completion (publisher.go:4188, :4679) updates the existing incarnation:
BirthID, format, protocol, epoch andCreatedAtstay;- the expected CAS version is a caller precondition, the one exception to "never the caller".
D4 — Children inherit the full binding, derived inside the port
A sub-bot, a pipeline child or a heartbeat child inherits the parent's format, protocol and BirthID link. Today the sub-bot path copies the format only (pkg/runview/subbot_invocation.go:24). The port derives the binding from the context; no caller sets Format or DataProtocol.
D5 — Creation is fenced at the store boundary, and the AST guard backs it
(a) Primary: the store. Every store-level birth consults BirthPolicyOf under the insert's lock or transaction. That covers:
- FS and Mongo
CreateRunWithValueFormat; - the create branch of
SaveRun; SaveParkedLaunchRun;runBirth.Publish.
From P17, the create branch of SaveRun refuses every birth.
(b) Secondary: the AST guard. It parses files of every build tag with go/parser, so goldens_record and iterion_exact files are seen. It denies:
CreateRun*,CreateRunWithValueFormat,AsRunValueFormatCreatorandSaveParkedLaunchRun;- literals of
NewLegacyRunInvocationandReservedRunInvocation; - method values of all of the above.
Each is denied outside a committed birth inventory (site → arm → policy). The guard checks the inventory both ways.
(c) Disposable stores. dryrun, botreplay and storetest follow the real store's policy.
(d) Imports are not births. migrate to-cloud uses its own import port (D5b).
D5b — Transition matrix (operator: strict)
On a store where exact-births is applied:
- Fresh launches and their children are born Exact × Incarnation.
- Resume and fork of a legacy run are typed refusals: relaunch instead.
migrate to-cloudimports only finished runs, as read-only historical records. It refuses resumable or non-terminal runs with a typed error. A re-import replaces the record underCheckRunFormatReplacement.- The invariant: no legacy run is born or executed on a migrated store. Historical legacy records may exist.
D6 — The drain is enforced from outside; the census is its witness
Exclusion is enforced in the v8 window, in this order (plan §3):
- Fence launches.
- Drain.
- Export the DLQ.
- Pause KEDA/Argo and scale every workload to 0.
- Rotate the Mongo and S3 credentials. Only v8 workloads receive the new secret. This is the one fence that a direct client (
migrate to-cloud, operatormcp, a CLI holding a Mongo URI) or a pre-P15 binary cannot skip. - Dump.
migrate epoch --apply, withexact-birthslast.- Reseed with
MinSchemaVersion = SchemaVersion(L6-04). - Roll with
runnerEpoch+1.
The existing runnerEpoch fence keeps a reverted Deployment off the queue:
- a superseded runner never consumes (
cmd/iterion/runner.go:432-446); - a superseded server serves only probes (
pkg/server/server_lifecycle.go:166-195).
The exact-births census is a witness, taken on a fingerprinted snapshot (run count, the maximum updated_at, the stream's last sequence). It requires all of the following:
- The fleet registry is EMPTY. No server or runner record, draining ones included. Presence expires after 60 s and does not stop running work, so presence is evidence, not exclusion.
- No run with
!IsTerminal() || IsResumable(). That coverspaused_*,failed_resumableandcancelled, unless the run is listed for L6-14's typed refusal. - The run stream holds no message. No pending acknowledgement and no delayed redelivery; the DLQ is exported and empty.
- No premature format-2 or protocol-1 document.
Apply re-takes the census and refuses if the fingerprint moved. It also refuses without the token.
Abort. A window can stop between census and apply. From P15a on, a censused or applying ledger refuses every birth (D2), so rolling back to the v7 digest alone would reopen a store where no run can launch. P15 therefore adds iterion migrate epoch --abort:
- it moves a censused or applying
exact-birthsstep back to absent with a CAS on both ledgers (FS and Mongo) and records who aborted and when; - it is allowed only while that step's apply has written nothing beyond the ledger, which holds for
exact-birthsbecause its apply is the census plus the ledger flip; - it refuses once the step is applied: past that point, rollback is D10's rule.
An earlier step of the same window that did write data is rolled back by restoring the step-6 dump, never by --abort. The runbook in docs/migrations/v8.md lists both paths.
Boot floor. It runs before presence join and at the D2 creation boundary. It refuses a store whose ledger capability is not a subset of the binary's tokens. It fences binaries built from P15 on. A pre-P15 image started under a fresh epoch is fenced only by the rotated credentials. Runbook rule: once the store is reopened, no pre-P15 digest is ever redeployed.
D7 — Storage layout, frozen (operator: L6-D9 amended)
Protocol 1 keeps the layout #3507 shipped:
- events, logs, sequence counters, plans, notes and inbox go to the shared collections
run_data_v1_*; - rows are keyed by the namespace
run-data-v1/f2/<runID>/<birthID>/, plusrun_idandtenant_id; - the unique key is
(data_namespace, position).
Plan decision L6-D9 now reads: "run-ID keyed; protocol 1 adds the birth suffix".
The -v2 roots split two ways:
- S3
{attachments,tools,sessions,runfiles,artifacts}-v2/and Mongo scratch-v2are reachable only through format 2 × protocol 0, which D2 never creates. L6-13 may delete them once the census proves that no such document exists. - FS
artifact_files-v2lives inside the protocol-1 root and stays. L6-13 names it as its exception.
An appendix table is frozen before P4, P10 and P15. One row per domain: run document, events, logs, seq, plans, notes, inbox, artifacts, IR, S3 objects, FS run files, scratch, and the FS .run-data-v1 root. Columns: location under protocol 0 and protocol 1, key and unique index, TTL, archive treatment (L6-16) and cleanup owner.
D8 — Readers and transports are in scope, not afterthoughts
Initial observation.
- The single door. One seam,
store.ObserveRun, is the only entry point for a fresh read: observe the header, capture it, bind, then load. An AST guard refuses a bareLoadRunoutside a census-built allowlist of delayed operations that already carry a binding. - Queue pickup. It binds before its first load. Today
pkg/runner/loop.go:254builds an identity-only context. A capability refusal is negatively acknowledged or parked, never ended. - Listings. They capture a per-record observation instead of skipping the record (
pkg/store/mongo/run_window.go:145). - Queue messages. They carry the full originating header (format, protocol,
BirthID) across retries. A successor birth under the same ID is refused, never adopted.
Value transports (today they destroy exact values):
- Backend output parsing: claw, plus the delegate
parseSDKOutput. It uses the exact decoder for format-2 runs, and the legacy path stays byte-identical. - Delegate IPC:
IOResult.Output, tool-call and ask-user data, and relay envelopes (pkg/backend/delegate/io.go:257,pkg/backend/model/sandbox_relay.go:434).IOTaskcarries the run's format as a capability marker. An image that does not advertise it gets a typed refusal before dispatch. - scripthost and codemode: for format-2 runs, a structured frame either crosses losslessly or gets a typed refusal. Refusal is the default.
- Studio: exact-or-refuse for format-2 runs.
- A class guard refuses
json.Unmarshalintoanyormap[string]anyin the value-path packages unless an allowlisted reason is given. - Parity proof. One fixture (
2^53+1, the lexeme1.10, a nested tool input) crosses four paths: claw in-process, claw sandboxed, claude_code in-process and claude_code sandboxed.
D9 — The qualification lane cannot pass vacuously
One skip helper. Admission cases go through a single helper, storetest.RequireIncarnation:
- it skips when the build is untagged and fails under
iterion_exact; - all 28 sites migrate to it;
- a guard refuses an inline admission skip.
Missing infrastructure fails. Under the tag, a missing Mongo or NATS URI is a failure, not a skip.
Composition. The lane runs tagged unit, tagged mongo-conformance, tagged nats-conformance and tagged race jobs. A guard derives its package list by grep and proves it is complete.
Skip census. A go test -json census asserts zero admission or infrastructure skips. The mutation "restore the protocol-1 refusal" must turn the lane red.
Exact births are exercised, not assumed. The lane's birth, genesis and Applied-row cases run under the D1 test grant. A second mutation, "drop the grant", must also turn the lane red: a lane that stays green without it is testing Legacy births only.
Placement. Until .github/workflows/tests.yml is free (after 2026-12-08), the lane lives in the Taskfile and is owed by every Exact PR. It becomes a CI job afterwards.
D10 — Compatibility matrix and rollback
This section lands with P1. It is a table with these rows: pre-7.26 binary; v7.26+ default build; tagged v7.x (lane); v8 before the flip; v8 after the flip. Its columns: read protocol 0 and 1; mutate protocol 1; birth Exact; Mongo v accepted; boot-floor verdict.
Consequence for rollback. Once exact-births is applied, no v7 binary built from P15 on can open the store: the boot floor refuses it. A pre-P15 binary is kept out only by the rotated credentials (D6); given credentials, it would start and could create legacy births on a migrated store, which breaks D5b. A rollback target inside the hold must therefore be a v8 digest. Before exact-births is applied, a stopped window is rolled back by D6's abort path first, then by the v7 digest. All of this goes on docs/migrations/v8.md.
The series
Every unit is a single-concern PR, dormant in v7.x. Each carries a test seen red under a named code mutation and runs the D9 lane, tagged and untagged.
| # | Unit | Depends on |
|---|---|---|
| P1 | Token, test grant (D1), iterion_exact lane (D9), source guard + artifact probe (D1), compatibility matrix (D10) | — |
| P2 | Witness of the existing protocol-1 writer fence, FS and Mongo (test only) | — |
| P3 | BirthPolicyOf at the creation boundary (D2, D5a); binding inherited inside the port (D4) | P1 |
| P4 | Phased RunLaunchPreimage + creator, FS and Mongo, with the replay invariant (D3); the layout appendix (D7) frozen first | P3 |
| P5 | Runtime preimage; the stamp compares only the immutable projection | P4 |
| P5b | store.ObserveRun seam + bare-LoadRun guard (D8) | P1 |
| P5c | Queue pickup binds first | P5b |
| P5d | Listings capture per-record observations | P5b |
| P5e | API and background readers, by census, one package group per PR | P5b |
| P6 | Local launchers through the port | P5 |
| P7a | Sub-bots, pipeline, operatormcp, heartbeat through the port | P6, L5-16 |
| P7b | Fork: Exact parent → Exact child; legacy parent → typed refusal (D5b) | P6 |
| P7c | migrate to-cloud import port (D5b) | P15a |
| P8a | Publisher exclusive birth (PersistLaunchBirth) | P4 |
| P8b | Acknowledged replay: no write, pinned | P8a |
| P8c | Conditional completion that preserves the incarnation (D3) | P8a |
| P9 | Runtime numeric contract from the bound format | P5b, P6, P7a |
| P9b | Backend and sandbox value transport + class guard + four-path parity (D8) | P3 |
| P10 | Remaining protocol-1 gates, one PR each: rewind, Mongo query and index paths, cleanup, signed URLs, stream selection | P1, D7 |
| P11a | Queue: tagged consumer window [27,36] + exact message codec (truly dormant: release builds stay at 35) | P5c |
| P12 | Exact HTTP/WS ingress and egress | P5e, P11a |
| P13 | Studio exact-or-refuse for format-2 runs | P12 |
| P14 | Barrier reading over the fleet registry (witness) | #3866 |
| P15 | exact-births step (D6 census, apply and abort) + capability-subset boot floor | #3573, #3574, P14 |
| P15a | Store genesis + ledger-state birth behaviour (D2 table) | P3, P15 |
| P16 | Mongo v=2 on Exact documents: defence in depth against pre-P15 Mongo binaries | P4 |
| PW | Windows: PID lock that does not pin its path, atomic no-replace publication, native windows-latest lane (plan L8-03). Coordinates with #3075/#3083 | — |
| P17 | Flip (breaking, in the hold): delete the tag; P17 mints the token; RunFormatVersion = 2; legacy creators refuse; the producer emits schema 36 (P11b) together with the L6-04 reseed | all of the above (P1–P16, P15a, PW); lands in the hold before R1 and R2, which rehearse it. The cut, not P17, is gated on R2 |
Consequences
- Production never runs Exact code before the v8 window. The qualification lane runs the Exact birth path in process on every Exact PR, under the D1 test grant. A built binary first reaches it at P17, and the rehearsals R1 and R2 cover that.
- Release builds carry two guards: the source guard and the artifact probe.
- The window adds a credential rotation and requires an empty fleet registry. Once the store is reopened, the rollback target is a v8 digest.
- No legacy run is born or executed on a migrated store. Historical legacy records may exist. This holds under D6's exclusion, D2's creation-boundary policy and D5b.
- Named residuals, recorded on
docs/migrations/v8.md:- a pre-P15 binary that holds old credentials;
- pre-v7.26 local binaries pointed at a fresh v8 store;
- resumable legacy runs, which must be relaunched.
- Local Windows reaches parity before the flip, so v8 has one regime.
Operator arbitrations (2026-12-01)
- Windows: the Windows workstream (PW) is a prerequisite of the flip. No platform exception in v8.
- Legacy lineage: strict (D5b).
- Storage layout: L6-D9 is amended (D7).
The orchestrator made these calls and stated them:
- No per-birth fleet gate. It would turn a NATS KV outage into a launch outage; D6 census, boot floor and credential rotation are used instead.
- P16 is adopted.
- JavaScript is exact-or-refuse, refuse by default.
- Queue emission at the flip, with acceptance dormant in v7.x.
What this does not establish
- Same-format ABA, revocation of external handles, and Mongo+S3 atomicity. They stay out of scope, as
run-value-formats.mdalready says. - The absence of bytes written by a binary that held old credentials and was never stopped. The window's scale-to-0 and the credential rotation are the guarantee, not a witness.
- Arbitrary decimal arithmetic. The numeric contract preserves lexemes and integer range.
Adversarial review disposition (codex gpt-6-astra, xhigh — 15 findings, each re-verified against the code)
- Adopted into the plan:
- F4: phased birth (D3);
- F5: completion never mints, P8a/b/c;
- F7: creation boundary + inventory (D5);
- F8: ledger-state table + genesis, P15a;
- F11: transports in scope, P9b (D8);
- F12: non-vacuous lane (D9);
- F15: artifact probe + scope by workflow (D1).
- Adjusted:
- F1 (medium after verification): exclusion is enforced by scale-to-0 and credential rotation, the census requires an empty registry, and the existing
runnerEpochfence is credited (D6). - F3: a reader/admission sub-series P5b–e rather than one PR.
- F6 (medium): a replay invariant on the guard arm (D3); the reserved-birth framing was dropped.
- F10 (medium): P11a dormant under the tag, emission folded into P17.
- F13: the layout was confirmed as shared collections, not per-incarnation collections; L6-D9 amended,
-v2split (D7). - F14: D1 kept, with reasons the code supports, a versioned token and the D10 matrix.
- F1 (medium after verification): exclusion is enforced by scale-to-0 and credential rotation, the census requires an empty registry, and the existing
- Decided by the operator:
- F2: Windows workstream PW before the flip.
- F9: strict lineage (D5b).
- Deferred follow-ups: a decidability probe for uncertain commits, using the once-minted
BirthID(F6); it gets its own ticket.
Pull-request review disposition (Revi, three rounds on #3983 — 5 medium, 4 distinct)
- Adopted:
- R24d164 / Re9325e: before P17 no tagged build reached an Exact birth, so the lane would have qualified P3–P15a against Legacy births only. Added the test-only grant (D1), its "drop the grant" mutation (D9) and the corrected consequence; a built binary first reaches the path at P17, covered by R1 and R2.
- R78a42b (third round): the series table made P17 depend on R2, so R1 and R2 would have rehearsed digests without the token. P17 now lands in the hold before R1 and R2, which rehearse it, and the cut is gated on R2 (the suggested row).
- R932f2b: a window stopped between census and apply had no way back. Added
migrate epoch --abortfor a censused or applyingexact-birthsstep whose apply wrote nothing (D6, P15), with the dump restore for earlier steps. - Re2ded1: D10 claimed that every v7 binary is fenced. It now says that only binaries built from P15 on are, and that pre-P15 digests are kept out by the rotated credentials alone.
