From a08aa67ef0b8a4f24d9c9381d5e7572f3dd6ccc9 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 11:05:05 -0600 Subject: [PATCH] docs(id): design jurisdiction-partitioned worlds --- doc/2026-11-01_design_id3397.md | 129 ++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 doc/2026-11-01_design_id3397.md diff --git a/doc/2026-11-01_design_id3397.md b/doc/2026-11-01_design_id3397.md new file mode 100644 index 0000000000..d43a074510 --- /dev/null +++ b/doc/2026-11-01_design_id3397.md @@ -0,0 +1,129 @@ +# Design: jurisdiction-partitioned hosted worlds and world blobs + +- Date: 2026-11-01 +- Status: **proposed design only** — this note does not authorize implementation or make a residency claim. +- Issue: [#3397](https://github.com/developing-today/code/issues/3397), coordinated with [#2283](https://github.com/developing-today/code/issues/2283), [#2284](https://github.com/developing-today/code/issues/2284), and [#2059](https://github.com/developing-today/code/issues/2059). +- Source of truth: the authoritative account jurisdiction established by #2283; this design adds a fixed jurisdiction to each hosted world and its owned data. A client-supplied region or world name is never authoritative. +- Implementation follow-ons #3399–#3404 already exist under #2283. They are dependencies, not authorization to implement this issue; this note calls out the world-specific gaps they do not fully cover. + +## Decision to make + +Choose what a jurisdiction partition means for hosted-world identity, names, membership, participant metadata, shards, world-owned blobs, and lifecycle. The central product decision is whether an account from another jurisdiction can be an explicitly invited guest in a world hosted in one partition, or whether account and world jurisdictions must always match. + +### Recommendation + +Give every hosted world exactly one immutable jurisdiction, selected from the account's authoritative jurisdiction at creation. Names, world state, participant records, shards, and world-owned blobs resolve and remain inside that partition. Do not replicate a world across jurisdictions or move it live. + +Following the later, issue-specific recommendation recorded on #3397, support **explicit guest membership** as the proposed cross-jurisdiction case: the guest's account store remains in its home jurisdiction, while that guest's world activity and membership metadata are world data in the hosting jurisdiction. A mismatch without an explicit, valid guest grant fails closed. This is not federation or a second copy of the world. + +This guest recommendation conflicts with the open #2284 investigation PR #3407, which recommends denying cross-jurisdiction membership, reads, writes, invites, and participant-list visibility. The contract and tests below make the guest exception explicit rather than silently treating a mismatch as valid. Drew must settle the policy before guest admission is enabled; until then, deployments deny it. See [Open questions](#open-questions). + +## Context and grounding + +The current `id serve` world path is self-hosted Iroh storage, not a jurisdiction-aware hosted Durable Object/R2 implementation. `WorldHub` maps names to services and stores slots in `HashMap` ([`world_hub.rs:3-19,201-208`](../pkgs/id/src/world_hub.rs#L3-L19)); the durable path is `.id-worlds/` and checks for a journal at that path ([`serve.rs:419-431,533-535`](../pkgs/id/src/commands/serve.rs#L419-L431)). The hub's current cross-world gate checks isolation and a write setting, not jurisdiction ([`world_hub.rs:282-314`](../pkgs/id/src/world_hub.rs#L282-L314)). These are useful existing seams, not hosted partition behavior. + +Each `ServeWorlds` instance holds one `iroh_blobs::api::Store` and passes a clone to world services ([`serve.rs:504-520,560-585`](../pkgs/id/src/commands/serve.rs#L504-L520)). The existing `blob_gate` has fail-closed policy logic, but its reference index has no producer and it is not wired into `id serve` ([`blob_gate.rs:13-21,110-118`](../pkgs/id/src/blob_gate.rs#L13-L21)). Therefore R2 ownership, partition-local references, and deletion are new hosted-world responsibilities; they should not be described as existing protections. + +Participant metadata is part of the world snapshot: `WorldSnapshot` includes a participant list ([`world/mod.rs:935-953`](../pkgs/id/src/world/mod.rs#L935-L953)); `snapshot` requires JOIN scope ([`world/core.rs:1051-1057`](../pkgs/id/src/world/core.rs#L1051-L1057)), and its projection includes every active JOIN participant ([`world/core.rs:1170-1208`](../pkgs/id/src/world/core.rs#L1170-L1208)). Hosted admission must therefore protect lists and membership facts as well as world events and blobs. + +The closed #2059 investigation says sharding preserves the world's identity/membership model and treats topic/region shards as parts of that world, with explicit consistency costs ([sharding investigation §§4–5](2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md#L142-L181)). This design adds the invariant that no shard or coordinator crosses the world's jurisdiction. The prior jurisdiction investigation identifies the unresolved product choice between no cross-participation and explicit, consented, disclosed participation ([jurisdiction investigation §2](2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning.md#L301-L319)). + +## Viable options + +| Option | Behavior | Benefits | Costs and risks | +| --- | --- | --- | --- | +| One global namespace and shared blob store | Names and hashes resolve globally; jurisdictions are metadata only. | Lowest operational complexity; simple discovery. | Does not partition world data or metadata, permits cross-partition existence signals and fetch paths, and cannot support the requested residency boundary. Reject. | +| Replicated/federated world | A world is copied or jointly served in multiple jurisdictions. | Cross-jurisdiction collaboration with local copies. | Requires replication, conflict/ordering, membership-metadata, revocation, and deletion semantics. #2284 is still the source of that investigation; defer rather than invent federation here. | +| One fixed world partition, explicit guests | One canonical world and blob copy; a foreign-jurisdiction account joins only through a world-scoped guest grant. | Matches the later #3397 recommendation; keeps account stores separate and avoids multi-writer world replication. | World-side guest activity and participant metadata reside in the host partition; requires explicit authorization and accurate disclosure. Conflicts with #2284 PR #3407's stricter recommendation. **Recommended, subject to Drew's decision.** | +| One fixed world partition, matching jurisdictions only | Only accounts assigned to the world partition may join or inspect it. | Simplest fail-closed rule; aligns with the recommendation in #2284 PR #3407 and avoids guest-specific residency semantics. | Prevents cross-jurisdiction collaboration even when the world itself remains in one partition. Keep as the fallback if the guest policy is rejected. | + +## Proposed contract + +### Partition identity, world identity, and names + +1. `Jurisdiction` is the same validated value and authority used by #2283. Resolve it from the account's authoritative record before world lookup or mutation. Missing, unsupported, or unprovisioned values fail closed; there is no default jurisdiction or client-selected override. +2. A hosted world stores its jurisdiction at creation and never changes it in place. Its stable opaque world ID and every lookup are scoped by `(world jurisdiction, world ID)`; a display name is not an identity or authorization token. +3. Name lookup is partition-local: `(jurisdiction, name)`. Identical names in different partitions identify independent worlds. A lookup in one partition returns the same indistinguishable refusal whether the world is absent or exists only elsewhere. It never redirects, searches globally, or reveals a remote match. +4. The world, its coordinator, and all topic/region shards inherit one jurisdiction. Shard creation rejects a different jurisdiction. The #2059 escalation/consistency model still applies inside a partition; sharding is not a cross-jurisdiction escape hatch. + +### Admission, guest membership, and metadata + +1. Every read, write, invite, WebSocket operation, background job, and administrative operation is authorized against a trusted account identity, the resolved world ID, and the world's stored jurisdiction. Client-supplied jurisdiction values are ignored. A missing identity/world jurisdiction, a routing mismatch, or an unknown value rejects before side effects. +2. Same-jurisdiction accounts use the world's normal capability and access policy. A different-home-jurisdiction account is denied unless the guest policy has been enabled and the world has issued a valid, revocable, world-scoped guest grant. The grant is not an account-store move and grants no other world's access. Until Drew resolves the question below, guest grants are disabled. +3. If enabled, the host-partition grant must cover each operation; possession of a world ID, display name, content hash, invite URL, or account-store credential alone is insufficient. Invitations are checked at issue and redemption. Revocation blocks new reads/writes and participant-list access, including existing sessions and cached routes. +4. Participant lists, invite state, join/leave events, access logs, and the fact of participation are residency-bearing world metadata. They are stored with the world in its partition and returned only under the same world authorization as other protected world data. A foreign account without an active guest grant cannot see the list or learn whether it is a member. +5. The account's private store and account history remain in its home jurisdiction. If it migrates, a world in another partition does not move with it. Under the guest recommendation, retain membership only if an explicit grant remains valid; otherwise revoke/exit it. This policy must be deterministic and auditable per world. + +### World-owned blobs and deletion + +1. A world owns references to its world blobs. Place bytes in the R2 bucket set for the **world's** jurisdiction, not based on the uploader's current account bucket. Bind world authorization to every fetch/observe path; a hash is a locator, never authority. +2. Deduplicate and garbage-collect only within one jurisdiction. Identical hashes in two partitions are independent objects. Do not fall back to another bucket, another region, a global cache, or a peer when the local read misses. Direct URLs, caches, retries, backups, and administrative reads are part of the same policy. +3. Maintain a complete reference index for every durable world/module/artifact reference. Deletion is allowed only after a concurrency-safe last-reference check scoped to that partition and its in-flight imports/exports/retention roots. A failed lookup for a still-referenced object is an integrity failure; it must not silently fetch across partitions. +4. World deletion first tombstones and fences the world, revokes membership/invites, and removes name resolution. Blob bytes are reclaimed only by the same reference-safe partition-local GC; deleting one world or account must not delete bytes still referenced by another world. + +### World and account lifecycle + +- **World creation:** resolve the creator's authoritative jurisdiction, validate that partition's resources, then atomically bind a new world ID and name to it. Do not create an empty/default world on an invalid or missing jurisdiction. +- **World migration:** no live move and no dual-homing. Export under source authorization, import and verify as a **new world with a new ID** in the target partition, reissue memberships and invitations under the target policy, then switch explicit discovery and tombstone the source. Keep the source authoritative until verification succeeds. Retention and reference-safe cleanup are separate from the switch. +- **Account migration:** #2283's account migration moves the account store, not worlds or their history. It must use the guest/exit rule above for each membership. It must not implicitly rewrite a world's jurisdiction because its owner moved; a world move is a separate lifecycle operation. +- **Deletion:** tombstones are durable and idempotent. Name reuse does not resurrect old IDs, memberships, invites, or blob references. Cleanup waits for outstanding leases/imports and does not infer that shutting down an idle world deletes its durable data (current idle eviction only shuts the service down; see [`world_hub.rs:661-690`](../pkgs/id/src/world_hub.rs#L661-L690)). + +## Invariants and implementation acceptance criteria + +The implementation is acceptable only when all of the following hold: + +- Every hosted world and shard has exactly one validated, immutable jurisdiction from its creation record; every operation routes to that partition. +- No missing or mismatched jurisdiction silently creates/opens a second world or account store. A cross-jurisdiction guest is possible only through the explicitly approved guest grant; without it, mismatch is refused uniformly. +- Same-name worlds are independently addressable per partition, with no cross-partition existence oracle. +- Participant lists and other membership metadata receive the same cross-partition authorization as world reads; unknown, revoked, or absent grants reveal no membership. +- World data and world-owned blobs are served only from the world partition. Dedup, references, GC, direct URL/cache behavior, and error paths do not cross partitions. +- A referenced blob cannot be collected; a missing in-partition blob fails closed. World deletion and migration preserve unrelated references. +- Shards and background work cannot cross the world partition; stale sessions and workers are rejected after fencing/revocation. +- Migration is resumable and verified: the source remains authoritative until target verification, the target is a new world, and cleanup is reference-safe. Account migration does not silently move worlds. +- Deployment/configuration and disclosures distinguish an intended architecture from verified platform placement. No residency promise is made until account-level DO/R2 support, all processing/storage paths, backups/logs, and operational/legal requirements are verified (including #2285). + +### Negative-test matrix + +| Test | Expected result | +| --- | --- | +| Missing/unsupported jurisdiction on account or world creation | Refuse before ID derivation, name resolution, storage creation, or side effects. | +| Read, write, or invite with wrong world routing jurisdiction | Uniform denial; no access, mutation, invite, or cross-partition existence signal. | +| Foreign account with no guest grant, expired grant, revoked grant, or stale session | Uniform denial for reads, writes, invites, and participant metadata. | +| Foreign account with an approved guest grant (if Drew approves) | Only the granted world/action is accessible; account store stays home; world data and membership metadata stay in the host partition. If strict matching wins, this case is denied instead. | +| Same name exists in another jurisdiction | Local lookup returns the same result as a nonexistent world; no remote hint or redirect. | +| Shard or coordinator assignment names a different jurisdiction | Reject creation and refuse any cross-partition handoff. | +| Blob read/observe/direct URL/cache request uses the wrong world or bucket | Refuse without probing/falling back to another bucket or peer. | +| GC attempts to delete a referenced blob | Refuse deletion; authorized in-partition read still succeeds. | +| Referenced blob is missing from its own bucket | Fail closed and report integrity failure; never fetch from a different jurisdiction. | +| Account/world deletion races with a reference, import, or migration | Preserve the live reference; resume cleanup only after a fresh partition-local reachability check. | +| World migration interrupted before verification or racing stale writers | Source remains authoritative; old sessions/writers are fenced; target remains non-serving; retry is idempotent. | +| World migration after target verification | Switch to the new ID only after verification; source is tombstoned and cleaned under retention/reference rules, not live-moved. | + +## Operational costs and prerequisites + +- Provision a restricted world namespace/deployment binding and an R2 bucket set per supported jurisdiction. This creates fixed configuration, observability, and operational cost even when a partition has no worlds; budget for partition-local duplicate blobs. +- Use the #2283 authoritative account jurisdiction and routing contract. Do not add a second jurisdiction vocabulary or infer it from a hostname, region hint, `WorldHub` name, or blob hash. +- Gate a jurisdiction on actual account-level support, deployed bindings, credentials, schema/config validation, and a canary covering create, route, read/write, mismatch denial, and bucket isolation. #2285 owns platform/vendor verification; the open #2283 design and issues #3399–#3404 do not establish that a jurisdiction is available or that a residency promise is true. +- Partition logs, audit records, caches, backups, support access, and failure paths in the operational inventory. A world partition limits the intended hosted world store; it does not by itself prove request-processing, metadata, or end-to-end residency. +- Recommendation: model `N` configured partitions, but operate one verified partition until an actual product/legal requirement and provisioning evidence justify a second. Keeping the data model partition-ready is cheaper than claiming an unsupported second deployment. + +## Phased implementation plan + +Each step is intended to merge independently behind fail-closed defaults. Steps 0–3 establish the hosted path; step 4 adds world lifecycle operations; steps 5–6 are the separate account-store migration path. Existing issue links are prerequisites, not authority from #3397 to implement. + +| Phase | Independently mergeable deliverable | Dependencies / tracking | +| --- | --- | --- | +| 0. Provisioning gate | Validate configured jurisdiction, restricted world namespace, and R2 binding; block creation when unsupported or incomplete. | #2285 evidence; related follow-on [#3403](https://github.com/developing-today/code/issues/3403). | +| 1. Authoritative jurisdiction records | Reuse #2283's account record and migration metadata; ensure world creation receives a trusted validated value before deriving a world ID. | Phase 0; [#3399](https://github.com/developing-today/code/issues/3399). | +| 2. World routing, names, and admission | Add partition-scoped world lookup, fail-closed guards, explicit guest-grant seam (disabled until decided), participant-list checks, and shard inheritance. | Phase 1; [#3400](https://github.com/developing-today/code/issues/3400) is the account-routing foundation. The world-specific routing/admission work is not fully represented by #3400 and needs a distinct implementation follow-on before hosted-world traffic is enabled. | +| 3. Partition-local world blobs | Bind per-jurisdiction R2 buckets; add complete world-reference indexing, authorization, local dedup, and safe GC. | Phases 0–2; [#3401](https://github.com/developing-today/code/issues/3401) covers the related user-blob/directory foundation, but world-owned references need explicit acceptance in the world implementation packet. | +| 4. World lifecycle and migration | Add tombstone/delete, export/import as a new target world, verification, reissued membership, and source cleanup under retention/reference rules. | Phases 1–3; this world-specific lifecycle packet is distinct from user-store transfer #3402 and should be filed from the approved design, not silently folded into it. | +| 5. Account migration fencing | Implement pending state, CAS epochs, source freeze, and target activation without changing a world's jurisdiction. | Phases 1–2; [#3404](https://github.com/developing-today/code/issues/3404). Can proceed independently of Phase 4 once the guest/exit rule is fixed. | +| 6. Verified account transfer and cleanup | Export/import the account store, verify its content, and clean source safely; reconcile each world membership by the approved guest/exit rule. | Phase 5; [#3402](https://github.com/developing-today/code/issues/3402). Does not implement world migration in Phase 4. | + +No phase above is an implementation authorization from #3397. The separate world-routing/admission and world-lifecycle packets are called out because the already-filed #3399–#3404 issues mainly implement the #2283 user-store design. + +## Open questions + +1. **Cross-jurisdiction guest membership:** Should v1 allow an account from another jurisdiction to join one explicitly chosen hosted world as a guest, with its world activity and membership metadata stored in the host partition, or must account and world jurisdictions match for every operation? **Recommendation:** follow the later, issue-specific #3397 triage and permit only explicit, revocable guest grants, while keeping guest admission disabled until Drew and the #2284 policy review confirm it. The stricter option is the current recommendation in open PR [#3407](https://github.com/developing-today/code/pull/3407); if adopted, remove the guest exception and reject every mismatch. +2. **Jurisdictions deployed for v1:** Is there a real second-jurisdiction deployment requirement, or should v1 be partition-ready but operate one verified jurisdiction? **Recommendation:** support `N` in the design, deploy one until #2285 confirms account-level support and a legal/product requirement names another. This affects provisioning and ongoing fixed cost, not the partition invariants.