Docs / MVP-SANDBOX-GATE-AUDIT

MVP sandbox-emulation gate: independent read-only audit (item 168)

Source: docs/MVP-SANDBOX-GATE-AUDIT.md

  • Date: 2026-11-28
  • Base revision: main @ 161322c (worktree kitty-mvp-gate-audit, clean before this file)
  • Auditor model receipt: claude-opus-5-5 (Claude Code worker, Orca task task_182897fb82be)
  • Scope: read-only. No code, fixture, container, Kiri, push or PR action. The only Kiri command run was ~/.kiri/bin/kiri --help (help text, no container touched).
  • Gate under audit (owner directive 2026-11-28): a real Kiri sandbox starts, the emulator runs inside it, the game launches and is genuinely playable with input, video, audio and saves. Simulated or browser-only proof of sandboxed emulation does not count.

Labels: OBSERVED = I read it in code or artifacts at 161322c. REPORTED = stated by a doc or report but not re-run by me. NOT_CHECKED = no evidence exists or I did not verify. BLOCKED = cannot be checked without an action outside this audit's scope.

This audit makes no playability PASS claim.


1. Evidence per gate element

# Gate element Label Evidence
1 Kiri sandbox create/start OBSERVED (code) / REPORTED (run) gamecomposer/runtime.py:566-597 builds kiri run --detach --init … and runs it. The run evidence is tests/e2e-desktop/artifacts/nes-table-tennis/report.json → sessions[*].kiri: container gc-c49ce1883364-nes, state running, startedAt after the Up click, freshStart: true, containerAbsentBefore/After: true, image sha256:f45cbdd5…468d. I did not re-run it.
2 Emulator location OBSERVED: emulator runs in the host browser, not in the container See the chain below.
3 Game launch REPORTED (in browser) report.json → playerResources lists /jsnes.js and /rom fetched from 127.0.0.1:<port>. analysis.authenticity.reason = "jsnes loaded and /rom fetched". Frame session-1/20-before-input.png shows the ROM's title screen (I viewed it). The ROM is decoded and executed by new jsnes.Browser(...) in the page (examples/nes/image/player.html:13), not by the container.
4 Input REPORTED (browser-local) report.json → inputs: Enter, x, ArrowUp, ArrowDown are sent as Playwright keyboard events (tests/e2e-desktop/run.cjs:167-169). analysis.inputDiff.changedShare = 0.19837 against an idle diff of 0. session-1/21-after-input.png shows the in-game court (I viewed it). Input goes to jsnes in the page (player.html:30-55, plus the built-in jsnes.Browser keyboard handler). It never reaches the container.
5 Video REPORTED (browser-local) Frames are element screenshots of the jsnes canvas drawn by the page. Frames 21 and 22 are byte-identical (3a3571bd5a93…), so the record shows a state change after input but no continuous motion. counterAdvanced: null because no frame counter exists for NES. The container produces no video.
6 Audio NOT_CHECKED outputs.audio: browser-local (templates/02-nes-local-homebrew/gamecomposer.yml:51) means jsnes plays sound through the page's WebAudio. `git grep -nE "audio
7 Saves NOT_CHECKED (no run) / OBSERVED (code path) player.html:17-24 sends the browser-side player.nes.toJSON() to POST /checkpoint. serve.py:13-34 writes it atomically to the bind-mounted /gamecomposer/saves/checkpoint.json (mount: runtime.py:594). The container only stores bytes produced in the browser. report.json has no save or restore step, and nothing shows persistence across down/up.

Emulator-location chain (element 2), all OBSERVED at 161322c

  1. examples/nes/image/Dockerfile:1-3: the image is python:3.12-alpine plus player.html, JSNES-LICENSE and serve.py. It has no Node, no native emulator and no display or audio stack. templates/02-nes-local-homebrew/image/ is byte-identical (diff -r is clean).
  2. templates/02-nes-local-homebrew/gamecomposer.yml:24-27: the declared emulator.executable is /usr/local/bin/python with args /opt/player/serve.py {game}. The only process the sandbox runs is an HTTP file server.
  3. templates/02-nes-local-homebrew/gamecomposer.yml:20-23: emulator.source (jsnes 2.1.0, sha256-pinned) is mounted in the container at /gamecomposer/emulator (runtime.py:546,584). It is only served as a static file: serve.py:10-11 maps /jsnes.js to that file.
  4. examples/nes/image/player.html:3,13: the browser loads <script src="#"> and runs new jsnes.Browser({romData,…}). CPU, PPU and APU emulation, rendering, audio and input all execute in the host browser process (an Electron window in the E2E run: report.json → app.electron 38.8.6).
  5. runtime.py:576-577 publishes the port to 127.0.0.1 only, so the sandbox is a loopback asset server.
  6. The spec states this design explicitly. docs/GAMECOMPOSER-SPEC.md:148: "browser-local publishes a loopback page; it is browser-executed emulation, not relayed video." The schema allows only browser-local | none for outputs.video and outputs.audio (gamecomposer/game-compose.schema.json:168-169).
  7. PR #6's own brief (docs/MVP-REPOSITORY-AUDIT.md, unmerged) agrees: "Browser-only emulation is not proof of emulator execution inside the sandbox."

