todo-wear: a reflected quick-add leaves the pending queue instead of re-sending forever
- Commit
7d91dba0a956817f0838da7fe09682113cad0ced- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 10:41 UTC (5 days ago)
- Parents
6f94882
dropReflected kept every op kind except SET_DONE/EDIT/ DELETE forever, but a QUICK_ADD is page-reflectable: the phone-created task carries the op's syncId, so its presence in a republished page is exactly the reflection signal the other kinds already use. The op could never be dropped: WearLinkBridge resends every pending op on each reconnect, so the identical quick-add fired again on every reconnect, and the home screen showed 'Waiting for your phone to confirm N change(s)' forever (pendingOps never zeroed). The decision is extracted to a pure pendingOpsNotReflectedBy: SET_DONE/EDIT/QUICK_ADD drop when the page (including subtasks) carries the syncId, DELETE drops when it no longer does, SNOOZE stays queued (no page-visible target value). Three regression tests pin the reflected drop, the not-yet-reflected keep, and unchanged semantics for the rest. Catalog staleness, the pending overlay and navigation were audited and cleared. Verified: :todo-wear: testDebugUnitTest and lint BUILD SUCCESSFUL.
Diff
todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.kt
diff --git a/todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.kt b/todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.ktindex 0728e7253b..381a8b8390 100644--- a/todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.kt+++ b/todo-wear/src/main/java/com/vayunmathur/todo/wear/data/WearTodoStore.kt@@ -7,6 +7,7 @@ import com.vayunmathur.todo.wear.domain.WearTodoOp import com.vayunmathur.todo.wear.domain.WearTodoOpKind import com.vayunmathur.todo.wear.domain.WearTodoPage import com.vayunmathur.todo.wear.domain.WearTodoProtocol+import com.vayunmathur.todo.wear.domain.pendingOpsNotReflectedBy import java.io.File import java.util.UUID import kotlinx.coroutines.flow.MutableStateFlow@@ -132,17 +133,7 @@ class WearTodoStore private constructor(private val context: Context) { private fun dropReflected(page: WearTodoPage) { if (_pendingOps.value.isEmpty()) return- val ids = page.tasks.flatMap { listOf(it.syncId) + it.subtasks.map { s -> s.syncId } }.toSet()- val kept = _pendingOps.value.filter { op ->- when (op.kind) {- // A republished page decides these: present tasks carry the- // phone's post-op state; a delete is reflected by absence- // once its page is republished (checked by caller pages too).- WearTodoOpKind.SET_DONE, WearTodoOpKind.EDIT -> op.syncId !in ids- WearTodoOpKind.DELETE -> op.syncId in ids- else -> true- }- }+ val kept = pendingOpsNotReflectedBy(_pendingOps.value, page) if (kept.size != _pendingOps.value.size) { _pendingOps.value = kept persist(pendingFile, WearTodoProtocol.json.encodeToString(kept))
todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt
diff --git a/todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt b/todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.ktindex 56b6e871a5..06ee039724 100644--- a/todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt+++ b/todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt@@ -197,6 +197,31 @@ data class WearTodoOp( val priority: Int? = null, ) +/**+ * Pending ops that a republished [page] does NOT yet reflect, in queue order.+ *+ * A page reflects SET_DONE/EDIT/QUICK_ADD by carrying the target task (for+ * QUICK_ADD, the task the phone created carries the op's [WearTodoOp.syncId]);+ * it reflects DELETE by no longer carrying the task. SNOOZE ops carry no+ * page-visible target value, so a page can never prove them reflected and+ * they stay queued.+ */+fun pendingOpsNotReflectedBy(+ pendingOps: List<WearTodoOp>,+ page: WearTodoPage,+): List<WearTodoOp> {+ if (pendingOps.isEmpty()) return pendingOps+ val ids = page.tasks.flatMap { listOf(it.syncId) + it.subtasks.map { s -> s.syncId } }.toSet()+ return pendingOps.filter { op ->+ when (op.kind) {+ WearTodoOpKind.SET_DONE, WearTodoOpKind.EDIT,+ WearTodoOpKind.QUICK_ADD -> op.syncId !in ids+ WearTodoOpKind.DELETE -> op.syncId in ids+ WearTodoOpKind.SNOOZE_HOUR, WearTodoOpKind.SNOOZE_TOMORROW -> true+ }+ }+}+ /** Builds a bounded catalog: view caps then the byte cap (last entries drop first). */ fun buildWearCatalog( views: List<WearTodoViewEntry>,
todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.kt
diff --git a/todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.kt b/todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.ktindex 186ced03c5..9ef92d3c2a 100644--- a/todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.kt+++ b/todo-wear/src/test/java/com/vayunmathur/todo/wear/domain/WearTodoProtocolTest.kt@@ -9,6 +9,7 @@ import com.vayunmathur.todo.wear.domain.WearTodoTask import com.vayunmathur.todo.wear.domain.WearTodoViewEntry import com.vayunmathur.todo.wear.domain.buildWearPage import com.vayunmathur.todo.wear.domain.overlayPendingTasks+import com.vayunmathur.todo.wear.domain.pendingOpsNotReflectedBy import kotlinx.serialization.encodeToString import kotlin.test.Test import kotlin.test.assertEquals@@ -103,6 +104,53 @@ class WearTodoProtocolTest { assertTrue(bytes <= WearTodoProtocol.MAX_JSON_BYTES, "page $bytes bytes over cap") } + @Test+ fun quickAddDroppedOncePageCarriesTheCreatedTask() {+ // Regression: QUICK_ADD fell into the keep-forever branch, so a+ // reflected quick-add stayed pending and was resent on every+ // reconnect (WearLinkBridge.flushPending) for the same opId/syncId.+ val quickAdd = WearTodoOp(+ WearTodoOpKind.QUICK_ADD, opId = "o2", syncId = "n1",+ text = "Buy milk tomorrow", pageKey = "today",+ )+ val reflectedPage = WearTodoPage(+ pageKey = "today", generatedAtMillis = 2_000L,+ tasks = listOf(task("n1", "Buy milk tomorrow")),+ )+ assertEquals(emptyList(), pendingOpsNotReflectedBy(listOf(quickAdd), reflectedPage))+ }++ @Test+ fun quickAddKeptWhilePageDoesNotCarryTheCreatedTask() {+ val quickAdd = WearTodoOp(+ WearTodoOpKind.QUICK_ADD, opId = "o2", syncId = "n1",+ text = "Buy milk tomorrow", pageKey = "today",+ )+ val otherPage = WearTodoPage(+ pageKey = "today", generatedAtMillis = 2_000L,+ tasks = listOf(task("a")),+ )+ assertEquals(listOf(quickAdd), pendingOpsNotReflectedBy(listOf(quickAdd), otherPage))+ }++ @Test+ fun reflectedPageKeepsExistingDoneEditDeleteAndSnoozeSemantics() {+ val setDone = WearTodoOp(WearTodoOpKind.SET_DONE, syncId = "a", done = true)+ val edit = WearTodoOp(WearTodoOpKind.EDIT, syncId = "b", title = "Edited")+ val delete = WearTodoOp(WearTodoOpKind.DELETE, syncId = "c")+ val snooze = WearTodoOp(WearTodoOpKind.SNOOZE_HOUR, syncId = "a")+ val page = WearTodoPage(+ pageKey = "today", generatedAtMillis = 2_000L,+ tasks = listOf(task("a"), task("b")),+ )+ // a/b present -> done/edit reflected; c absent -> delete reflected;+ // snooze has no page-visible proof, so it stays queued.+ assertEquals(+ listOf(snooze),+ pendingOpsNotReflectedBy(listOf(setDone, edit, delete, snooze), page),+ )+ }+ @Test fun overlayAppliesDoneEditAndDeleteButNotSnoozeOrQuickAdd() { val tasks = listOf(task("a"), task("b"), task("c"))