Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
/follow: size and rate checks #78
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
/follow now has a size limit and a rate limit on both the arm server and the relay. Both checks run before a frame is parsed, before the turn and STOP checks, and before anything reaches the arm. Size: a frame over 1 KiB closes the stream with code 1009.
shipped merged
/follow now has a size limit and a rate limit on both the arm server and the relay. Both checks run before a frame is parsed, before the turn and STOP checks, and before anything reaches the arm.
- Size: a frame over 1 KiB closes the stream with code 1009. The
wsoptionmaxPayloadwas already 4096 on the arm server, but Bun'swsdoesn't enforce it. So the size is now counted in the message handler, andmaxPayloadis set to the same 1 KiB on both servers. - Rate: frames pass at up to 200 a second, with a burst of 50 after a quiet spell. Frames past that are dropped, never queued; the arm server counts them as
gatedin its stream stats. A stream with more than 400 frames dropped within 2 s (twice the rate, kept up) is closed with code 1008. Leaders send 50–100 frames a second, so normal driving never hits either limit. - The arm holds, it doesn't park: when a stream is closed for breaking a limit, the arm server treats it as ended, not lost, whatever close code the client sends back. The relay closes its side toward the arm with 1000, not
LOST_CLOSE. - Files: the limits and a token bucket are in the new
src/frame-limit.ts. It is used in the/followmessage handlers insrc/server.tsand inbridgeinsrc/relay.ts. The README's/followline names the limits.
Tests: src/frame-limit.test.ts covers byte counting, the bucket and flood detection. It also checks, on a real arm server, a frame at exactly 1 KiB passing and one byte over closing with 1009, then dropping and flood-closing. On the relay it checks that an oversized frame is not passed on and the arm side is closed with 1000, and that frames past the rate are not passed on.
One test changed: "frames faster than the command rate are merged" in server.test.ts sent 100 frames at once, which is now over the burst limit. It now sends 50 and expects at least 44 merged. That test's premise was what changed; the merging code didn't.
The type check passes. frame-limit, server, relay, stop, lobby, teleop, admin-relay and fake-serve tests pass (121 tests).
To try it: bun --cwd Software/so101 test src/frame-limit.test.ts.
Closes #36
🤖 Generated with Claude Code
Approved. Size is counted by bytes actually read, before parsing, on both the arm server and the relay. Rate is per stream, which is per socket, and no client header is involved. Frames over the limit are dropped, never queued. A stream closed for breaking a limit makes the arm hold rather than park, and tests cover both the arm server and the relay. The one changed test is justified in the pull. I could not load the preview from my sandbox (network denied), so this verdict rests on the diff and the tests.
Two things to do next:
- The flood threshold is described as twice the rate, but it counts drops (more than 400 in 2 s). A sender must therefore send about 600 a second, three times the rate, before it is closed. Either fix the wording in the README and frame-limit.ts, or count arrivals instead of drops.
- The relay drops frames silently, while the arm server counts them as gated. Count them in the relay too, so the Machine panel shows a throttled driver.
/follownow has a size limit and a rate limit on both the arm server and the relay. Both checks run before a frame is parsed, before the turn and STOP checks, and before anything reaches the arm.wsoptionmaxPayloadwas already 4096 on the arm server, but Bun'swsdoesn't enforce it. So the size is now counted in the message handler, andmaxPayloadis set to the same 1 KiB on both servers.gatedin its stream stats. A stream with more than 400 frames dropped within 2 s (twice the rate, kept up) is closed with code 1008. Leaders send 50–100 frames a second, so normal driving never hits either limit.LOST_CLOSE.src/frame-limit.ts. It is used in the/followmessage handlers insrc/server.tsand inbridgeinsrc/relay.ts. The README's/followline names the limits.Tests:
src/frame-limit.test.tscovers byte counting, the bucket and flood detection. It also checks, on a real arm server, a frame at exactly 1 KiB passing and one byte over closing with 1009, then dropping and flood-closing. On the relay it checks that an oversized frame is not passed on and the arm side is closed with 1000, and that frames past the rate are not passed on.One test changed: "frames faster than the command rate are merged" in
server.test.tssent 100 frames at once, which is now over the burst limit. It now sends 50 and expects at least 44 merged. That test's premise was what changed; the merging code didn't.The type check passes.
frame-limit,server,relay,stop,lobby,teleop,admin-relayandfake-servetests pass (121 tests).To try it:
bun --cwd Software/so101 test src/frame-limit.test.ts.Closes #36
🤖 Generated with Claude Code
Closes #36