Repository navigation
SCA-4876: reuse WAL transaction after failed local flush - #26462
Git-on-my-level wants to merge 1 commit into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20c1a35f9c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await file.writeAsBytes(data, flush: true); | ||
| final writeWalBytes = _writeWalBytesOverride; | ||
| if (writeWalBytes == null) { | ||
| await file.writeAsBytes(data, flush: true); |
There was a problem hiding this comment.
Stage retry bytes before replacing the recoverable audio file
If an attempt writes all bytes but fails during the final flush—the failure modeled by the new test—the existing file and receipt can already be replayed after process termination. Retrying now calls writeAsBytes on that same basename, truncating it before writing. A process kill or another partial-write failure during this retry destroys the last complete copy, and LiveWalReceipt.recover() rejects the remaining file on length/hash mismatch; previously, the complete first attempt stayed untouched under its original basename. Keep the transaction identity stable, but stage and flush retry bytes before atomically replacing the reserved audio file.
Useful? React with 👍 / 👎.
| final pendingWrite = _pendingLiveWalWrites[wal]; | ||
| final filePath = wal.filePath ?? pendingWrite?.fileName; |
There was a problem hiding this comment.
Prefer the pending basename when purging a failed capture write
After a full-byte write followed by a final-flush error on a claimable capture WAL, wal.filePath still contains the planned basename assigned by _storeSelectedRuns(), while the actual audio and receipt use pendingWrite.fileName. This expression selects the planned path, so when that path is absent, deletion removes the row and reservation without touching the actual files. This regresses account deletion because _purgeUnindexedAccountWals() now skips the actual basename through the new reservation set, whereas previously it could purge the matching receipt and audio. Prefer the reserved basename whenever a transaction is pending.
Useful? React with 👍 / 👎.
| } catch (_) { | ||
| _emitLiveWalReceipt(WalWriteReceiptResult.publishFailed); | ||
| if (pendingWrite != null) rethrow; |
There was a problem hiding this comment.
Preserve the no-receipt fallback on unfinished-write retries
When receipt publication is unavailable—for example, .wal-live-receipts is a file rather than a directory, as covered in wal_orphan_recovery_test.dart—and the first audio write also fails, the reservation is retained without a digest. Every subsequent flush takes this rethrow on the same publication error, so it never retries the audio write even once audio writes would succeed again. The outer catch then breaks the flush loop, leaving subsequent recordings RAM-only. The first-attempt behavior deliberately permits audio/index persistence without a receipt, so distinguish a conflicting stored receipt from publication I/O failures rather than disabling that fallback for every pending write.
Useful? React with 👍 / 👎.
Summary
Retries of an in-memory local WAL write now retain the same transaction identity and file name. Receipt refresh is allowed only when the stored receipt matches that WAL and transaction. Successful writes release the reservation, and discarding a pending WAL retires its matching receipt.
Verification
flutter test --no-pub test/unit/local_wal_live_custody_test.dart— 10 tests passed through the M1 heavy-check gate.flutter analyze --no-pub lib/services/wals/local_wal_sync.dart lib/services/wals/live_wal_receipt.dart lib/services/wals/live_wal_receipt_replay.dart test/unit/local_wal_live_custody_test.dart— no issues found through the M1 heavy-check gate.make preflight— passed all 27 selected local checks.Product invariants affected
Failure-Class: none
UI-Evidence: none -- persistence change only; no interface changed.
Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 3362 -> 3419 | Keep retry reservation and its cleanup with the existing WAL owner.