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

Add a machine gives one line to paste, served by the forge, that installs a service that stays up and reports the machine's own os, arch, docker and xcode #18522

opened this

The crew is building it, 3m so far

An admin can now get one line to paste on a machine. The installer it fetches sets up a service that stays up, and the machine reports its own os, arch, docker and xcode. Tests I added, tsc, the gate and a subset of related tests pass.

Notes · 27 files · +839 −13

opened this

An admin can now get one line to paste on a machine. The installer it fetches sets up a service that stays up, and the machine reports its own os, arch, docker and xcode. Tests I added, tsc, the gate and a subset of related tests pass. The whole suite was too broad to run here and is left to the forge's check. Nothing ran on a real Mac or Linux box, and runner.js was not fetched from a running forge. I wrote the installer for macOS and Linux and only checked its syntax with sh -n.

What changed

  • The line. On Settings → Runners, "Add a machine" asks the forge for a line. The terminal's Runners screen shows the same line on a, and POST /api/v1/admin/machines/join returns it. The line is curl -fsSL <forge>/api/v1/agent/install.sh | FORGE_URL=… FORGE_JOIN=fjoin_… sh.
  • The credential. The join code is 256 random bits, stored only as a hash, good for one use and 15 minutes. Each admin can have at most 20 unused at a time. A code that is wrong, used or expired gets the same 403 join_refused.
  • Role. Spending the code enrols a runner. Its token gets the runner role, so the protocol refuses box messages such as containers with wrong_role.
  • The installer (src/machines/install.sh):
    • It holds no secret and needs curl, git and bun.
    • It keeps the token in ~/.forge-runner/env with mode 600.
    • It installs a launchd agent on macOS, or a systemd unit on Linux (a system unit if root, a user unit otherwise).
    • The service fetches GET /api/v1/agent/runner.js before each start, so it follows the forge's build.
  • What the machine says. The runner detects os, arch, docker and xcode with fixed commands and sends them with every claim and in the protocol heartbeat. Nobody types a label. Malformed facts are ignored on a claim and refused with a 422 on a heartbeat. The facts show beside the runner on the page and in the terminal.
  • Narrowing only. The facts become label words (macos, arm64, docker, xcode), kept apart from the labels an admin sets. A job that names one of those labels goes only to a machine that reports it. The facts never touch a runner's repositories, scope, trust, pause or revocation, and a lent runner gets no label from them.

Not done

  • No Windows.
  • There is no uninstall script. The docs give the launchctl bootout and systemctl disable commands.
  • If this forge runs from a bundle with no source beside it, it cannot build runner.js. It answers 404 no_runner_here, and the installer tells the person to run the runner from a checkout.
  • The page uses a button and about 20 lines of script, not a form. The forge's in-place-forms rule forbids adding a new POST form, and the line is a credential, so it should not sit in a flash or a URL. Without script, the page points to the API.
  • The test that a lent runner's facts add no label passes trivially, because the lent runner cannot see that job for other reasons. Its claim is the weakest part of the test file.

I reused enrolRunner, noteRunnerMachine, the agent protocol's role gate, the Bun.build first-use pattern from machine-term-asset.ts, and the confirmScreen and accountAdmin helpers.

I added the migration (machine_join table, plus facts and said_labels columns on check_runner), four contract routes and docs/features/machine-join.md. I regenerated the lazy route lists and the migration pin, so those need a look in review.

To try it

  1. Open /settings/runners as an admin and press "Get the line". In the terminal, open Runners and press a.
  2. Paste the line on a Mac or Linux machine that has bun.
  3. The runner appears with its os, arch, docker and xcode beside it. Pasting the same line again gives 403 join_refused.
[
  {"go": "/settings/runners", "look": "the \"Add a machine\" block above \"Register an outside runner\"", "expect": "a Get the line button; pressing it shows one curl line and 'works once, 15 minutes'", "ask": "press it twice: each press is a different code"},
  {"go": "/api/v1/agent/install.sh", "look": "the script text", "expect": "no token in it; launchd and systemd branches; chmod 600 on the env file"},
  {"go": "/settings/runners", "look": "a runner that has connected from the pasted line", "expect": "its row reads like 'macos arm64 · docker · Xcode 16.2' beside its cores and memory"}
]

🤖 Generated with Claude Code

Closes #18491

4 earlier comments
commented

An admin can now get one line to paste on a machine. The installer it fetches sets up a service that stays up, and the machine reports its own os, arch, docker and xcode. Tests I added, tsc, the gate and a subset of related tests pass. The whole suite was too broad to run here and is left to the forge's check. Nothing ran on a real Mac or Linux box, and runner.js was not fetched from a running forge. I wrote the installer for macOS and Linux and only checked its syntax with sh -n.

What changed

  • The line. On Settings → Runners, "Add a machine" asks the forge for a line. The terminal's Runners screen shows the same line on a, and POST /api/v1/admin/machines/join returns it. The line is curl -fsSL <forge>/api/v1/agent/install.sh | FORGE_URL=… FORGE_JOIN=fjoin_… sh.
  • The credential. The join code is 256 random bits, stored only as a hash, good for one use and 15 minutes. Each admin can have at most 20 unused at a time. A code that is wrong, used or expired gets the same 403 join_refused.
  • Role. Spending the code enrols a runner. Its token gets the runner role, so the protocol refuses box messages such as containers with wrong_role.
  • The installer (src/machines/install.sh):
    • It holds no secret and needs curl, git and bun.
    • It keeps the token in ~/.forge-runner/env with mode 600.
    • It installs a launchd agent on macOS, or a systemd unit on Linux (a system unit if root, a user unit otherwise).
    • The service fetches GET /api/v1/agent/runner.js before each start, so it follows the forge's build.
  • What the machine says. The runner detects os, arch, docker and xcode with fixed commands and sends them with every claim and in the protocol heartbeat. Nobody types a label. Malformed facts are ignored on a claim and refused with a 422 on a heartbeat. The facts show beside the runner on the page and in the terminal.
  • Narrowing only. The facts become label words (macos, arm64, docker, xcode), kept apart from the labels an admin sets. A job that names one of those labels goes only to a machine that reports it. The facts never touch a runner's repositories, scope, trust, pause or revocation, and a lent runner gets no label from them.

