Skip to content

SCA-4876: reuse WAL transaction after failed local flush - #26462

Open
Git-on-my-level wants to merge 1 commit into
BasedHardware:mainfrom
Git-on-my-level:agent/m1-studio-codex-luna/317ba3ec83f8
Open

Git-on-my-level wants to merge 1 commit into
BasedHardware:mainfrom
Git-on-my-level:agent/m1-studio-codex-luna/317ba3ec83f8

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

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

  • INV-CAP-1

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.

View guided diff

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T01:02:08.666556Z 20c1a35 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +1988 to +1989
final pendingWrite = _pendingLiveWalWrites[wal];
final filePath = wal.filePath ?? pendingWrite?.fileName;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines 1516 to +1518
} catch (_) {
_emitLiveWalReceipt(WalWriteReceiptResult.publishFailed);
if (pendingWrite != null) rethrow;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

This branch has not been deployed

No deployments
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.

1 participant