notes-wear: a truncated snapshot can no longer clear a pending delete
- Commit
57447308fecefb4a716df0ea554cf6dd321b28a8- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 10:44 UTC (5 days ago)
- Parents
7d91dba
reflectedOps cleared a DELETE whenever the note was absent from the snapshot, but truncated=true is set precisely when the 50-note/byte caps drop notes from the window: the note may still be live on the phone outside it. The pending delete was dropped and persisted away, never resent, and when a later snapshot included the note again there was no pending delete left to hide it โ the deleted note resurrected on the watch and the phone never re-applied the delete. The UPSERT branch was already conservative about absence; DELETE was asymmetric. A delete now reflects only against a complete snapshot; against a truncated one it stays pending (and keeps hiding the note in the merge), resent on reconnect โ phone-side tombstone re-application is harmless. Because the protocol file is a declared copy, the same change must be mirrored into notes/ โ a follow-up is spawned for that side. New test pins truncated absence keeping the op, the hide, and complete absence still reflecting. Verified: :notes-wear: testDebugUnitTest 10 tests and lint BUILD SUCCESSFUL.
Diff
notes-wear/src/main/java/com/vayunmathur/notes/wear/domain/WearNotesProtocol.kt
diff --git a/notes-wear/src/main/java/com/vayunmathur/notes/wear/domain/WearNotesProtocol.kt b/notes-wear/src/main/java/com/vayunmathur/notes/wear/domain/WearNotesProtocol.ktindex b28c33dc72..dc888e2257 100644--- a/notes-wear/src/main/java/com/vayunmathur/notes/wear/domain/WearNotesProtocol.kt+++ b/notes-wear/src/main/java/com/vayunmathur/notes/wear/domain/WearNotesProtocol.kt@@ -187,9 +187,12 @@ fun reflectedOps(snapshot: WearNotesSnapshot, pendingOps: List<WearNoteOp>): Lis pendingOps.filter { op -> val remote = snapshot.notes.firstOrNull { it.syncId == op.note.syncId } when {- // A delete is reflected when the note is gone from the live snapshot- // at a stamp that cannot beat it, or simply absent entirely.- op.kind == WearOpKind.DELETE -> remote == null+ // A delete is reflected when the note is gone from a complete live+ // snapshot. Absence from a truncated snapshot proves nothing: the+ // count/byte caps may have dropped the still-live note, so the+ // delete stays pending (and is resent) until a complete snapshot+ // confirms the phone no longer holds it.+ op.kind == WearOpKind.DELETE -> remote == null && !snapshot.truncated remote == null -> false else -> !wearNoteWins(op.note, remote) }
notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.kt
diff --git a/notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.kt b/notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.ktindex 53bb25870e..31d83cd81f 100644--- a/notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.kt+++ b/notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.kt@@ -145,4 +145,26 @@ class WearNotesProtocolTest { ).size, ) }++ @Test+ fun deleteIsNotReflectedByAbsenceFromTruncatedSnapshot() {+ // Truncated means the count/byte caps dropped notes: "a" may still be+ // live on the phone at 100L, just outside the snapshot window. Dropping+ // the pending delete here would lose it, and "a" would resurrect on+ // the watch when a later snapshot includes it again.+ val delete = WearNoteOp(WearOpKind.DELETE, note("a", 200L, deleted = true))+ val truncated = WearNotesSnapshot(1_000L, listOf(note("b", 300L)), truncated = true)+ assertEquals(emptyList(), reflectedOps(truncated, listOf(delete)))+ // The still-pending delete keeps hiding any snapshot copy meanwhile.+ assertEquals(+ listOf(note("b", 300L)),+ mergeWearSnapshot(+ WearNotesSnapshot(1_100L, listOf(note("a", 100L), note("b", 300L))),+ listOf(delete),+ ),+ )+ // A complete snapshot without the note does reflect the delete.+ val complete = WearNotesSnapshot(1_200L, listOf(note("b", 300L)), truncated = false)+ assertEquals(listOf(delete), reflectedOps(complete, listOf(delete)))+ } }