Skip to content

feat(position)!: give position-history points contiguous, stable sequences - #176

Merged
b0czek merged 2 commits into
mainfrom
feat/position-history-stable-sequences
Nov 26, 2026
Merged

b0czek merged 2 commits into
mainfrom
feat/position-history-stable-sequences

Conversation

@b0czek

@b0czek b0czek commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Makes position-history sequence numbers contiguous and stable, so a consumer can identify every point it receives and the stream stops resending the whole history once it is full.

Why

  • Gaps in the numbering. A collinear sample used to overwrite the newest point under a new sequence. That left gaps in the numbering, so consumers couldn't tell which sequence a point in a frame had. Deltas also needed replacement_count to replace a tail the consumer had already seen.
  • Full resends at capacity. Evicting at capacity advanced the generation, because a cursor can't describe which prefix a consumer still holds. Once the history was full, every 50 ms delivery became a full replacement of the whole history.

What changes

  • Merging: a collinear sample extends the newest point only while no read has returned it. snapshot() and since() finalize every point they return.
  • Sequences: a merged point keeps its sequence, so point i of a frame has sequence first_sequence + i, and a delivered point never changes. Deltas only append; replacement_root and replacement_count are removed.
  • Eviction: it no longer advances the generation. Every frame carries oldest_sequence, the oldest point still retained, and consumers drop their points before it.
  • When full replacements still happen:
    • the initial frame
    • clear() and reconfiguration
    • a cursor that fell behind the oldest retained point
    • a cursor ahead of next_sequence
  • Docs: the position stream section of native/server/README.md describes the new contract.

Compatibility

Breaking change in PositionHistoryFrame:

  • Fields: field 5 changes from replacement_count to oldest_sequence. The number is reused rather than reserved, since consumers have to update together with the server anyway.
  • Consumers: an old consumer still decodes frames. But eviction no longer sends a replacement, so its copy grows without bound unless it trims to oldest_sequence. Consumers must update together with the server.

Trade-off

Merging stops at each read, so a long straight move now adds about one point per delivery (50 ms) instead of staying a single point. With the default 10 ms sampling and a 20,000-point history, that covers about 17 minutes of continuous straight motion, or about 3 minutes of continuous curves (curves never merged). Idle time adds nothing.

Tests

native_edge_tests.cc now covers:

  • merging only into a point no read has returned, with the merged point keeping its sequence
  • sequences staying contiguous across reads
  • a partial read finalizing only the points it returned
  • eviction keeping the generation, staying a delta and reporting the right oldest_sequence
  • a cursor behind the oldest point still resetting

The replacement_count tests are removed.

Not verified

The full server build and the live websocket integration tests were not run, because no current patched LinuxCNC build was available. The domain-only build and its tests pass, telemetry_session.cc compiles against the regenerated proto, and clang-format and clang-tidy are clean on the changed files.

🤖 Generated with Claude Code

b0czek and others added 2 commits November 26, 2026 10:28
…ences

Collinear samples now extend only the newest point while no read has
returned it; snapshot() and since() seal every point they return. A
coalesced point keeps its sequence, so point i of a frame always has
sequence first_sequence + i and a delivered point never changes. Deltas
therefore only append, and the tail-replacement bookkeeping is gone.

Capacity eviction no longer advances the generation, which used to turn
every delivery into a full replacement once the history was full. Frames
carry oldest_sequence instead, and consumers drop their points before it.
Replacements remain for the initial frame, clear and reconfiguration, and
a cursor that fell behind the oldest retained point.

BREAKING CHANGE: PositionHistoryFrame field 5 (replacement_count) is
reserved and new field 7 (oldest_sequence) reports the retained window.
Eviction no longer sends a replacement, so consumers must trim their copy
to oldest_sequence to stay bounded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The frame's wire format changes incompatibly anyway, so reuse the
removed replacement_count's number instead of reserving it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@b0czek
b0czek merged commit 4152a7d into main Nov 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant