Skip to content

lab/server: Slice 2 attach-only read server (#131) - #482

Merged
dayfine merged 4 commits into
agentsfrom
lab/server-slice2
Nov 14, 2026
Merged

dayfine merged 4 commits into
agentsfrom
lab/server-slice2

Conversation

@dayfine

@dayfine dayfine commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Depends on #478 and #481. Base: agents-lab-server-slice0; the diff shows only this change.

The read-only lab server from #131 Slice 2: an MCP endpoint on 127.0.0.1 that serves console B's state, save, shot and ensure_game from the app's Lab/ files, with no lease, no write path and no press.

  • Streamable HTTP on stdlib http.server: one POST /mcp, bearer token from an owner-only file, loopback Host and own-Origin checks, sessions, 1 MiB cap. The server's own config must list exactly B.
  • console://B/state and console://B/save from strict reads of Lab/state.json (Lab channel: write Lab/state.json for the lab server (#131 Slice 1) #481) and Lab/save.json. No file, a partial or malformed file, an unsupported schema, another profile's app, a dead pid and a stale heartbeat (10 s) are each unavailable with that reason. A UI Start/Stop is reported as the user lease; there is nothing to enforce it yet.
  • ensure_game reads the app's observations and only verifies; unknown never verifies, so it says game_unknown until detectors exist.
  • shot checks state.json once, then sends Lab channel: write Lab/state.json for the lab server (#131 Slice 1) #481's snapshot frame <timeout_ms> at once and returns the saved frame's exact frame_seq and captured_at. It works on any panel with video, whatever the controller. Replies map to refusals: snapshot timeout is timeout (evidence {instance_id, frame_seq: after}), reason=no_video is video_stale, panel_changed / app_closing / save_failed are app_unavailable with that evidence.reason, and a reply naming another instance is app_unavailable / instance_replaced. Only the PNG path the server chose is opened, never one read from the journal.

Contract gaps for #131's owner:

  • No shot-result document: shot returns {console, path, instance_id, frame_seq, captured_at, call_started_at, request} beside the image, and the app's reply format is only Lab.md's lines.
  • app_unavailable has no reason enum: instance_replaced, panel_changed, app_closing, save_failed and unknown (a reason the server does not know) are free text in evidence.reason. App instance replacement also has no availability.reason in the v1 state enum.
  • No code for "the panel has no video": no_video is mapped to video_stale for now.
  • runs:// is left for Slice 6.

Testing: 46 unit tests in lab/server/tests for this slice (65 in lab/server) against a fake Lab/ folder and a fake app that answers snapshot as LabChannel does, in temp dirs: partial writes, stale files, app restarts, each snapshot reply, a journal naming a decoy path, timeouts, and 10 concurrent clients reading and shooting while the app rewrites its state. Run with python3 -m unittest discover -s lab/server/tests -t lab/server (Python 3.8). Nothing touched console B or the lab-B profile.

🤖 Generated with Claude Code

https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss

dayfine and others added 2 commits November 14, 2026 02:36
MCP over Streamable HTTP on 127.0.0.1 (stdlib http.server): bearer token,
Host/Origin checks, sessions, size caps, and a config that serves only
console B. Resources console://B/state and console://B/save from strict
reads of Lab/state.json and Lab/save.json; missing, partial, malformed,
unsupported-schema, dead-pid and stale-heartbeat files are explicit
unavailable states. Tools: ensure_game (verification only) and shot, which
waits for a frame newer than the call before asking the app's read-only
shot line. Fake-lab tests cover partial writes, stale files, sequence
resets, app restarts, timeouts and concurrent readers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
shot now sends `snapshot frame <timeout_ms>` at once and returns the exact
frame_seq / captured_at from the `snapshot saved` line. The panel and
controller refusals are gone; the app's timeout and unavailable replies map
to timeout, video_stale and app_unavailable (evidence.reason), and a reply
from another instance is instance_replaced. Only the expected outbox path is
opened. The fake app answers snapshot requests as LabChannel does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
dayfine added a commit that referenced this pull request Nov 14, 2026
Moves the seven open questions to settled with their recommended answers,
writes the nine answers from the 2026-11-14 implementation review into the
resources, lease, tool and slice text, corrects the legacy Lab/state fields
and what 7c44e72 does, and records Slices 0-3 as built (#478, #481, #482,
#483) and Slice 4 as approved on PokemonAutomation#1881's branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
@dayfine
dayfine changed the base branch from agents-lab-server-slice0 to agents November 14, 2026 23:45
@dayfine
dayfine marked this pull request as ready for review November 14, 2026 23:45
@dayfine
dayfine merged commit 61309b5 into agents Nov 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant