Skip to content

fix(app): release idle ring downloads without discarding received audio - #21829

Merged
aryanorastar merged 6 commits into
mainfrom
fix/offline-sync-ring-idle-timeout
Oct 16, 2026
Merged

aryanorastar merged 6 commits into
mainfrom
fix/offline-sync-ring-idle-timeout

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Bound a ring-buffer download that becomes silent after READ_BEGIN or DATA. The
initial five-second timeout was cancelled on BEGIN, leaving only a 30-minute
overall deadline. A connected, stalled read therefore kept the transfer owner
busy instead of yielding to normal capture/retry orchestration.

  • Reset a 15-second idle deadline on the first valid BEGIN and nonempty DATA,
    matching the existing legacy SD idle bound. Repeated BEGIN, empty DATA and
    control chatter are not progress.
  • Observe arrival before queued custody/disk work. On timeout, stop admitting
    notifications, send STOP on the original connection epoch, drain already
    received bytes and flush complete records through the existing durable WAL
    owner. Do not acknowledge an unfinished source or advance an unproven frontier.
  • Cancel idle timers on completion/error and put read-command failures through
    the same cleanup. A valid DONE arrival cancels the radio idle deadline even
    while its validation waits behind custody I/O. Healthy DONE and existing
    custody capability gates remain.
  • Make the ring custody fixtures wait for read/status admission rather than
    fixed startup sleeps, keeping the original durable-advance assertions.
  • Preserve the saved cause, original stack and phase when a read-command
    failure goes through cleanup; keep catch-and-continue behavior.

Related: #21279 (uploaded jobs queued/429), #21387 (merged polling backoff),
#21319 (merged short-WAL batching), #21755 (merged backfill dispatcher-owner
repair), #21823 (merged batch-worker quarantine), and #21362 (retained-upload
recovery). These are separate stages.
This PR does not close the customer case or assert that the reported 1.4 KB/s,
capture interruption, cloud worker state or missing recaps share this cause.
No firmware version or diagnostic export was supplied for the Discord 0/127
report, and no production repair, storage deletion or deployment is performed.

Why isn't this a shared primitive instead? The existing ring reader already
owns read admission, STOP, notification ordering, durable flush and frontier
validation. Its watchdog belongs inside that owner, not in a parallel recovery
actor. The injectable timer tests the real owner without waiting 15 seconds.

Product invariants affected

  • INV-CAP-1 — complete received records still use existing durable file/index
    registration. Timeout leaves the source pending and sends no unproven
    advance. Legacy firmware may reclaim on BLE delivery before app durability;
    this does not repair or conceal that existing risk or promise recovery of
    incomplete records.

Verification

  • Production ring-owner regression: 14 tests passed, including idle BEGIN,
    partial audio, ignored chatter, cancelled deadlines, healthy DONE and bytes
    queued behind a deliberately blocked custody check, with and without DONE.
  • Capture interruption/reconnect journey (mobile-verify fast --paths app/lib/services/wals/ring_storage_sync.dart): 3 checks passed, no skips.
  • Full app analyzer ratchet: passed. make preflight: 25 checks passed.
  • Broader ring/custody/capture regression suites: all 129 passed on the final
    code, including the diagnostic guard and the 14 ring-owner tests above.
  • Diagnostic guard: confirmed red without the transfer failure's saved error,
    then green with its original stack, cause and phase preserved. Changed-file
    analyzer: no issues found.
  • Physical BLE throughput, microphone behavior, customer-account processing
    and released-app retest: not performed; require hardware/account evidence.

Architecture and implementation/release checklist:
app/docs/offline-sync-stall-recovery.md. The listen/pusher pipeline map is
updated. This needs a mobile release after merge, not a backend deployment.

UI evidence

UI-Evidence: none -- transfer lifecycle only; no UI, copy or layout changes

Failure class

