Public: anyone can read this; the crew can change it.

Crew: after an agent.sh release, watch the box (check-in, idle CPU between syncs, no rollback) and post it on the release #18276

opened this

Merged 8h 34m ago, live in production

After a release that changes agent.sh, the forge now watches the game boxes and posts one comment on the release's pull. It says whether each box checked in with the new agent, whether the agent stayed near idle between syncs, and whether the rollback fired.

Notes

opened this

After a release that changes agent.sh, the forge now watches the game boxes and posts one comment on the release's pull. It says whether each box checked in with the new agent, whether the agent stayed near idle between syncs, and whether the rollback fired.

I ran the new tests, the diag tests, the migration, unused-export and module-state rules, and tsc; all pass. I did not run the whole suite. scripts/fast.ts named 2,905 files, so I picked the covering ones myself. I never ran the new agent against a real box. The CPU reading is only tested on the forge side with hand-built numbers: the agent test checks that the diag carries the sha and the rolled-back sha, not the CPU figure.

What changed

  • Agent side (src/games/agent.sh): each full sync's diag now carries agent: { sha, cpuPct, rolledBackSha }. cpuPct is the share of one core used by the agent and the commands it ran since the previous full sync. The sha is the script's own sha256.
  • Forge side (src/games/agent_watch.ts): the first sync answered with an agent sha the forge hasn't watched before opens a watch on the newest forge release's pull. Each box needs three CPU readings from the new sha. A box counts as idle if the median is at most 15% of a core. A box rolled back if it reports the new sha as rolledBackSha. The comment posts as forge-engine once every box has a verdict, or after 30 minutes. At 30 minutes it names the boxes that never checked in, or gave fewer than three readings.
  • Wiring: the sync route (src/http/games_routes.ts) calls watchAgent, and a failure there is logged without breaking the sync. A new migration, 20261204200000-game-agent-watch (pinned), keeps the readings per release.
  • Docs: docs/features/games.md has a paragraph on it.

Choices to know about

  • First sync ever: it only records a baseline, so deploying this posts nothing about a release nobody watched. The first release it can watch is the one after this.
  • Idle limit: the 15% limit and the three readings are my choices, not figures from the issue.
  • No new screen: the result is a comment, which every door already shows. The commit says No door.
  • Reused: median from src/efficiency/baseline.ts.
  • Test changes: test/game-diag.test.ts now uses toMatchObject, because the diag gained an agent field. I added assertions to test/game-agent-rollback.test.ts.

Not done

  • Part 1 of #18250 (validator run) and part 2 (ubuntu:24.04 agent tests recorded on the release).
  • Plugin QA with a bot.
  • I did not use keep_plan, estimate or similar.ts. Those tools weren't in my toolset (similar.ts I never ran).

Try it

  • Run bun test test/game-agent-watch.test.ts.
  • On a preview, POST /api/v1/games/agent/sync with a box token, a diag agent.sha equal to the forge's agentSha, and agent.cpuPct set. After three full syncs from each box, the release's pull gets the comment.

🤖 Generated with Claude Code

Closes #18272

3 earlier comments
commented

After a release that changes agent.sh, the forge now watches the game boxes and posts one comment on the release's pull. It says whether each box checked in with the new agent, whether the agent stayed near idle between syncs, and whether the rollback fired.

I ran the new tests, the diag tests, the migration, unused-export and module-state rules, and tsc; all pass. I did not run the whole suite. scripts/fast.ts named 2,905 files, so I picked the covering ones myself. I never ran the new agent against a real box. The CPU reading is only tested on the forge side with hand-built numbers: the agent test checks that the diag carries the sha and the rolled-back sha, not the CPU figure.

What changed

  • Agent side (src/games/agent.sh): each full sync's diag now carries agent: { sha, cpuPct, rolledBackSha }. cpuPct is the share of one core used by the agent and the commands it ran since the previous full sync. The sha is the script's own sha256.
  • Forge side (src/games/agent_watch.ts): the first sync answered with an agent sha the forge hasn't watched before opens a watch on the newest forge release's pull. Each box needs three CPU readings from the new sha. A box counts as idle if the median is at most 15% of a core. A box rolled back if it reports the new sha as rolledBackSha. The comment posts as forge-engine once every box has a verdict, or after 30 minutes. At 30 minutes it names the boxes that never checked in, or gave fewer than three readings.
  • Wiring: the sync route (src/http/games_routes.ts) calls watchAgent, and a failure there is logged without breaking the sync. A new migration, 20261204200000-game-agent-watch (pinned), keeps the readings per release.
  • Docs: docs/features/games.md has a paragraph on it.

Choices to know about

  • First sync ever: it only records a baseline, so deploying this posts nothing about a release nobody watched. The first release it can watch is the one after this.
  • Idle limit: the 15% limit and the three readings are my choices, not figures from the issue.
  • No new screen: the result is a comment, which every door already shows. The commit says No door.
  • Reused: median from src/efficiency/baseline.ts.
  • Test changes: test/game-diag.test.ts now uses toMatchObject, because the diag gained an agent field. I added assertions to test/game-agent-rollback.test.ts.

Not done

  • Part 1 of #18250 (validator run) and part 2 (ubuntu:24.04 agent tests recorded on the release).
  • Plugin QA with a bot.
  • I did not use keep_plan, estimate or similar.ts. Those tools weren't in my toolset (similar.ts I never ran).

Try it

  • Run bun test test/game-agent-watch.test.ts.
  • On a preview, POST /api/v1/games/agent/sync with a box token, a diag agent.sha equal to the forge's agentSha, and agent.cpuPct set. After three full syncs from each box, the release's pull gets the comment.

🤖 Generated with Claude Code

commented

The check failed because the box's diag now carries the agent sha, and three assertions in test/game-volume.test.ts expected diag to be exactly { hold: … }. I changed those three assertions (lines 403, 412 and 481) from toEqual to toMatchObject, so they still check the hold and ignore the extra field. The code is unchanged.

The third failure in the check log ("a failure opens one issue naming the step") is in test/one-click-drill.test.ts. It passes here, and the forge's own re-run found it green on main, so I treated it as unrelated to this change.

test/game-volume.test.ts and test/one-click-drill.test.ts now pass locally (37 tests), and bun x tsc --noEmit is clean. The new commit is pushed to the branch.

bun scripts/gate.ts --fix reported four files with comment lines over 100 columns and left them for the nightly rewrap; I didn't commit any rewrap.

commented

This update takes all five of sentinel's points; the one open question is the pinning limit in item 5, which I documented instead of fixing. The watch tests, the agent rollback and update tests, tsc, the gate, the dead-code test and the module-state test pass. I did not run the full suite.

  • Silent boxes: settleWatches in src/games/agent_watch.ts now runs from a new 60-second timer in src/main.ts, so the comment posts after WATCH_MS even if no box syncs. A test calls it with nobody syncing and checks the comment names every box, and that it posts only once. A new timer is a new process-wide state, so I kept it to one setInterval, cleared at shutdown.
  • Route wiring: a test POSTs /api/v1/games/agent/sync with a box token and diag.agent.sha equal to AGENT_SHA. It checks that the readings are stored and that the comment is posted on the third reading.
  • Agent CPU: a new test in test/game-agent-rollback.test.ts runs the real agent.sh as a loop, because FORGE_GAME_ONCE restarts the counters on every run. It asserts the first full sync has no cpuPct and the second has a number from 0 to under 100.
  • Which boxes are judged: the watch stores the box ids when it opens, in a new box_ids column added to the not-yet-released migration. Only those boxes are judged. A test creates a box after the watch opens and checks the comment is neither held for it nor mentions it.
  • Pinning the pull: I stated the limit instead of pinning. The forge does not know which commit changed agent.sh, so if another release lands before a box first syncs with the new script, the comment goes on that later release's pull. This is now in the module header and in docs/features/games.md.

The commits carry Direction: … (#18272) and No door:, because a comment on a pull has no screen of its own. The gate also flagged a timer in the new test, so that test now waits for the second sync and relies on its own timeout.

commented

Both failures are fixed and pushed. The forge's check hasn't run on the new push yet. Locally, test/job-slices.test.ts, test/schema-migrations.test.ts, test/timers-named.test.ts and bun scripts/gate.ts pass.

  • Untimed job: the new agent-watch timer in src/main.ts wasn't named in test/job-slices.test.ts. I added it to UNTIMED with its reason: every 60 s it makes a few indexed reads and at most one comment. settleWatches in test/game-agent-watch.test.ts drives it with a clock.
  • Migration pin: my last round added a box_ids column to 20261204200000-game-agent-watch, but that migration's pin file was already committed on this branch. I deleted that pin and pinned the migration again with bun scripts/pin-migrations.ts. This is safe because the migration is not on main; its pin has not been merged.

I did not run the whole suite.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs