Modern Apps git

← Modern-Apps.git

notes: mirror the truncated-snapshot delete guard into the phone protocol copy

Commit
533f88df19e92700dcee5278fee9d810cd9c62f9
Author
Vayun Mathur <[email protected]>
When
2026-12-01 10:46 UTC (5 days ago)
Parents
f2cba2f
The wear fix (57447308f) guarded DELETE reflection with
!snapshot.truncated; the phone copy of WearNotesProtocol
(declared copy — the whole-file normalized diff showed this
was the only semantic drift, and the tests had the same
single gap) still cleared a pending delete on absence from
any snapshot. Mirrored exactly: DELETE reflects only on a
complete snapshot, with the same comment and the same
regression test. Both protocol files, and both test files,
are now identical modulo the package line. Verified:
:notes:testDevUnitTest 252 tests pass; lint 0 errors with
only pre-existing warnings.

Diff

notes/src/main/java/com/vayunmathur/notes/domain/WearNotesProtocol.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/domain/WearNotesProtocol.kt b/notes/src/main/java/com/vayunmathur/notes/domain/WearNotesProtocol.ktindex 11a346859c..ce979d8927 100644--- a/notes/src/main/java/com/vayunmathur/notes/domain/WearNotesProtocol.kt+++ b/notes/src/main/java/com/vayunmathur/notes/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/src/test/java/com/vayunmathur/notes/sync/WearNotesProtocolTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/sync/WearNotesProtocolTest.kt b/notes/src/test/java/com/vayunmathur/notes/sync/WearNotesProtocolTest.ktindex 83a4df8c11..9078917c9e 100644--- a/notes/src/test/java/com/vayunmathur/notes/sync/WearNotesProtocolTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/sync/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)))+    } }