Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
/precision reports browser→relay and read-back→browser hops on a clock the page aligns with the relay #498
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
/precision now reports browser→relay and read-back→browser with p50/p95 in hops, and both show in the admin Precision panel. bun test passed apart from one failure in bench/precision.test.ts, fixed below and re-run green.
shipped merged
1 earlier comment · 1 event
/precision now reports browser→relay and read-back→browser with p50/p95 in hops, and both show in the admin Precision panel. bun test passed apart from one failure in bench/precision.test.ts, fixed below and re-run green. Of the type checks, I only confirmed that the files I changed or added, plus src/ui/lobby-panel.js, have no errors; the repo has other type errors that predate this. scripts/design-lint.ts isn't in this checkout, so I couldn't run the lint.
- Page clock:
src/ui/clock-sync.jssends{"type":"sync","t0"}over/liveevery 3 s. The relay answers with its receive and send times (src/lobby.ts). The page takes the offset from the lowest-delay of the last 8 answers. It sends{"type":"clock","offsetMs","readBack":[…]}every 5 s. This is a separate frame from the health-meter report, because that one is capped at one per second per socket. browser→relay: the relay corrects each/followframe'stby the driver's last reported offset. It forwards the result to the arm server as{"hop","ms"}, in the batch it already sends for the relay→Pi hops. The arm server accepts only the four named link hops.read-back→browser: the relay now sendsreadAton its own clock, converted from the arm server's using the offset it already keeps. If that offset isn't known yet, the field is left out. The page timesnow + offset − readAt.- Panel: the Precision section lists every hop that has a measurement. Input checks for the clock frame are in
src/page-clock.ts. - Real arm only: the two new hops are recorded only against the real arm. In simulation they aren't recorded, because the simulated arm has no relay link to carry them.
New tests: src/ui/clock-sync.test.ts covers the offset math, src/page-clock.test.ts covers input validation, and src/relay.test.ts runs a fake page whose clock is 7 s behind, against an arm server whose clock is 5 s ahead. It checks that both hops come out at a few ms rather than seconds. There is also a panel test.
I also fixed bench/precision.ts, which referenced an out-of-scope server (left over from #493) and failed bench/precision.test.ts; it now passes.
The clock math and the tests are good, but two things block it. (1) Anyone can feed the scorecard. The new sync and clock frames on /live are accepted from every socket, guests and anonymous included, with no identity check and no rate limit. A guest can send a clock frame of 40 hops every few ms, and onReadBack forwards them straight into the arm server scorecard as read-back→browser. A guest also sets the offsetMs for their own id. Fix first: take clock hops only from a signed-in, non-banned person, or better only from the current driver, and rate-limit sync and clock per socket as who is limited, at most one clock per second. (2) The terminal door is not covered. The hops show in the admin Precision panel, but src/tty.ts does not list them, and the README is not updated for the new hops. Add the hop list to the terminal precision output, with a test, and say in the README how to read it. Smaller points: the doc comment for onTurnEnd now sits above onReadBack in lobby.ts; start() in clock-sync leaves two intervals running in the test; and in simulation the new hops are never recorded, so the preview cannot show them working. Say so on the page rather than showing an empty list.
Both blockers and the smaller points are addressed and pushed to the same branch. The six affected test files pass (127 tests), including the new ones; I did not re-run the full suite or the type check on the whole repo.
1. Gating the new frames (src/lobby.ts)
clockframes are taken only from the current driver. A signed-in, non-banned person counts; in a local run, where everyone drives, any socket does. A guest, a non-driver or a banned person is ignored, so they can neither feedonReadBacknor set an offset.syncandclockare each limited to one per second per socket. The page sends asyncevery 3 s and aclockevery 5 s, so it stays well inside that.- New test in
src/lobby.security.test.ts. A guest and a signed-in non-driver are refused, the driver is taken once, a secondclockin the same second is dropped, and a repeatsyncgets no answer.
2. Terminal and README
/precisionin the terminal now ends with a "latency by hop:" list, one line per timed hop with p50 and p95.src/terminal.test.tscovers it, including the case with no hops.- The README has a "Reading the latency hops" section: where to see them, what each hop is timed by, and when the list is empty.
Smaller points
- The
onTurnEnddoc comment is back aboveonTurnEnd, andonReadBackhas its own. start()insrc/ui/clock-sync.jsnow returnsstop(), and its test calls it.- When no hop was timed, both the admin panel and the terminal say "No link hops timed: they are measured against the real arm only, while someone drives it." I took the simulation point to mean saying this rather than recording hops in simulation, so the preview shows that note rather than numbers.
Approved. The page clock (four-timestamp ping over /live), the aligned readAt, the driver-only and rate-limited clock frames, the input checks in page-clock.ts, the terminal listing and the README section are all there, with tests that would fail without them. The preview serves / and the clock-sync.js asset; /precision is 404 to me, as it should be for a non-owner. The two hops are only visible to the owner, so I could not see numbers in the preview.
Two things to do next:
- Negative hops (a few ms of clock error) are dropped by the arm server and filtered out in clock-sync.js report(), which biases p50/p95 upward. Clamp small negatives to 0 or count them.
- The viewer.html listeners for clock-sync/clock-status attach after the dynamic import resolves, so the first pong can be missed. Attach them before the import.
/precisionnow reportsbrowser→relayandread-back→browserwith p50/p95 inhops, and both show in the admin Precision panel.bun testpassed apart from one failure inbench/precision.test.ts, fixed below and re-run green. Of the type checks, I only confirmed that the files I changed or added, plussrc/ui/lobby-panel.js, have no errors; the repo has other type errors that predate this.scripts/design-lint.tsisn't in this checkout, so I couldn't run the lint.src/ui/clock-sync.jssends{"type":"sync","t0"}over/liveevery 3 s. The relay answers with its receive and send times (src/lobby.ts). The page takes the offset from the lowest-delay of the last 8 answers. It sends{"type":"clock","offsetMs","readBack":[…]}every 5 s. This is a separate frame from the health-meter report, because that one is capped at one per second per socket.browser→relay: the relay corrects each/followframe'stby the driver's last reported offset. It forwards the result to the arm server as{"hop","ms"}, in the batch it already sends for the relay→Pi hops. The arm server accepts only the four named link hops.read-back→browser: the relay now sendsreadAton its own clock, converted from the arm server's using the offset it already keeps. If that offset isn't known yet, the field is left out. The page timesnow + offset − readAt.src/page-clock.ts.New tests:
src/ui/clock-sync.test.tscovers the offset math,src/page-clock.test.tscovers input validation, andsrc/relay.test.tsruns a fake page whose clock is 7 s behind, against an arm server whose clock is 5 s ahead. It checks that both hops come out at a few ms rather than seconds. There is also a panel test.I also fixed
bench/precision.ts, which referenced an out-of-scopeserver(left over from #493) and failedbench/precision.test.ts; it now passes.Closes #482