Repository navigation
fix(app): stop deleting a recording from clearing the device's SD card - #13510
Conversation
WalSyncs.deleteWal fans every delete out to all sub-syncs. The ring sync already ignores wals it does not own (BasedHardware#7218), but the SD card and storage syncs sent their device delete for any wal. With a DevKit connected, deleting a phone recording sent DELETE_COMMAND, which clears the SD card audio file regardless of the file number. Both now return early unless the wal is one of their own SD recordings. Failure-Class: new
There was a problem hiding this comment.
3 issues found across 4 files
Confidence score: 2/5
app/lib/services/wals/storage_sync.dartcan accept a stale WAL from the previous device and delete itsfileNumon the newly connected device, risking deletion of unrelated device data — requirewal.idto match the current device ID before deleting.app/lib/services/wals/sdcard_wal_sync.dartleavesflash_page_wal_sync.deleteWaloutside the new ownership guard, so deleting a synced phone recording while a Limitless/Rayban is connected may still delete the wrong device’s WAL — apply the guard to that fifth fan-out path as well.app/test/unit/wal_delete_cascade_test.dartrelies on the internal “Service manager is not initiated” exception text to verify a device write, making tests brittle if that implementation message changes — assert the write attempt through a stable mock or explicit interaction instead.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/test/unit/wal_delete_cascade_test.dart">
<violation number="1" location="app/test/unit/wal_delete_cascade_test.dart:43">
P3: The 'still sends the delete to the device' tests assert that the device write is attempted by matching the internal exception text 'Service manager is not initiated' thrown by an uninitialized ServiceManager. This couples the tests to both the exception message and the test environment never initializing ServiceManager; if either changes, these tests break or silently pass for the wrong reason, and they never verify the actual deletion outcome (the wal removed from _wals, or a write sent). Inject/assert observable behavior instead, e.g. keep the wal list as the assertion after forcing the device call, or stub the connection write.</violation>
</file>
<file name="app/lib/services/wals/storage_sync.dart">
<violation number="1" location="app/lib/services/wals/storage_sync.dart:226">
P1: When the device changes before `_wals` refreshes, this membership check accepts a stale WAL from the previous device and deletes its `fileNum` on the new device. Require `wal.id` to match the current device ID and reject a null device before issuing the delete.</violation>
</file>
<file name="app/lib/services/wals/sdcard_wal_sync.dart">
<violation number="1" location="app/lib/services/wals/sdcard_wal_sync.dart:116">
P2: The ownership guard added here is not applied to flash_page_wal_sync.deleteWal, the fifth sub-sync in the same fan-out. When a synced phone recording is deleted while a Limitless/Rayban is connected, WalSyncs.deleteWal fans the delete to FlashPageWalSyncImpl.deleteWal, which still runs `_acknowledgeProcessedData` (for `wal.status == synced`) and clears the pendant's flash. This is the same cascade/data-loss class the SD-card/storage guards and the new failure class describe. Apply the same ownership guard (storage == flashPage and id present in `_wals`) to flash_page_wal_sync.deleteWal, or note explicitly why that receiver is exempt.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| @override | ||
| Future deleteWal(Wal wal) async { | ||
| if (wal.storage != WalStorage.sdcard || !_wals.any((w) => w.id == wal.id)) return; |
There was a problem hiding this comment.
P1: When the device changes before _wals refreshes, this membership check accepts a stale WAL from the previous device and deletes its fileNum on the new device. Require wal.id to match the current device ID and reject a null device before issuing the delete.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/lib/services/wals/storage_sync.dart, line 226:
<comment>When the device changes before `_wals` refreshes, this membership check accepts a stale WAL from the previous device and deletes its `fileNum` on the new device. Require `wal.id` to match the current device ID and reject a null device before issuing the delete.</comment>
<file context>
@@ -219,6 +223,7 @@ class StorageSyncImpl implements StorageSync {
@override
Future deleteWal(Wal wal) async {
+ if (wal.storage != WalStorage.sdcard || !_wals.any((w) => w.id == wal.id)) return;
await _deleteWalsOnDevice([wal]);
_wals = _wals.where((w) => w.id != wal.id).toList();
</file context>
There was a problem hiding this comment.
Fixed in 3d4e247. The device command now only goes out when wal.device is the connected device, so a stale recording from the previous device is dropped from the list without deleting anything on the new one. Same check in the SD card and flash page syncs, with a test per sync that fails on main.
|
|
||
| @override | ||
| Future deleteWal(Wal wal) async { | ||
| if (wal.storage != WalStorage.sdcard || !_wals.any((w) => w.id == wal.id)) return; |
There was a problem hiding this comment.
P2: The ownership guard added here is not applied to flash_page_wal_sync.deleteWal, the fifth sub-sync in the same fan-out. When a synced phone recording is deleted while a Limitless/Rayban is connected, WalSyncs.deleteWal fans the delete to FlashPageWalSyncImpl.deleteWal, which still runs _acknowledgeProcessedData (for wal.status == synced) and clears the pendant's flash. This is the same cascade/data-loss class the SD-card/storage guards and the new failure class describe. Apply the same ownership guard (storage == flashPage and id present in _wals) to flash_page_wal_sync.deleteWal, or note explicitly why that receiver is exempt.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/lib/services/wals/sdcard_wal_sync.dart, line 116:
<comment>The ownership guard added here is not applied to flash_page_wal_sync.deleteWal, the fifth sub-sync in the same fan-out. When a synced phone recording is deleted while a Limitless/Rayban is connected, WalSyncs.deleteWal fans the delete to FlashPageWalSyncImpl.deleteWal, which still runs `_acknowledgeProcessedData` (for `wal.status == synced`) and clears the pendant's flash. This is the same cascade/data-loss class the SD-card/storage guards and the new failure class describe. Apply the same ownership guard (storage == flashPage and id present in `_wals`) to flash_page_wal_sync.deleteWal, or note explicitly why that receiver is exempt.</comment>
<file context>
@@ -106,6 +113,7 @@ class SDCardWalSyncImpl implements SDCardWalSync {
@override
Future deleteWal(Wal wal) async {
+ if (wal.storage != WalStorage.sdcard || !_wals.any((w) => w.id == wal.id)) return;
_wals.removeWhere((w) => w.id == wal.id);
</file context>
There was a problem hiding this comment.
Same cascade, agreed. Guarded in 3d4e247 with storage == flashPage plus membership, and the ack only goes to the connected device. Phone recordings carry storageTotalBytes 0, so today that path acks index 0 and I couldn't show it frees anything on the pendant, but it shouldn't run for a wal the flash page sync doesn't own.
| originalStorage: WalStorage.sdcard, | ||
| ); | ||
|
|
||
| final _reachedDevice = throwsA(predicate((e) => '$e'.contains('Service manager is not initiated'))); |
There was a problem hiding this comment.
P3: The 'still sends the delete to the device' tests assert that the device write is attempted by matching the internal exception text 'Service manager is not initiated' thrown by an uninitialized ServiceManager. This couples the tests to both the exception message and the test environment never initializing ServiceManager; if either changes, these tests break or silently pass for the wrong reason, and they never verify the actual deletion outcome (the wal removed from _wals, or a write sent). Inject/assert observable behavior instead, e.g. keep the wal list as the assertion after forcing the device call, or stub the connection write.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/test/unit/wal_delete_cascade_test.dart, line 43:
<comment>The 'still sends the delete to the device' tests assert that the device write is attempted by matching the internal exception text 'Service manager is not initiated' thrown by an uninitialized ServiceManager. This couples the tests to both the exception message and the test environment never initializing ServiceManager; if either changes, these tests break or silently pass for the wrong reason, and they never verify the actual deletion outcome (the wal removed from _wals, or a write sent). Inject/assert observable behavior instead, e.g. keep the wal list as the assertion after forcing the device call, or stub the connection write.</comment>
<file context>
@@ -0,0 +1,90 @@
+ originalStorage: WalStorage.sdcard,
+ );
+
+final _reachedDevice = throwsA(predicate((e) => '$e'.contains('Service manager is not initiated')));
+
+void main() {
</file context>
There was a problem hiding this comment.
There's no injection point here: ServiceManager builds a bare DeviceService and these syncs only reach the device through ServiceManager.instance(), so the uninitialized-manager error is the narrowest signal that the device path ran. The negative tests also assert the sync's own list is untouched, and a control per sync pins the positive path.
…connected device The flash page sync had the same cascade: it acknowledged the Limitless pendant for any synced wal. It now gets the same ownership guard. The storage sync also keeps its list across a device switch, so a stale recording from the previous device could be deleted by file number on the new one. All three syncs now only send the device command when wal.device is the connected device, and still drop the stale entry. Failure-Class: new
|
Verified the full chain behind this one — the reported root cause and the fix both check out end to end. Root cause, confirmed on main:
The fix mirrors the ring guard in all three receivers, and the two-condition form is the right one: the The tests in
Human maintainer sign-off wanted before merge — not out of doubt about the change, but because it alters destructive device-side delete/ack semantics on the recording pipeline, and that class of change keeps a human in the loop. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
Bug-fix, confidence 5/5: real ownership bug (SD-card/storage/flash-page syncs missing the membership guard #7218 already has for ring sync), scoped diff (182 lines, 4 files), test demonstrates 9/12 failing on main and passing after fix, CI green. Not already fixed on main (verified).
|
PR: FAILED AUTO (AI Agent). Authorship disclosed. |
WalSyncs.deleteWalsends every recording delete to all five sub-syncs, whichever one owns it. The ring sync already checks membership first (the guard added in #7218, whose comment calls out exactly this cascade), but the SD card, storage and flash page syncs don't. So deleting any recording from the sync page, the auto-sync page or a recording's detail page while a device is connected also runs their device-side action.For the SD card sync that is
writeToStorage(fileNum, 1, 0). The DevKit firmware handles command 1 asDELETE_COMMANDand runsclear_audio_file(1)andsave_offset(0)whatever file number was sent (omi/firmware/devkit/src/storage.c). Phone recordings default tofileNum = 1, so deleting a phone recording with a DevKit connected wipes the audio still waiting on its SD card. The storage sync sends[0x12, fileIndex]; the current Omi firmware reads0x12as ring advance and rejects a 2-byte write, so CV1 on the ring firmware isn't hit by either path. The flash page sync acknowledges the Limitless pendant up towal.storageTotalBytesfor any synced wal. Phone recordings carry 0 there, so I couldn't show that ack frees anything, but it shouldn't run for a recording that sync doesn't own.All three now return early unless the wal is one of their own device recordings (the storage type they manage and listed in
_wals), the same way the ring sync does. The storage type matters because a chunk copied to the phone keeps the originaldeviceandtimerStart, andWal.idis'${device}_$timerStart', so an id-only check would still clear the card when that phone copy is deleted. The device command also only goes out whenwal.deviceis the connected device: the storage sync keeps its list across a device switch, so a stale recording from the previous device would otherwise be deleted by file number on the new one. The stale entry is still dropped from the list. Bulk deletes aren't affected because those only walk each sync's own list.test/unit/wal_delete_cascade_test.dartbuilds each sync with a connected device and one of its own recordings, then deletes a phone recording, the phone copy of a device recording, a device recording it doesn't list, and a recording from a previous device. These classes can't take a fake connection, so reaching the device shows up in the test asServiceManagerthrowing "Service manager is not initiated"; a control per sync deletes its own recording and expects exactly that. Against main with only the@visibleForTestingsetters added, 9 of the 12 fail (every case where the sync doesn't own the recording) and the three controls pass. With the fix all 12 pass.No existing class covers a fan-out receiver acting on a target it doesn't own, so this adds
FC-fanout-delete-skips-ownership-checkwith #7218 as the earlier instance.Failure-Class: new