Repository navigation
fix(app): stop auto-retrying a recording the server refuses for its audio - #14337
Merged
Merged
Conversation
…udio An iOS client re-uploaded the same 2.2 KB WAL to /v2/sync-local-files 39 times in ~21 hours. Every attempt was accepted with 202 and every job then failed identically: the decoder produced no PCM, so decode_files_to_wav raised and the pipeline finalized the job `failed` with reason_code=sync_invalid_audio. The client treated that verdict as retryable. syncJobTerminalPolicy returns `retry` for every terminal status but `completed`, so reconcileUploadedWals put each member WAL back to `miss` and bumped retryCount — and nothing consulted retryCount afterwards. The automatic drain filtered only on `status == miss && storage == disk`, so RecordingTransferCoordinator's reconcile-then-drain pass re-sent the same bytes on every wake, forever. walMaxAutoRetries existed but only coloured the sync row. - Classify the failure: `syncJobFailureIsPermanent` treats a whole-job `failed` carrying an input-caused reason (sync_invalid_audio, stt_invalid_input) as unchangeable by another upload. `partial_failure` is excluded — segments that landed prove the batch is not wholly bad, and the backend drops individually unreadable files rather than failing their siblings, so a permanent verdict cannot strand a good recording. - Spend the budget on that verdict instead of one attempt per pass, and gate every automatic loop on it: `isAutoUploadEligible` now applies walMaxAutoRetries in _syncAll and getOrphanedWals, so an unclassified permanent failure also stops after the budget rather than looping. - Never drop audio: the recording stays `miss` on disk and renders as WalSyncDisplayState.failed, keeping its manual Retry and Delete. A deliberate single-recording retry restores the budget, including when SyncProvider coalesces that tap into a running drain. - Transient failures (capacity, paced, backend-busy, upstream, timeout) keep their existing per-attempt accounting untouched. Verified: - flutter analyze on the touched files: no new diagnostics (9 pre-existing baseline infos on untouched lines). - flutter test test/unit/capture_recovery_replay_scenarios_test.dart test/unit/sync_job_terminal_policy_test.dart test/unit/local_wal_sync_test.dart test/unit/wal_sync_display_state_test.dart test/unit/wal_sync_upload_test.dart test/unit/wal_upload_resilience_test.dart test/unit/sync_response_handling_test.dart test/unit/wal_delete_cascade_test.dart test/unit/session_wal_sync_test.dart test/unit/sync_manifest_claim_drain_test.dart test/unit/wal_recovery_test.dart — 162 passed. - The new replay test reproduces the incident against unpatched code: 7 wakes produced 7 uploads; with the fix, 1. - bash test.sh — 2031 passed, 1 pre-existing failure (test/unit/search_rank_grouping_test.dart), reproduced on unmodified origin/main. Not exercised on a device: this is the offline-sync policy seam, covered by the deterministic replay world; a live run needs an undecodable WAL on a real phone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Git-on-my-level
deleted the
fix/wal-sync-permanent-failure-retry-loop
branch
September 17, 2026 11:30
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.
What
A recording the server refuses because of its own audio now stops being auto-uploaded. It is retained on disk and presented in the sync UI as failed with a manual Retry, instead of being re-sent on every recovery wake forever.
Why (the measured loop)
An iOS client (1.0.551+1217) re-uploaded the same 2.2 KB WAL to
POST /v2/sync-local-files39 times in ~21 hours. Every attempt was accepted with 202, and every job then failed identically:The backend is behaving correctly.
decode_files_to_wavdrops unreadable files individually and only raises once the batch has nothing left (backend/utils/sync/files.py:289); the pipeline turns that into a terminalfailedwithreason_code=sync_invalid_audio(backend/utils/sync/pipeline.py:1786-1800). A file that decodes to zero PCM will decode to zero PCM again — the verdict is final.The client never read that. Root cause, on
origin/main:syncJobTerminalPolicy(app/lib/services/wals/local_wal_sync.dart:42-45) returnsretryfor every terminal status butcompleted.reconcileUploadedWals(local_wal_sync.dart:1213-1233) therefore puts each member WAL back toWalStatus.missand doesw.retryCount += 1(:1219).retryCount. The automatic drain filters only onstatus == miss && storage == disk(local_wal_sync.dart:685, and the same predicate in the initial snapshot), so the WAL is immediately eligible again.RecordingTransferCoordinator._runPassreconciles and then drains in the same pass (recording_transfer_coordinator.dart:246then:256), and re-arms on foreground, connectivity, device-connect, cooldown and startup. That is the loop that produced the 39 uploads — one upload per wake, indefinitely.walMaxAutoRetriesexisted but only coloured the row (wal.dart:52, read solely bysyncDisplayStateat:168).getOrphanedWalshad its own hardcodedretryCount < 3, which no upload path went through.app/test/unit/wal_upload_resilience_test.dartalready carried a test literally namedKNOWN GAP: syncAll picks up miss WAL regardless of retryCount, whose comment prescribed this fix.Changes
Client-only. The backend already sends everything needed:
reason_codeis in the job-status payload (backend/routers/sync.py:1489) andSyncJobStatusResponsealready parses it (app/lib/backend/schema/conversation.dart:823). No wire change, so old clients are unaffected.syncJobFailureIsPermanenttreats a whole-jobfailedcarrying an input-caused reason (sync_invalid_audio,stt_invalid_input) as unchangeable by another upload.partial_failureis deliberately excluded: segments that landed prove the batch is not wholly bad. Combined with the decoder dropping unreadable files individually, a permanent verdict can never strand a good sibling — a 1-of-5 bad file still lets the other four through, and the job only fails when nothing decoded.isAutoUploadEligiblenow applieswalMaxAutoRetriesin_syncAllandgetOrphanedWals. So an unclassified future permanent failure also stops after the budget rather than looping — the bound does not depend on knowing the reason code.misson disk and renders asWalSyncDisplayState.failed, keeping the manual Retry and the swipe-to-delete the sync pages already offer. No new state was invented.SyncProvider.syncWalcoalesces that tap into a running drain, which would otherwise have silently dropped it. One tap buys exactly one upload.Tests
app/test/unit/capture_recovery_replay_scenarios_test.dart— two behavioural tests through the deterministic replay world (realLocalWalSyncImpl+RecordingTransferCoordinator, scripted upload boundary and clock):failed/sync_invalid_audiojob, then a wake of everyWakeTrigger. Against unpatched code this produced 7 uploads for 7 wakes; with the fix, 1. It also asserts the file is retained byte-identical, the row readsfailed, and a manual retry still reaches the server exactly once.stt_upstream_errorkeeps costing one attempt per pass and staysretrying.app/test/unit/sync_job_terminal_policy_test.dart— classification unit tests (permanent vs transient vspartial_failure, and the budget predicate againstsyncDisplayState). These fail to compile against unpatched code.app/test/unit/wal_upload_resilience_test.dart— theKNOWN GAPtest is rewritten to assert the closed behaviour, plus a twin proving a WAL with budget left is still uploaded. Per the repo's rule on same-PR test rewrites: the external source is the test's own prescribed fix (its comment says "syncAll() should skip WALs with retryCount >= N") and the measured incident above.Commands run:
flutter analyzeon the touched files — no new diagnostics (9 pre-existing baseline infos on untouched lines).flutter test test/unit/capture_recovery_replay_scenarios_test.dart test/unit/sync_job_terminal_policy_test.dart test/unit/local_wal_sync_test.dart test/unit/wal_sync_display_state_test.dart test/unit/wal_sync_upload_test.dart test/unit/wal_upload_resilience_test.dart test/unit/sync_response_handling_test.dart test/unit/wal_delete_cascade_test.dart test/unit/session_wal_sync_test.dart test/unit/sync_manifest_claim_drain_test.dart test/unit/wal_recovery_test.dart— 162 passed.bash test.sh— 2031 passed, 1 failure intest/unit/search_rank_grouping_test.dart, which reproduces identically on unmodifiedorigin/main(pre-existing, unrelated to this diff).Not exercised on a device: this is the offline-sync policy seam, covered by the replay world. A live run would need an undecodable WAL on a real phone.
Risk
Low and bounded to the offline-upload drain.
WalSyncDisplayState.failedis an existing state the sync pages already render with a Retry button.retryCountis only incremented by genuine terminal job failures and job-not-found reverts; transient network/5xx paths never touch it, so a flaky connection cannot exhaust the budget.Failure-Class
Failure-Class: FC-permanent-write-rejection-retried-forever
The registry entry is written around the backend's Firestore instance, but the violated contract is the same one: a rejection no retry of the same payload can satisfy, replayed by an automatic sweep, leaving the row non-terminal for good. This is the second instance in this subsystem — #10995 fixed the 422
backfill_lookback_exceededchannel by addingoutsideRecoveryWindow; this is the same class arriving through the async job'sreason_code. Per the bug-fix guidance the reusable guard surface lands here rather than another call-site exception: one sharedisAutoUploadEligiblepredicate that every automatic loop reads, and one classifier for terminal verdicts. A client-scoped class definition would describe it more precisely; adding a.github/failure-classes/entry was out of scope for this PR.Invariants
scripts/pr-preflight --suggestreports no affected product invariants for this diff.🤖 Generated with Claude Code