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

Moving a forge to another machine is copy, start, flip the router — and a test kills a machine #16989

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A forge in its own sandbox can now move to another declared machine: copy through the bucket, start, flip the router, receipt. If the machine dies, recover brings the forge back on another one from the bucket's last copy. The new tests, test/mcp-size.test.ts, the gate, tsc and design-lint pass.

Notes

opened this

A forge in its own sandbox can now move to another declared machine: copy through the bucket, start, flip the router, receipt. If the machine dies, recover brings the forge back on another one from the bucket's last copy. The new tests, test/mcp-size.test.ts, the gate, tsc and design-lint pass. I did not run the whole suite or bun scripts/similar.ts; scripts/fast.ts named 3,769 files, so I picked the tests covering the touched modules (130 pass). The forge's check runs the full suite on this push.

What changed

  • Move: src/spawn/move_machine.ts holds the forge's address and stops it. It packs the data and ledger into the backup destination under forge-moves/<name>/ and reads the copy back. It restores that copy on the target, starts the forge, waits for /healthz, then flips the route. Any failure before the flip leaves the route unchanged and removes the target's copy. The old machine keeps its data as the way back.
  • Budget: unreachable time is measured and the receipt says whether it was within MOVE_BUDGET_S (60 s). The plan states the budget before you confirm.
  • Router: src/spawn/routes.ts writes routes.json atomically. answerFromCell in host.ts forwards a moved forge's requests to its machine. startRefused stops a second copy from starting on this host.
  • Recover: recoverForge restores the newest bucket copy on another machine and flips. It refuses while the old machine still runs the forge.
  • Machines: declared with FORGE_MACHINES=name=/abs/root,… in src/spawn/machines.ts. processMachine runs the forge's entry as a process group, so one kill ends the whole tree.
  • Page: /forges/:name/machine previews, asks, then shows the receipt. A "Move to another machine" button appears on a sandboxed forge's row once a machine is declared.
  • MCP: forges with action: "move" or "recover" plus forge and to. It previews unless dryRun: false, which needs an admin token. I did not add a tool, and trimmed kind's schema to stay under the size ceiling.
  • Terminal: g on the Forges screen picks the forge and machine, shows the plan on a confirm, then shows the receipt. Page, MCP and terminal all use the plan's and receipt's own sentences.
  • Reused: archive.ts's tar and unpack validation, now exported as packForge and unpackForge, plus its destination probe, holdClosed, sleepChild and forward.

Tests

  • test/move-machine.test.ts moves a real process tree with a sleep child, kills it with a.stop, and checks the grandchild is dead.
  • It then recovers on machine B from the bucket and checks a request through answerFromCell returns the restored data.
  • It also covers refusing recovery while the old machine is alive, and recovery with no copy in the bucket.
  • test/move-machine-doors.test.ts covers the MCP and page previews and receipts, a cross-origin POST, and the terminal's key binding. It reads the terminal screen's source rather than driving the screen.

Left out

  • Streaming: nothing streams continuously to the bucket. The copy is the move's own, so a dead machine loses what was written since its last move. The receipt names the copy's time.
  • Failure detection: nothing detects a dead machine by itself; recover is asked for.
  • Remote machines: only the local process driver ships, and a remote machine needs another driver. That driver runs the forge's own entry unsandboxed on the declared root, so the machine itself is the boundary.
  • API route: there is no REST route, because the issue asked for the page and MCP.
  • No door: a commit line says the existing Forges screen carries the terminal door, so no new screen was added.
  • Allowlist: scripts/unused-exports-allow.json gained three test-only seams: registerMachine, forgetMachines and forgetRoutes.

Try it: set FORGE_MACHINES=m1=/abs/root and a backup destination, then open /forges and press "Move to another machine" on a forge in its own sandbox. Or call the MCP forges tool with {action:"move", forge, to:"m1"}.

🤖 Generated with Claude Code

Closes #16859

8 earlier comments
commented

A forge in its own sandbox can now move to another declared machine: copy through the bucket, start, flip the router, receipt. If the machine dies, recover brings the forge back on another one from the bucket's last copy. The new tests, test/mcp-size.test.ts, the gate, tsc and design-lint pass. I did not run the whole suite or bun scripts/similar.ts; scripts/fast.ts named 3,769 files, so I picked the tests covering the touched modules (130 pass). The forge's check runs the full suite on this push.

