diff --git a/doc/2026-11-01_design_id2819.md b/doc/2026-11-01_design_id2819.md index 95e2cb11a3..1a4a9184ca 100644 --- a/doc/2026-11-01_design_id2819.md +++ b/doc/2026-11-01_design_id2819.md @@ -1,8 +1,10 @@ # Design: Native-spill write lease protocol for hot worlds - Date: 2026-11-01 +- Revision: 2026-11-24 — sufficient-design additions; original decision date retained. - Status: **decision-ready proposal** — design only; no protocol code is implemented here. - Issue: [#2819](https://github.com/developing-today/code/issues/2819), from [#2059](https://github.com/developing-today/code/issues/2059); consumer [#2046](https://github.com/developing-today/code/issues/2046). +- Work item: Fleet queue task `21547` (design-only slice). - Related: [#2818](https://github.com/developing-today/code/issues/2818) shares the journaled-entry pattern, not the lease or coordinator protocol. - Latest decision source: [#2819 triage record](https://github.com/developing-today/code/issues/2819#issuecomment-6560910098). Where its wording and the existing implementation leave a gap, this note makes that gap an implementation requirement rather than assuming it already works. @@ -10,6 +12,12 @@ How can one hot world move program execution from its hosted Durable Object (DO) to a native `id` node and back without ever accepting two writers, while keeping one auditable journal of record? +## Goals and non-goals + +**Goals:** permit one opted-in native node to execute a world's turns temporarily; preserve the DO as sole lease grantor and append authority; make accepted mutations ordered, fenced, durable-before-acknowledgment, and idempotent across retries and handoff; recover or hand back without requiring the old executor to cooperate; retain a reconstructible audit trail across restart and compaction. + +**Non-goals:** increasing one world's write throughput with concurrent executors; moving journal ownership, world identity, membership, or capability roots; allowing a native node to commit to a local or writable mirrored journal; defining multi-node failover pools or read-replica service (the later v2 design is [#5787](2026-11-08_design_id5787.md)); or changing turn-level atomicity. If native execution cannot reach the DO append gate, availability is sacrificed rather than fencing safety. + ## Recommendation Use a **journal-resident lease with the DO as the only lease authority and the only append gateway**. A native node may execute program turns while it holds the current journaled lease, but it never writes an independent journal or commits locally. It submits proposed journal entries to the DO. The DO serializes lease transitions and mutations, checks the holder, epoch, term, and journal position at the same append boundary, then fsyncs the accepted entry before acknowledging it. @@ -44,6 +52,14 @@ The newest #2819 triage comment resolves the original “DO? coordinator? operat ## Protocol +### Trust, security, and capability boundaries + +- The DO append gate is the trust boundary. It authenticates the node using credentials bound to its signing identity; a payload's `writer` string is metadata, never proof of identity. The gate authorizes only the currently granted holder and epoch, while the DO alone can append control records. +- A native node receives the minimum capability needed to execute one world and submit fenced proposals for that world. It cannot grant, renew, revoke, change membership, select another holder, or address another world's journal. The DO derives the world scope from the authenticated grant/session rather than trusting a caller-supplied world ID. +- Native execution is treated as potentially stale or compromised: all durable effects pass the same gate, and the node has no alternate local-commit, mirror-write, or publish/acknowledge path. A failed fence discards speculative state and reveals no accepted mutation receipt. +- The DO validates and bounds request size and records a digest in rejection audits; audit records must not copy credentials or secrets. Authentication failure is rejected before lease checks and does not create an authenticated stale-writer audit. Credential issuance, rotation, revocation, and transport protection are implementation obligations of #3805; they must not weaken the journal fencing contract. +- This design protects journal consistency, not arbitrary external side effects. Programs must continue to obey the no-network/no-filesystem rule; any future side-effect capability requires its own idempotency and fencing design before native spill can use it. + ### Lease state and journal records The append authority maintains one derived lease state: @@ -101,6 +117,8 @@ The native executor checks lease state before beginning a turn and the append ga - To recover after expiry, the DO appends `LeaseRevoked` (advancing the epoch and clearing the holder), then `LeaseGranted` for itself at the next epoch. The DO resumes execution only after its grant is durable and its program is restored through the latest journal position. A crash between revoke and grant leaves the world unavailable, not split-brained. - Operators may request revocation through the DO. No operator edits a native node's local state to transfer ownership. +**Deferred timing decision and owner:** 30-second terms and 10-second renewals are safe initial defaults, not benchmarked product requirements. The maintainer implementing #3805 owns collecting term-expiry, renewal, false-expiry, and replay-to-ready measurements from the failure-injection tests and the first game-day or production spill. That maintainer records the evidence and any proposed value change on #2819; absent both test measurements and an observed failover timeline, keep the defaults. Tuning may change availability/overhead, but must not change DO-clock expiry, append-gate fencing, or fail-closed recovery. + ### Handoff in both directions **DO → native (spill start):** @@ -174,14 +192,24 @@ Thus two accepted writers would require either two different epochs to be curren - [ ] Both handoffs test queued/in-flight commands and require the new executor to replay through the handoff position before accepting work. - [ ] Native spill remains opt-in until those failure tests pass; normal DO-only worlds retain existing behavior. -## Phased implementation plan +## Dependency-ordered implementation slices The latest triage comment already lists the independently mergeable packets [#3803](https://github.com/developing-today/code/issues/3803), [#3804](https://github.com/developing-today/code/issues/3804), and [#3805](https://github.com/developing-today/code/issues/3805). Keep each phase safe to merge with native spill disabled: -1. **Lease schema and replay foundation — #3803.** Add typed lease/control records, logical position and checkpoint representation, backward-compatible DO epoch-0 bootstrap, and the required header-version/replay/compaction tests. No new writer is enabled. This design record supplies the decisions; the packet owns the schema implementation. -2. **Lease renewal and append fencing — #3804.** Upgrade the append contract to accept authenticated writer/epoch/operation-ID/expected-position context; implement the single DO gate, DO-only control records, expiry/renewal, stale-attempt audit, idempotent receipts, and race/failure tests. Keep execution DO-only while proving the gate. -3. **Native spill and return handoff — #3805.** Add opt-in DO→native and native→DO drains, replay barriers, in-flight command handling, mirror-lag behavior, expiry recovery, and failure-injection integration tests. Enable only after phases 1 and 2 pass; operational rollout remains reversible by handing the lease back to the DO. +1. **Lease schema and replay foundation — #3803.** Add typed lease/control records, logical position and checkpoint representation, backward-compatible DO epoch-0 bootstrap, and header-version/replay/compaction tests. No new writer is enabled. **Acceptance:** legacy fixtures restore as DO epoch 0; new records replay in position order; compaction/reopen preserves position, epoch, lease history, and dedupe state; old readers reject the bumped header before writes. +2. **Lease renewal and append fencing — #3804; depends on #3803.** Upgrade the append contract to accept authenticated writer/epoch/operation-ID/expected-position context; implement the single DO gate, DO-only control records, expiry/renewal, stale-attempt audit, idempotent receipts, and race/failure tests. Keep execution DO-only while proving the gate. **Acceptance:** model/oracle tests show stale, wrong-holder, expired, duplicate, and journal-behind submissions cannot create a second mutation; accepted writes are fsynced before receipts; retries return the original receipt; concurrent handoff and append produce one valid journal order. +3. **Native spill and return handoff — #3805; depends on #3804.** Add opt-in DO→native and native→DO drains, replay barriers, in-flight command handling, mirror-lag behavior, expiry recovery, and failure-injection integration tests. Enable only after phases 1 and 2 pass; operational rollout remains reversible by handing the lease back to the DO. **Acceptance:** with the feature disabled, behavior stays DO-only; when enabled, both handoffs drain and replay through their boundary before admitting work; crash, partition, expiry, and unavailable-native rollback cases fail closed and resume only under a newer durable DO grant. + +## Rollout, rollback, and operational ownership + +- **Rollout gate:** phases #3803 and #3804 must be merged with their compatibility, replay, compaction, fencing, and dedupe tests passing before #3805 enables any native execution. Keep the feature disabled by default; enable only for an explicitly selected world and authenticated node after the failure matrix below passes. Expand exposure one world at a time while observing append rejection, renewal, lease expiry, replay lag, and handoff metrics. +- **Rollback:** stop admitting new spill handoffs, then use the DO-mediated native→DO handback protocol. If the native node is unavailable, wait for expiry, journal revoke then a newer DO grant, and restore through the durable tip. Do not roll back binaries that cannot read the journal header/version; preserve a compatible reader or use the journal's supported migration path. Rollback may make a world unavailable while fencing is restored; it must never bypass the append gate or delete lease history. +- **Ownership:** #3803 owns schema/replay/compaction compatibility; #3804 owns the DO append gate, lease lifecycle, and command dedupe; #3805 owns execution transfer, opt-in controls, failure-injection coverage, rollout telemetry, and the deferred timing evidence. The operator enabling a world owns monitoring and initiating handback; the DO remains the sole authority that performs it. + +## Verification and decision oracles + +The acceptance checklist below is the implementation gate. Tests should use a small deterministic model of `(holder, epoch, expiry, position, committed request IDs)` as the oracle: at every journal position, at most one authenticated holder's mutation can be accepted; accepted entries form one consecutive position chain; a request identity/payload pair yields at most one durable receipt; and replay/compaction reconstructs the same authority state and dedupe outcomes. Exercise the listed crash, partition, expiry, and handoff interleavings with controlled clocks and injected append/fsync/reply failures. Also verify legacy fixtures restore as DO epoch 0, unsupported versions fail before replay or writes, unauthenticated requests cannot mutate or generate stale-writer audits, and the disabled-by-default path remains behaviorally DO-only. A test passes only when its oracle checks both the journal and the externally visible acknowledgment/publication; absence of a panic or successful restart alone is not sufficient. -## Drew questions +## Open questions and deciders -**None.** The latest triage record already recommends DO-only grant authority and a 30-second term with 10-second renewals. The term is an operational default that implementation may tune without changing the safety protocol; no product decision is needed to begin the phases. +1. **Should the 30-second lease / 10-second renewal defaults change after evidence?** Decider: the maintainer implementing #3805. Keep the defaults unless failure-injection measurements and a game-day or production failover timeline justify a change; record the evidence and chosen values on #2819. This is operational tuning, not a prerequisite product decision, and cannot alter the safety invariants above.