diff --git a/doc/2026-11-08_design_id5859.md b/doc/2026-11-08_design_id5859.md new file mode 100644 index 0000000000..a50aa22229 --- /dev/null +++ b/doc/2026-11-08_design_id5859.md @@ -0,0 +1,96 @@ +# Decision record: live-object embeds in playable posts + +- **Date:** 2026-11-08 +- **Status:** decided contract for the #5680 expansion; no implementation is included here. +- **Issue:** [#5859](https://github.com/developing-today/code/issues/5859), follow-on to [#5680](https://github.com/developing-today/code/issues/5680). +- **Baseline:** [#2054 boards v1](2026-11-01_design_id2054.md#L74-L102) and [the #2053 playable-posts investigation](2026-10-30T19-45-00Z_investigation_playable_posts/2026-10-30T19-45-00Z_investigation_playable_posts.md#L32-L54). +- **Decision task:** queue task 13004 (`repo-worker-code`). +- **Scope:** the embed contract only: execution sandbox and grants, liveness, lifecycle/versioning, unsupported-client behavior, and loading/resource budgets. This is not a design for live-session transport or a change to boards v1. + +## Decision in brief + +A playable post remains a signed board object that **references immutable package bytes by content hash**. The existing ID world sandbox, capability ceiling/grants, and execution-profile limits are the only execution authority and resource boundary; a package signature proves provenance, not safety. Execution stays in a host-side ID world: clients receive validated presentation data, never the guest module. An embed has an explicit liveness mode: **per-viewer is the default**, while shared play requires an explicit declaration and a user-initiated join to one identified live session. “Per-viewer” means an isolated host-side world instance for that viewer; “shared” means one logical session shared through the host, never a process or ambient capability shared between viewers. + +The post's exact signed version and package hash never move in place. Edits and package updates create new objects. Offline, deleted, disabled, unsupported, or over-budget embeds remain visible as a safe, non-executable card with an honest status. Metadata may load with the post; preview assets and executable bytes are lazy, and code starts only after an explicit user action. Live-session hosting and discovery remain deferred as #2054 says; this record defines their embed boundary but does not make real-time games part of boards v1. + +## 1. Sandbox and capability grants + +1. **Reuse the host-side world runtime; do not add client-side guest execution or an iframe/HTML path.** The verified package runs as an ID world under the existing guest sandbox and host-set execution profile. Clients render only host-validated text or the versioned screen/cell presentation; they do not run the package. This is required for host-enforced fuel, memory, and capability limits. A valid package signature is attribution only. Board content, themes, descriptions, and preview assets are data, not markup to interpret as code. +2. **No ambient authority.** A newly embedded program starts with no grants to filesystem, arbitrary network, identity, cross-board data, or graph writes. It may render its own declared state and process user input locally. An external effect is available only through an explicit host-mediated capability that is both inside the server/world ceiling and granted for that use. A board owner's blanket approval does not substitute for the viewer's grant; a viewer grant cannot exceed the host ceiling. Grants are revocable and checked at use, not inferred from package authorship, a board role, or a transport connection. +3. **Shared-session access is explicit.** Joining or publishing shared state requires the compatible session capability and an affirmative user action. The host mediates the session channel; the package receives no unrestricted socket/network import. A client that lacks the required capability can spectate only if its supported data path permits it, otherwise it shows the fallback card. +4. **Resource requests only narrow.** Package metadata cannot raise a host's configured profile, world budget, or capability ceiling. Use the limits of the existing ID world runtime; do not introduce a second embed-specific runtime or a more permissive fallback for unsupported clients. + +## 2. Liveness: shared session versus per-viewer instance + +Every interactive object declares its liveness mode in its signed game-post object; clients must display the mode before running it. An omitted mode is treated as **per-viewer**. A client must never infer shared play from the package's behavior or the presence of a network capability. + +| Mode | Contract | +| --- | --- | +| **Per-viewer (default)** | A user action asks a world host to create an isolated host-side world instance from the pinned package/configuration, scoped to that viewer. Its state is private and ephemeral unless the viewer explicitly exports/publishes a signed object. It does not synchronize or imply that another viewer sees the same state. The client only renders validated presentation data. The host stops/pauses work when the viewer leaves the foreground or its lease expires. | +| **Shared live session (opt-in)** | A join action targets one explicit host-side session identity bound to the exact post and package version. Participants observe/update one logical session while it is available. Each participant's client separately renders validated presentation data; only the mediated world-session protocol shares state. If there is no live session host, the object is unavailable—not silently converted to a per-viewer game. A new session has a new identity and is not a continuation unless an explicit signed save point/handoff says so. | + +For shared sessions, the live host is authoritative for the **ephemeral current session state**, consistent with the existing world-session boundary. That is not evidence that a particular player signed an input: a host-authored event or snapshot must not be presented as a player-signed board turn or ranked result. Any durable board result/checkpoint is a separate signed object with its signer and provenance visible. This preserves #2054's player-evidence invariant and does not change the async-turn/succession model from #2053. + +## 3. Object lifecycle and version pinning + +The identity of a running embed is the tuple **(signed GamePost object hash, package content hash, session/instance ID)**. A session is never looked up by a mutable package name alone. + +- **Edit:** editing the post creates a superseding signed board object. New starts use the new object. An already-running session remains bound to its old object and may continue only while its host and policy allow; it is never silently retargeted. The old reference continues to resolve to its old version or its tombstone/status. +- **Package update:** an update is a new content hash and a new game-post version. Existing posts and sessions keep the bytes they named. Migration or save-point import requires an explicit new object/transition; no in-place update changes rules or state. +- **Offline or lost host:** show `offline`/`unavailable`, retain the post and pinned version, and do not create a replacement session automatically. Rejoin is possible only if the same session identity is still available. A restarted/new session gets a new ID and starts from its declared genesis or an explicit signed save point. +- **Board/host freeze or disable:** stop new starts/joins and stop local execution under that board/host's authority. Treat this as an availability/moderation view, not a rewrite of the GamePost, a new package grant, or global deletion. The board-role/action mechanism itself remains with the board moderation design (#5861); the #5680 reference to #835 does not make #835 the source of board-role authority. This record only requires the embed effect to be enforceable and visible. +- **Delete/tombstone:** a signed tombstone hides the embed from ordinary board presentation and prevents new discovery/joins through that view. A client that observes it stops its local guest and leaves the shared session; request best-effort session shutdown where the host is reachable. It cannot erase signed history, remote replicas, or snapshots already copied. A client with a remaining reference displays the tombstone/availability state rather than claiming global erasure. +- **Revocation, invalidity, or resource refusal:** fail closed for execution. Keep the safe card and state the reason (`permission denied`, `invalid package`, `disabled`, or `resource limit`); do not transparently retry with broader grants or another runtime. + +## 4. Unsupported-client fallback + +Every post has a useful non-executable rendering path. A client without a presentation feature, a client that lacks a required capability, and a client whose host cannot fetch or verify the pinned package show a **static playable-post card** made from the signed post's ordinary text/metadata and optional content-addressed preview asset. The card identifies the package/version, declared mode, current availability when known, and the action/status (`open in compatible client`, `unsupported`, `offline`, `disabled`, or `unavailable`). It leaves the post, discussion, and any separately readable signed state accessible. No client downloads or executes the package to render either the live view or fallback. + +The preview is supplied as data by the post author or produced/cached from validated host presentation output. An author-supplied image is visibly a preview, not proof of current game state; a cached host-rendered frame is not canonical state. Both use the normal bounded, content-addressed attachment path. Fallbacks never execute embedded HTML/JavaScript, fetch mutable remote URLs for code/assets, or auto-run a package to generate the preview. Unknown presentation fields degrade to the board-v1 safe rendering behavior. + +## 5. Lazy loading and resource budgets + +- **Post first, program on demand.** Loading a board/post may load its bounded signed GamePost metadata and references. It does not fetch executable package bytes or instantiate a guest. Fetching preview media is lazy (when the card is visible or requested); downloading/verifying/starting the package requires an explicit **Play**, **Join**, or **Resume** action. Scrolling, hovering, pre-rendering, or opening a board never starts a guest. +- **Foreground only.** Initial policy is at most one active per-viewer world instance per viewer on a host, in addition to the host's existing world/session caps; a host must reject or queue excess requests rather than overcommit. Leaving the embed pauses/stops that viewer's instance when the host observes the foreground/lease change. A client does not keep a guest running in a hidden tab or background view. Shared-session service availability is controlled by its host/session lease, not by a guest left running on every viewer's device. Clients only render validated output. +- **Enforce existing ceilings, not package claims.** The current ID Wasm defaults are a **16 MiB module**, **10,000,000 fuel per guest invocation**, **16 MiB linear memory**, and **1 MiB input/output message** (`id-core::world_limits::SandboxLimits`). The default logical per-world memory ceiling is **64 MiB**. Existing world defaults also cap each world at **256 participants**, **16 KiB input**, **8 KiB presentation output**, **512 KiB snapshots**, **1,024 retained events**, and a **1,000 ms minimum tick interval**; the hub defaults to **256 open worlds / 1,024 sessions**. Existing native-worker limits, if a future approved runtime uses that backend, remain **256 MiB address space, 10 CPU seconds, and a 10-second call deadline**. These are ceilings/defaults from the current runtime, not guarantees of measured RSS or a promise that every client has identical capacity or that live games meet a latency target. A server's lower configured ceiling wins; package-declared requests can only reduce it. +- **Fetch and state remain bounded.** The world module maximum and existing attachment size/hash checks apply before execution/rendering. Post metadata and configuration use the existing board-object validation and message limits; large packages, previews, and save states are references, never inline post bytes. No unbounded package or preview prefetch is allowed. Existing world event/rate/profile limits apply to shared session traffic; this design does not authorize a package to create an unlimited event stream. +- **Visible failure, not silent fallback execution.** If any fetch, verification, capability, fuel, memory, message, or host budget is exceeded, stop/decline the run, preserve the last valid signed state/snapshot, and show a limit/unavailable status. Do not automatically restart, switch to another backend, or weaken the ceiling. A future live-session implementation must add its own bounded join/input/tick/egress and session-lifetime quotas before it is enabled; it cannot infer them from the local guest limits. + +## Rejected alternatives + +| Alternative | Decision | +| --- | --- | +| Trust signed packages or inherit the board owner's grants | Reject: signature is provenance, not safety; board authority cannot grant for a reader or escape the host ceiling. | +| Run guest code in the browser/client, or give embedded code a shared process or ambient network | Reject: client-side execution bypasses host-enforced fuel/capability limits; a shared process collapses viewer isolation. Clients render validated host output. Shared means one logical session protocol, not one process. | +| Make every embed globally shared or silently per-user | Reject: the signed object declares the semantics; per-viewer is the omission-safe default, and shared requires an explicit join. | +| Track a mutable “latest” package or migrate running games on edit | Reject: it changes game rules/state under an existing signed reference and breaks #2054 package pinning. | +| Autoplay or eagerly download/instantiate for smooth scrolling | Reject: board rendering is not consent to execute code or consume unbounded resources. | +| Require a compatible client or show a blank/broken embed | Reject: every client gets the safe card and status; unsupported execution does not hide the signed post. | +| Turn live-session transport, discovery, or async succession into this ticket | Reject: #2054 defers live hosting/discovery; #2053/#2054 already define async turns and save-point succession. This is an embed contract, not a second design of those systems. | + +## Invariants implementation must hold + +1. **One authority path:** execution is inside the existing ID world sandbox; effective capabilities are bounded by the host ceiling and explicit grants. A signature, board role, client transport, or package declaration alone never grants authority. +2. **Explicit liveness:** each game post says shared or per-viewer; per-viewer is the default. Shared state is never confused with a shared runtime process, clients execute no guest code, and per-viewer state is never mislabeled as synchronized state. +3. **Immutable identity:** every run/session names the exact signed post, package hash, and instance/session ID. Edits and updates create new objects; no silent migration or name-based “latest” lookup. +4. **Honest lifecycle:** offline, disabled, deleted, revoked, invalid, and over-budget states are visible. A host/view can stop serving or running an embed locally but cannot claim to erase signed history or remote copies. +5. **Player provenance:** host state/snapshots do not become player-signed turns or ranked results. Durable state is separately signed and attributed. +6. **Safe fallback:** every client can render a non-executable card from bounded signed metadata; optional previews are data-only and labeled as previews. +7. **Lazy and bounded execution:** visibility is not consent; no package runs before user action. Existing world/module/message/resource ceilings and host rate limits are enforced, and a refusal never retries with broader authority. +8. **No background persistence by accident:** local per-viewer simulation stops when not foregrounded; shared runtime lifetime belongs to the explicit session host/lease. + +## Relationship to existing decisions and splits + +- **No #2054 decision changes.** Boards v1 stays public and signed, themes stay data-only, packages stay content-addressed and pinned, and games remain async-turn/succession-first. Real-time `live-session` hosting/discovery/tick transport is still deferred; this contract does not make it a v1 feature. In particular, the #2054 invariant that a host journal is not player-signed evidence remains intact. +- **No #2053 redesign.** Async turns, save points, succession, and forks retain their #2053/#2054 model. The shared-session rule here is only the boundary for the separately deferred live mode. +- **#5680 is answered locally, not silently forked.** The #5680 choices are resolved as explicit liveness declaration (per-viewer default), no blanket board-owner capability grant, author-provided/data-only fallback, immutable version pinning, and user-triggered lazy loading under existing budgets. A board moderation freeze is an availability action, not content deletion or an execution grant. +- **No further split is filed.** The facets above form one embed contract and fit #5859. Live-session hosting, rendezvous/discovery, tick protocol, and operational service guarantees remain deferred rather than being partially designed here; implementation must not ship them until their own design/issue settles those mechanics. This record does not modify any other #5680 follow-on. + +## References + +- [#5859 — live-object embed contract](https://github.com/developing-today/code/issues/5859) +- [#5680 — boards expansion](https://github.com/developing-today/code/issues/5680) +- [#2054 — ID boards v1 design](2026-11-01_design_id2054.md#L74-L102), especially its host-side guest / data-only client presentation boundary ([existing world presentation contract](2026-10-31T17-47-20Z_design_world_presentation_and_fuel/2026-10-31T17-47-20Z_design_world_presentation_and_fuel.md#L54-L56)). +- [#2053 — playable-posts investigation](2026-10-30T19-45-00Z_investigation_playable_posts/2026-10-30T19-45-00Z_investigation_playable_posts.md#L32-L54) +- Existing resource defaults: [`pkgs/id/crates/id-core/src/world_limits.rs` (module and world ceilings)](../pkgs/id/crates/id-core/src/world_limits.rs#L12-L33), [guest and native runtime limits](../pkgs/id/crates/id-core/src/world_limits.rs#L183-L232); board object references and bounds: [`pkgs/id/src/boards.rs`](../pkgs/id/src/boards.rs#L34-L43). +- Existing world grants and ceilings: [`pkgs/id/src/world_manifest.rs`](../pkgs/id/src/world_manifest.rs#L31-L53). diff --git a/doc/README.md b/doc/README.md index bc9700fc89..67446f3597 100755 --- a/doc/README.md +++ b/doc/README.md @@ -57,6 +57,7 @@ Folders are named `__`. The kinds in use are `feature` - [Reserved admin authority (LambdaMOO governance arc)](2026-11-08T12-50-00Z_design_id6004_lambdamoo_governance_arc/2026-11-08T12-50-00Z_design_id6004_lambdamoo_governance_arc.md) (design note for #6004: the explicit reserved-vs-delegable authority split for world governance, the Mr. Bungle capability-abuse lesson mapped to id's delegation and per-user-function surface, and quota as a governance tool) - [Personalized search ranking for notes](2026-11-09T01-10-00Z_design_id_search_ranking/2026-11-09T01-10-00Z_design_id_search_ranking.md) (decision record for #5836: per-searcher tier ranking over #5675 filtered results - own-edit-first absolute by tier, explainability via reason codes, graffiti demotion without erasure, boundaries with #5732 recommendations and #5677 sovereignty) - [A native Android client for ID](2026-11-08T22-06-00Z_design_id_android_client/2026-11-08T22-06-00Z_design_id_android_client.md) (design for #5780: thick local-first client, Keystore/StrongBox custody under #5684, offline journal + sync through the #3447 seams, shell contract with #1831 remote drive, phone as a two-gate #5686 provider, and honest presence with no guaranteed background wake) +- [Live-object embeds in playable posts](2026-11-08_design_id5859.md) (decision record for #5859: host-side execution only under the existing world sandbox and ceilings, explicit liveness with per-viewer as the default, immutable version pinning, safe non-executable fallback cards, and lazy user-triggered loading under existing budgets) Two names break the pattern. They stay as they are because other documents link to them: `2026-03-23T00:00:00Z_feature_file_list_ui/` has colons in its name, and `2026-10-14T10-18-19Z_design_p7_2_cloudflare_workers.md` is a file, not a folder.