From dbbbf44a0034faf22c5e64ebb5e9712575db642f Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 11:08:07 -0600 Subject: [PATCH 1/2] docs(id): design native-spill lease protocol --- doc/2026-11-01_design_id2819.md | 187 ++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 doc/2026-11-01_design_id2819.md diff --git a/doc/2026-11-01_design_id2819.md b/doc/2026-11-01_design_id2819.md new file mode 100644 index 0000000000..646324ebf3 --- /dev/null +++ b/doc/2026-11-01_design_id2819.md @@ -0,0 +1,187 @@ +# Design: Native-spill write lease protocol for hot worlds + +- Date: 2026-11-01 +- 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). +- 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. + +## Decision to make + +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? + +## 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. + +This preserves #2059's defining shape: execution moves, while the journal and world identity do not ([investigation §3 rung 3, lines 183–202](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md#L183-L202); [§4, line 229](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md#L222-L230)). It also makes the latest triage decision—journal-resident state, DO-only grants, monotonically increasing epochs, and rejection auditing—implementable without interpreting “native appends” as permission for a second writable journal. + +**Authority distinction:** during spill, the native node is the sole *program executor*; the DO remains the sole *lease grantor and journal append authority*. The DO stops executing world turns, not serving the journal's fenced append/control path. A read mirror is allowed; a writable mirror or offline local commit is not. + +Recommended operational default: a **30-second native lease, renewed by the DO every 10 seconds**, using only the DO authority's clock. This is the latest triage record's suggested starting value, not a settled product requirement ([#2819 triage record](https://github.com/developing-today/code/issues/2819#issuecomment-6560910098)). A missed renewal stops writes at expiry; recovery does not depend on the native node voluntarily shutting down. + +## Context and evidence + +- The #2059 investigation says the hosted DO keeps the journal of record (or a mirror), while a native node runs the hot world's turns and returns signed results; it names a journaled single-writer lease as the safety design and split-brain as catastrophic ([§3 rung 3, lines 183–202](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md#L183-L202)). Its de-escalation signal is temporary spill after the warning band clears ([§3 rung 3, lines 203–206](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md#L203-L206)). +- The current `WorldHandle` documents one actor task as the authoritative event order ([`handle.rs:1–12`](../pkgs/id/src/world/handle.rs#L1-L12)); the actor owns the core, program, and journal ([`actor.rs:248–256`](../pkgs/id/src/world/actor.rs#L248-L256)) and handles commands serially ([`actor.rs:288–324`](../pkgs/id/src/world/actor.rs#L288-L324)). +- `WorldJournal::append` currently accepts one `JournalEntry`, has no writer identity, epoch, idempotency key, or returned position, and is documented as preceding acknowledgment ([`world/mod.rs:685–707`](../pkgs/id/src/world/mod.rs#L685-L707)). `FileJournal` writes one JSON line and `sync_data`s it before returning ([`world_store.rs:177–197`](../pkgs/id/src/world_store.rs#L177-L197)). This is a durable local append seam, not yet a multi-writer fencing API. +- The actor currently mutates program/core state before persisting some entries: input updates the program before `persist` ([`actor.rs:1137–1155`](../pkgs/id/src/world/actor.rs#L1137-L1155)); chat updates core before `persist` ([`actor.rs:1114–1125`](../pkgs/id/src/world/actor.rs#L1114-L1125)). Append failure makes the actor read-only ([`actor.rs:375–392`](../pkgs/id/src/world/actor.rs#L375-L392)), but it does not roll back already-mutated in-memory program state. +- `WorldEvent.sequence` sequences events, not every journal entry ([`world/mod.rs:315–323`](../pkgs/id/src/world/mod.rs#L315-L323)); system entries and control entries also exist. A stable journal position therefore must not be conflated with the event sequence. +- Current checkpoints preserve program and selected world state ([`world/mod.rs:616–643`](../pkgs/id/src/world/mod.rs#L616-L643); [`core.rs:455–559`](../pkgs/id/src/world/core.rs#L455-L559)), but have no lease epoch, holder, journal high-water position, or lease audit history ([`core.rs:7–42`](../pkgs/id/src/world/core.rs#L7-L42)). Compaction atomically replaces the file ([`world_store.rs:200–253`](../pkgs/id/src/world_store.rs#L200-L253)); lease history would otherwise disappear and an epoch could reset. +- Journal compatibility is deliberately versioned: a reader rejects an unsupported header before replay, and new entry kinds require a header bump before append ([`world/mod.rs:646–682`](../pkgs/id/src/world/mod.rs#L646-L682); [`core.rs:130–171`](../pkgs/id/src/world/core.rs#L130-L171)). Lease entries must follow that rollback contract. +- Programs run in the actor's serial loop and must not perform network or filesystem I/O ([`world/mod.rs:871–879`](../pkgs/id/src/world/mod.rs#L871-L879)). The lease protocol can therefore fence durable world effects at the append gateway; the native process must not add an unjournaled side-effect path. + +The newest #2819 triage comment resolves the original “DO? coordinator? operator?” question as **DO-only grantor** and selects journal-resident state and epoch fencing. #2818's own triage says its coordinator concerns shard membership/segments and does not interact with this lease; do not import that protocol ([#2818 triage record](https://github.com/developing-today/code/issues/2818#issuecomment-6560923802)). + +## Viable options + +| Option | Trade-offs | Decision | +| --- | --- | --- | +| **Journal-resident lease; DO grants and gates every append** | One auditable order; survives process restarts; stale epochs can be rejected at the point that makes a write durable. Requires a journal append API change, explicit positions, and checkpoint/version work. | **Recommend.** It is the latest recorded decision and fits the existing single-actor / append-before-ack pattern. | +| Separate coordinator or external TTL lock grants leases | Can make lease acquisition look independent of the journal, but its state can race or disagree with journal history; adds a second authority and still needs append fencing. | Reject. A lease that is not ordered with the protected append cannot prove exclusive ownership at a journal position. | +| Timeouts only; native writes its local/mirrored journal directly | Small apparent handoff surface, but a partitioned old node can keep accepting local work while the DO resumes. A mirror cannot fence an already disconnected writer. | Reject. This reintroduces the split-brain failure #2059 identifies. | +| Keep the DO as both executor and append authority; never transfer execution | Safest with today's code, but does not provide the native execution spill this issue is designing. | Safe fallback if fencing is unavailable; do not call it native spill. | + +## Protocol + +### Lease state and journal records + +The append authority maintains one derived lease state: + +```text +(holder, epoch, expires_at, last_position) +``` + +Add typed control records to `JournalEntry` (names are illustrative; the state transitions and fields are normative), and a position/authority envelope for each newly written line: + +```text +JournalRecord { position, previous_position, writer, epoch, operation_id?, entry } + +LeaseGranted { holder, expires_at } +LeaseRenewed { holder, expires_at } +LeaseHandedOff { from, to, expires_at } +LeaseRevoked { former_holder, reason } +LeaseWriteRejected { + writer, presented_epoch, operation_id, expected_position, + observed_epoch, payload_digest, reason, received_at +} +``` + +- `JournalRecord.position` is assigned by the DO append authority in the same serialized operation as the append; callers cannot choose it, and `previous_position` must equal the current high-water mark. Every entry has a monotonically increasing **logical journal position**, including entries without a `WorldEvent.sequence`. `writer`, `epoch`, and optional `operation_id` describe the authority context for that line; for lease-control/audit lines, `writer` is the DO and the entry contains the target or rejected writer. Persisting the operation ID with committed entries supports deduplication after restart/compaction. The append API returns a durable receipt containing the position. +- For a mutation record, the envelope epoch is the epoch it was authorized under. For a grant, revoke, or handoff control record, it is the resulting epoch; renewal records the unchanged epoch; a rejection audit records the authority's observed epoch while the entry retains the attempted epoch. +- Legacy v1/v2 lines remain readable as unwrapped DO/epoch-0 records in their existing order; their position is derived from that order. New writes use the envelope after the journal header is bumped. A checkpoint stores the global position it covers; the first appended line after compaction continues at the next position. This makes a handoff boundary and every mutation's lease interval reconstructible without pretending `WorldEvent.sequence` counts all journal entries. +- Existing worlds with no lease records bootstrap as `holder=DO, epoch=0` (the pre-spill single actor is the incumbent). A normal handoff to native advances to epoch 1. New lease epochs never decrease or repeat. Grant, handoff, and revoke advance the epoch; renewal retains it. Revocation leaves no holder; a later grant advances again. +- The DO is the only authority that appends grant, renew, handoff, revoke, or rejection records. A native node can request a renewal or handoff, but cannot create one, extend its own expired term, or grant a third party. +- Use authenticated writer identity bound to the native node's signing identity, as the #2059 investigation's signed-result transport implies ([§3 rung 3, lines 185–190](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md#L183-L190)). The current `WorldJournal` interface does not supply this; the implementation must bind authentication to the append request rather than trusting a caller-provided name. + +### Fenced append contract + +Every mutation submitted by a world writer carries: + +```text +{ authenticated_writer, lease_epoch, operation_id, expected_position, entry } +``` + +The DO's single append gate, serialized with lease-control entries, performs this decision and durable append as one linearized operation. Persist the result as the positioned `JournalRecord` above; do not merely keep the position in process memory: + +1. Authenticate the writer. If `operation_id` already committed with the same payload digest, return its original receipt rather than applying it again; if the ID was used with different content, reject it. A rejected-attempt audit is deduplicated by `(writer, presented_epoch, operation_id)`, not by `operation_id` alone, so the client can retry the same uncommitted operation ID after it reaches the new holder. +2. Require `authenticated_writer == holder`, `lease_epoch == current epoch`, the lease to be unexpired according to the DO clock, and `expected_position == last_position`. +3. Assign the next logical position; append and fsync the world entry; advance the authority's high-water mark; then acknowledge with the position and event sequence. + +A failed check does not apply the proposed entry and returns a retryable `not-holder`, `expired`, or `journal-behind` result. If an authenticated stale request reaches the DO, the DO appends one `LeaseWriteRejected` audit record (deduplicated by `(writer, presented_epoch, operation_id)`) through its control path; the attempted payload itself is not executed. An unreachable native node cannot make an authoritative journal record while partitioned: it must not acknowledge or commit locally. On reconnect, a retried stale request is rejected and audited by the DO. This is the explicit limit of the latest triage's “attempt itself journaled” rule; the authoritative journal cannot record a packet it has not received. + +`operation_id` is required because the current event shape has no client request ID ([`world/mod.rs:315–323`](../pkgs/id/src/world/mod.rs#L315-L323)), and a process can lose the reply after the journal fsync. Preserve committed IDs through compaction so retry after an uncertain acknowledgment does not duplicate an event. Repeated network deliveries of the same request produce one commit receipt and one rejection audit per attempted writer/epoch, not unbounded duplicates. + +The native executor checks lease state before beginning a turn and the append gate checks it again at commit. The second check is authoritative: a lease may expire or hand off while a turn is running. If the final append is rejected after the program has changed in-memory state, the native actor stops and is discarded; the next holder restores/replays from the last durable journal position. It must not publish, acknowledge, or continue from that speculative state. A turn is **not** an atomic journal transaction: entries durably appended before expiry stand; the first rejected append and later work do not. This follows the current per-entry append semantics, not a new all-or-nothing turn guarantee ([`world/mod.rs:690–707`](../pkgs/id/src/world/mod.rs#L690-L707); [`actor.rs:1137–1171`](../pkgs/id/src/world/actor.rs#L1137-L1171)). + +### Term, renewal, and expiry + +- A native lease begins with `expires_at = DO_authority_time + 30s`; the DO appends `LeaseRenewed` for the same epoch every 10s while the node is healthy and caught up. Renewal is effective only after its append is durable and only before the current term expires. The DO streams each renewal's journal position to the native executor; if a concurrent control append advances the tip first, the native receives `journal-behind`, catches up, and retries with the same operation ID. +- The DO append gate checks expiry at the append decision, not against the native node's clock. After expiry, the old epoch is fenced even if the DO has not yet recorded recovery. Expiry alone grants no new owner. +- 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. + +### Handoff in both directions + +**DO → native (spill start):** + +1. The DO stops admitting new world mutations to its executor and drains commands already queued for it. Commands durably appended before the boundary remain committed. +2. After the old executor is quiescent, the DO appends `LeaseHandedOff { from: DO, to: native, epoch: old_epoch + 1, ... }`. That entry is the ownership boundary; the DO ceases to execute world turns. +3. The native node replays the authoritative journal through the handoff's `position`. It does not accept work or submit appends until caught up. Its first append presents the new epoch and the handoff position as its expected position. +4. The DO remains the append/control gateway and validates each native append. It does not run the world program during spill. + +**Native → DO (de-escalation):** + +1. When the warning band has cleared for about one hour (the #2059 de-escalation signal at [investigation lines 114–117](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md#L114-L117), referenced by #2819), the DO requests handback. The native executor stops admitting turns, finishes only appends that the DO durably accepts under the current epoch, and reports its last durable position. +2. The DO verifies that position against its journal, then appends `LeaseHandedOff { from: native, to: DO, epoch: old_epoch + 1, ... }`. The native process stops execution at this boundary. +3. The DO restores/replays through the handoff position and only then admits world mutations again. + +At either boundary, a command received by the old executor but not durably appended before the handoff is rejected as retryable `not-holder`; the new executor does not silently replay that uncommitted command. The client retries with the same `operation_id`, allowing the append gate to return the original receipt if the command actually committed before its acknowledgment was lost. + +### Compaction, recovery, and compatibility + +Compaction must retain safety state, not just program state. Extend the checkpoint (or an equivalent journal-resident compacted ledger) with: + +- the global `last_position`, current holder/epoch/expiry, and a lease-history baseline; +- every lease transition and every unique authenticated rejection audit needed to prove lease ownership at represented positions; +- the operation-ID dedupe state needed to make retries idempotent after compaction. + +Do not reset the epoch or position when replacing the journal. A future retention policy may bound audit or dedupe history only as an explicit change to the audit/retry contract; it is not implicit in this design. The `WorldJournal` append seam must become a conditional, position-returning append authority. New `JournalEntry` variants must bump the journal header before the first such append so older binaries reject the journal at restore time, following the existing version contract ([`world/mod.rs:646–682`](../pkgs/id/src/world/mod.rs#L646-L682)). Lease entries are control metadata: replay validates their order and rebuilds lease state but does not deliver them to the world program as user inputs. + +## Failure walkthroughs + +| Failure | Required result | +| --- | --- | +| **Native crashes holding the lease** | At term expiry the append gate rejects its old epoch. The DO records revoke then grant at newer epochs, restores through the last fsynced position, and resumes. Work that was never appended is uncommitted; clients retry with the same operation ID. | +| **DO/native partition, both alive** | The native node cannot reach the sole append authority and must not accept a durable write or acknowledge success. The DO does not resume its executor before expiry/revocation/grant. A stale request arriving after reconnect is rejected and audited. A read mirror is never an alternate append path. | +| **Lease expires mid-turn** | Appends accepted before expiry remain. The first append after expiry fails the final epoch/term check; no acknowledgment or publication follows. The old executor is discarded and the new holder replays the durable prefix. Turn-level rollback is not promised. | +| **Journal mirror lags at handoff** | The new executor waits until it has replayed through the DO-issued handoff position. The DO checks the presented expected position against its own high-water mark. Lag delays activation; a mirror cannot authorize or append from a stale tip. | +| **Handoff races an in-flight command** | The serialized append gate orders the command and handoff. If the command append linearizes first, it is committed under the old epoch and included in the handoff prefix. If handoff linearizes first, the command is rejected under the old epoch. | +| **DO crashes after fsync but before replying** | On retry, the durable operation ID returns the original append receipt instead of committing a second copy. Recovery rebuilds the lease state from the journal/checkpoint before serving writes. | + +## Why split-brain is excluded + +The proof depends on mechanics, not on lease timing alone: + +1. There is one authoritative append order, serialized by the DO's append gate. This is an implementation requirement; a single journal file by itself does not make concurrent independent writers safe. +2. A mutation can be acknowledged only after that gate atomically validates the current holder, current epoch, term, and expected position and fsyncs the entry. +3. A handoff is one journal position that advances the epoch. Before it, only the old epoch can pass. After it, only the new epoch can pass. The new holder does not execute until it has replayed that position. +4. Expiry can stop the current holder but cannot create a second holder. The DO must journal revoke/grant before resuming its executor. Old-epoch submissions after either expiry or handoff fail the gate. +5. A partitioned native node has no write path other than the DO gate. It can continue computing speculatively, but cannot commit, publish, or acknowledge a world mutation. + +Thus two accepted writers would require either two different epochs to be current at one serialized append position or a second append authority. Both are prohibited by the protocol. The safety proof does **not** hold if native nodes can append to their own writable mirror, if lease checks occur outside the append linearization point, or if the DO resumes before its newer lease entry is durable. + +## Invariants + +1. One authoritative journal and one append gate exist per world; the DO is the only lease/control-record writer. +2. Every accepted mutation is authenticated, fenced by the current epoch and term, ordered at a logical journal position, and durable before acknowledgment or publication. +3. Epochs and logical positions are monotonic across grant, renewal, handoff, restart, and compaction; epochs are never reused. +4. No native mutation is committed locally or through a writable mirror. A disconnected native node cannot promise durable success. +5. Rejected authenticated stale appends are not applied and are represented by a DO-authored audit record when they reach the authority; duplicate delivery is idempotent. +6. Handoff changes execution ownership only. Journal, world identity, membership, and capability roots stay in place, matching #2059's rung-3 strategy ([investigation §4, line 229](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md#L222-L230)). +7. Recovery or uncertainty fails closed: it may stop writes, but it never lets two holders commit. + +## Implementation acceptance criteria + +- [ ] Journal lease records cover grant/bootstrap, renewal, revoke, both handoffs, and rejected stale attempts, with an unambiguous logical position and authenticated holder. +- [ ] The append API checks holder, epoch, term, operation ID, and expected journal position atomically with append; stale/expired entries are never applied. +- [ ] DO-only control writes are distinct from program mutations; lease records are replayed as control metadata, not sent to the world program. +- [ ] Existing journals restore as DO-owned epoch 0; new entry versions are rejected early by old readers per the current header contract. +- [ ] Compaction/reopen preserves current lease state, monotonic epoch/position, auditable transition history, and retry dedupe state. +- [ ] Every mutation path (including chat, input, host/system events, schedules, and program administration) uses the same fencing gate; no path can acknowledge before durable append. +- [ ] A stale/expired result after speculative program execution discards that executor and restores from the last durable position before serving another turn. +- [ ] Integration tests race old-writer append vs handoff, exercise expiry/revoke/grant, partition/reconnect, mirror lag, crash recovery, compaction, and fsync-before-lost-reply retry. +- [ ] 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 + +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. + +## Drew questions + +**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. From c7456d4b01ccac95ec5fab21722db4c8c482d56d Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 08:23:17 -0600 Subject: [PATCH 2/2] docs(id): specify command-level dedupe before program execution (#2819) --- doc/2026-11-01_design_id2819.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/2026-11-01_design_id2819.md b/doc/2026-11-01_design_id2819.md index 646324ebf3..247e5b09be 100644 --- a/doc/2026-11-01_design_id2819.md +++ b/doc/2026-11-01_design_id2819.md @@ -84,13 +84,13 @@ Every mutation submitted by a world writer carries: The DO's single append gate, serialized with lease-control entries, performs this decision and durable append as one linearized operation. Persist the result as the positioned `JournalRecord` above; do not merely keep the position in process memory: -1. Authenticate the writer. If `operation_id` already committed with the same payload digest, return its original receipt rather than applying it again; if the ID was used with different content, reject it. A rejected-attempt audit is deduplicated by `(writer, presented_epoch, operation_id)`, not by `operation_id` alone, so the client can retry the same uncommitted operation ID after it reaches the new holder. +1. Authenticate the writer, then deduplicate at the **command** level, before any event is generated or the program executes: look up the durable dedupe record keyed by the command's original request identity — `(client identity, operation_id)` from the client's original request, independent of which holder or epoch presents the retry — together with a digest of the client command payload (not of the generated journal entry). If a committed record matches, return its original receipt without re-executing; if the identity was used with a different command payload, reject it. This lookup must precede event generation because re-execution is not deterministic: `WorldCore::prepare_input` assigns `current_sequence + 1` when the program runs (`pkgs/id/src/world/core.rs:1025–1032`) and the actor runs the program update before appending (`pkgs/id/src/world/actor.rs:1143–1155`), so a retry re-executed by a new holder produces a *different* journal entry for the same client command, and an append-level digest check on the entry would reject the retry instead of returning its receipt. A rejected-attempt audit is deduplicated by `(writer, presented_epoch, operation_id)`, not by `operation_id` alone, so the client can retry the same uncommitted operation ID after it reaches the new holder. 2. Require `authenticated_writer == holder`, `lease_epoch == current epoch`, the lease to be unexpired according to the DO clock, and `expected_position == last_position`. 3. Assign the next logical position; append and fsync the world entry; advance the authority's high-water mark; then acknowledge with the position and event sequence. A failed check does not apply the proposed entry and returns a retryable `not-holder`, `expired`, or `journal-behind` result. If an authenticated stale request reaches the DO, the DO appends one `LeaseWriteRejected` audit record (deduplicated by `(writer, presented_epoch, operation_id)`) through its control path; the attempted payload itself is not executed. An unreachable native node cannot make an authoritative journal record while partitioned: it must not acknowledge or commit locally. On reconnect, a retried stale request is rejected and audited by the DO. This is the explicit limit of the latest triage's “attempt itself journaled” rule; the authoritative journal cannot record a packet it has not received. -`operation_id` is required because the current event shape has no client request ID ([`world/mod.rs:315–323`](../pkgs/id/src/world/mod.rs#L315-L323)), and a process can lose the reply after the journal fsync. Preserve committed IDs through compaction so retry after an uncertain acknowledgment does not duplicate an event. Repeated network deliveries of the same request produce one commit receipt and one rejection audit per attempted writer/epoch, not unbounded duplicates. +`operation_id` is required because the current event shape has no client request ID ([`world/mod.rs:315–323`](../pkgs/id/src/world/mod.rs#L315-L323)), and a process can lose the reply after the journal fsync. Preserve committed IDs through compaction so retry after an uncertain acknowledgment does not duplicate an event. The dedupe record is keyed by the original request identity, so it survives a handoff: a command committed under one holder whose acknowledgment was lost returns its original receipt when the client retries to the next holder — the new holder must not replay it as a fresh command or re-execute it. Repeated network deliveries of the same request produce one commit receipt and one rejection audit per attempted writer/epoch, not unbounded duplicates. The native executor checks lease state before beginning a turn and the append gate checks it again at commit. The second check is authoritative: a lease may expire or hand off while a turn is running. If the final append is rejected after the program has changed in-memory state, the native actor stops and is discarded; the next holder restores/replays from the last durable journal position. It must not publish, acknowledge, or continue from that speculative state. A turn is **not** an atomic journal transaction: entries durably appended before expiry stand; the first rejected append and later work do not. This follows the current per-entry append semantics, not a new all-or-nothing turn guarantee ([`world/mod.rs:690–707`](../pkgs/id/src/world/mod.rs#L690-L707); [`actor.rs:1137–1171`](../pkgs/id/src/world/actor.rs#L1137-L1171)). @@ -170,7 +170,7 @@ Thus two accepted writers would require either two different epochs to be curren - [ ] Compaction/reopen preserves current lease state, monotonic epoch/position, auditable transition history, and retry dedupe state. - [ ] Every mutation path (including chat, input, host/system events, schedules, and program administration) uses the same fencing gate; no path can acknowledge before durable append. - [ ] A stale/expired result after speculative program execution discards that executor and restores from the last durable position before serving another turn. -- [ ] Integration tests race old-writer append vs handoff, exercise expiry/revoke/grant, partition/reconnect, mirror lag, crash recovery, compaction, and fsync-before-lost-reply retry. +- [ ] Integration tests race old-writer append vs handoff, exercise expiry/revoke/grant, partition/reconnect, mirror lag, crash recovery, compaction, and fsync-before-lost-reply retry — including a lost acknowledgment followed by a handoff and a client retry, which must return the original receipt without re-executing the command or appending a duplicate event (command-level dedupe). - [ ] 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.