Skip to content

fix(sync): stop reconcile polling loop on rate limit and clear uploaded wals on delete pending (#21279) - #21387

Merged
kodjima33 merged 6 commits into
BasedHardware:mainfrom
PINYOPATTANAWASANPORN:fix/sync-reconcile-rate-limit-and-delete-pending-21279
Oct 13, 2026
Merged

kodjima33 merged 6 commits into
BasedHardware:mainfrom
PINYOPATTANAWASANPORN:fix/sync-reconcile-rate-limit-and-delete-pending-21279

Conversation

@PINYOPATTANAWASANPORN

@PINYOPATTANAWASANPORN PINYOPATTANAWASANPORN commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

Root Cause / Technical Context

  1. In _reconcileUploadedWals(), when a 429 was returned, case SyncJobFetchOutcome.throttled only executed a break within the switch statement without breaking the outer for (var i = 0; i < entries.length; i += maxConcurrent) loop. As a result, when large queues of jobs were present, the client continued hammering the server sequentially for all entries, generating thousands of 429s.
  2. In deleteAllPendingWals(), only WalStatus.miss items were collected, offering no client-side recovery to clear stuck server jobs (WalStatus.uploaded).

Verification & Testing

  • Clean minimal diff strictly in app/lib/services/wals/local_wal_sync.dart.
  • Preserved existing SyncRateLimiter semantics and cooldown reasons.
  • Verified CRLF -> LF line ending hygiene.

Product invariants affected

  • INV-CAP-1

Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 2641 -> 2651 | Add SyncRateLimiter 429 backoff handling and stuck uploaded wal clearing on delete pending
UI-Evidence: none -- Non-UI background WAL synchronization rate limiter fix and storage cleanup
Failure-Class: none

Closes #21279.

View guided diff

@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.

Confirmed root cause (break statement didn't stop the outer poll loop or install the rate-limit cooldown) and confirmed still present on main; small scoped fix (17 lines), closes real issue #21279, mirrors existing SyncRateLimiter pattern.

@kodjima33
kodjima33 merged commit 70dd7c8 into BasedHardware:main Oct 13, 2026
35 checks passed
aryanorastar added a commit that referenced this pull request Oct 16, 2026
…io (#21829)

## 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
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.

Offline Sync: server jobs stay "queued" 0% forever, Pending grows every ~10s, and job-status polling floods 429s (persists after full reinstall)

2 participants