What changed

  • Move: src/spawn/move_machine.ts holds the forge's address and stops it. It packs the data and ledger into the backup destination under forge-moves/<name>/ and reads the copy back. It restores that copy on the target, starts the forge, waits for /healthz, then flips the route. Any failure before the flip leaves the route unchanged and removes the target's copy. The old machine keeps its data as the way back.
  • Budget: unreachable time is measured and the receipt says whether it was within MOVE_BUDGET_S (60 s). The plan states the budget before you confirm.
  • Router: src/spawn/routes.ts writes routes.json atomically. answerFromCell in host.ts forwards a moved forge's requests to its machine. startRefused stops a second copy from starting on this host.
  • Recover: recoverForge restores the newest bucket copy on another machine and flips. It refuses while the old machine still runs the forge.
  • Machines: declared with FORGE_MACHINES=name=/abs/root,… in src/spawn/machines.ts. processMachine runs the forge's entry as a process group, so one kill ends the whole tree.
  • Page: /forges/:name/machine previews, asks, then shows the receipt. A "Move to another machine" button appears on a sandboxed forge's row once a machine is declared.
  • MCP: forges with action: "move" or "recover" plus forge and to. It previews unless dryRun: false, which needs an admin token. I did not add a tool, and trimmed kind's schema to stay under the size ceiling.
  • Terminal: g on the Forges screen picks the forge and machine, shows the plan on a confirm, then shows the receipt. Page, MCP and terminal all use the plan's and receipt's own sentences.
  • Reused: archive.ts's tar and unpack validation, now exported as packForge and unpackForge, plus its destination probe, holdClosed, sleepChild and forward.

Tests

  • test/move-machine.test.ts moves a real process tree with a sleep child, kills it with a.stop, and checks the grandchild is dead.
  • It then recovers on machine B from the bucket and checks a request through answerFromCell returns the restored data.
  • It also covers refusing recovery while the old machine is alive, and recovery with no copy in the bucket.
  • test/move-machine-doors.test.ts covers the MCP and page previews and receipts, a cross-origin POST, and the terminal's key binding. It reads the terminal screen's source rather than driving the screen.

Left out

  • Streaming: nothing streams continuously to the bucket. The copy is the move's own, so a dead machine loses what was written since its last move. The receipt names the copy's time.
  • Failure detection: nothing detects a dead machine by itself; recover is asked for.
  • Remote machines: only the local process driver ships, and a remote machine needs another driver. That driver runs the forge's own entry unsandboxed on the declared root, so the machine itself is the boundary.
  • API route: there is no REST route, because the issue asked for the page and MCP.
  • No door: a commit line says the existing Forges screen carries the terminal door, so no new screen was added.
  • Allowlist: scripts/unused-exports-allow.json gained three test-only seams: registerMachine, forgetMachines and forgetRoutes.

Try it: set FORGE_MACHINES=m1=/abs/root and a backup destination, then open /forges and press "Move to another machine" on a forge in its own sandbox. Or call the MCP forges tool with {action:"move", forge, to:"m1"}.

🤖 Generated with Claude Code

commented

<!-- look-pages df4c275ce435 --> Look pages for df4c275, from the gate:

  • look pages (none): this pull changes src/web/pages/forge_machine.ts, src/web/pages/forges.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

I fixed the four failing scan tests and pushed. The four scan tests and test/move-machine.test.ts and test/move-machine-doors.test.ts pass locally, and tsc --noEmit is clean. I did not run the full suite; the forge's check does that on this push.

  • Fetch timeout: the health probe in src/spawn/machines.ts now carries AbortSignal.timeout(2000).
  • Spawn sites: src/spawn/machines.ts is listed in test/spawn-sites.test.ts with a sentence on why it starts a process.
  • Event audience: finish() in src/spawn/move_machine.ts now appends forge.moved and forge.recovered with literal kinds, so the scanner can read them. forge.recovered is classified in src/core/event_audience.ts with forge.moved.
  • Process-wide state: I added registered (src/spawn/machines.ts), busy (src/spawn/move_machine.ts) and tables (src/spawn/routes.ts) to test/module-state.baseline.txt. That file is meant to only shrink, so a reviewer may prefer these moved onto the app object, keyed in a WeakMap. I did not do that here.

forge.moved already existed for moving a forge into its own cell (src/spawn/move_cell.ts). The machine move reuses that kind for a different action, which may blur the activity feed.

bun scripts/gate.ts --fix listed three function pairs as near-duplicates, each with a similarity score. The machine-move code is in src/spawn/routes.ts save, src/tui/screens/forges.ts machineOne, and src/web/pages/forge_machine.ts forgeMachineSubmit. I left them as they are.

commented

<!-- look-pages e2c62f257dca --> Look pages for e2c62f2, from the gate:

  • look pages (none): this pull changes src/web/pages/forge_machine.ts, src/web/pages/forges.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

I answered the look-pages note with a commit line, Looks: /forges, and pushed it. I did not change any code or run the full suite.

The gate couldn't trace the route for the machine-move pages. /forges is the page the move button sits on. I took /settings/security/controls in the gate's message to be a stray path from its trace and did not look into it.

I ran the suites behind the other three listed failures, test/job-slices.test.ts, test/route-timing-coverage.test.ts, test/unused-exports.test.ts and test/tui-crawlers.test.ts, and none of them fail. I didn't open them to check which one holds each named test.

My one assumption is that those names map to these suites, so if the check still reds on one of them, send me its log.

commented

<!-- look-pages a9f527dbc2ab --> Look pages for a9f527d, from the gate:

  • look pages (none): "Looks: /forges" is not a page of app.looks in forge.json; this pull changes src/web/pages/forge_machine.ts, src/web/pages/forges.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

I pushed two commits that fix the two gate refusals. Neither changes any code or tests.

  • Look pages: The gate refused Looks: /forges because /forges isn't in app.looks. It also couldn't trace a handler for /settings/security/controls, the nearest listed page. A commit now carries a No look: line instead. The reason it gives is that the move button is owner-only on a forge row and needs FORGE_MACHINES and a second machine, which a look can't provide.
  • Replaces: A local gate run showed a second refusal, a missing Replaces: line for the new src/web/pages/forge_machine.ts. A second commit adds Replaces: nothing, moving a forge to another machine had no page or action before this.
  • Gate: A local bun scripts/gate.ts run no longer reports any rule refusal. It still prints notes about possible duplicate implementations, such as freePort in src/spawn/machines.ts and test/egress-leak.test.ts, and about an over-long comment in src/spawn/host.ts. I left those alone.
  • Checks not rerun: I didn't rerun tsc or any tests. The four recurring refusals in the feedback (the as never test inputs, dead-code exports, the untimed during jobs, and the screen test about the share and budgets) didn't come up in this feedback or the gate output, and I didn't check for them separately. The forge's check will report if any of them applies.

If a reviewer would rather have a look on this page, adding /forges to app.looks in forge.json is the alternative.

🤖 Generated with Claude Code

commented

This round fixes eight of the nine points. Point 6 (the stream) is still not built. The 19 test files I ran pass, as does tsc; I did not run the full suite, so the forge's check does that. scripts/fast.ts named 3774 test files, so I picked the relevant ones by hand. gate --explain shows 0 failures. It notes duplicate-function candidates, including freePort and the registryOf helper, which I did not fold into existing code.

Fixed

  1. Forge goes dark. If a move fails after the source machine was stopped, the source is started again there. The route follows its new port, and the error says if the restart also failed.
  2. Two copies. A machine's process-group pid is written to <root>/pids/<forge>.pid. After a host restart alive and stop read it back, so recover still refuses while the old copy runs. The test builds a second processMachine on the same root to stand in for the restart. A recycled pid is an accepted risk.
  3. Deleting data. bringUp no longer removes anything. Data the target already holds for the forge, and its ledger on a machine, is renamed <dir>.before-<time>. A failed move puts it back.
  4. Way back. to: "here" is now a target for move and recover. It restores into this forge's own root and clears the route. The page, terminal and MCP tool offer it.
  5. Recover preview. planRecover gives the copy, its time and what is lost.
    • MCP and page: action: recover without dryRun: false uses it, and the page has ?recover=1.
    • Terminal: v restores a forge.
    • Mutations: the MCP token scope and the same-origin form check stay on both.
  6. State and events.
    • Events: the machine move uses its own kind, forge.machine_moved, with an audience entry.
    • State: the three process-wide maps are now WeakMaps keyed on the app, and the three baseline lines are removed. This changes routeOf, setRoute, registerMachine and machinesOf to take the app.
  7. Tests and cleanup.
    • Terminal test: it drives g through the Forges screen (pick, pick, confirm) instead of reading source.
    • Removal: removeForge ends a machine forge, clears its route and removes its data on the machine.
    • Archive: a forge on a machine is refused, because the copy here is stale.
    • New tests: failure restart, restart-proof pid, aside and move back, recover plan, removal, and the archive refusal.
  8. Design. The page shows the plan sentence once. The four step rows are gone from the page. The terminal confirm still lists them.

Not done

  • Box 2 (stream). Nothing streams, and I did not build it. It needs a periodic consistent copy of live SQLite per forge, which is a separate piece of work. The copy is made at the move, and a machine that dies loses what was written since. The docs say so.
  • Dead route port. forward has no fallback when a route points at a dead port. The restart on failure covers the failed-move case.
  • Removal confirmation. Removing a forge on a machine deletes its data there, as removal already says it does.

Try it Set FORGE_MACHINES=m1=/abs/root with a backup destination, open /forges, and press Move to another machine on a forge in its own sandbox. Then use here to come back, or Restore after killing the machine. In the terminal, g moves and v restores.

🤖 Generated with Claude Code

commented

Left #16859 open: 1 unticked item remain (A test ends a machine's process tree and the forge comes back elsewhere from its stream.).

Sign in to join this conversation.

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

Keyboard shortcuts

Docs