No in-container emulator path exists anywhere in the repo. git grep -liE "xvfb|novnc|fceux|retroarch|nestopia|mednafen|ffmpeg|gstreamer|pulseaudio|websockify" matches only docs/PS3-ADAPTER-FEASIBILITY.md and docs/research/project-landscape.md, both prose.


2. Verdict

The current NES Desktop E2E PASS (2/2 at b3e5644, still valid on 161322c) does NOT satisfy the MVP gate as written.

It is honest evidence of something narrower: the desktop app starts a real, fresh Kiri container, and the container serves a pinned emulator file and a ROM that a browser on the host then runs with real input. For the gate's purpose, that is browser-only proof of emulation, with assets served from the sandbox. Audio and saves were never exercised in that run.

The single architecture gap: jsnes executes in the host browser (Electron/Chrome renderer). The Kiri container only runs a static file server. There is no in-sandbox emulator process and no container-to-client video, audio or input channel, and the v0.2 schema cannot express one (outputs.* ∈ {browser-local, none}).


3. Smallest bounded path to satisfy the gate

Design (one sentence): run the same pinned jsnes 2.1.0 headless under Node inside the Kiri container. It emulates and produces frames and audio samples there, and streams them over one loopback WebSocket to a thin page that only draws frames, plays PCM and sends button events. Saves are taken server-side with nes.toJSON() and written by the container process.

Why this is the smallest route:

  • It reuses the already-pinned emulator source (same URL and sha256 in the manifest).
  • It needs no X server, VNC, GPU or video encoder. Raw 256×240 frames at 60 fps are about 3.7 MB/s palette-indexed (about 14.7 MB/s RGBA), which loopback handles easily.
  • It keeps the existing Kiri lifecycle, port publishing, save mounts and desktop flow unchanged.

The decisive property is that the thin page does not contain or load an emulator. Any frame, sound or state change it shows must come from the container.

Non-overlapping file sets, one owner each

Owner Files (exact) Change
A: sandbox image and emulator host templates/02-nes-local-homebrew/image/Dockerfile, templates/02-nes-local-homebrew/image/player.html, templates/02-nes-local-homebrew/image/serve.py (replace with new templates/02-nes-local-homebrew/image/emulator-host.mjs), templates/02-nes-local-homebrew/gamecomposer.yml Base image node:<pinned>-alpine@sha256:…. emulator-host.mjs loads $GAMECOMPOSER_EMULATOR_SOURCE with new jsnes.NES({onFrame,onAudioSample}), ticks at 60 Hz, pushes frames and PCM over a WebSocket (hand-rolled RFC 6455 or a vendored, hash-pinned ws), applies button events from the socket, and implements save/load against $GAMECOMPOSER_SAVE_DIR/checkpoint.json. It exposes GET /health → {frame, pid, pausedReason}. player.html becomes canvas + WebAudio + keyboard/gamepad → socket, with no /jsnes.js route and no emulator code. Manifest: executable: /usr/local/bin/node, args /opt/player/emulator-host.mjs {game}, outputs.video/audio: sandbox-stream.
B: runtime and schema gamecomposer/runtime.py, specs/game-compose.schema.json (the package copy gamecomposer/game-compose.schema.json is a symlink) Add the enum value sandbox-stream to outputs.video and outputs.audio. In runtime.py, treat sandbox-stream like browser-local for port publishing and health wait (the needs_browser/is_web expressions at :423, :527, :536, :564), and allow controls.gamepads with it (:426). No other runtime change is needed.
C: acceptance harness tests/e2e-desktop/profiles.cjs, tests/e2e-desktop/run.cjs, tests/e2e-desktop/png.cjs (only if an RMS helper goes there), new tests/e2e-desktop/artifacts/nes-sandbox-stream/ New profile nes-sandbox with the assertions listed below.
D: docs (after acceptance only) docs/GAMECOMPOSER-SPEC.md (§4.6 line 148), docs/DESKTOP-E2E-EVIDENCE.md Record sandbox-stream semantics and the new evidence. Do not edit before C has a real result.

Out of MVP scope: examples/nes/image/* and templates 01, 03-05 and 10, which share the old player. Migrate them after the gate passes, with owner A or a new owner.

Acceptance test (real Kiri, real app, no simulation)

Run node tests/e2e-desktop/run.cjs nes-sandbox 2 from the desktop app at the implementation SHA. Every session must pass all of the following:

  1. Sandbox: the container is absent before Up. After Up, kiri container inspect shows running with StartedAt later than the click (same checks as today).
  2. Emulator is in the container, not the page:
    • Page resource timing lists no jsnes, and typeof window.jsnes === 'undefined' and typeof window.NES === 'undefined'.
    • kiri exec <container> ps (exec is listed in kiri --help) shows the node … emulator-host.mjs process.
    • /health.frame advances while the page is closed.
  3. Causality: with the page open, record /health.frame and the last rendered frame. Then run kiri stop on the container. Frames must stop arriving, the canvas must freeze, and the socket must close. Video depends on the container.
  4. Input: mapped Start, A and D-pad keys produce socket button messages, logged by the container (kiri logs shows button 1 START down, etc.). The canvas reaches the in-game court (≥ 5% pixel change against a 0% idle control). The D-pad must cause a paddle displacement between two in-game frames, which proves continuous control and not only a scene change.
  5. Video: at least 50 distinct frame sequence numbers per second are received during play, measured client-side from container-stamped frame numbers.
  6. Audio: the container emits PCM. The page's AnalyserNode on the playback graph reports RMS > a small threshold during play, and AudioContext.state === 'running'. Store a 2 s WAV capture of received samples as an artifact. An owner listen check is reported separately and labelled REPORTED.
  7. Saves: play to the court, press Save, and check that the host file templates/02-nes-local-homebrew/data/saves/checkpoint.json changed mtime and size. Then click Down, then Up (a new container ID), Load, and verify that the restored frame matches the pre-save frame (pixel diff < 1%) without pressing Start again.
  8. Two consecutive sessions both pass. All artifacts are recorded, and no step is stubbed except shell.openExternal → Electron window (same disclosure as today).

4. PRs #1-#6: prerequisites vs post-MVP

All six PRs are open and documentation-only (gh pr view): each changes exactly one docs/*.md file and no code. None of them is a code prerequisite for the gate.

PR Title (short) MVP class Reason
#6 Repository audit and MVP readiness Prerequisite (definition only) It defines the acceptance wording this gate uses ("Browser-only emulation is not proof…"). Merging it, or adopting its check list, fixes the target before implementation. It blocks no code.
#5 Declarative configuration and template capabilities Post-MVP (coordinate) It would reshape the schema that owner B edits. Land the single sandbox-stream enum value first, then fold it into #5.
#4 Declarative input and controller profiles Post-MVP The current controls.mapping is enough for one NES pad. #4 should then be rebased on the in-container input channel built in §3.
#2 Git for video games: snapshots and branches Post-MVP (depends on MVP) Exact snapshots need emulator-side state. §3 makes nes.toJSON() server-side, and #2 builds on that.
#1 Multiplayer via WebRTC invitations Post-MVP (depends on MVP + #4) It needs an authoritative emulator in the sandbox (§3) and normalized multi-slot input (#4) before WebRTC media relay.
#3 Extensions marketplace, hooks, Discord Post-MVP (last) It has no dependency from the gate. Its hooks need stable lifecycle, input and state APIs from the items above.

Dependency order: #6 → MVP implementation (§3, owners A/B/C, then D) → #5 → #4 → #2 → #1 → #3.


5. Blocked and unchecked items, with next hop and action

Owner chain: worker → supervisor → director → chief → CEO Agent.

Item State Next hop Concrete action
Gate cannot pass on the current architecture (§2) BLOCKED (needs implementation) Director (coordinates item 168) Approve or adjust §3. Dispatch owners A, B and C as three bounded workers in separate worktrees from 161322c, with file sets exactly as in the §3 table. D starts only after C reports a real result.
Audio never exercised (element 6) NOT_CHECKED Supervisor of owner C Make assertion 6 mandatory in the new profile. Do not accept a PASS without the RMS and WAV artifact.
Save persistence never exercised (element 7) NOT_CHECKED Supervisor of owner C Make assertion 7, the round trip across down/up, mandatory.
kiri exec behaviour on Kiri (assertion 2) NOT_CHECKED: listed in kiri --help, not run here Worker owner C Run kiri exec <c> ps once against the template-02 container during implementation. If it is unsupported, fall back to the /health pid plus the kiri stop causality check (assertion 3), and record that fallback.
Merge or adopt PR #6 as the gate definition Awaiting decision CEO Agent (via chief) Decide whether to merge PR #6 or treat this report's §3 assertions as the gate text. Merging needs owner approval for merge scope.
Naming of the new output value (sandbox-stream) and the schema bump Product/API decision Director → chief Confirm the name, and whether it stays in v0.2 (additive enum) or bumps the apiVersion. Owner B needs this before editing the schema.

Files read (all at 161322c)

  • gamecomposer/runtime.py, gamecomposer/core.py, gamecomposer/game-compose.schema.json
  • examples/nes/image/{Dockerfile,serve.py,player.html}, templates/02-nes-local-homebrew/{gamecomposer.yml,image/*}
  • tests/e2e-desktop/artifacts/nes-table-tennis/report.json, plus the frames session-1/20-before-input.png and session-1/21-after-input.png (viewed)
  • tests/e2e-desktop/run.cjs and tests/e2e-desktop/profiles.cjs (grep)
  • docs/DESKTOP-E2E-EVIDENCE.md, docs/GAMECOMPOSER-SPEC.md, docs/architecture.md
  • gh pr view 1..6 (bodies and file lists), plus the gh pr diff 6 excerpt

Back to all docs