Skip to content

Lab channel: write Lab/state.json for the lab server (#131 Slice 1) - #481

Merged
dayfine merged 3 commits into
lab/toolingfrom
lab/observation-seam
Nov 15, 2026
Merged

dayfine merged 3 commits into
lab/toolingfrom
lab/observation-seam

Conversation

@dayfine

@dayfine dayfine commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Follows #131 Slice 1 (app observation seam). Base: lab/tooling (#107); the diff shows only this change. Contract: #478's app_state goldens at ff209b3.

The lab channel now writes Lab/state.json beside the unchanged legacy Lab/state, so the lab server (#478) has a versioned state to read: instance UUID, pid and profile, panel, program state, the last start/stop and its source (ui, lab with the request id, program, error), controller, the newest frame's sequence and capture time, and unknown observations. It is rewritten at every 500 ms poll as the heartbeat. Program code is untouched; the seam is LabChannel plus one new LabConsoleCommands::video().

A new channel command, snapshot LABEL [TIMEOUT_MS], gives the server a frame newer than its call: it waits for the first frame that arrives after the line starts (100 to 60000 ms, default 5000), saves it as <request>_<LABEL>.png and prints snapshot saved instance=<uuid> frame_seq=<n> captured_at=<time> after=<n> path=<path>. It needs no owner token, program state or controller, only the panel's video. Otherwise the line fails after printing snapshot timeout instance=<uuid> after=<n> timeout_ms=<ms> or snapshot unavailable instance=<uuid> reason=no_video|panel_changed|app_closing|save_failed. The contract has no document for a shot result yet, so these lines are the channel's format (Lab.md).

Where #131's doc and #478 differ, this follows #478's goldens; other choices for #131's owner:

  • channel object (last_request, last_error, owner_claimed) and instance.profile: in the goldens, not in the doc's example. Written as the goldens have them.
  • The request id: lab/server: Slice 0 contracts and fixtures for the lab server (#131) #478 says the daemon puts it on the request. This adds a request <uuid> header line to request files (Lab.md); a request without one gets an app-made UUID, since source: lab needs a non-null id.
  • Transition source: the doc wants the widget to pass ui. Instead the channel listens to the program's state changes and marks its own start/stop on the UI thread just before calling it, so anything else (the Start/Stop button, the Discord integration's stop) reads as ui. No change to ProgramSession or the widget.
  • frame_seq: the doc says thread the video cache's sequence. The cache's counter is private to the camera backends, so this counts frames at VideoSession's frame listener: per app instance and increasing, but not the cache's number.
  • lab/server: Slice 0 contracts and fixtures for the lab server (#131) #478's README says legacy program= is empty for a non-program panel; the app writes that panel's identifier, and this keeps it (byte-compatible). panel.id in state.json is null for those.
  • video.state is live up to 2 s after the newest frame (shot's default max_age_ms). paused is supported by the writer but not written: lab/tooling has no breakpoints.
  • Not in this PR: the manual app-restart check that (instance, seq) changes (needs console B).

Testing: new CommonFramework::LabStateJson unit tests check the writer against the three app_state goldens byte for byte (copied into the test from #478), plus field mapping, video state and transition sources; CommonFramework::LabChannel gains request-id and UUID tests; new CommonFramework::LabSnapshot tests cover the snapshot's arguments, its wait for a newer frame and its reply lines. Compiled the touched files locally and ran these tests in a scratch driver; fork CI runs the full build and suite.

🤖 Generated with Claude Code

https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss

The lab channel now writes Lab/state.json beside the legacy Lab/state,
version 1 of the lab server's app_state contract (fork #478): instance
UUID, pid and profile, panel, program state, the last start or stop and
where it came from (ui, lab with the request's id, program, error), the
controller, the newest video frame's sequence and capture time, and
unknown observations. It is rewritten at every poll as a heartbeat; the
legacy file is unchanged.

A request may carry the lab server's id on a "request <uuid>" line.
LabTransitionTracker names the source of each start and stop from the
program's state changes; LabConsoleCommands gains video() so the channel
can count frames.

Tests: LabStateJson checks the writer against the contract's goldens
byte for byte, and the transition sources; LabChannel covers the request
id and the UUIDs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…lice 1)

"snapshot LABEL [TIMEOUT_MS]" waits for the first frame of the selected
console's video that arrives after the line starts, saves it as
<request>_<LABEL>.png and prints its instance id, frame_seq and capture
time, the same numbers Lab/state.json uses. It reads only: no owner
token, and no program state or controller check, so it works on a
stopped panel with no controller. No newer frame in time fails the line
with "snapshot timeout ..."; no video, a panel change, app shutdown or a
failed save fail it with "snapshot unavailable ... reason=...".

LabFrames takes over the frame counting from LabChannel's listener and
keeps a frame only while a snapshot waits for one.

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
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 marked this pull request as ready for review November 15, 2026 00:16
@dayfine
dayfine merged commit d9bbbed into lab/tooling Nov 15, 2026
8 of 9 checks 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