Modern Apps git

← Modern-Apps.git

things: a rejected scale-slot wipe no longer cancels the pending reset

Commit
7f44b99476ffcc1ae145958a4ac73f348218a938
Author
Vayun Mathur <[email protected]>
When
2026-12-01 05:03 UTC (5 days ago)
Parents
224497c
The VA delete-all-users result called onScaleResetDone() —
which removes the persisted scale_pending_reset flag and the
local slot claim — before checking ok, i.e. on rejection
too. The pending flag is itself the retry driver: the next
connection sends the wipe only if scaleResetPending() is
still set. Clearing it on a refused delete meant the wipe
was never retried, while requestScaleReset had already
deleted the local slot index and its key: the scale-side
slots stay occupied holding a key the phone no longer has,
stranded until slot exhaustion forces visitor mode and loses
offline attribution.

onScaleResetDone + syncUser now run only on acceptance; a
rejection just logs and leaves the flag so the next
connection retries. New regression test dispatches a refused
delete and asserts the flag survives, then an accepted one
clears it (failed pre-fix). Bottle telemetry, the live
measurement paths, Health Connect construction and the GATT
lifecycles were audited and cleared. Verified:
:things:testDevUnitTest 158 tests pass; lint errors are
pre-existing on untouched files.

Diff

things/src/main/java/com/vayunmathur/things/platform/ScaleBleMeasurement.kt
diff --git a/things/src/main/java/com/vayunmathur/things/platform/ScaleBleMeasurement.kt b/things/src/main/java/com/vayunmathur/things/platform/ScaleBleMeasurement.ktindex 33c5a64a91..801d31368b 100644--- a/things/src/main/java/com/vayunmathur/things/platform/ScaleBleMeasurement.kt+++ b/things/src/main/java/com/vayunmathur/things/platform/ScaleBleMeasurement.kt@@ -118,8 +118,15 @@ internal fun ScaleBleManager.handleUserSyncResult(v: ByteArray) {             requestStoredRecords()         }         VA_SUB_DELETE -> {-            DeviceController.onScaleResetDone()-            if (ok) syncUser() else Log.status(ScaleBleManager.TAG, "scale reset rejected")+            // Only an accepted wipe completes the reset: on rejection the pending flag+            // (and the retry it drives on the next connection) must survive, or the+            // still-occupied slots are stranded with no way to clear them.+            if (ok) {+                DeviceController.onScaleResetDone()+                syncUser()+            } else {+                Log.status(ScaleBleManager.TAG, "scale reset rejected")+            }         }     } }
things/src/test/java/com/vayunmathur/things/platform/ScaleBlePacketTest.kt
diff --git a/things/src/test/java/com/vayunmathur/things/platform/ScaleBlePacketTest.kt b/things/src/test/java/com/vayunmathur/things/platform/ScaleBlePacketTest.ktindex c01b2da0b7..19785a5cf7 100644--- a/things/src/test/java/com/vayunmathur/things/platform/ScaleBlePacketTest.kt+++ b/things/src/test/java/com/vayunmathur/things/platform/ScaleBlePacketTest.kt@@ -359,6 +359,33 @@ class ScaleBlePacketTest {         }     } +    @Test+    fun `rejected delete keeps the pending reset for the next connection`() {+        val mgr = manager(va = true)+        fun result(sub: Int, index: Int, ok: Boolean): ByteArray {+            val b = ByteArray(6)+            b[0] = PACKET_USER_SYNC.toByte()+            b[2] = sub.toByte(); b[3] = index.toByte(); b[4] = (if (ok) 1 else 0).toByte()+            return b+        }+        DeviceController.onScaleResetDone()+        DeviceController.requestScaleReset()+        assertTrue(DeviceController.scaleResetPending())+        // The scale refused to wipe its slots: the reset has not happened, so the+        // pending flag must survive for the next connection to retry it. Clearing+        // it here would strand the still-occupied slots with no way to retry.+        mgr.dispatch(result(VA_SUB_DELETE, 0, ok = false))+        flush()+        assertTrue(+            DeviceController.scaleResetPending(),+            "a rejected delete must keep the pending reset",+        )+        // A later accepted delete completes the reset.+        mgr.dispatch(result(VA_SUB_DELETE, 0, ok = true))+        flush()+        assertFalse(DeviceController.scaleResetPending())+    }+     @Test     fun `user frames visitor identify and stored requests enqueue safely`() {         val mgr = manager(va = true)