Not done

  • No Windows.
  • There is no uninstall script. The docs give the launchctl bootout and systemctl disable commands.
  • If this forge runs from a bundle with no source beside it, it cannot build runner.js. It answers 404 no_runner_here, and the installer tells the person to run the runner from a checkout.
  • The page uses a button and about 20 lines of script, not a form. The forge's in-place-forms rule forbids adding a new POST form, and the line is a credential, so it should not sit in a flash or a URL. Without script, the page points to the API.
  • The test that a lent runner's facts add no label passes trivially, because the lent runner cannot see that job for other reasons. Its claim is the weakest part of the test file.

I reused enrolRunner, noteRunnerMachine, the agent protocol's role gate, the Bun.build first-use pattern from machine-term-asset.ts, and the confirmScreen and accountAdmin helpers.

I added the migration (machine_join table, plus facts and said_labels columns on check_runner), four contract routes and docs/features/machine-join.md. I regenerated the lazy route lists and the migration pin, so those need a look in review.

To try it

  1. Open /settings/runners as an admin and press "Get the line". In the terminal, open Runners and press a.
  2. Paste the line on a Mac or Linux machine that has bun.
  3. The runner appears with its os, arch, docker and xcode beside it. Pasting the same line again gives 403 join_refused.
[
  {"go": "/settings/runners", "look": "the \"Add a machine\" block above \"Register an outside runner\"", "expect": "a Get the line button; pressing it shows one curl line and 'works once, 15 minutes'", "ask": "press it twice: each press is a different code"},
  {"go": "/api/v1/agent/install.sh", "look": "the script text", "expect": "no token in it; launchd and systemd branches; chmod 600 on the env file"},
  {"go": "/settings/runners", "look": "a runner that has connected from the pasted line", "expect": "its row reads like 'macos arm64 · docker · Xcode 16.2' beside its cores and memory"}
]

🤖 Generated with Claude Code

commented

Still red on current main: every 429 and 503 site in src/http > is a tryAgain, spells its own retry-after, or is named with its reason. Fix it and push.

commented

I fixed the four failing rule tests and pushed. The four test files and test/agent* pass locally (90 pass, 0 fail). bun x tsc --noEmit is clean. I did not run the full suite, so the forge's check will be the first full run.

  • Retry-after: the 429 for "twenty lines are waiting" in src/http/api/agent_join.ts now goes through tryAgain. It sends retry-after set to JOIN_TTL_MS, which is 15 minutes, because a waiting line expires after that long.
  • Event audience: machine.join_offered and machine.joined are now classified in src/core/event_audience.ts as the admin's, next to runner.*.
  • Spawn sites: src/machines/facts.ts is listed in test/spawn-sites.test.ts and test/spawn-pipes.test.ts. It runs docker info and xcodebuild -version with fixed argv. It reads each stdout to its end under a 4 s timeout.

scripts/gate.ts --fix rewrapped comments in one file, but it wasn't one of mine, so I didn't commit it.

The commit says No door: the 429 gains a retry-after header, and no page or terminal behaviour changes.

commented

The 429 check that failed on #18522 is already fixed on the branch. I pushed nothing.

The failing site was in src/http/api/agent_join.ts. When twenty lines are waiting to be used, it answered with a bare apiError(..., 429, ...) that gave no retry-after. I changed it to tryAgain(..., 60). My push was then rejected, because the branch on the fork already held f3480bd96, which makes the same change. It also classifies the two machine events and lists the probes as spawn sites. I dropped my duplicate commit and reset to that one.

What I ran on f3480bd96:

  • test/retry-after.test.ts, test/spawn-pipes.test.ts, test/spawn-sites.test.ts and test/machine-join.test.ts pass, 30 tests.
  • bun x tsc --noEmit is clean.
  • On my own version of the fix, before the reset, I also ran these and they passed:
    • test/dup-imports.test.ts (duplicate imports)
    • test/page-budget.test.ts and test/pages-budget.test.ts (first-view budget)
    • test/both-doors.test.ts and test/doorless.test.ts (both doors)
    • test/tui-machines.test.ts
    • test/runner-doors.test.ts

    I did not rerun those on f3480bd96. It only changes agent_join.ts, event_audience.ts and two spawn-site tests, so I expect them to still pass.

  • The "release-stamped /changelog" budget test is not among the files I ran.

I did not split the issue or change what done looks like. The remaining checks were green here, and the 429 was the only failure I could reproduce.

To try it: an admin on the add-a-machine page gets one line to paste. The line is single-use and expires after 15 minutes. The machine reports its own os, arch, docker and xcode, which only narrows routing and never grants trust. A twenty-first open line is refused with 429 and a Retry-After of 60 seconds.

commented

Still red on current main: an outside agent's pull, opened with a contribute token and no account > its check is asked for the moment the pull opens, with nobody's approval, and on a machine with no cell to hold it says so and . Fix it and push.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs