Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

The arm keeps a 5 Hz intent-and-read-back trace per joint for its last 20 drive sessions and serves it at GET /precision/trace?session=<id> #541

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

The arm server now keeps a 5 Hz trace of each joint's intent and read-back for every driven session, and serves it at GET /precision/trace?session= . The new tests and the neighbouring precision, node-loads and jam-stream suites pass here.

Notes

shipped merged

opened this

The arm server now keeps a 5 Hz trace of each joint's intent and read-back for every driven session, and serves it at GET /precision/trace?session=<id>. The new tests and the neighbouring precision, node-loads and jam-stream suites pass here. I did not run the full bun --cwd Software/so101 test, and the type check could not run here (tsc can't find the bun types in this sandbox). The forge's check will cover both.

  • Sampling: a 200 ms timer per stream records each joint's intent and read-back from the tracker's cached values (Tracker.levels() in src/precision.ts). It adds nothing to the per-frame write path, and the timer is cleared when the stream ends. A session records at most 3000 samples, which is 10 minutes.
  • What counts as intent: the driver's target for that joint. When no target is being chased (after a hold or a jam), the joint's own position is recorded instead.
  • Storage: a traces table in precision.sqlite (src/precision-history.ts). The trace's session is the same id as the session's row. Only the newest 20 traces are kept.
  • Endpoint: returns { session, t0, hz, joints: { [name]: { intent, actual } } } (the added session filter in src/server.ts). A missing or non-numeric id is a 400. An unknown or evicted id is a 404.
  • Tests: in src/precision-history.test.ts, on the fake bus:

- a short drive gives the right length and a 5 Hz rate; - the 21st session evicts the first; - a 10-minute cap holds at 3000 samples; - the HTTP route returns 400, 404 and a real trace.

Two behaviours to know about:

  • A session that measured nothing is not stored, so it has no trace.
  • A joint first read part-way through a session is padded with its first value, so all series stay the same length.

The relay does not proxy /precision/trace; I only added the arm half.

The "Cannot use a closed database" lines in the jam-stream test output also appear without my change.

Closes #533

1 earlier comment · 1 event
commented

The arm server now keeps a 5 Hz trace of each joint's intent and read-back for every driven session, and serves it at GET /precision/trace?session=<id>. The new tests and the neighbouring precision, node-loads and jam-stream suites pass here. I did not run the full bun --cwd Software/so101 test, and the type check could not run here (tsc can't find the bun types in this sandbox). The forge's check will cover both.

  • Sampling: a 200 ms timer per stream records each joint's intent and read-back from the tracker's cached values (Tracker.levels() in src/precision.ts). It adds nothing to the per-frame write path, and the timer is cleared when the stream ends. A session records at most 3000 samples, which is 10 minutes.
  • What counts as intent: the driver's target for that joint. When no target is being chased (after a hold or a jam), the joint's own position is recorded instead.
  • Storage: a traces table in precision.sqlite (src/precision-history.ts). The trace's session is the same id as the session's row. Only the newest 20 traces are kept.
  • Endpoint: returns { session, t0, hz, joints: { [name]: { intent, actual } } } (the added session filter in src/server.ts). A missing or non-numeric id is a 400. An unknown or evicted id is a 404.
  • Tests: in src/precision-history.test.ts, on the fake bus:

- a short drive gives the right length and a 5 Hz rate; - the 21st session evicts the first; - a 10-minute cap holds at 3000 samples; - the HTTP route returns 400, 404 and a real trace.

Two behaviours to know about:

  • A session that measured nothing is not stored, so it has no trace.
  • A joint first read part-way through a session is padded with its first value, so all series stay the same length.

The relay does not proxy /precision/trace; I only added the arm half.

The "Cannot use a closed database" lines in the jam-stream test output also appear without my change.

Changes requested — before the latest push

The arm half looks sound, but it is not reachable or documented. Fix first: the preview answers GET /precision/trace?session=1 with 404 {"error":"no such route"}, because the relay does not proxy it (the pull says so). A trace nobody can fetch from the deployed app does not show the change working. Add the relay route, with a test. Also: (1) README: no mention of the endpoint, the 20-session/10-minute limits, or that a session that measured nothing has no trace; src/server.ts header comment alone is not usage docs. (2) Both doors: nothing in src/tty.ts reads the trace; add a terminal read (or say why not), gated as the page gates /precision. (3) Tests: no test that sampleTrace cannot be skipped by the stream (the setInterval wiring in server.ts is only covered indirectly); the HTTP test depends on sleeps and >=2 samples, so make it deterministic if you can. Smaller: the pad loop in TraceBuffer.take repeats work every sample; levels() is fine.

commented

The review's four points are done and pushed. The new tests and the neighbouring precision and terminal suites pass here, 72 in all. I did not run the full suite or the type check, which can't run in this sandbox. The forge's check will.

  • Relay route: GET /precision/trace?session=<id> now goes through the relay (src/relay.ts). It is gated like /precision: owner and moderators only, and everyone else gets 404 without the arm being asked. A bad id is rejected as 400 at the relay. The arm's own 404 and its answer pass through unchanged, and an arm that doesn't answer gives 502. A relay test in src/precision-panel.test.ts covers all of this.
  • README: a new "Reading a session's trace" section covers the endpoint and its shape, the 5 Hz rate, the 10-minute cap, the last-20 eviction, and that a session that measured nothing has no trace. It also covers the 400 and 404 cases and who may read it.
  • Terminal: /trace <session> prints each joint's sample count, seconds spanned and worst gap between intent and read-back, in ticks. The terminal fetches it through the relay, so it is gated the same way as the page. It is wired in src/tty.ts and src/terminal.ts, listed in the help text, and tested for parsing, output, URL, refusal and a missing reader.
  • Stream test: the HTTP test no longer relies on a fixed sleep and a minimum of two samples. It keeps a stream open for about 1 s, polls until the trace appears, and checks the sample count against the stream's measured lifetime at one sample per 200 ms, give or take two. If the stream's timer were not wired, the count would be 0 and the test would fail. It is still timing-based; a fully deterministic version would need an injected clock in the server.
  • Pad loop: TraceBuffer.take now only repeats the last value for joints not read in that tick, instead of walking every joint each sample.

I haven't looked at the preview since pushing. Check GET /precision/trace?session=1 on it as the owner once it has redeployed.

Approved

Approved. The trace does what the issue asked and nothing more. The 5 Hz timer is per stream, outside the frame path, and cleared on close. The cap is 3000 samples and the last 20 sessions are kept. The relay route is gated to the owner and moderators. On the preview, a guest gets 404 {"error":"no such route"} for all three forms, as designed. I could not try the owner path there. Tests cover the cap, eviction, the 400/404 statuses, the relay gate and the terminal. The README has a section, and /trace is in src/tty.ts and the help text.

Two things to do next:

  1. The HTTP test is timing-based (sleep plus a +/-2 sample tolerance). Inject a clock or a tick hook so it is deterministic and cannot flake on a loaded CI box.
  2. In src/terminal.ts, the worst-gap reduce indexes j.actual with an as never cast. Take the paired arrays as typed number[] after validating them, and drop the cast.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs