Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
The relay keeps the turns and the hold state under FORGE_APP_DATA, so a restart restores the queue, the driver and a held arm #296
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
The relay now restores the queue, the current driver and a STOP hold after a restart. I couldn't run the type check here because bun couldn't write its tempdir. One test fails here: server.test.ts expects the vendored three.module.js and gets a 404.
shipped merged
3 earlier comments · 2 events
The relay now restores the queue, the current driver and a STOP hold after a restart. I couldn't run the type check here because bun couldn't write its tempdir. One test fails here: server.test.ts expects the vendored three.module.js and gets a 404. That has nothing to do with this change, and I did not confirm it passes on main. The forge's check will run both.
- Turns:
Lobbytakes a newturnsFileoption and hands it toTurns, using the file option from piece 1.bench/fake-serve.tspassesturns.jsonunder its data dir, which isFORGE_APP_DATA/so101when that is set. - Hold:
CommandGatetakes an optional file and writes the hold onhold()andresume(). It restores the hold on construction.startRelaygets a newholdFileoption, andbench/fake-serve.tspasseshold.json. A held arm stays held after a restart, and only/resumelifts it. An unreadable hold file counts as held, by "restart", so a corrupt file can't free the arm. - E-stop: The relay only holds the gate on
POST /stop. E-stop is kept by the arm server, so I did not persist it here. - Test:
src/relay-restart.test.tsis new. It seats a driver and two queued people, issues/stop, then restarts the lobby and relay on the same dir. The driver, their turn end, the queue order and the hold (via/status) all come back the same. - Unchanged:
forge.jsonis untouched. The turns, command-gate, stop and lobby suites pass.
🤖 Generated with Claude Code
I merged main into the branch and pushed it. The only conflict was Software/so101/bench/fake-serve.ts, in the startRelay call, and I kept both sides' options. main added summaryEveryMs: 60_000 and this branch added holdFile: join(dir, "hold.json").
I re-ran only the suites covering this change (restart, command-gate, lobby and stop). They pass, 48 tests. I did not re-run the whole suite after the merge. The type check still can't run in this sandbox, so the forge's check will cover that.
The change is still as before: the relay keeps the turns file and STOP's hold under FORGE_APP_DATA. It restores the queue, the driver and a held arm on start, and the new relay-restart.test.ts covers it. E-stop is still kept by the arm server, so it is not persisted here.
🤖 Generated with Claude Code
The persistence works and the restart test is a good end-to-end check, but two things on the list are missing.
Fix first: add tests for the new CommandGate behaviour in the command-gate suite. relay-restart.test.ts only covers hold followed by restart. Nothing would fail if (a) resume() stopped saving, so a restart brought back a hold that had been lifted, or (b) a corrupt hold.json stopped counting as held 'by restart'. That second case is the safety claim of the change, so it needs a test. Cover these cases: hold then resume then a new gate on the same file is not held; a garbage file gives held.by === 'restart'; a missing file gives null.
Second: the README does not say that the queue, the driver and a STOP hold now survive a restart. It also does not say where they live (turns.json and hold.json under FORGE_APP_DATA/so101) or that only /resume lifts a restored hold. Add a short paragraph.
Smaller points:
- Smith's notes say the type check was not run and the full suite was not re-run after the merge. I did not run them either, so I'm relying on the forge's check for that.
- I did not look at the live preview, and I did not review the turns.ts side of the change.
I added the gate tests and the README paragraph, and the new tests turned up a bug in the hold loader, now fixed. The command-gate and relay-restart suites pass (13 tests). I have not run the type check or the full suite since the merge.
- The bug: a
hold.jsonthat was valid JSON but had noheldkey ([], for example) was read as "not held". That freed the arm, which is the case you were worried about. Now only an explicit{"held": null}frees it. A missing file still means no hold. Anything else that can't be read, or has the wrong shape, comes back as held "by restart". - Tests:
src/command-gate.test.tshas a new "a hold kept in a file" block with these cases:
- Hold, then a new gate on the same file, comes back held.
- Resume, then a new gate on the same file, is not held. This fails if resume() stops saving.
- A missing file gives no hold.
- Garbage, a wrong-typed held, "held":"yes" and [] all give held.by === "restart".
- An explicit {"held":null} gives no hold.
- README: a paragraph in
Software/README.md, after the E-stop section, says three things. The queue, the driver with their turn end, and the STOP hold live inturns.jsonandhold.jsonunderFORGE_APP_DATA/so101. OnlyPOST /resumelifts a restored hold. The arm server keeps its own E-stop inestop.json.
I also said in the paragraph that a turn which ended while the relay was down is not restored and the next person in line is called. That comes from Turns' load code, which I read but did not re-test.
Fix first: loadHeld frees the arm when hold.json exists but cannot be read (EACCES, EISDIR, EIO). Only ENOENT may mean no hold; every other read error must return the held-by-restart value, as the README and the doc comment promise. The tests only cover unreadable content, not an unreadable file, so add a test (e.g. make hold.json a directory) that fails without the fix. Otherwise the design is sound: atomic save, explicit {held:null} as the only freeing content, and turns plus hold restored in the restart test. Also: production wiring. The only startRelay/Lobby callers shown are bench/fake-serve.ts, which is fine if that is the entry point; say so in the pull.
An unreadable hold.json now keeps the arm held. loadHeld returns the held-by-restart value for any read error except ENOENT, and logs "cannot read …, staying held". A missing file is still no hold. The command-gate suite passes (13 tests). I did not re-run the type check or the full suite.
I added a test that makes hold.json a directory, so reading it fails with EISDIR. It checks the gate comes back held by "restart". With the old code (log, then return null) it would fail. I only checked that by inverting the ENOENT condition, which also broke other tests, so it doesn't show this test failing on its own. The doc comment on loadHeld now says "content or file".
On production wiring: Software/so101/bench/fake-serve.ts is the only place that builds the Lobby and calls startRelay, and it is what the forge runs. That is where turnsFile and holdFile are set, under FORGE_APP_DATA/so101 beside the other state. startRelay and Lobby called without those options still keep everything in memory, so tests and any other caller behave as before.
🤖 Generated with Claude Code
Does what #296 asks: Lobby passes turnsFile to the existing Turns file support, CommandGate keeps its hold in hold.json (atomic tmp+rename, missing file means no hold, anything unreadable or oddly shaped stays held by "restart"), and fake-serve wires both under FORGE_APP_DATA. The tests would fail without the change: gate round-trip, corrupt, EISDIR and explicit-null cases, plus a relay restart test covering driver, endsAt, queue order and hold. README is updated. Preview / answers 200. No new dependency and no scope beyond the issue. Next: (1) the safe-side failure has no way out except POST /resume, so say in the README where an admin sees a hold by "restart"; (2) the pull says the type check was not run here, so watch the forge check output for it.
The relay now restores the queue, the current driver and a STOP hold after a restart. I couldn't run the type check here because bun couldn't write its tempdir. One test fails here:
server.test.tsexpects the vendoredthree.module.jsand gets a 404. That has nothing to do with this change, and I did not confirm it passes on main. The forge's check will run both.Lobbytakes a newturnsFileoption and hands it toTurns, using the file option from piece 1.bench/fake-serve.tspassesturns.jsonunder its data dir, which isFORGE_APP_DATA/so101when that is set.CommandGatetakes an optional file and writes the hold onhold()andresume(). It restores the hold on construction.startRelaygets a newholdFileoption, andbench/fake-serve.tspasseshold.json. A held arm stays held after a restart, and only/resumelifts it. An unreadable hold file counts as held, by "restart", so a corrupt file can't free the arm.POST /stop. E-stop is kept by the arm server, so I did not persist it here.src/relay-restart.test.tsis new. It seats a driver and two queued people, issues/stop, then restarts the lobby and relay on the same dir. The driver, their turn end, the queue order and the hold (via/status) all come back the same.forge.jsonis untouched. The turns, command-gate, stop and lobby suites pass.🤖 Generated with Claude Code
Closes #252