Skip to content
Like what we’re building? Star on GitHub

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:

WhereWhat it refuses
pkg/store/run_invocation.go:120-129An Exact birth: "exact invocation birth is not connected".
pkg/store/value_format.go:150-153A SaveRun that births Exact. This one stays, because a birth is an insert.
pkg/store/run_data_storage.go:11-20Protocol 1 (IncarnationRunData), with ErrRunDataCapability.
pkg/store/run.go:389It 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: RequireRunDataStorage through loadRunRawContext (pkg/store/store_run.go:290).
  • Mongo: RequireRunDataStorage through decodeRunFormatObservation (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:

  1. Two independent drafts, birth-first and barrier-first, were written and judged.
  2. A cross-family plan review (codex gpt-6-astra, 15 findings) attacked the result.
  3. 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 tagged iterion or 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:

  1. A source ciguard covers every workflow that uploads or pushes a binary or an image:
    • release.yml;
    • image.yml and _build-image.yml with their Dockerfiles, including ENV GOFLAGS and the build ARGs;
    • desktop-release.yml and the Taskfile build tasks it calls;
    • scripts/build.sh.
  2. An artifact probe reads each built binary's buildinfo before upload, push or promotion, and fails if -tags contains iterion_exact. For darwin universal binaries, it probes each architecture slice before lipo.

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.New and 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 stateBefore P17From P17
Absent, store emptyLegacyGenesis. 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 runsLegacyTyped refusal naming iterion migrate epoch --census/--apply
Censused or applyingBirths refused (typed), reads allowedSame
AppliedBuilt binaries: not reachable without the token. Tests under the D1 grant: Exact × IncarnationExact × Incarnation
Unreadable, or a state the binary does not knowBirths refusedBirths 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, and ExecutionContext resolution.
  • Each effect keeps the compensation it already has:
    • grants use ReleaseGrant when the launch did not happen;
    • slots use releaseCredSlots when nothing was persisted;
    • the sealed bundle is left to its TTL.
  • The admission outputs join the preimage: credential-derived stamps, pinned providers, and inputs injected at publisher.go:4271 and :4319.

Phase 2 — the single insert.

  • The RunLaunchPreimage is 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.Workspace is execution; the rest of ExecutionContext is launch.
  • Budget is 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 and CreatedAt stay;
  • 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, AsRunValueFormatCreator and SaveParkedLaunchRun;
  • literals of NewLegacyRunInvocation and ReservedRunInvocation;
  • 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-cloud imports 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 under CheckRunFormatReplacement.
  • 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):

  1. Fence launches.
  2. Drain.
  3. Export the DLQ.
  4. Pause KEDA/Argo and scale every workload to 0.
  5. 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.
  6. Dump.
  7. migrate epoch --apply, with exact-births last.
  8. Reseed with MinSchemaVersion = SchemaVersion (L6-04).
  9. 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 covers paused_*, failed_resumable and cancelled, 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-births step 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-births because 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>/, plus run_id and tenant_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 -v2 are 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-v2 lives 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 bare LoadRun outside 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:254 builds 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). IOTask carries 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.Unmarshal into any or map[string]any in the value-path packages unless an allowlisted reason is given.
  • Parity proof. One fixture (2^53+1, the lexeme 1.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.

#UnitDepends on
P1Token, test grant (D1), iterion_exact lane (D9), source guard + artifact probe (D1), compatibility matrix (D10)—
P2Witness of the existing protocol-1 writer fence, FS and Mongo (test only)—
P3BirthPolicyOf at the creation boundary (D2, D5a); binding inherited inside the port (D4)P1
P4Phased RunLaunchPreimage + creator, FS and Mongo, with the replay invariant (D3); the layout appendix (D7) frozen firstP3
P5Runtime preimage; the stamp compares only the immutable projectionP4
P5bstore.ObserveRun seam + bare-LoadRun guard (D8)P1
P5cQueue pickup binds firstP5b
P5dListings capture per-record observationsP5b
P5eAPI and background readers, by census, one package group per PRP5b
P6Local launchers through the portP5
P7aSub-bots, pipeline, operatormcp, heartbeat through the portP6, L5-16
P7bFork: Exact parent → Exact child; legacy parent → typed refusal (D5b)P6
P7cmigrate to-cloud import port (D5b)P15a
P8aPublisher exclusive birth (PersistLaunchBirth)P4
P8bAcknowledged replay: no write, pinnedP8a
P8cConditional completion that preserves the incarnation (D3)P8a
P9Runtime numeric contract from the bound formatP5b, P6, P7a
P9bBackend and sandbox value transport + class guard + four-path parity (D8)P3
P10Remaining protocol-1 gates, one PR each: rewind, Mongo query and index paths, cleanup, signed URLs, stream selectionP1, D7
P11aQueue: tagged consumer window [27,36] + exact message codec (truly dormant: release builds stay at 35)P5c
P12Exact HTTP/WS ingress and egressP5e, P11a
P13Studio exact-or-refuse for format-2 runsP12
P14Barrier reading over the fleet registry (witness)#3866
P15exact-births step (D6 census, apply and abort) + capability-subset boot floor#3573, #3574, P14
P15aStore genesis + ledger-state birth behaviour (D2 table)P3, P15
P16Mongo v=2 on Exact documents: defence in depth against pre-P15 Mongo binariesP4
PWWindows: PID lock that does not pin its path, atomic no-replace publication, native windows-latest lane (plan L8-03). Coordinates with #3075/#3083—
P17Flip (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 reseedall 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) ​

  1. Windows: the Windows workstream (PW) is a prerequisite of the flip. No platform exception in v8.
  2. Legacy lineage: strict (D5b).
  3. 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.md already 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 runnerEpoch fence 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, -v2 split (D7).
    • F14: D1 kept, with reasons the code supports, a versioned token and the D10 matrix.
  • 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 --abort for a censused or applying exact-births step 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.