Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
STOP can lose to a command already in flight: the relay must drop what it holds, and the Pi must refuse commands older than its last STOP #435
Merged 43d 18h ago
A STOP now beats any command the relay had already accepted, and the Pi refuses commands stamped before its last STOP. Tests. With four CPU burners running, the STOP property test (the "STOP through the relay" group, cases a–c) passed 24 of 24, which is 8 reruns of 3 tests.
-
Reviews
Changes requested — before the latest pushThe design is right: gate shut, a rising epoch, arm-side sockets cut, then the STOP forwarded, and the Pi refuses frames stamped before its last STOP. One thing blocks it, and it is a test gap.
Fix first: the Pi-side wiring in
server.ts(gate.stopped(body.epoch)on POST /stop) has no test. Delete that line and every test still passes.command-gate.test.tscallsgate.stoppeddirectly. Thestop.test.tscases (a–c) use aFakePithat re-implements the epoch check, so they never run the real server. Add a test in the server suite that startsstartServerwith a fake bus, opens/followwith a stamped frame, POSTs/stopwith{epoch: N}, then sends a frame stampedepoch: N-1, and expects it to be refused. Also send a frame stamped N, and check that it is still refused while the gate is held. That is the behaviour the issue asks for, and nothing exercises it end to end.Smaller points:
fake-serve.test.tsdroppingARM_*from the child env is unrelated to the issue. The reason is plausible, but it is a separate change. Keep it only if the pull body says so, or split it out.arm.terminate()on STOP is an unclean close. The pull itself says the real Pi may read that as a lost driver. Say in the README or a code comment what the Pi does with it, or prefer a clean close with code 1000, which the Pi treats as a deliberate close.- The preview shows no visible change, as expected for this change. I checked the code and tests only, not the pictures.
ApprovedDoes what #435 asks and stays inside the safety pillar. On STOP the relay shuts the gate, raises a clock-based epoch, cuts the arm-side sockets and forwards the epoch. The Pi refuses frames stamped below its last STOP. The relay overwrites any client-supplied epoch (stamped() spreads the frame, then sets epoch), so a browser cannot forge one. Tests cover the gate rule, the real server (fails without gate.stopped) and the slow-link interleaving. The fake-serve hermetic change was asked for in the issue. I did not exercise the preview beyond reading the diff. Two things to do next: (1) the terminate() on STOP makes the Pi see a lost driver, so a park can start briefly before the STOP lands. Either send the STOP first and cut the socket right after, or add a test that the arm does not move in that window. (2) Add a line to the README or the gate doc on the epoch field in the wire format, so LAN senders know that omitting it is allowed.
-
Checks
shipped merged
-
History
- Test the arm server's STOP epoch end to end; say what the Pi does with the cut arm socket (#434) 51a43c6
- Tests read frames without the STOP epoch the relay stamps (#434) 76663f9
- STOP outruns frames in flight: the relay cuts its arm sockets and stamps a STOP epoch the Pi enforces; fake-serve test no longer inherits ARM_SERVER (#434) a7faf20
- The page runs again: the notes cache is noteFallback, not a second top-level fallback 037dab0
- Frame age p95 and bytes per viewer for H.264 versus MJPEG are measured on the public URL and written in the README (#430) 2bd0103
- Tapping the presence line opens a list of who is here, the driver highlighted and guests with a colour dot; Escape or an outside tap closes it (#429) ac045d7
- /admin shows today's peak viewers and joins per hour for the last 24 h, owner only, kept under FORGE_APP_DATA across a restart (#414) 40cb8df
- README: this forge repository is the arm app's home; the GitHub fork is deprecated (#428) 561d97a
- video-player.test.ts proves stop() closes the socket and the decoder and that no frame is drawn after it - test only (#427) be904f9
- The page plays a camera's H.264 through video-pane.js when it offers it and WebCodecs exists, and falls back to the frame feed when no picture comes within 3 s (#422) 5ed77fd
- docs/launch-check.md lists the signed-in half of the launch check as steps a person ticks on the real arm (#423) 9c2744f
- A stylesheet test proves the chat Report button is at least 44x44 px and its line keeps that room before and after 'Reported' - test only (#425) f01be40
- The long-press moderation dialog offers Mute (with its length) and Ban to a verified moderator on a plain user's line, not only to the owner (#412) 3358b0b
- /live answers {type:'who'} with who is here: usernames, guest names with their colour, and driving, queued or watching - lobby and test only (#424) 0c92f2e
- Owners and moderators get a 44 px menu button on each other person's chat line that opens the moderator menu; Escape or an outside tap closes it (#421) e9b9cd7
- chat.test.ts proves a timed mute survives a reload and still ends on time - test only (#420) 472bf14
- Each anonymous /live viewer gets a stable guest name from src/guest-names.ts, keyed by an HttpOnly browser-id cookie - lobby and test only (#411) 05e8009
- docs/launch-check.md records bench/launch-check.ts's PASS/FAIL lines from a run against production, and says how to rerun it (#413) 63d46c9
- src/ui/video-pane.js chooses H.264 or the frame feed for a camera and builds a labelled 44 px quality select - module and test only (#410) 6ea12c2
- src/ui/mod-menu.js builds the moderator menu for one chat line - Remove, Mute 10m/1h/24h/forever, Ban - and the exact /live frame each sends - module and test only (#409) 58cbfc8
2 earlier comments
A STOP now beats any command the relay had already accepted, and the Pi refuses commands stamped before its last STOP.
Tests.
- With four CPU burners running, the STOP property test (the "STOP through the relay" group, cases a–c) passed 24 of 24, which is 8 reruns of 3 tests. That is short of the 50 of 50 the issue asks for, because each rerun takes about 11 s here.
- The affected suites (relay, gate, stop, frame-limit, teleop, slider-follow, leader-arm, machine-feed, fake-serve) pass.
- I did not run the rest of
bun testor the unix-socket suites; the forge's check runs those. tscreports one error, insrc/visitor-counts.ts, which I didn't touch.
Relay (src/relay.ts)
- On
POST /stopthe relay now shuts the gate, raises a STOP epoch, and terminates every arm-side/followsocket. That discards anything accepted but not yet written. Only then does it close the browser streams and forward the STOP. - The epoch is a clock-based counter, so it never repeats across a relay restart. It goes out on the STOP body and on every frame forwarded to the Pi.
Pi (src/command-gate.ts, src/server.ts)
POST /stoprecordsepoch, and the gate drops any frame with a lower epoch (before-stop), however the network orders them.- Frames with no epoch, such as the LAN leader's, are unaffected.
Tests
command-gate.test.tscovers the epoch rule.stop.test.ts: the fake Pi now enforces the epoch the way the real one does. New case (c) runs the interleaving property with each write landing 50 ms late.frame-limit.test.tsandrelay.test.tscompared forwarded frames exactly. They now strip theepochfield first; the tests were right, the wire format changed.
Real-Pi address in tests: src/fake-serve.test.ts spawned bench/fake-serve.ts with all of process.env. In the check cell that includes the live ARM_SERVER, so the child dialled the real Pi at 100.89.95.68. It now drops every ARM_* variable. That is my inference from reading the code. I did not reproduce it, since ARM_SERVER isn't set here. The other tests that mention that address only parse strings.
An unclean arm-socket close, as the relay now does on STOP, may be treated by the real Pi as a lost driver rather than a deliberate close. The STOP holds the Pi anyway, so I left it.
🤖 Generated with Claude Code
The failure you pasted was from the earlier push, a7faf20. The pull's current head, 76663f9, shows the deploy as ok: "running at https://arm--435--forge-trevato-apps.open-platform.sh · its tests passed". I found nothing to change, so I pushed nothing.
The first push still had two tests that compared forwarded /follow frames exactly (frame-limit.test.ts, relay.test.ts). The relay now adds an epoch field to those frames, which broke the comparison, and the second commit made the tests ignore it. The log excerpt you pasted ends mid-run and doesn't show the failing test.
On 76663f9 the full local bun test gave 694 pass, 0 fail. It also passed with six CPU burners running beside it. tsc reports only the existing src/visitor-counts.ts error, which is the same on main.
The pull has no new preview failure to fix, so I'm leaving the code as it is.
I added the server-level test and documented the unclean close. I kept terminate() on the arm socket rather than switching to a clean close, and I did not split out the fake-serve.test.ts change. stop.test.ts and relay.test.ts pass (28 tests); I did not run the full suite for this round.
Server-level test. A new case in the "STOP on the arm server itself" group runs the real startServer. It sends a stamped frame, POSTs /stop with {epoch: N}, then resumes and opens a new stream. A frame stamped N-1 (fresh seq and t) moves nothing. A frame stamped N moves the arm to its target. I checked that the test fails when gate.stopped(body.epoch) is commented out in server.ts, and passes with it restored.
I did not test "a frame stamped N is still refused while the gate is held" as you described it. The STOP closes the stream, so there is no open socket to send on, and a new stream is refused while held. The existing "while held, a stream is refused and nothing it sends moves the arm" test already covers the held case.
terminate() on STOP. I kept it, because a clean close(1000) would flush the queue it is meant to drop. The comment at relay.ts:629 now says what the Pi does with the cut:
- It reads the close as a lost driver and would park the arm.
parkreturns at once while the gate is held, and the STOP the relay sends holds the Pi and aborts a park in progress.- The old-epoch frames that got out ahead of the STOP are refused once the Pi has the STOP.
Residual risk. The cut socket can reach the Pi before the STOP HTTP request does, so a park could start for a moment before the STOP aborts it. I left that because I judged it small and bounded. If you would rather avoid it, the alternative is to send the STOP to the Pi first and cut the socket after, which gives up the ahead-of-the-STOP ordering.
fake-serve.test.ts. The change drops ARM_* from the child's environment, and the issue explicitly asks for that ("make it hermetic"). That is why I left it in this pull. It stays in the pull body as its own bullet.
🤖 Generated with Claude Code
A STOP now beats any command the relay had already accepted, and the Pi refuses commands stamped before its last STOP.
Tests.
bun testor the unix-socket suites; the forge's check runs those.tscreports one error, insrc/visitor-counts.ts, which I didn't touch.Relay (
src/relay.ts)POST /stopthe relay now shuts the gate, raises a STOP epoch, and terminates every arm-side/followsocket. That discards anything accepted but not yet written. Only then does it close the browser streams and forward the STOP.Pi (
src/command-gate.ts,src/server.ts)POST /stoprecordsepoch, and the gate drops any frame with a lower epoch (before-stop), however the network orders them.Tests
command-gate.test.tscovers the epoch rule.stop.test.ts: the fake Pi now enforces the epoch the way the real one does. New case (c) runs the interleaving property with each write landing 50 ms late.frame-limit.test.tsandrelay.test.tscompared forwarded frames exactly. They now strip theepochfield first; the tests were right, the wire format changed.Real-Pi address in tests:
src/fake-serve.test.tsspawnedbench/fake-serve.tswith all ofprocess.env. In the check cell that includes the liveARM_SERVER, so the child dialled the real Pi at 100.89.95.68. It now drops everyARM_*variable. That is my inference from reading the code. I did not reproduce it, sinceARM_SERVERisn't set here. The other tests that mention that address only parse strings.An unclean arm-socket close, as the relay now does on STOP, may be treated by the real Pi as a lost driver rather than a deliberate close. The STOP holds the Pi anyway, so I left it.
🤖 Generated with Claude Code
Closes #434