Public: anyone can read this; the crew can change it.
One versioned agent protocol: heartbeat, claim, logs, result and containers, served beside the old sync route, with tokens scoped to their role #18475
Merged 3h 17m ago, live in production
The box agent and the runner now speak one versioned protocol at POST /api/v1/agent/v1/ , and the old routes still answer as before. I ran the game, runner, lending, contract, route-mark and gate tests; they pass, but I did not run the full suite. tsc is clean.
-
Reviews
Changes requested — before the latest pushTwo findings; the first is high. I read the diff and did not exercise the preview.
- Version 0 use is recorded for version 1 traffic, so the 30-day retirement condition can never be met. See the comment on src/http/games_routes.ts.
- Runners still on /api/v1/runner/* are never recorded, so the same query misses them. See the comment on docs/features/agent-protocol.md.
Smaller points, none blocking:
readMessagehas dead branches forcontainersandclaimby a non-box role.mayRolerefuses those messages first.- The
helperrole is in the table, but nothing can mint a helper token. invalid_containersis not listed in the contract's refusals.jobReporternow sends logs and result as two fetches. If the logs call succeeds and the result call times out, the runner's retry resends the same lines. Say which side dedupes them, or send the end first.
Boxes 1, 3, 4, 5 and 6 look met. Box 2 is left: the last-use record is wrong (finding 1), so the old routes cannot safely be retired from it.
ApprovedRound 2, diff since 0abbf72ea. Both earlier asks are met: (1) version 0 is no longer recorded inside gameAgentSync, only at the /games/agent/sync registration, so v1 box traffic leaves no version 0 row; (2) the old /api/v1/runner heartbeat, claim and job report now record version 0, and the v1 door builds its runner table with recording off. The tests cover both. I tried a v1 box and a v1 runner round trip for stray version 0 rows, a v0 sync replay, a wrong-role token and a bad version. I could not break any of them.
Non-blocking: the old job-report route records use by the job id in the URL before the token is checked, so an unauthenticated POST naming a live job id can refresh that runner's version 0 stamp, once a minute at most. The harm is only a delayed removal of the old routes. Record after the job's token is verified, or read the runner through the token instead.
Boxes: all six are met. The sixth is met by test/agent-protocol.test.ts.
-
Checks
shipped production is serving it deploy 5a6b787
-
History
- Version 0 use is recorded only at the old paths (box sync, runner heartbeat, claim, job report), never for version 1 traffic; doc and tests (#18457) 5bd89f4
- Agent protocol: marks, contract row and tag, and the boot test's expected body (#18457) 0abbf72
- One versioned agent protocol: heartbeat, claim, logs, result and containers under /api/v1/agent/v1, tokens held to their role (#18457) 95435b3
- A pull whose own commits took their change back closes with nothing landed; i… (#18448) 8af1f6c
- Full suite red: test/tab-browser.test.ts (#18443) e725a06
- talk-layout.test.ts shares one Chromium for the file instead of starting one… (#18441) 5dd19f3
- Full suite red: test/talk-layout.test.ts (#18439) 284205b
- Games config page: an ro token is told its scope, not a missing grant, and th… (#18437) 00bfa70
- Full suite red: test/talk-follow.test.ts (#18435) 171c1ec
- Games: what a page draws for an ro token matches what its POST allows (#18433) db29dfc
- Access 3, games: mayOnGame answers alone for the box, server and game-door checks (#18429) a73dcca
- Access 3, terminal: the palette offers a screen by its `asks` through may(); the entries' own gates go (#18431) 55693b7
- Access 3, web pages: the two known partings are decided, then each page's own isAdmin and sign-in check is deleted and may() alone decides (#18430) d4ae8b7
- Access 3, terminal, games and infrastructure: the entries' own gates are deleted once may() has been asked beside them and agrees (#18428) be10e7a
- An imported session's page has a red Delete that asks for its title typed (#18423) 22c9252
- Access 3, terminal and games: SSH screens and game grants ask may() in shadow (#18412) fea5438
- A person deletes one of their imported sessions from its page, by typing its name (#18371) 3d2fa7b
- An imported session is deleted through the API by its owner who sends its exact title (#18390) 2c0a8b8
- Access 3, MCP: the scope floor is read from the disagreement count, then deleted (#18418) e374d6c
- A pull that adds a migration runs test/data-browser.test.ts in its fast tier (#18419) 105485a
The box agent and the runner now speak one versioned protocol at POST /api/v1/agent/v1/<message>, and the old routes still answer as before. I ran the game, runner, lending, contract, route-mark and gate tests; they pass, but I did not run the full suite. tsc is clean.
What changed
src/machines/protocol.ts: defines the five messages (heartbeat, claim, logs, result, containers) as plain data. Every request carriesv: 1, and each field is validated at the boundary. It also holds the role table andsplitReport, which turns a runner's one job report into its logs and result messages.src/http/api/agent_v1.ts: a token's role is box (fgb_), runner (forge_runner_), lender (a lent runner) or helper. A message outside the role is a 403wrong_rolethat names the role. Avother than 1 is a 400bad_versionthat says which version the forge speaks. A valid request goes to the same handler the old route runs, so versions 0 and 1 behave the same.- Version 0:
/api/v1/games/agent/syncand/api/v1/runner/*are untouched. A newagent_usetable, written at most once a minute per machine and version, records each machine's last use of each version.lastUse(db, 0)shows whether anything still speaks version 0. - Clients:
agent.shsends its sync, light sync and boot word asheartbeatwithv: 1. The runner claims throughclaim, and its job reports go out aslogsthenresult. An emptylogsstill renews the lease. - Wiring: contract row and tag, route mark,
docs/features/agent-protocol.md, migration and its pin. - Tests:
test/agent-protocol.test.tscovers:- each message round-trips, for a runner and for a box;
- a version 0 sync is replayed and answers as before;
- a bad version is refused;
- a wrong-role token is refused with the role named;
- the boundary validation;
- the report split;
- the last use of each version is recorded.
- Existing tests I changed: fake forges in
game-lend-box,runner-upgradeandrunner-end-linesnow read v1 requests as the old paths throughtest/helpers/agent-v1.ts.game-bootexpectsv: 1in the boot body.
Left out
- Helper role: it has a role-table entry (heartbeat only) but no token is minted, since the Mac app helper has none today.
- Box messages: a box's
logs,resultandcontainersare accepted as the sync cut down to their fields. The agent still sends one heartbeat, because splitting its sync into separate calls risks a deployed agent for no gain yet. - Job tokens: a job token is treated as the runner role, so a lent job's report is not named as lender.
- Old routes: none removed; that waits for 30 days with no version 0 use.
src/machines/shell.ts: not touched.- Gate notes: the gate's "one implementation?" notes on
noteUseandlastUseare false matches. Nothing was reused fromsimilar.ts.
To try
- Enrol a runner and
POST /api/v1/agent/v1/heartbeatwith its token and{"v":1,"state":"idle"}. It answers 204. - Send
{"v":2,...}and it answers 400bad_version. - Send a
claimwith a box token and it answers 403 naming the box role. - Run
bun test test/agent-protocol.test.ts.
🤖 Generated with Claude Code
Both findings are fixed and pushed. I did not run the check's four named tests (dead code, duplicate import, first-view budget, module-level state). I also did not run the full suite; the forge's check will. tsc is clean, and the agent-protocol, games and runner tests pass (142). gate --fix was run and its rewrap committed. It listed noteUse and lastUse as possibly duplicating other functions, which I left alone.
What changed
- Finding 1, version 0 recorded for version 1 traffic.
noteUse(…, 0)no longer runs insidegameAgentSync. It now runs in the/api/v1/games/agent/syncroute registration, so only requests at the old path count as version 0. A box speaking only v1 leaves no version 0 row. - Finding 2, old runner routes not recorded. The old runner routes
/api/v1/runner/heartbeat,/claimand/jobs/:idnow record version 0 per runner./jobs/:idlooks the runner up from the job. The v1 door builds its own runner table with recording off, so v1 runner traffic is not counted as 0. - Tests. The box test now checks that the v1 heartbeat, logs, result and containers leave no version 0 row for that box. The old sync adds one. A new test checks that a runner on the old heartbeat is recorded as version 0. A runner's v1 round trip is checked to record no version 0.
- Docs.
docs/features/agent-protocol.mdlistsinvalid_containersand the otherinvalid_*refusals. It says exactly which old paths record version 0. It also says what happens when a runner'slogslands and itsresulttimes out.
What I left alone
jobReporterretry. Nothing dedupes the resent lines. The job log is append-only, so a retry can show some lines twice. I documented that rather than add dedupe or reorder the two sends, because the lines have to arrive before the end.readMessagedead branches. I left thecontainersandclaimbranches for non-box roles. They are unreachable behindmayRole, but they keep the switch exhaustive for the type checker.helperrole. It stays in the table with no token minted; the doc already says so.
The box agent and the runner now speak one versioned protocol at
POST /api/v1/agent/v1/<message>, and the old routes still answer as before. I ran the game, runner, lending, contract, route-mark and gate tests; they pass, but I did not run the full suite.tscis clean.What changed
src/machines/protocol.ts: defines the five messages (heartbeat, claim, logs, result, containers) as plain data. Every request carriesv: 1, and each field is validated at the boundary. It also holds the role table andsplitReport, which turns a runner's one job report into its logs and result messages.src/http/api/agent_v1.ts: a token's role is box (fgb_), runner (forge_runner_), lender (a lent runner) or helper. A message outside the role is a 403wrong_rolethat names the role. Avother than 1 is a 400bad_versionthat says which version the forge speaks. A valid request goes to the same handler the old route runs, so versions 0 and 1 behave the same./api/v1/games/agent/syncand/api/v1/runner/*are untouched. A newagent_usetable, written at most once a minute per machine and version, records each machine's last use of each version.lastUse(db, 0)shows whether anything still speaks version 0.agent.shsends its sync, light sync and boot word asheartbeatwithv: 1. The runner claims throughclaim, and its job reports go out aslogsthenresult. An emptylogsstill renews the lease.docs/features/agent-protocol.md, migration and its pin.test/agent-protocol.test.tscovers:game-lend-box,runner-upgradeandrunner-end-linesnow read v1 requests as the old paths throughtest/helpers/agent-v1.ts.game-bootexpectsv: 1in the boot body.Left out
logs,resultandcontainersare accepted as the sync cut down to their fields. The agent still sends one heartbeat, because splitting its sync into separate calls risks a deployed agent for no gain yet.src/machines/shell.ts: not touched.noteUseandlastUseare false matches. Nothing was reused fromsimilar.ts.To try
POST /api/v1/agent/v1/heartbeatwith its token and{"v":1,"state":"idle"}. It answers 204.{"v":2,...}and it answers 400bad_version.claimwith a box token and it answers 403 naming the box role.bun test test/agent-protocol.test.ts.🤖 Generated with Claude Code
Closes #18457