From 4dfcaa3965c86aab19ca47cae34f67394a3f6020 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 11:26:10 -0600 Subject: [PATCH 1/2] docs(id): design region-seam handoff format --- doc/2026-11-01_design_id2818.md | 195 ++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 doc/2026-11-01_design_id2818.md diff --git a/doc/2026-11-01_design_id2818.md b/doc/2026-11-01_design_id2818.md new file mode 100644 index 0000000000..501ce54dab --- /dev/null +++ b/doc/2026-11-01_design_id2818.md @@ -0,0 +1,195 @@ +# Design: Journaled region-seam handoff for ID worlds + +- Date: 2026-11-01 +- Status: **decision-ready design** — no implementation is included in this change. +- Issue: [#2818](https://github.com/developing-today/code/issues/2818), from [#2059](https://github.com/developing-today/code/issues/2059); consumer: [#2046](https://github.com/developing-today/code/issues/2046); sibling: [#2819](https://github.com/developing-today/code/issues/2819). +- Implementation follow-up: [#3870](https://github.com/developing-today/code/issues/3870) tracks the phases in §8. + +## Decision + +Use a **journaled intent → source export/fence → destination import → coordinator completion** protocol for **application-owned entities**. A versioned program transfer hook supplies the entity payload and the program event that removes/adds the entity; the host records both together with the handoff metadata. The source journal owns the last writable copy until its export entry commits; after that commit the entity is visibly in transit and the source rejects entity-targeted mutations. The destination becomes the routable owner only after its import is durable and the coordinator journals completion. The coordinator records and recovers progress; it does not emulate a transaction spanning the regions. + +This selects the two-step export/import seam described by #2059 and makes its transient unavailability explicit. It avoids both silent loss (the source's durable export remains the retry source until completion) and duplication (the source is fenced before the destination import can become routable; imports deduplicate by handoff ID). It does **not** transfer `WorldCore` participants, capabilities, sessions, credentials, files, modules, or other world-level state. + +## 1. Context and constraints + +The #2059 investigation selected sibling shard-worlds under a thin coordinator for **spatial** locality (its rung 2; cross-region writes are expected to be rare). It explicitly accepts that cross-region atomicity does not exist and that an entity may be visibly in transit. It left the record format open. The #2818 acceptance criteria require a journaled export/import pair, client-visible state and legal operations, recovery for missing/duplicate imports and coordinator/region failures, and a coordinator that never emulates a cross-region transaction. These are design constraints, not implementation claims. ([#2818](https://github.com/developing-today/code/issues/2818); [#2059 completion comment](https://github.com/developing-today/code/issues/2059#issuecomment-6532089391), 2026-10-30; [landed investigation](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md:161–181,228–269,307–326).) + +The newer #2059 landing says the source-of-truth journal remains single-writer; it rejects multi-writer journal splitting. The sibling #2819 design is separate and concerns native-node write leases; this handoff does not depend on that lease protocol. Both designs should reuse the current journaled-entry conventions rather than invent another persistence path. ([#2059 completion comment](https://github.com/developing-today/code/issues/2059#issuecomment-6532089391); [#2819](https://github.com/developing-today/code/issues/2819), latest comment.) + +Each world currently has one serialized authority owning its core, program, and journal; durable append includes fsync, and an append failure makes that world read-only (`pkgs/id/src/world/actor.rs:248–259,375–392`; `pkgs/id/src/world/mod.rs:685–708`). The `WorldProgram` interface accepts opaque input and can snapshot the **whole** program, but has no entity-level transfer hooks (`pkgs/id/src/world/mod.rs:871–925`). Therefore this proposal adds a transfer contract rather than claiming the code already supports entity export/import. + +The issue calls out `CrossWorldWrite` as an entry-pattern reference, but current code gives it a narrower meaning: it journals whether a world accepts policy-approved writes from other worlds; it does not move data or provide a handoff (`pkgs/id/src/world/mod.rs:579–585`; `pkgs/id/src/groups/worlds.rs:33–39`). Reuse only the single-writer actor, durable append, and versioned journal/replay machinery. The design adds new handoff entry kinds and an application transfer contract; no region coordinator or entity-level export/import API exists today. (`pkgs/id/src/world_hub.rs:1–19,62–100`.) + +## 2. Options and recommendation + +| Option | Benefits | Costs / failure mode | Decision | +| --- | --- | --- | --- | +| **A. Coordinator-mediated distributed transaction / 2PC** | Could hide the transit state if every participant stayed available. | Conflicts with #2059's explicit no-cross-region-atomicity decision; failure recovery requires transaction emulation and can block both regions. | Reject. | +| **B. Copy state to B, then delete/fence A** | Simple happy path; short apparent handoff. | A and B can both accept writes between the copy and fence; a lost acknowledgement can cause duplicate ownership or an ambiguous rollback. | Reject. | +| **C. Journaled intent, export/fence, import, completion** | Each side records durable local facts; retry and recovery use stable IDs; source stops writes before destination activation; coordinator state is reconstructible without a cross-world commit. | An entity can be unavailable while in transit; completion may wait for a down region or coordinator. Requires an app-level transfer hook because host program state is opaque. | **Recommend.** | +| **D. Move the whole world program snapshot** | Uses the existing `WorldProgram::snapshot`/restore path. | Moves every entity in a shard, not one entity at a seam; cannot implement selective region handoff and bypasses the required per-entity coordinator state. | Reject for this issue. | + +The outage is deliberate: preserving a single writer and recoverable state outranks seamless writes. Do not automatically roll an exported entity back to A while B's journal is unavailable; absence of an import cannot be proven when B cannot be inspected. + +## 3. Journal format + +Use an opaque, coordinator-generated `handoff_id` that is stable across retries, and an application-defined stable `entity_ref` that is not a world-local participant ID. The coordinator serializes handoffs per entity. The program hook returns a versioned, opaque entity payload and deterministic app event that removes/adds that entity. The host journals the payload, digest, and corresponding app event in one per-world journal entry, so replay applies the ownership-changing app event from the same durable fact. Source and destination must run the same program module hash for v1; schema/module mismatch is rejected before either region commits a handoff record. Do not treat a region-local event sequence as globally ordered; each side's sequence is local and is carried as an opaque receipt value. + +There is no existing entity-transfer size limit. Add `transfer_payload_bytes`, independent of `input_bytes` and `snapshot_bytes`; start with a conservative **16 KiB v1 payload cap** (the current default opaque-input size is 16 KiB) and reject an oversized proposal before source export/fencing. Encode the destination event's payload as hex so the versioned system-event JSON (payload plus app event and metadata) stays below the existing 64 KiB event limit (`pkgs/id/src/world_caps.rs:65`; `pkgs/id/src/world/actor.rs:409–417`); enforce a separate checked maximum on the full handoff journal entry. Chunking is not part of v1: it needs its own manifest/chunk durability and recovery protocol. These are recommended limits to revisit with real entity-size measurements, not limits already enforced by the code (`pkgs/id/src/world/mod.rs:57–100`). + +The following is the protocol contract; concrete journal types should follow the enum/serde conventions in `world/mod.rs`, while actor sequencing follows `world/actor.rs`. + +```text +Coordinator journal: + HandoffStarted { + handoff_id, entity_ref, source_region, target_region, + expected_owner_epoch, region_map_epoch, program_module_hash, + payload_schema, requested_at + } + HandoffExportObserved { handoff_id, payload_digest, observed_at } + HandoffImportObserved { handoff_id, payload_digest, observed_at } + HandoffCompleted { + handoff_id, entity_ref, source_region, target_region, + payload_digest, new_owner_epoch, program_module_hash, payload_schema + } + HandoffCancelled { handoff_id, entity_ref, reason } + // legal only before SourceExported is committed + +Source-region journal: + EntityExported { + handoff_id, entity_ref, source_region, target_region, prior_owner_epoch, + source_event: WorldEvent, payload_schema, program_module_hash, + payload, payload_digest + } + +Destination-region journal: + EntityImported { + handoff_id, entity_ref, source_region, target_region, + prior_owner_epoch, new_owner_epoch, program_module_hash, + payload_schema, payload_digest, + destination_event: WorldEvent + } +``` + +Add one pure `WorldProgram::prepare_entity_transfer(request) -> plan` interface with typed `Export` and `Import` request/plan variants. The export plan returns `{payload_schema, payload, app_event}`; the import plan validates the envelope and returns a destination `app_event`. A default implementation returns `unsupported`, so programs without the transfer adapter continue to work. The host wraps the event in a host-originated `WorldEventKind::System` (`sequence = 0`, `participant_id = 0`) using a versioned envelope: `{protocol, direction, handoff_id, entity_ref, module_hash, payload_schema, payload_digest, payload_hex?, app_event}`. `payload_hex` is present for import; source export stores the payload beside the source event. System events are journaled/replayed but are not sequenced or broadcast to clients (`pkgs/id/src/world/mod.rs:334–340`; `pkgs/id/src/world/core.rs:310–332`). `EntityExported` stores its payload plus the source system event; `EntityImported` stores the destination system event, which carries the imported payload. On restore, the core replays the embedded event into the program and rebuilds the fence/import receipt. The hook does no I/O or mutation; the ordinary `update` applies the event, following the existing host-event order (update, then persist; `pkgs/id/src/world/actor.rs:401–440`). The actor rejects entity-targeted input for an exported `entity_ref`, and the coordinator routes that entity only after completion. The adapter owns app-payload serialization/versioning; the coordinator never parses it. This keeps application-owned state opaque while making the transfer seam explicit. + +In a region-sharded world, every state-changing application command must use an entity-addressed event (proposed `WorldEventKind::EntityInput { entity_ref, input }`) so the actor can fence the exported `entity_ref` without inspecting opaque app bytes. Reject legacy unscoped `Input(Vec)` in this mode; unsharded worlds retain existing `Input` behavior. A command that mutates multiple entities must declare all affected refs and is rejected if it crosses a seam; v1 does not emulate a cross-region transaction. This is an app-sharding contract: an `EntityInput` for one ref must not mutate other entities as a side effect. + +`handoff_id` is the receipt key in each independent journal; the coordinator verifies the source and destination entries by ID, entity, epoch, module/schema, and digest before completion. Internal handoff system events have no event sequence; ordering comes from their per-world journal order and the coordinator's durable state machine. The current `WorldJournal::append` returns `Result<()>`, not a storage position (`pkgs/id/src/world/mod.rs:685–708`), so this design does not invent a journal-offset API. `new_owner_epoch` is `prior_owner_epoch + 1`; it fences stale routes and is not a timestamp. + +Journal versioning and compaction are part of the format, not cleanup details. The current world journal max is version 2; reserve **version 3** for `EntityInput`, `EntityExported`, `EntityImported`, and the new checkpoint transfer metadata. Bump the world journal header atomically before the first append containing any of those kinds, so an older binary refuses the journal at open rather than failing mid-replay (`pkgs/id/src/world/mod.rs:646–683`; `pkgs/id/src/world_store.rs:143–197`). Extend `Checkpoint` with active source export payloads/fences, active destination import receipts/dedupe keys, and each entity's owner epoch; the program snapshot carries the actual app state. The coordinator checkpoint carries the region map and active handoff ledger. Without these fields compaction could resurrect an exported entity, forget an import, or drop the region map (`pkgs/id/src/world/core.rs:455–559`). A completed transfer's full payload may be released only after the existing retention/checkpoint rules preserve a compact ownership-epoch/tombstone record sufficient to reject stale commands and duplicate imports. The coordinator journal has its own versioned format and rollback gate. + +### Append order and idempotency + +1. The coordinator appends `HandoffStarted` before requesting export. It records the expected owner epoch and region-map epoch. Until export commits, A remains the owner and may continue normal writes; the export captures the state after those writes. A rejects the request if its current owner epoch no longer matches. +2. A applies the app's deterministic export system event, then appends one `EntityExported` entry containing both that internal event and the payload. Only after durable append does A acknowledge export. From this point A rejects mutations for this entity and retains the export record/payload until completion is durable. If append fails after the in-memory update, the existing actor contract makes A read-only; it must restart/replay before retrying. +3. After verifying A's durable receipt by `handoff_id`, the coordinator appends `HandoffExportObserved`, then sends the exact export envelope to B. +4. B applies the deterministic import system event, then appends one `EntityImported` entry before acknowledging. The first import for a `handoff_id` creates the entity; an identical retry returns the existing digest/receipt. Same ID with different entity, epoch, or digest is a hard conflict, never an overwrite. +5. After verifying B's durable receipt, the coordinator appends `HandoffImportObserved`, then appends `HandoffCompleted`. On replay, completion atomically changes the coordinator's owner map to B and increments the owner epoch. The destination accepts routed client operations only at that epoch; the source's export tombstone rejects old-epoch operations. +6. Completion is the sole success condition. A timeout is **stuck/in-transit**, not completed or rolled back. Keep source export data until the completion record is durable and normal retention policy permits deletion. + +On restart, the coordinator queries each side by `handoff_id` and appends any missing observation before continuing. It may resend at every seam. Each step is safe to retry by `handoff_id`, and every acknowledgement means the corresponding journal append is durable. No step assumes a transaction across journals. + +## 4. Client-visible states and legal operations + +| State | Authoritative copy / route | Reads | Writes | Client signal | +| --- | --- | --- | --- | --- | +| `at_source` (no source export committed; includes a journaled `HandoffStarted`) | A | Normal reads from A. | Normal writes to A. | Normal entity response. | +| `in_transit` (source export committed; destination not yet routable) | Durable export in A; B may have a duplicate import record but is not yet routed. | Entity data reads are rejected; the coordinator's handoff-status metadata is readable. | Reject; do not queue or replay commands. | Typed `ENTITY_IN_TRANSIT` with `handoff_id`, retryable flag, and status lookup/retry guidance. | +| `at_destination` (coordinator completion committed) | B at `new_owner_epoch`; routing map points to B. | Normal reads from B. | Normal writes to B. | Normal response, with new owner epoch available for stale-route detection. | +| `stuck` (in-transit with no coordinator-observed progress for 60 seconds) | Same durable owner as `in_transit`; this is an alert classification, not a new ownership state. | Same as `in_transit`. | Same as `in_transit`. | In-transit response plus operator-visible age/reason; no false success. | + +Rejecting entity data reads is conservative because the host cannot render an arbitrary app-owned payload: the existing program API renders the whole program's participant view and has no entity snapshot projection. A future app hook may support a clearly labeled read-only transit view. A client with a stale source route after completion receives a moved/stale-epoch response and retries through the coordinator; A never resumes writes. Command acceptance is not queued, so clients must retry after the entity is routable. + +Classify a handoff as `stuck` only after source export, when the latest coordinator-journaled progress (`HandoffExportObserved` or `HandoffImportObserved`) is more than **60 seconds** old. A stalled `HandoffStarted` with no source export is still `at_source`: A remains writable, and the coordinator retries or cancels only after proving no export exists. This configurable initial alert threshold does not alter the protocol, retry policy, or ownership; timestamps are for operator visibility only. + +The response is status-only, for example: + +```text +EntityInTransit { + entity_ref, handoff_id, source_region, target_region, + stage: Exported | ImportedAwaitingCoordinator | Stuck, + retryable: true +} +``` + +It contains neither the transfer payload nor a success-shaped entity view. Clients retry the original command only after the coordinator reports `at_destination`; the server does not retain/replay it. + +## 5. Recovery matrix + +| Failure | Durable facts after restart | Recovery | Must not do | +| --- | --- | --- | --- | +| Import never arrives / B is down before import | `HandoffStarted`; after export, A also has `EntityExported` and the full payload. | Keep the entity in transit; retry the same envelope when B is available. Alert after the stuck threshold. The state remains recoverable from A's journal. | Do not delete A's export, declare completion, or reactivate writes at A merely because a timer expired. | +| B commits import but reply is lost; import is sent twice | A has export; B has one `EntityImported` keyed by the same ID and digest. | B returns the existing import receipt on exact duplicate. Coordinator verifies the receipt and proceeds to completion. | Do not create a second entity or accept a different payload for that ID. | +| B goes down after import but before coordinator completion | A has export; B's journal has import (assuming durable append completed). | Keep routing/status in transit until B can be inspected and its import receipt is verified; then append completion. | Do not infer import failure from an unavailable B or roll back A. | +| Coordinator dies after `HandoffStarted`, before source export | Coordinator has start; A has no export and remains writable owner. | Replay the start and retry export. If cancelling, append `HandoffCancelled` only after verifying no source export committed. | Do not expose transit or move the route before the source fence. | +| Coordinator dies after source export, before import | Coordinator has start; A has durable export. | Reconcile by `handoff_id`, append missing `HandoffExportObserved`, resend payload to B, then continue. Until completion the entity is in transit. | Do not unfreeze A. | +| Coordinator dies after B import, before completion | Coordinator has start; A has export; B has import. | On recovery, query both receipts, compare ID/entity/epoch/digest, append any missing observed-receipt entries, then append completion and update the route. | Do not re-import as a new entity or infer success without both receipts. | +| A dies after export | A's committed journal is the durable source of transfer payload; coordinator has the start. | Recover A's journal, then resume the same handoff. If A cannot be recovered, surface a hard data-recovery fault; never silently complete. | Do not garbage-collect or replace the only durable export. | +| Append response is ambiguous on either side | The append may or may not be present. | Reopen/replay that side's journal by `handoff_id`; append only if absent, and treat an identical existing entry as success. If in-memory program state advanced but the append failed, the actor is read-only and must restart/replay before another attempt. | Do not blindly create a new handoff ID or acknowledge an unpersisted event. | + +If a journal is corrupted or the same ID is observed with a different digest, stop automatic recovery and surface an integrity error. No “best effort” merge is safe for a single-writer entity. + +If B refuses a payload or cannot load the matching program after A has durably exported, the handoff remains in transit and raises an operator-visible incompatibility fault. Preflight module hash/schema before `HandoffStarted`; a post-export rejection is not proof that B has no import and is not grounds to unfreeze A. Retry after repairing B. The durable source export remains the recovery copy. + +## 6. Coordinator responsibilities and non-responsibilities + +The coordinator journals the current region map/owner epoch, `HandoffStarted`, observed source/destination receipts, and `HandoffCompleted` (plus a pre-export cancellation if needed). It serializes handoffs for one entity, correlates receipts, retries idempotently, exposes transit/stuck status, and reconciles missing observations/completion after restart. Its owner map changes only through replay of a verified completion. + +The coordinator does **not** apply entity state, co-commit journals, make both regions writable, choose a winner between divergent copies, or roll back a post-export transfer without proving B did not import. The region journals remain the authorities for their own durable facts. This is coordination and recovery, not cross-region transaction emulation. + +## Non-goals + +- Selecting the region-sharding rung or its hotness/locality thresholds; this protocol runs only after that decision. +- Hosting-jurisdiction migration (here, “region” means a spatial shard), native-node write leases from #2819, or shard re-merge. The #2059 investigation treats re-merge as a separate state-import/reconciliation design, not journal concatenation. +- Cross-region atomic writes, multi-entity transfer transactions, a durable client command queue, or automatic rollback after export. +- Moving `WorldCore` identity, world-level files/modules/outboxes, or credentials with the application entity. + +## 7. Invariants and implementation acceptance + +1. **No duplicate writer:** at most one region accepts entity mutations at a given owner epoch. A's export append fences A before B's import can become routable; stale epoch/region writes are rejected. +2. **No silent loss:** after export commits, the payload remains durably recoverable in A until B's matching import and coordinator completion are verified. Do not report success based only on a message/timeout. +3. **Exactly-once effect, at-least-once delivery:** retry may deliver export/import repeatedly, but each `handoff_id` materializes one destination entity and one owner-map transition. +4. **Replay is deterministic:** rebuilding coordinator routing and per-world entity state from journals yields the same outcome; repeated/reordered network messages cannot bypass journal order. +5. **Monotonic ownership:** `new_owner_epoch` increases once per completed handoff; an old owner cannot become writable again by replaying a stale route. +6. **No cross-region atomicity claim:** a committed export with no completed import is observably in transit, not a successful transfer. +7. **Retention:** source export payload is not removed until the completion receipt is durable and the implementation's ordinary journal-retention/checkpoint rules preserve an equivalent recoverable record. +8. **Application-state scope:** only the app-defined entity payload and its deterministic export/import event move. World-local participants, join capabilities, sessions, IDs, world policy, modules, files, and outboxes are not silently copied. A destination must authorize/rebind clients under its own world-local identity rules. +9. **Format compatibility:** source and destination program module hashes and payload schema versions must match the transfer contract, or the destination refuses import before it mutates. Source event sequence is provenance only; B allocates its own local event sequence and never imports source participant IDs/capabilities. +10. **Compaction safety:** checkpoints preserve active transfer state, owner epochs, and enough import dedupe/fence data to make replay and retries equivalent to the un-compacted journal. + +Before marking implementation complete, tests must cover: all three normal states and legal operations; source append failure before/after commit; target append failure and ambiguous acknowledgement; exact and conflicting duplicate imports; coordinator restart after each protocol transition; B unavailable before/after import; stale source route after completion; replay and checkpoint compaction; module/schema mismatch; payload oversize rejected before the source fence; and source export retention until completion. A failure-injection end-to-end test must prove no duplicate entity, no accepted write at A after export, and no completion without a matching durable B import. + +## 8. Phased implementation plan + +These are independently mergeable packets. Each keeps existing worlds readable and leaves the handoff path unreachable until its packet is complete; the final integration packet enables the flow. + +1. **Journal/schema/checkpoint foundation.** Add typed coordinator/source/destination entries, the entity-addressed input kind, stable ID/epoch/digest fields, world journal version 3 bump-on-first-write and rollback behavior, checkpoint preservation for active handoffs/tombstones, and serialization/restore/compaction fixtures. No routing behavior changes. This can merge independently and establishes the exact durable format. +2. **Program transfer contract and source export/fence.** Extend `WorldProgram` with the pure `prepare_entity_transfer` hook and add the region-sharded mode gate. Source update + payload + `EntityExported` receipt form one replayable local journal fact; actor rejects later input for that `entity_ref`. Bound the payload and reject oversize before fencing. Tests prove deterministic replay, per-journal append order, and durable fence. No external route exposes it yet. +3. **Destination import primitive.** Validate module/schema/digest and apply the app-provided system event through one `EntityImported` journal fact; same-ID exact retry returns the existing receipt without replaying the app event. Conflicting duplicate IDs fail closed. Tests cover retry, replay, dedupe after checkpoint, and unsupported payload. No coordinator route changes yet. +4. **Coordinator state machine and reconciliation.** Journal starts, observed source/destination receipts, and completion; serialize handoffs per entity; drive source then destination; retry ambiguous outcomes; recover by querying receipts; and switch owner map only on verified completion. Add failure-injection coverage for coordinator and region restarts. +5. **Client routing and operations.** Expose transit/stuck status, retryable typed responses, fail-closed entity reads/writes while in transit, stale-route responses, and observability for age/reason. Enable region-seam handoffs behind a feature gate; run the full no-loss/no-duplicate acceptance suite before enabling by default. + +Dependencies: 1 → 2 → 3 → 4 → 5. Each packet is independently mergeable after its predecessor; source and destination work are sequential because they extend the same actor/journal seams. No packet before 4 claims the protocol works end-to-end. + +## 9. Open questions for Drew + +1. **What is the transfer unit?** (A) An app-owned domain entity, with a stable app-defined `entity_ref`; (B) a world participant/capability/session as well; or (C) an entire program/world snapshot. Recommend **A**: `WorldCore` identity and capabilities are world-local, while the app state is opaque; copying B's identity wholesale would bypass its own membership/auth rules, and C moves every entity rather than one seam-crossing entity. This design assumes A and explicitly excludes world-level identity/state. +2. **Should entity reads work during transit?** (A) Reject entity reads and writes but expose handoff status; (B) add an app-specific, explicitly read-only projection of the frozen payload; or (C) queue/replay writes. Recommend **A** for v1 because the host cannot render arbitrary app payloads today, it gives an unambiguous no-write window, and queuing introduces a separate durable command-replay/deduplication protocol. B can be added by an app hook; C is out of scope. +3. **Is a 16 KiB initial payload cap sufficient?** (A) Keep v1 bounded at 16 KiB and reject larger transfers before export; (B) require chunked manifests now; or (C) choose a larger measured bound. Recommend **A** until representative entity sizes are known; issue a separate chunking design if the cap blocks real workloads. The existing 16 KiB input cap is only a sizing reference, not an existing transfer limit. + +The protocol can proceed with the recommendations as defaults; no question blocks completing the design or beginning implementation. In particular, no cross-region transaction, rollback-on-timeout, or write queue depends on a Drew decision. + +## References + +- [Issue #2818](https://github.com/developing-today/code/issues/2818): record-pair, client-observation, failure-recovery, and coordinator requirements. +- [Issue #2059 completion comment](https://github.com/developing-today/code/issues/2059#issuecomment-6532089391), 2026-10-30: region-shard rung, in-transit semantics, no cross-region atomicity, journal remains single-writer, and follow-up routing. +- [Landed hot-world investigation](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md:161–181,228–269,307–326): source-of-truth region-shard decisions and explicit non-goals. +- [Issue #2819](https://github.com/developing-today/code/issues/2819): sibling native-spill lease protocol; not a prerequisite for this region transfer. +- `pkgs/id/src/world/actor.rs:248–259`: one serialized actor owns core, program, and journal; `375–392`: durable append includes fsync and append failure makes the world read-only. +- `pkgs/id/src/world/mod.rs:468–644`: current `JournalEntry` kinds; `579–585`: `CrossWorldWrite` is an acceptance-policy setting, not a transfer; `646–683`: journal-version compatibility and bump requirement; `685–708`: append-before-ack contract; `871–925`: `WorldProgram` has opaque input and whole-program snapshot/view hooks, but no entity transfer hooks. +- `pkgs/id/src/world/core.rs:130–171,333–423`: restore validates world header/sequence and replays committed input; `455–559`: compaction rebuilds a reduced journal with a whole-program checkpoint, so transfer fences/receipts must be preserved explicitly. +- `pkgs/id/src/world/mod.rs:57–100`: current default limits include 16 KiB opaque input and a 512 KiB client snapshot frame; neither is an entity-transfer limit. +- `pkgs/id/src/world_hub.rs:1–19,62–100`: `WorldHub` opens/leases named worlds but has no region map/handoff coordinator; `pkgs/id/src/groups/worlds.rs:33–39`: cross-world writes are explicitly not allowed by the current group model. +- `pkgs/id/src/world_store.rs:366–398`: each world also has separate directory, petname, outbox, and module storage; those remain outside the app-entity transfer payload in v1. From c8dfed7cab11a42394f68ec54c904f0f2da5fc17 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 11:36:39 -0600 Subject: [PATCH 2/2] docs(id): align handoff design with triage --- doc/2026-11-01_design_id2818.md | 54 ++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/doc/2026-11-01_design_id2818.md b/doc/2026-11-01_design_id2818.md index 501ce54dab..f1a9ccea3f 100644 --- a/doc/2026-11-01_design_id2818.md +++ b/doc/2026-11-01_design_id2818.md @@ -15,7 +15,7 @@ This selects the two-step export/import seam described by #2059 and makes its tr The #2059 investigation selected sibling shard-worlds under a thin coordinator for **spatial** locality (its rung 2; cross-region writes are expected to be rare). It explicitly accepts that cross-region atomicity does not exist and that an entity may be visibly in transit. It left the record format open. The #2818 acceptance criteria require a journaled export/import pair, client-visible state and legal operations, recovery for missing/duplicate imports and coordinator/region failures, and a coordinator that never emulates a cross-region transaction. These are design constraints, not implementation claims. ([#2818](https://github.com/developing-today/code/issues/2818); [#2059 completion comment](https://github.com/developing-today/code/issues/2059#issuecomment-6532089391), 2026-10-30; [landed investigation](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md:161–181,228–269,307–326).) -The newer #2059 landing says the source-of-truth journal remains single-writer; it rejects multi-writer journal splitting. The sibling #2819 design is separate and concerns native-node write leases; this handoff does not depend on that lease protocol. Both designs should reuse the current journaled-entry conventions rather than invent another persistence path. ([#2059 completion comment](https://github.com/developing-today/code/issues/2059#issuecomment-6532089391); [#2819](https://github.com/developing-today/code/issues/2819), latest comment.) +The newest #2818 triage record fixes the handoff as dedicated shard journal entries plus coordinator open/close records, requires journal-before-apply, and limits coordinator state to membership, region map, and handoffs (no entity payload). It also pins payload shape/bounds and complete-vs-stuck as decisions for this note ([#2818 triage](https://github.com/developing-today/code/issues/2818#issuecomment-6560923802)). The sibling #2819 design uses a DO-only lease append gate for native spill and explicitly says #2818 shares only journal-entry conventions, not its lease or coordinator protocol ([#2819 design](https://github.com/developing-today/code/pull/3857), `doc/2026-11-01_design_id2819.md:5`; [#2819 triage](https://github.com/developing-today/code/issues/2819#issuecomment-6560910098)). Both designs should persist typed records before applying in-memory ownership/control state, but the region handoff and native execution lease remain separate protocols. Each world currently has one serialized authority owning its core, program, and journal; durable append includes fsync, and an append failure makes that world read-only (`pkgs/id/src/world/actor.rs:248–259,375–392`; `pkgs/id/src/world/mod.rs:685–708`). The `WorldProgram` interface accepts opaque input and can snapshot the **whole** program, but has no entity-level transfer hooks (`pkgs/id/src/world/mod.rs:871–925`). Therefore this proposal adds a transfer contract rather than claiming the code already supports entity export/import. @@ -25,16 +25,22 @@ The issue calls out `CrossWorldWrite` as an entry-pattern reference, but current | Option | Benefits | Costs / failure mode | Decision | | --- | --- | --- | --- | -| **A. Coordinator-mediated distributed transaction / 2PC** | Could hide the transit state if every participant stayed available. | Conflicts with #2059's explicit no-cross-region-atomicity decision; failure recovery requires transaction emulation and can block both regions. | Reject. | -| **B. Copy state to B, then delete/fence A** | Simple happy path; short apparent handoff. | A and B can both accept writes between the copy and fence; a lost acknowledgement can cause duplicate ownership or an ambiguous rollback. | Reject. | -| **C. Journaled intent, export/fence, import, completion** | Each side records durable local facts; retry and recovery use stable IDs; source stops writes before destination activation; coordinator state is reconstructible without a cross-world commit. | An entity can be unavailable while in transit; completion may wait for a down region or coordinator. Requires an app-level transfer hook because host program state is opaque. | **Recommend.** | -| **D. Move the whole world program snapshot** | Uses the existing `WorldProgram::snapshot`/restore path. | Moves every entity in a shard, not one entity at a seam; cannot implement selective region handoff and bypasses the required per-entity coordinator state. | Reject for this issue. | +| **1. Dedicated `EntityExported` / `EntityImported` journal variants plus coordinator open/close records** | Each shard journal is authoritative for its side; replay semantics are explicit; coordinator restart can reconcile from receipts. Matches the typed `JournalEntry` convention at `world/mod.rs:468–475`. | Adds new versioned entry types and checkpoint state; entity can be unavailable while in transit. | **Recommend.** | +| **2. Encode handoff payloads in generic `Committed` events** | Reuses the existing app-event path and sequence. | Hides the handoff state machine inside opaque program bytes, mixes host control with client-visible event streams, and makes recovery/dedupe less explicit. | Reject. | +| **3. Coordinator-only records; shard journals store nothing** | Smallest coordinator format. | Contradicts #2059's requirement that each region journals its export/import; the coordinator cannot prove which side applied or deduplicate a retry after a region restart without shard-local receipts. It would also have to store entity state, contrary to the latest #2818 triage. | Reject. | +| **4. Coordinator-mediated distributed transaction / 2PC** | Could hide the transit state if every participant stayed available. | Conflicts with #2059's explicit no-cross-region-atomicity decision; failure recovery requires transaction emulation and can block both regions. | Reject. | +| **5. Copy state to B, then delete/fence A** | Simple happy path; short apparent handoff. | A and B can both accept writes between the copy and fence; a lost acknowledgement can cause duplicate ownership or an ambiguous rollback. | Reject. | +| **6. Move the whole `WorldProgram` snapshot** | Uses the existing whole-program snapshot/restore path. | Moves every entity in a shard, not one entity at a seam; it cannot implement selective region handoff. | Reject. | + +### Payload choice + +Transfer a **complete application-defined snapshot of the one entity** in `EntityExported`, not the whole `WorldProgram` snapshot and not a source-journal reference. A source-journal reference can reduce bytes, but it makes B depend on A's journal retention/availability and on reconstructing source-local history; compaction or A loss would strand the transfer. The self-contained entity payload is larger but lets B import from the source's durable export record and then lets A release the payload after coordinator completion. The v1 transfer payload is capped at 16 KiB; oversized entities are refused before A is fenced. Chunking is a separately designed extension, not an implicit fallback. The outage is deliberate: preserving a single writer and recoverable state outranks seamless writes. Do not automatically roll an exported entity back to A while B's journal is unavailable; absence of an import cannot be proven when B cannot be inspected. ## 3. Journal format -Use an opaque, coordinator-generated `handoff_id` that is stable across retries, and an application-defined stable `entity_ref` that is not a world-local participant ID. The coordinator serializes handoffs per entity. The program hook returns a versioned, opaque entity payload and deterministic app event that removes/adds that entity. The host journals the payload, digest, and corresponding app event in one per-world journal entry, so replay applies the ownership-changing app event from the same durable fact. Source and destination must run the same program module hash for v1; schema/module mismatch is rejected before either region commits a handoff record. Do not treat a region-local event sequence as globally ordered; each side's sequence is local and is carried as an opaque receipt value. +Use a fresh coordinator-generated random 128-bit `handoff_id`, uniqueness-checked and persisted in `HandoffStarted` before any shard side effect; reuse it for every retry and never derive it from a timestamp or entity ID. A new crossing (including a later crossing back) gets a new ID; it is not a shard/journal merge. Pair it with an application-defined stable `entity_ref` that is not a world-local participant ID. The coordinator serializes handoffs per entity. The program hook returns a versioned, opaque **complete entity snapshot** and deterministic app event that removes/adds that entity. The host journals the payload, digest, and corresponding app event in one per-shard journal entry, so replay applies the ownership-changing app event from the same durable fact. Source and destination must run the same program module hash for v1; schema/module mismatch is rejected before either region commits a handoff record. Journal order is local to each shard; correlate the two sides by `handoff_id` and verify matching payload digests, not by comparing event sequences. There is no existing entity-transfer size limit. Add `transfer_payload_bytes`, independent of `input_bytes` and `snapshot_bytes`; start with a conservative **16 KiB v1 payload cap** (the current default opaque-input size is 16 KiB) and reject an oversized proposal before source export/fencing. Encode the destination event's payload as hex so the versioned system-event JSON (payload plus app event and metadata) stays below the existing 64 KiB event limit (`pkgs/id/src/world_caps.rs:65`; `pkgs/id/src/world/actor.rs:409–417`); enforce a separate checked maximum on the full handoff journal entry. Chunking is not part of v1: it needs its own manifest/chunk durability and recovery protocol. These are recommended limits to revisit with real entity-size measurements, not limits already enforced by the code (`pkgs/id/src/world/mod.rs:57–100`). @@ -51,7 +57,8 @@ Coordinator journal: HandoffImportObserved { handoff_id, payload_digest, observed_at } HandoffCompleted { handoff_id, entity_ref, source_region, target_region, - payload_digest, new_owner_epoch, program_module_hash, payload_schema + payload_digest, new_owner_epoch, new_region_map_epoch, + program_module_hash, payload_schema } HandoffCancelled { handoff_id, entity_ref, reason } // legal only before SourceExported is committed @@ -72,7 +79,11 @@ Destination-region journal: } ``` -Add one pure `WorldProgram::prepare_entity_transfer(request) -> plan` interface with typed `Export` and `Import` request/plan variants. The export plan returns `{payload_schema, payload, app_event}`; the import plan validates the envelope and returns a destination `app_event`. A default implementation returns `unsupported`, so programs without the transfer adapter continue to work. The host wraps the event in a host-originated `WorldEventKind::System` (`sequence = 0`, `participant_id = 0`) using a versioned envelope: `{protocol, direction, handoff_id, entity_ref, module_hash, payload_schema, payload_digest, payload_hex?, app_event}`. `payload_hex` is present for import; source export stores the payload beside the source event. System events are journaled/replayed but are not sequenced or broadcast to clients (`pkgs/id/src/world/mod.rs:334–340`; `pkgs/id/src/world/core.rs:310–332`). `EntityExported` stores its payload plus the source system event; `EntityImported` stores the destination system event, which carries the imported payload. On restore, the core replays the embedded event into the program and rebuilds the fence/import receipt. The hook does no I/O or mutation; the ordinary `update` applies the event, following the existing host-event order (update, then persist; `pkgs/id/src/world/actor.rs:401–440`). The actor rejects entity-targeted input for an exported `entity_ref`, and the coordinator routes that entity only after completion. The adapter owns app-payload serialization/versioning; the coordinator never parses it. This keeps application-owned state opaque while making the transfer seam explicit. +`HandoffStarted.region_map_epoch` records the map version observed when the transfer was requested. At completion the coordinator rechecks this entity's current owner against `expected_owner_epoch`, updates only that entity, and records `new_region_map_epoch = current_map_epoch + 1`; unrelated map changes do not invalidate this handoff. + +Add one pure `WorldProgram::prepare_entity_transfer(request) -> plan` interface with typed `Export` and `Import` request/plan variants. The export plan returns `{payload_schema, payload, app_event}`; the import plan validates the envelope and returns a destination `app_event`. A default implementation returns `unsupported`, so programs without the transfer adapter continue to work. The host wraps the event in a host-originated `WorldEventKind::System` (`sequence = 0`, `participant_id = 0`) using a versioned envelope: `{protocol, direction, handoff_id, entity_ref, module_hash, payload_schema, payload_digest, payload_hex?, app_event}`. `payload_hex` is present for import; source export stores the payload beside the source event. System events are journaled/replayed but are not sequenced or broadcast to clients (`pkgs/id/src/world/mod.rs:334–340`; `pkgs/id/src/world/core.rs:310–332`). `EntityExported` stores its payload plus the source system event; `EntityImported` stores the destination system event, which carries the imported payload. On restore, the core replays the embedded event into the program and rebuilds the fence/import receipt. The hook does no I/O or mutation; it pre-validates the event so the actor can journal first and apply second. The actor rejects entity-targeted input for an exported `entity_ref`, and the coordinator routes that entity only after completion. The adapter owns app-payload serialization/versioning; the coordinator never parses it. This keeps application-owned state opaque while making the transfer seam explicit. + +The required order is **prepare/validate → persist typed record → apply in-memory state → acknowledge**. This follows `set_cross_world_write`, which persists before mutating `WorldCore` (`pkgs/id/src/world/actor.rs:882–900`), and the newest #2818 triage invariant. Do not route handoffs through `WorldActor::deliver`: that existing host-event path updates the program before persistence because it lacks a pure prepare step (`pkgs/id/src/world/actor.rs:401–440`). If the post-append `update` still fails despite pre-validation, mark the actor/program unavailable, withhold the receipt, and recover by replaying the durable event; never roll back the journal or continue serving from divergent memory. In a region-sharded world, every state-changing application command must use an entity-addressed event (proposed `WorldEventKind::EntityInput { entity_ref, input }`) so the actor can fence the exported `entity_ref` without inspecting opaque app bytes. Reject legacy unscoped `Input(Vec)` in this mode; unsharded worlds retain existing `Input` behavior. A command that mutates multiple entities must declare all affected refs and is rejected if it crosses a seam; v1 does not emulate a cross-region transaction. This is an app-sharding contract: an `EntityInput` for one ref must not mutate other entities as a side effect. @@ -83,13 +94,13 @@ Journal versioning and compaction are part of the format, not cleanup details. T ### Append order and idempotency 1. The coordinator appends `HandoffStarted` before requesting export. It records the expected owner epoch and region-map epoch. Until export commits, A remains the owner and may continue normal writes; the export captures the state after those writes. A rejects the request if its current owner epoch no longer matches. -2. A applies the app's deterministic export system event, then appends one `EntityExported` entry containing both that internal event and the payload. Only after durable append does A acknowledge export. From this point A rejects mutations for this entity and retains the export record/payload until completion is durable. If append fails after the in-memory update, the existing actor contract makes A read-only; it must restart/replay before retrying. -3. After verifying A's durable receipt by `handoff_id`, the coordinator appends `HandoffExportObserved`, then sends the exact export envelope to B. -4. B applies the deterministic import system event, then appends one `EntityImported` entry before acknowledging. The first import for a `handoff_id` creates the entity; an identical retry returns the existing digest/receipt. Same ID with different entity, epoch, or digest is a hard conflict, never an overwrite. -5. After verifying B's durable receipt, the coordinator appends `HandoffImportObserved`, then appends `HandoffCompleted`. On replay, completion atomically changes the coordinator's owner map to B and increments the owner epoch. The destination accepts routed client operations only at that epoch; the source's export tombstone rejects old-epoch operations. -6. Completion is the sole success condition. A timeout is **stuck/in-transit**, not completed or rolled back. Keep source export data until the completion record is durable and normal retention policy permits deletion. +2. A runs the pure transfer hook, validates the proposed event, then durably appends one `EntityExported` entry **before applying** that internal event. After append, A installs the source fence and applies the pre-validated event; only then does it acknowledge export. A rejects mutations from the moment the entry is durable and retains its payload until completion. If application fails after append, A becomes unavailable/read-only, emits no export receipt, and must restore/replay that entry before service resumes. +3. After verifying A's durable, applied receipt by `handoff_id`, the coordinator appends `HandoffExportObserved`, then sends the exact export envelope to B. +4. B validates the envelope and proposed import event, then durably appends one `EntityImported` entry **before applying** the internal event. The first import for a `handoff_id` creates the entity; an identical retry returns the existing digest/receipt without applying twice. B acknowledges import only after the program event is applied (or successfully replayed after restart). Same ID with different entity, epoch, or digest is a hard conflict, never an overwrite. +5. After verifying B's durable, applied receipt, the coordinator appends `HandoffImportObserved`, then appends `HandoffCompleted` **before** changing the in-memory owner map or exposing B. On replay, completion changes the coordinator's owner map to B and increments the per-entity owner epoch and region-map epoch. The destination accepts routed client operations only at that owner epoch; the source's export tombstone rejects old-epoch operations. +6. A handoff is **complete iff** B's matching `EntityImported` entry is durable and applied **and** the coordinator's `HandoffCompleted` closure record is durable. A timeout is **stuck/in-transit**, not completed or rolled back. Keep source export data until the completion record is durable and normal retention policy permits deletion. -On restart, the coordinator queries each side by `handoff_id` and appends any missing observation before continuing. It may resend at every seam. Each step is safe to retry by `handoff_id`, and every acknowledgement means the corresponding journal append is durable. No step assumes a transaction across journals. +On restart, the coordinator queries each side by `handoff_id` and appends any missing observation before continuing. It may resend at every seam. Each step is safe to retry by `handoff_id`, and every externally visible acknowledgment means the relevant record is durable **and its local in-memory state change has applied**. If an event fails after its record commits, that actor fails closed and cannot return a receipt until journal replay succeeds. No step assumes a transaction across journals. ## 4. Client-visible states and legal operations @@ -126,8 +137,10 @@ It contains neither the transfer payload nor a success-shaped entity view. Clien | Coordinator dies after `HandoffStarted`, before source export | Coordinator has start; A has no export and remains writable owner. | Replay the start and retry export. If cancelling, append `HandoffCancelled` only after verifying no source export committed. | Do not expose transit or move the route before the source fence. | | Coordinator dies after source export, before import | Coordinator has start; A has durable export. | Reconcile by `handoff_id`, append missing `HandoffExportObserved`, resend payload to B, then continue. Until completion the entity is in transit. | Do not unfreeze A. | | Coordinator dies after B import, before completion | Coordinator has start; A has export; B has import. | On recovery, query both receipts, compare ID/entity/epoch/digest, append any missing observed-receipt entries, then append completion and update the route. | Do not re-import as a new entity or infer success without both receipts. | +| Coordinator dies after durable `HandoffCompleted`, before in-memory map update | Coordinator journal has completion; A is fenced; B has durable import. | Replay completion to derive B as owner before admitting routed operations. | Do not serve from stale in-memory map or reopen writes at A. | +| Region dies after a journal-before-apply record, before its app event applies | Export/import record is durable; the program may still be at the prior state. | Keep that actor unavailable; restore/replay the durable event, then return the receipt. Coordinator does not progress until the actor confirms replay/apply. | Do not treat the record alone as an applied receipt or serve partially applied state. | | A dies after export | A's committed journal is the durable source of transfer payload; coordinator has the start. | Recover A's journal, then resume the same handoff. If A cannot be recovered, surface a hard data-recovery fault; never silently complete. | Do not garbage-collect or replace the only durable export. | -| Append response is ambiguous on either side | The append may or may not be present. | Reopen/replay that side's journal by `handoff_id`; append only if absent, and treat an identical existing entry as success. If in-memory program state advanced but the append failed, the actor is read-only and must restart/replay before another attempt. | Do not blindly create a new handoff ID or acknowledge an unpersisted event. | +| Append response is ambiguous on either side | The append may or may not be present; if present, the actor may or may not have applied its event. | Reopen/replay that side's journal by `handoff_id`; if the identical entry exists, apply/replay it before returning the receipt; if absent, retry the same ID. A failed append leaves the actor unavailable/read-only until reopen. | Do not blindly create a new handoff ID, apply before durable append, or acknowledge an unpersisted event. | If a journal is corrupted or the same ID is observed with a different digest, stop automatic recovery and surface an integrity error. No “best effort” merge is safe for a single-writer entity. @@ -139,6 +152,8 @@ The coordinator journals the current region map/owner epoch, `HandoffStarted`, o The coordinator does **not** apply entity state, co-commit journals, make both regions writable, choose a winner between divergent copies, or roll back a post-export transfer without proving B did not import. The region journals remain the authorities for their own durable facts. This is coordination and recovery, not cross-region transaction emulation. +**Recovery ownership:** the coordinator is responsible for retry and reconciliation from `HandoffStarted` through completion/cancellation; A is responsible for retaining the self-contained export after its journal commits; B is responsible for its durable import/dedupe receipt. Once an exported handoff has no coordinator-observed progress for 60 seconds, the operator/on-call owner investigates the coordinator, A, or B and repairs availability. There is no automatic rollback; ownership and recovery evidence remain in the journals. + ## Non-goals - Selecting the region-sharding rung or its hotness/locality thresholds; this protocol runs only after that decision. @@ -166,8 +181,8 @@ Before marking implementation complete, tests must cover: all three normal state These are independently mergeable packets. Each keeps existing worlds readable and leaves the handoff path unreachable until its packet is complete; the final integration packet enables the flow. 1. **Journal/schema/checkpoint foundation.** Add typed coordinator/source/destination entries, the entity-addressed input kind, stable ID/epoch/digest fields, world journal version 3 bump-on-first-write and rollback behavior, checkpoint preservation for active handoffs/tombstones, and serialization/restore/compaction fixtures. No routing behavior changes. This can merge independently and establishes the exact durable format. -2. **Program transfer contract and source export/fence.** Extend `WorldProgram` with the pure `prepare_entity_transfer` hook and add the region-sharded mode gate. Source update + payload + `EntityExported` receipt form one replayable local journal fact; actor rejects later input for that `entity_ref`. Bound the payload and reject oversize before fencing. Tests prove deterministic replay, per-journal append order, and durable fence. No external route exposes it yet. -3. **Destination import primitive.** Validate module/schema/digest and apply the app-provided system event through one `EntityImported` journal fact; same-ID exact retry returns the existing receipt without replaying the app event. Conflicting duplicate IDs fail closed. Tests cover retry, replay, dedupe after checkpoint, and unsupported payload. No coordinator route changes yet. +2. **Program transfer contract and source export/fence.** Extend `WorldProgram` with the pure `prepare_entity_transfer` hook and add the region-sharded mode gate. Validate the source event, append event+payload in `EntityExported`, then install the fence and apply; the actor rejects later input for that `entity_ref`. Bound the payload and reject oversize before fencing. If apply fails, return no receipt and recover by replay. Tests prove deterministic replay, persist-before-apply, and durable fence. No external route exposes it yet. +3. **Destination import primitive.** Validate module/schema/digest, append the import event in one `EntityImported` journal fact, then apply the app event; same-ID exact retry returns the existing receipt without replaying twice. Conflicting duplicate IDs fail closed. A receipt is returned only after application/replay succeeds. Tests cover persist-before-apply, retry, replay, dedupe after checkpoint, and unsupported payload. No coordinator route changes yet. 4. **Coordinator state machine and reconciliation.** Journal starts, observed source/destination receipts, and completion; serialize handoffs per entity; drive source then destination; retry ambiguous outcomes; recover by querying receipts; and switch owner map only on verified completion. Add failure-injection coverage for coordinator and region restarts. 5. **Client routing and operations.** Expose transit/stuck status, retryable typed responses, fail-closed entity reads/writes while in transit, stale-route responses, and observability for age/reason. Enable region-seam handoffs behind a feature gate; run the full no-loss/no-duplicate acceptance suite before enabling by default. @@ -184,10 +199,13 @@ The protocol can proceed with the recommendations as defaults; no question block ## References - [Issue #2818](https://github.com/developing-today/code/issues/2818): record-pair, client-observation, failure-recovery, and coordinator requirements. +- [Issue #2818 triage record](https://github.com/developing-today/code/issues/2818#issuecomment-6560923802), 2026-11-01: dedicated journal variants, journal-before-apply, payload/stuck decisions, coordinator scope, and no packet enqueue before design. - [Issue #2059 completion comment](https://github.com/developing-today/code/issues/2059#issuecomment-6532089391), 2026-10-30: region-shard rung, in-transit semantics, no cross-region atomicity, journal remains single-writer, and follow-up routing. - [Landed hot-world investigation](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md:161–181,228–269,307–326): source-of-truth region-shard decisions and explicit non-goals. - [Issue #2819](https://github.com/developing-today/code/issues/2819): sibling native-spill lease protocol; not a prerequisite for this region transfer. -- `pkgs/id/src/world/actor.rs:248–259`: one serialized actor owns core, program, and journal; `375–392`: durable append includes fsync and append failure makes the world read-only. +- [Issue #2819 design](https://github.com/developing-today/code/pull/3857): shares journal-before-apply and typed journal records only; lease authority and protocol remain separate. +- `pkgs/id/src/world/actor.rs:248–259`: one serialized actor owns core, program, and journal; `375–392`: durable append includes fsync and append failure makes the world read-only; `882–900`: policy-state precedent persists before mutating core. +- `pkgs/id/src/world/actor.rs:401–440`: current host-event path updates program before persist; region handoff intentionally uses a new prepare/validate → persist → apply path to satisfy #2818's latest triage invariant. - `pkgs/id/src/world/mod.rs:468–644`: current `JournalEntry` kinds; `579–585`: `CrossWorldWrite` is an acceptance-policy setting, not a transfer; `646–683`: journal-version compatibility and bump requirement; `685–708`: append-before-ack contract; `871–925`: `WorldProgram` has opaque input and whole-program snapshot/view hooks, but no entity transfer hooks. - `pkgs/id/src/world/core.rs:130–171,333–423`: restore validates world header/sequence and replays committed input; `455–559`: compaction rebuilds a reduced journal with a whole-program checkpoint, so transfer fences/receipts must be preserved explicitly. - `pkgs/id/src/world/mod.rs:57–100`: current default limits include 16 KiB opaque input and a 512 KiB client snapshot frame; neither is an entity-transfer limit.