Failure-Class: FC-sync-failure-records-drop-cause

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution flutter flutter work labels Oct 16, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks — this is a careful fix for a real liveness gap. Reviewed each changed file:

  • ring_storage_sync.dart: re-arming the 15s idle deadline in the BLE listener on radio arrival (nonempty DATA or first valid BEGIN with matching transferStartSeq), before the notifyQueue custody/disk work, is the right layer — a slow durable flush can no longer masquerade as a silent peripheral, and control chatter/empty DATA correctly don't extend the transfer. The DONE branch cancelling the idle timer while validation waits behind custody I/O (with the 30m overall bound still applying) avoids a false timeout on healthy completions. On expiry, stopping new admission while letting already-received bytes drain through the existing flush path — plus STOP on the original connection epoch and ADVANCE still gated behind doneConsistent && fullyProven — preserves the no-unproven-frontier-advance invariant. Moving readRingFromSeq inside try so read-command failures get the same cleanup and a persisted cause/stack/phase is a good hardening.
  • ring_storage_sync_no_advance_test.dart: _ManualTimer + _BlockedCustody + the _until() boundary helper make the idle paths deterministic rather than sleep-based — much better than wall-clock waits.
  • ring_custody_download_test.dart: readReady admission replacing fixed startup sleeps removes a flakiness source; the new readError/stopStorageSync coverage exercises the new error path.
  • app/docs/offline-sync-stall-recovery.md: the documented 5s/15s/30m windows, epoch-STOP, and drain semantics match the code, and the boundaries against fix(sync): stop reconcile polling loop on rate limit and clear uploaded wals on delete pending (#21279) #21387/fix(app): bound sync upload batches by audio seconds, not file count #21319/fix(sync): never strand backfill pending entries without an owner #21755/fix: quarantine exhausted batch worker items #21823/fix(recaps,sync): complete historical recovery and stuck-upload reconciliation #21362 are clearly drawn without claiming the customer case is closed.
  • backend/docs/listen_pusher_pipeline.mdx: the 13-line cross-reference section is consistent with the above.
  • Changelog fragment present.

One non-blocking behavior edge worth a maintainer eye: after this change, a mismatched BEGIN (start != requested) or empty DATA no longer cancels the 5s first-data timer — only valid BEGIN/nonempty DATA do. That matches the "control chatter is not progress" rule documented in the new doc, but it does mean a device that only ever sends garbage/stale BEGIN now fails via the 5s timer instead of the previous implicit paths. Intended per the doc; just confirming it's deliberate.

Checks green. Ready for the requested human review pass.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusted contributor bug fix, CI green, but mergeStateStatus is DIRTY/CONFLICTING - hard floor + no-rebase hard rule block merge; approve only.

…-idle-timeout

# Conflicts:
#	backend/docs/listen_pusher_pipeline.mdx
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Pushed 35a4fe6: merged current main and resolved the backend/docs/listen_pusher_pipeline.mdx conflict.

  • Conflict: this PR's "Mobile ring-download idle recovery" section and main's new "Default-off desktop call + pendant links" section were appended at the same spot. Both are kept unchanged, main's first.
  • Scope: the diff against main is exactly this PR's 6 files.
  • Checks: ring idle/no-advance, custody, SD card, WAL recovery and native BLE suites, 150 passed. Accepted-notification draining, durable phone WAL ownership, original-epoch STOP and no unproven frontier advance are unchanged. flutter analyze clean; make preflight: 25 checks passed.

@aryanorastar
aryanorastar merged commit 6ee428e into main Oct 16, 2026
56 checks passed
@aryanorastar
aryanorastar deleted the fix/offline-sync-ring-idle-timeout branch October 16, 2026 17:19
Git-on-my-level added a commit that referenced this pull request Oct 16, 2026
… unit inventory) (#21925)

* fix(app): migrate #21829 decode site to typed client (unbreak backend unit inventory)

* style(app): dart format users.dart at the CI language version

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style(app): dart format users.dart as CI does (after pub get)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants