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

A game box runs a claimed check in a cell with no reach to Docker, worlds or its token, and a join freezes it at once #17607

opened this

Merged 16h 41m ago, live in production

The box side of "Run checks while servers sleep" is written and tested against stand-ins, but it has never run on a real box and I did not produce the tps/mspt and wake-time proof.

Notes

opened this

The box side of "Run checks while servers sleep" is written and tested against stand-ins, but it has never run on a real box and I did not produce the tps/mspt and wake-time proof. Two things were not run for real: bubblewrap here refuses user namespaces, so the cell's arguments were only checked against a recording stand-in, and starting anything on a real box needs your go. The boot, agent-update, lend, runner, TUI-games and openapi suites pass (1065 tests), and tsc and bun scripts/gate.ts are clean apart from "similar function" hints I judged to be noise.

What changed

  • Runner token to the box. The sync answers lend: {token} once to a box that says it holds none, and lend: {off: true} after the switch goes off. If the forge restarted before delivery or the reply was lost, the old runner is revoked and a new one enrolled, so the box is never left without one. The token lives only in forge memory until sent and in /opt/forge-game/.runner.auth (mode 600).
  • The cell (src/games/agent.sh).
    • Claiming. One job per tick, only when no container started in the last 90 s, no compose job is running, and at least 768 MiB is available.
    • Per-step cell. Each step is its own systemd unit with a memory, cpu and task cap and a cgroup to freeze. It runs as the unprivileged user forge-job in bubblewrap with --unshare-all, /usr read-only, only the checkout at /work, and a cleared environment. The cell sees no /run (the Docker socket), no /opt/forge-game (agent.env, the box's token) and no data volume.
    • Network. The check step has no network. The install step shares it, but iptables rejects that user's traffic to private, loopback, link-local and shared-range addresses.
    • Disk. The checkout is a size-capped tmpfs.
    • Handed back, not run. The box hands a job back (the forge runs it) when the job names egress hosts, declares no memory, or needs a tool the box lacks (exit 126/127); after a missing tool it rests 10 minutes.
  • Join order.
    1. A docker events reader stops claiming and freezes every job cgroup at once; nothing waits on a job.
    2. A guard checks twice a second and, still frozen with memory under the floor or frozen for 5 minutes, kills the job and answers interrupted.
    3. A quiet box thaws it.
  • interrupted (src/checks/runner_jobs.ts). A new report on POST /api/v1/runner/jobs/:id: the job goes back to queued with no result and its claim not counted. It is never red and never a try of MAX_CLAIMS, and the check's log says so.
  • Boot. New boxes install bubblewrap, git and iptables; an older box runs no jobs until they are there.
  • Tests.
    • test/runner-interrupted.test.ts evicts one job more than MAX_CLAIMS times and checks its claim count stays at 0 and the old token is dead.
    • test/game-lend-box.test.ts runs the real agent against a fake forge: token handling, cell contents, red only by exit code, hand-back cases, and a join that freezes first and then stops and answers interrupted.
    • test/game-lend.test.ts covers the token answer.
  • Docs. docs/features/game-box.md, docs/features/runners.md and the openapi route text.

What I left out or want you to know

  • No toolchain on the box. It has no bun. A job needing one is handed back until the owner puts a toolchain in /opt/forge-job-tools, which the cell mounts at /opt/tools. This also means almost every real job is handed back today, so the feature does little until a toolchain is provided.
  • The claim loop runs in the agent, not in a cell. The claim loop and the checkout are the agent's own shell code. They hold the runner token in a file no cell can see, and each job step is cell-run. I did not nest a second runner inside a cell.
  • Not done here: seeds, install caching, and bandwidth caps on the install step's network.
  • Ubuntu 24.04 may block it. Its AppArmor restriction on unprivileged user namespaces may need a bubblewrap profile for the cell to start.

To try

  • bun test test/runner-interrupted.test.ts test/game-lend-box.test.ts test/game-lend.test.ts.
  • To exercise it on a box, switch "Run checks while servers sleep" on at /games/<box> once you give the go.

Closes #17578

3 earlier comments · 1 event
commented

The box side of "Run checks while servers sleep" is written and tested against stand-ins, but it has never run on a real box and I did not produce the tps/mspt and wake-time proof. Two things were not run for real: bubblewrap here refuses user namespaces, so the cell's arguments were only checked against a recording stand-in, and starting anything on a real box needs your go. The boot, agent-update, lend, runner, TUI-games and openapi suites pass (1065 tests), and tsc and bun scripts/gate.ts are clean apart from "similar function" hints I judged to be noise.

What changed

  • Runner token to the box. The sync answers lend: {token} once to a box that says it holds none, and lend: {off: true} after the switch goes off. If the forge restarted before delivery or the reply was lost, the old runner is revoked and a new one enrolled, so the box is never left without one. The token lives only in forge memory until sent and in /opt/forge-game/.runner.auth (mode 600).
  • The cell (src/games/agent.sh).
    • Claiming. One job per tick, only when no container started in the last 90 s, no compose job is running, and at least 768 MiB is available.
    • Per-step cell. Each step is its own systemd unit with a memory, cpu and task cap and a cgroup to freeze. It runs as the unprivileged user forge-job in bubblewrap with --unshare-all, /usr read-only, only the checkout at /work, and a cleared environment. The cell sees no /run (the Docker socket), no /opt/forge-game (agent.env, the box's token) and no data volume.
    • Network. The check step has no network. The install step shares it, but iptables rejects that user's traffic to private, loopback, link-local and shared-range addresses.
    • Disk. The checkout is a size-capped tmpfs.
    • Handed back, not run. The box hands a job back (the forge runs it) when the job names egress hosts, declares no memory, or needs a tool the box lacks (exit 126/127); after a missing tool it rests 10 minutes.
  • Join order.
    1. A docker events reader stops claiming and freezes every job cgroup at once; nothing waits on a job.
    2. A guard checks twice a second and, still frozen with memory under the floor or frozen for 5 minutes, kills the job and answers interrupted.
    3. A quiet box thaws it.
  • interrupted (src/checks/runner_jobs.ts). A new report on POST /api/v1/runner/jobs/:id: the job goes back to queued with no result and its claim not counted. It is never red and never a try of MAX_CLAIMS, and the check's log says so.
  • Boot. New boxes install bubblewrap, git and iptables; an older box runs no jobs until they are there.
  • Tests.
    • test/runner-interrupted.test.ts evicts one job more than MAX_CLAIMS times and checks its claim count stays at 0 and the old token is dead.
    • test/game-lend-box.test.ts runs the real agent against a fake forge: token handling, cell contents, red only by exit code, hand-back cases, and a join that freezes first and then stops and answers interrupted.
    • test/game-lend.test.ts covers the token answer.
  • Docs. docs/features/game-box.md, docs/features/runners.md and the openapi route text.

What I left out or want you to know

  • No toolchain on the box. It has no bun. A job needing one is handed back until the owner puts a toolchain in /opt/forge-job-tools, which the cell mounts at /opt/tools. This also means almost every real job is handed back today, so the feature does little until a toolchain is provided.
  • The claim loop runs in the agent, not in a cell. The claim loop and the checkout are the agent's own shell code. They hold the runner token in a file no cell can see, and each job step is cell-run. I did not nest a second runner inside a cell.
  • Not done here: seeds, install caching, and bandwidth caps on the install step's network.
  • Ubuntu 24.04 may block it. Its AppArmor restriction on unprivileged user namespaces may need a bubblewrap profile for the cell to start.

To try

  • bun test test/runner-interrupted.test.ts test/game-lend-box.test.ts test/game-lend.test.ts.
  • To exercise it on a box, switch "Run checks while servers sleep" on at /games/<box> once you give the go.
the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

No new code this turn. I re-ran each check you named against the branch and none fails here. The branch was already pushed (git push said "Everything up-to-date"), so the forge's own check has to say whether it still refuses. If it does, its log is the next thing to read.

  • Both doors: bun scripts/gate.ts --explain passes. The commits carry "No door:" lines, because the sync answer and the runner report are machine routes with no page or terminal view of their own.
  • Name the issue: the Direction line in 604ec64c2 ends with (#17578), and the gate passes.
  • Tests with real input: the two new test files, test/game-lend-box.test.ts and test/runner-interrupted.test.ts, contain no as never or as unknown as.
  • Dead code: bun scripts/unused-exports.ts reports nothing in the files I touched. The two exports I added, interruptJob and lendAnswer, both have callers.

bun x tsc --noEmit is clean, and the four covering test files pass (45 tests). The gate's two notes are not gate failures. The duplicate-function notes are advisory and I left them; the comment-width note says the nightly rewrap handles it on main.

Pull description

A game box can now run a claimed check while servers sleep, and a join stops it at once.

  • Box agent: src/games/agent.sh claims jobs with the runner token the sync delivers once. It runs each step as an unprivileged user in a bubblewrap cell under its own cgroup, with no reach to Docker, worlds or that token. On a join it stops claiming, freezes the cgroup and stops the job.
  • Interrupted jobs: a stopped job is reported as interrupted, not red and not a try. POST /api/v1/runner/jobs/<id> with {"interrupted":"a server woke"} on a held job queues it again with no result (src/checks/runner_jobs.ts, src/http/api/runners.ts).
  • Token: lendAnswer sends the box its runner's token once, and a new one when it has none (src/games/lend.ts).
  • Left out: no page or terminal change, since the switch and its words already exist. The sync and runner routes are machine routes, and docs/features/game-box.md and runners.md cover them.

To try it, run bun test test/runner-interrupted.test.ts test/game-lend-box.test.ts.

🤖 Generated with Claude Code

commented

This push fixes the box-side findings and the forge-side bound on interruptions. Box 4's proof (tps, mspt and wake time) is still not delivered. The gate, tsc and the covering tests pass here. The tests cover the cell's argv, user and ownership calls, and firewall rules only through stand-ins. Nothing here ran against a real box with real mount, setpriv or iptables.

Fixed, box side (src/games/agent.sh):

  • Output (HIGH 1): a step's output now goes to $work/out, inside the job's capped tmpfs. A file-size limit also stops any write past 1 MiB (FORGE_GAME_LEND_OUT_KIB). A flooding step is killed with SIGXFSZ, so the job reports "killed (signal 25)" rather than an unbounded disk. Only the last 64 KiB is read. The new flood test passes.
  • Checkout ownership (HIGH 2): src is created through as_job, so the job user owns it. New host-mode tests (FORGE_GAME_LEND_HOST=1) use stand-ins for id, mount, setpriv, hostname, iptables, ip6tables and useradd. They check that the tmpfs is mounted with the job's uid and gid, and that mkdir and git run through setpriv --reuid=forge-job.
  • Token (MEDIUM 3): the job token is now in the environment of the as_job call, not on argv. The tests check that it reaches git by environment and appears in no setpriv, git or bwrap argument. The comment is corrected.
  • Network (MEDIUM 4): the reject rule now also covers the box's own addresses, v4 and v6. A missing ip6tables on a host with a non-loopback IPv6 address now hands the install step back instead of skipping IPv6. That last case is covered by a test, but it only asserts the handback when the machine running the test has such an address.

Fixed, forge side:

  • Interruptions (LOW 5): the first interruption of a job still gives its claim back. A job already interrupted keeps its claim, so a runner that interrupts forever brings the check to MAX_CLAIMS and the forge runs it itself. A lapsed lease clears result, so runner_step.ts no longer says "stopped the job" for a silent runner. Both are tested in test/runner-interrupted.test.ts.

Also: docs/features/game-box.md describes the output cap and the address rule.

Not done:

  • Box 4 proof: I have no real box in this sandbox. The box stays open, and a person should run it on a box and add the numbers, or split it into its own issue.
  • Box 1 bandwidth: the install step still has no bandwidth cap.
commented

Left #17578 open: 2 unticked items remain (When the switch is on, src/games/agent.sh runs the runner and each job in a cell (bubblewrap) with no route to the Docker socket, the game network, the data volume or agent.env, and with disk and network caps.; Proof in the pull: tps and mspt (src/games/metrics.ts) of an awake server with and without a job beside it, and the wake time on join with a job running.).

Sign in to join this conversation.

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

Keyboard shortcuts

Docs