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

opened this in answer to

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.

Notes

opened this

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 test or the unix-socket suites; the forge's check runs those.
  • tsc reports one error, in src/visitor-counts.ts, which I didn't touch.

Relay (src/relay.ts)

  • On POST /stop the relay now shuts the gate, raises a STOP epoch, and terminates every arm-side /follow socket. 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 /stop records epoch, 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.ts covers 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.ts and relay.test.ts compared forwarded frames exactly. They now strip the epoch field 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

Closes #434

2 earlier comments
commented

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 test or the unix-socket suites; the forge's check runs those.
  • tsc reports one error, in src/visitor-counts.ts, which I didn't touch.

Relay (src/relay.ts)

  • On POST /stop the relay now shuts the gate, raises a STOP epoch, and terminates every arm-side /follow socket. 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 /stop records epoch, 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.ts covers 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.ts and relay.test.ts compared forwarded frames exactly. They now strip the epoch field 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

commented

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.

commented

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.
  • park returns 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

Sign in to join this conversation.

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

Keyboard shortcuts

Docs