sync: log-only burst-completeness shortfall diagnostic (correct received-total signal) - #232
sync: log-only burst-completeness shortfall diagnostic (correct received-total signal)#232abdulsaheel wants to merge 2 commits into
Conversation
… received-total signal) Emit an honest, observation-only frame-loss signal at HISTORY_END without touching the commit/ACK decision. The band's num_packets counts every frame it transmitted (all types); the correct completeness comparison is against totalTrafficPacketCount — the all-types received total — not the banked R24 subset (which fabricates a shortfall whenever console/event frames ride along un-banked). This is type-agnostic and interleaving-immune. New pure helper burstPacketShortfall() = expected - (received_all_types + dropped_this_burst): a POSITIVE result is frames the band sent that never reached us (true loss); zero is complete; negative is retries/dupes, not loss. Gate-dropped (RecordGate) records are added back so plausibility rejections never read as radio loss. At burst end we now log a "would-flag" line and stamp burst_shortfall into the existing mismatch ledger entry — LOG-ONLY. Commit-before-ACK, the verbatim token echo, and the OK/FAIL decision are all unchanged. This is groundwork so we can SEE true frame loss in telemetry before ever wiring a field-validated FAIL gate; a hard FAIL/re-flood path is deliberately NOT included here. Rejected alternative: gating on the per-revision counter gap — the counter is a GLOBAL flash-log index sliced per revision, so gaps are the normal state and would false-positive constantly. Adds pure unit tests covering benign interleaving (no false positive), true loss, the gate-dropped add-back, negative/retry case, and shortfall==0 == burstPacketCountMatches.
|
Warning Review limit reached
Next review available in: 49 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe BLE engine adds ChangesTelemetry packet shortfall
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Reviewer Guide 🔍(Review updated until commit a974918)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to a974918
Previous suggestionsSuggestions up to commit d2ccec4
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/ble/ble_engine.dart`:
- Around line 2630-2636: Update the serialized frame-ingest flow in
lib/ble/ble_engine.dart#L2630-L2636 so all queued data-role packet types,
including console, event, unknown, and historical frames, are counted in the
burst traffic counters before burstPacketShortfall is calculated; use the
existing _drainOffloadFrames/_ingestHistoricalFrame path and preserve commit and
ACK behavior. Add a regression test in test/ble/ble_engine_test.dart#L125-L218
covering a HISTORY_END burst with data-role historical, console, and event
frames, asserting zero shortfall and unchanged commit and ACK behavior.
- Around line 169-174: Revise the documentation around droppedThisBurst in
lib/ble/ble_engine.dart:169-174 to describe a positive shortfall as potential
loss or missing valid traffic, not confirmed loss. Update the related log text
in lib/ble/ble_engine.dart:2682-2694 to remove the “true frame loss” claim.
Rename the affected test in test/ble/ble_engine_test.dart:165-178 to describe a
positive shortfall without asserting confirmed loss.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: fc03a79c-baa4-44f4-b897-011c82edb140
📒 Files selected for processing (2)
lib/ble/ble_engine.darttest/ble_engine_test.dart
A positive burst shortfall means frames the band counted that we did not count as valid received traffic. CRC-failed frames also never enter currentBurstTrafficCount, so a positive shortfall can be missing OR corrupted traffic — it cannot by itself prove a frame never arrived. Soften the helper doc, the would-flag log text, and the test name accordingly. Wording-only; no behavior change (still log-only).
|
Persistent review updated to latest commit a974918 |
|
Superseded by #235 — consolidated into the single |
User description
What
Adds an honest, log-only burst frame-loss diagnostic at
HISTORY_END. It computes the completeness signal against the all-types received total (totalTrafficPacketCount) instead of the banked R24 subset, and emits awould-flagline + aburst_shortfallledger field — without changing the commit/ACK decision.Why
The strap's
HISTORY_ENDmetadata carriesnum_packets(every frame it transmitted this burst — R24 data and interleaved console/event/unknown). The only correct completeness comparison is against the all-types received total. Comparing against the banked R24 subset fabricates a shortfall whenever console/event frames ride along un-banked — which is exactly why that gate was disabled andvalidateBurstwent advisory-only.Today, on a true frame drop the burst is committed + ACKed OK anyway and the loss is silent. Before wiring any FAIL gate we need to see true loss in telemetry. This PR is that groundwork.
The signal
New pure helper:
receivedTrafficCount=totalTrafficPacketCount(all types) — type-agnostic, interleaving-immune.droppedThisBurst(RecordGate plausibility rejections) is added back so gate drops never read as radio loss.At burst end we log a clear
would-flag (LOG-ONLY, commit+ACK unchanged)line when shortfall > 0, and stampburst_shortfallinto the existing mismatch ledger entry.Invariants (unchanged)
_ingestHistoricalFrame; live streams never persisted.Rejected alternative: per-revision counter-gap gate
The record counter is a global flash-log index sliced per revision, so gaps are the normal state — gating on the counter gap would false-positive constantly.
num_packetsvs received-total is the right signal.Tests
Pure unit tests for
burstPacketShortfall: benign console/event interleaving does not false-positive, true loss is quantified, gate-dropped add-back closes the gap, negative/retry case, andshortfall == 0⇔burstPacketCountMatches.flutter testgreen (49 pass),flutter analyzeclean on changed files.PR Type
Enhancement, Tests
Description
Adds log-only
burstPacketShortfall()helper comparingnum_packetsagainst all-types received totalEmits
would-flaglog line and stampsburst_shortfallinto mismatch ledger at HISTORY_ENDCommit-before-ACK, verbatim token echo, and OK/FAIL decision are all unchanged
Adds five unit tests covering interleaving, true loss, gate-drop add-back, retries, and equivalence with
burstPacketCountMatchesDiagram Walkthrough
File Walkthrough
ble_engine.dart
Add log-only burst shortfall diagnostic at HISTORY_ENDlib/ble/ble_engine.dart
burstPacketShortfall()helper (annotated@visibleForTesting)computing
expected - (receivedTrafficCount + droppedThisBurst)usingthe all-types traffic total
shortfallusingd.currentBurstTrafficCount(not the banked R24 subset) and
droppedThisBurstburst_shortfallinto the existing mismatch ledgermetaPatchwhen a mismatch is recorded
would-flag (LOG-ONLY, commit+ACK unchanged)log line whenshortfall > 0; commit-before-ACK and ACK decision are untouchedble_engine_test.dart
Unit tests for burstPacketShortfall helpertest/ble_engine_test.dart
group('burst completeness shortfall ...')with five unit testsfrom interleaved console/event frames, positive shortfall for true
loss, gate-dropped add-back, negative/retry case, and equivalence with
burstPacketCountMatches