Skip to content

fix(app): keep WAL until the device confirms deletion - #15156

Merged
Git-on-my-level merged 2 commits into
mainfrom
agent/m1-studio-omp-glm-5-3/53cc04905e61
Sep 20, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
agent/m1-studio-omp-glm-5-3/53cc04905e61

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Why

Deleted device recordings could resurrect: "I try to delete the files but they come back" (community signal: #14688 — referenced as evidence only; that issue tracks three symptoms and stays open for the team). Both device WAL syncs dropped the WAL from the app list before the device-side delete was confirmed:

  • Ring path (fw ≥ 3.0.20) — ring_storage_sync.dart deleteWal() called _clearRingOnDevice(), which logged the clearRing() result and returned void; the WAL was then removed unconditionally. A failed clear (no connection, BLE error, NACK) left the audio on the device ring, and the next sync re-imported it as a "new" recording.
  • Legacy SD path (fw < 3.0.20) — sdcard_wal_sync.dart deleteWal() removed the WAL from memory first, then fired writeToStorage(fileNum, 1, 0) and ignored the result. That bool is only "BLE write accepted", not "file deleted"; on disconnect or failure the file stayed on the card and start() → _getMissingWals() re-imported it. It also dropped the WAL outright when its owning device was absent or a different device was active — delete-while-disconnected with no command and no readback.

What changes

Deletion is now transactional, fail-closed on both paths — a WAL leaves the app list only after the device-side delete is confirmed:

  • ring_storage_sync.dart: _clearRingOnDevice() returns whether clearRing() was confirmed (absent device, missing connection, BLE error, and rejected command all return false). deleteWal() / deleteAllPendingWals() keep the WAL unless the clear was confirmed. The documented single-stream quirk (deleting one ring WAL clears the entire ring) is unchanged.
  • sdcard_wal_sync.dart: deleteWal() removes the WAL only when its owning device is the active device and the delete command is accepted and a getStorageList readback shows totalBytes dropped below the WAL's discovered size. An absent or mismatched owning device, a rejected write, an ambiguous (empty) readback, or an unchanged readback keeps the WAL — same fail-closed semantics as the ring path. The cascades (deleteAllSyncedWals / deleteAllPendingWals) inherit the semantics per item — a failed item survives while the rest of the batch proceeds.
  • Kept WALs self-heal: the next device refresh rebuilds _wals from actual device state, so an item whose bytes are really gone disappears then; the resurrection path no longer exists.
  • No UI changes: a failed delete simply leaves the item in the list (existing pending-state rendering already covers this).

Scope

Diff confined to app/lib/services/wals/** and app/test/** (one new test file, one inverted legacy assertion). No firmware, tombstones, timestamp/import, mute, or sync-scheduling changes.

Failure-Class

Failure-Class: none

Verification

  • TZ=UTC bash app/test.sh — green (2415 tests), including the spine c1_* acceptance contracts; analyze_ratchet.sh passed; touched files formatted with the pinned toolchain (pre-commit hook, 0 churn).
  • app/test/unit/wal_delete_durability_test.dart (13 cases) drives the real deleteWal / deleteAllPendingWals paths through a scripted DeviceConnection (the repo's hermetic seam for this path): confirmed delete removes the WAL; rejected ring clear, absent device, no connection, absent/mismatched owning device (sdcard), rejected delete command, readback that still shows the bytes, and empty (unconfirmable) readback each keep it; cascade partial-failure keeps the failed item and removes the confirmed one. wal_delete_cascade_test.dart's stale-device assertion was inverted to the fail-closed contract; its sync-phase and cascade-guard tests are unchanged and still pass.
  • No live Omi device on this host, so the BLE leg was not exercised against hardware; the connection seam is the same one the existing sdcard legacy-sync tests use.

## Summary
- Deleted device recordings could resurrect ("I try to delete the files
  but they come back", evidence: #14688): both device WAL syncs dropped
  the WAL from the app list before the device-side delete was confirmed,
  so a failed clear (no connection, BLE error, NACK) left the audio on
  the device and the next sync re-imported it as a new recording.
- ring_storage_sync: _clearRingOnDevice now returns whether clearRing()
  was confirmed; deleteWal / deleteAllPendingWals keep the WAL
  (fail-closed) unless the device confirmed the clear. Absent device or
  absent connection counts as failure. The documented single-stream
  quirk (deleting one ring WAL clears the whole ring) is unchanged.
- sdcard_wal_sync: deleteWal removes the WAL only after
  writeToStorage(delete) is accepted AND a getStorageList readback shows
  totalBytes dropped below the WAL's discovered size. Rejected write,
  ambiguous (empty) readback, or unchanged readback keeps the WAL. The
  cascades (deleteAllSyncedWals / deleteAllPendingWals) inherit the
  semantics per item: a failed item survives, the rest of the batch
  proceeds.
- No UI changes: a failed delete simply leaves the item in the list.

## Failure-Class
Failure-Class: none

## Verification
- TZ=UTC bash app/test.sh — green (2413 tests), including the spine
  c1_* acceptance contracts; analyze ratchet passed.
- New test/unit/wal_delete_durability_test.dart drives the real delete
  paths through a scripted DeviceConnection: confirmed clear removes the
  WAL; rejected command, unconfirmed readback, absent device, and no
  connection each keep it; cascade partial-failure keeps the failed
  item. No live Omi device on this host — BLE behavior is exercised via
  the connection seam, the repo's hermetic-test pattern for this path.

Co-authored-by: multica-agent <[email protected]>
## Summary
- Follow-up to review of #15156: sdcard deleteWal() still removed the
  WAL when _device was null or the WAL belonged to a different device
  than the active one — no delete command attempted, no readback, WAL
  gone from the app list. Delete-while-disconnected is the resurrection
  path from #14688 (evidence only); acceptance criterion 2 requires a
  no-connection delete to keep the WAL.
- deleteWal() now treats an absent or mismatched owning device as
  unconfirmed and keeps the WAL (fail-closed, same semantics as the
  ring path).
- Inverted the old fire-and-forget assertion in
  wal_delete_cascade_test.dart (a stale-device sdcard recording now
  stays until its own device confirms the delete) and added absent-
  device and mismatched-device cases to wal_delete_durability_test.dart.

## Failure-Class
Failure-Class: none

## Verification
- TZ=UTC bash app/test.sh — green (2415 tests), spine c1_* included;
  analyze ratchet passed; formatting clean (pinned toolchain, 0 churn).
- Focused suites all pass: wal_delete_durability_test.dart (13 cases),
  wal_delete_cascade_test.dart, sdcard_legacy_sync_test.dart.

Co-authored-by: multica-agent <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit b674783 into main Sep 20, 2026
43 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/m1-studio-omp-glm-5-3/53cc04905e61 branch September 20, 2026 14:28
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