feat: opt-in per-sender message ordering (sid/sn/gt) - #122
Merged
Conversation
Apps that care about ordered delivery (chat, telemetry, change-log streams) can now opt in by setting a stream id on submit. The daemon mints a monotonic per-(local, remote, stream) seq, the receiving daemon gates local MQTT delivery on a per-(originator, stream) cursor, and a configurable gap timeout chooses between strict (stall forever) and timeout (skip past the gap after N seconds) semantics. Wire form: three short keys on the ihave envelope (sid=, sn=, gt=) and a new flag bit on the binary datagram codec; gt=0 is the strict marker. All three travel together end-to-end, intermediate hops re-emit verbatim. Codec version bumped 6 -> 7. State: two new SQLite tables (streamsendstate, streamrecvstate); four new columns on messages; a StreamGapSweeperService advances cursors past elapsed deadlines on a 1-minute cadence. Strict-mode parked rows sit until the missing prior arrives or the regular TTL sweeper drops them. Dashboard: new /Streams page surfaces both sender-side counters and receive-side cursors with parked-row counts so a stalled stream shows up at a glance. Tests: 14 new in StreamOrderingTests covering codec round-trip, ihave parser, in-order drain on out-of-order arrival, strict-mode indefinite stall, timeout-mode sweeper-driven skip, stale-seq drop with stream-stale reason, and sender-counter persistence. Docs: extended app-developers/reference.md with the new wire fields and a Message ordering section (REST + MQTT examples, tradeoffs, sender-reset mitigation via stream-id rotation). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
streamIdon submit, the daemon mints monotonicsn=values, and the receiving daemon delivers insnorder via a per-(originator, stream) reorder buffer.gt=:0(strict, stall forever) and>0(timeout, skip the gap after N seconds viaStreamGapSweeperService).sid/sn/gt) on the ihave envelope plus a flag bit on the binary datagram codec (version 6 -> 7). Intermediate hops re-emit verbatim.streamsendstate,streamrecvstate) and four new columns onmessages(sid/sn/gt + PendingInOrder)./Streamsdashboard page lists both directions with pending-row counts so stalled streams are visible at a glance.Test plan
dotnet buildclean across dapps.client, dapps.core, dapps.core.tests, harness, uitests, FakeBpqAndDappsClientdotnet test: 565 / 565 passing (551 prior + 14 new inStreamOrderingTests)sid=c1, sn=42, gt=600gt=0(strict marker) from absentsnsn=3, sn=2, sn=1drains assn=1, 2, 3to MQTTgt=0) parked rows never set GapDeadline; sweeper finds nothing stalegt=600) parked rows: sweeper skips gap after deadline, advances cursor, drains pendingsnafter cursor drops with reasonstream-stale; no double-MQTT-deliverystreamIdis supplied🤖 Generated with Claude Code