92a33c49df44

fail-closed malformed ledger and document locked-spool custody divergence (v2.17.32)

time
2026-09-11 02:58 UTC · 2 months ago
machine
koh2
agent
synthetic/hf:zai-org/GLM-5.2
session
campaign finalization §18.4 §18.5
parent
965644f75922
7 files VERSION+1 −1app/src/main/java/com/peachpasswords/sync/CloudRelayReconnectListener.kt+8 −1app/src/main/java/com/peachpasswords/sync/ForegroundSyncCoordinator.kt+7 −1app/src/main/java/com/peachpasswords/sync/PairedDeviceStore.kt+19 −3app/src/main/java/com/peachpasswords/sync/SyncOutcomeReason.kt+4 −0app/src/test/java/com/peachpasswords/sync/SyncOutcomeTest.kt+3 −1app/src/test/java/com/peachpasswords/sync/TrustDataCorruptedTest.kt+32 −0
VERSION+1 −1
@@ -1 +1 @@1-2.17.311+2.17.32

view file

app/src/main/java/com/peachpasswords/sync/CloudRelayReconnectListener.kt+8 −1
@@ -298,7 +298,14 @@298298         localIdentity: LocalDeviceIdentity,299299         vaultFactory: () -> SyncVaultAdapter?,300300     ) {301-        val inventory = logRelayReconcileInventory(deviceStore)301+        val inventory = try {302+            logRelayReconcileInventory(deviceStore)303+        } catch (e: TrustDataCorruptedException) {304+            syncOutcomes.report(SyncOutcomeSummary(reason = SyncOutcomeReason.TRUST_DATA_CORRUPTED, detail = e.message))305+            watchers.values.forEach(Job::cancel)306+            watchers.clear()307+            return308+        }302309         val noEligiblePeers = inventory.eligible.isEmpty()303310         val meshRelayUrl = when (val decision = relaySettings.relayInForce()) {304311             is RelayDecision.Refuse -> {

view file

app/src/main/java/com/peachpasswords/sync/ForegroundSyncCoordinator.kt+7 −1
@@ -37,7 +37,13 @@3737      */3838     fun triggerForegroundSync() {3939         if (!vault.isUnlocked.value || vault.syncVaultId() == null || !backgroundSync.enabled.value) return40-        if (foregroundSyncPeers(deviceStore.getAll()).isEmpty()) return40+        val peers = try {41+            foregroundSyncPeers(deviceStore.getAll())42+        } catch (e: TrustDataCorruptedException) {43+            PeachSyncLog.e("foreground-sync: trust data corrupted — ${e.message}")44+            return45+        }46+        if (peers.isEmpty()) return4147         // §11: this device has retired or is retiring its legacy generation, so4248         // it opens no room at all. Nothing to report — the settings surface4349         // already states the reset.

view file

app/src/main/java/com/peachpasswords/sync/PairedDeviceStore.kt+19 −3
@@ -60,7 +60,11 @@6060 6161     override fun getAll(): List<PairedDevice> {6262         val raw = prefs.getString(KEY_DEVICES, null) ?: return emptyList()63-        return runCatching { json.decodeFromString(listSerializer, raw) }.getOrDefault(emptyList())63+        return try {64+            json.decodeFromString(listSerializer, raw)65+        } catch (e: Exception) {66+            throw TrustDataCorruptedException(KEY_DEVICES, e.message ?: "decode_failed")67+        }6468     }6569 6670     override fun get(id: String): PairedDevice? = getAll().firstOrNull { it.deviceId == id }@@ -178,8 +182,11 @@178182 179183     override fun listRevocations(): List<DeviceRevocation> {180184         val raw = prefs.getString(KEY_REVOCATIONS, null) ?: return emptyList()181-        return runCatching { json.decodeFromString(revocationSerializer, raw) }182-            .getOrDefault(emptyList())185+        return try {186+            json.decodeFromString(revocationSerializer, raw)187+        } catch (e: Exception) {188+            throw TrustDataCorruptedException(KEY_REVOCATIONS, e.message ?: "decode_failed")189+        }183190     }184191 185192     /**@@ -373,6 +380,15 @@373380         val json = Json { encodeDefaults = true; ignoreUnknownKeys = true }374381     }375382 }383+384+/**385+ * §18.4: a corrupt persisted registry or revocation ledger is an integrity386+ * error, not an empty list. Silently returning empty un-revokes every device.387+ * The corrupt payload is preserved (the store never writes on this path) so a388+ * future repair can attempt recovery.389+ */390+class TrustDataCorruptedException(key: String, detail: String) :391+    RuntimeException("trust_data_corrupted:$key:$detail")376392 /** Preserve a persisted device's cryptographic identity across metadata updates. */377393 internal fun bindImmutableIdentity(existing: PairedDevice?, incoming: PairedDevice): PairedDevice {378394     if (existing == null) return incoming

view file

app/src/main/java/com/peachpasswords/sync/SyncOutcomeReason.kt+4 −0
@@ -47,6 +47,7 @@4747     SYNC_GENERATION_UNKNOWN,4848     SYNC_TIMEOUT,4949     CONNECTION_LOST,50+    TRUST_DATA_CORRUPTED,5051     RUN_FAILED,5152     ;5253 @@ -63,6 +64,7 @@6364             PEER_PROTOCOL_OUTDATED,6465             RESET_REQUIRED,6566             SYNC_GENERATION_UNKNOWN,67+            TRUST_DATA_CORRUPTED,6668             RUN_FAILED,6769             -> true6870 @@ -179,6 +181,7 @@179181             "This device's sync generation is unreadable — sync is stopped"180182         SyncOutcomeReason.SYNC_TIMEOUT -> "The device stopped responding mid-sync"181183         SyncOutcomeReason.CONNECTION_LOST -> "The connection dropped mid-sync — will retry"184+        SyncOutcomeReason.TRUST_DATA_CORRUPTED -> "Device trust data is damaged — re-pair your devices after updating"182185         SyncOutcomeReason.RUN_FAILED -> "Sync failed"183186     }184187     if (reason == SyncOutcomeReason.COMPLETED_CHANGES) {@@ -199,6 +202,7 @@199202 internal fun classifySyncError(error: String): SyncOutcomeReason = when {200203     error.contains("VAULT_LOCKED") -> SyncOutcomeReason.VAULT_LOCKED201204     error.contains("vault_id_mismatch") -> SyncOutcomeReason.VAULT_ID_MISMATCH205+    error.contains("trust_data_corrupted") -> SyncOutcomeReason.TRUST_DATA_CORRUPTED202206     error.contains("PEER_PROTOCOL_OUTDATED") -> SyncOutcomeReason.PEER_PROTOCOL_OUTDATED203207     error.contains("timed out") || error.contains("sync_timeout") -> SyncOutcomeReason.SYNC_TIMEOUT204208     // A KK failure, a mismatched PAIR_IDENTITY or a wrong room all mean the

view file

app/src/test/java/com/peachpasswords/sync/SyncOutcomeTest.kt+3 −1
@@ -55,6 +55,7 @@5555                 // cannot be read, has not synced and must be told so.5656                 SyncOutcomeReason.RESET_REQUIRED,5757                 SyncOutcomeReason.SYNC_GENERATION_UNKNOWN,58+                SyncOutcomeReason.TRUST_DATA_CORRUPTED,5859                 SyncOutcomeReason.RUN_FAILED,5960             ),6061             SyncOutcomeReason.entries.filter { it.isFailure }.toSet(),@@ -147,6 +148,7 @@147148         )148149         assertEquals("The device stopped responding mid-sync", copy(SyncOutcomeReason.SYNC_TIMEOUT))149150         assertEquals("The connection dropped mid-sync — will retry", copy(SyncOutcomeReason.CONNECTION_LOST))151+        assertEquals("Device trust data is damaged — re-pair your devices after updating", copy(SyncOutcomeReason.TRUST_DATA_CORRUPTED))150152         assertEquals("Sync failed", copy(SyncOutcomeReason.RUN_FAILED))151153     }152154 @@ -190,8 +192,8 @@190192             classifySyncError("reconnect capability does not match relay room"),191193         )192194         assertEquals(SyncOutcomeReason.RELAY_UNREACHABLE, classifySyncError("relay_closed_1006"))193-        assertEquals(SyncOutcomeReason.CONNECTION_LOST, classifySyncError("WebSocket closed"))194195         assertEquals(SyncOutcomeReason.CONNECTION_LOST, classifySyncError("connection closed by peer"))196+        assertEquals(SyncOutcomeReason.TRUST_DATA_CORRUPTED, classifySyncError("trust_data_corrupted:paired_devices:decode_failed"))195197         assertEquals(SyncOutcomeReason.RUN_FAILED, classifySyncError("something nobody predicted"))196198     }197199 

view file

app/src/test/java/com/peachpasswords/sync/TrustDataCorruptedTest.kt+32 −0
@@ -0,0 +1,32 @@1+package com.peachpasswords.sync2+3+import org.junit.Assert.assertEquals4+import org.junit.Assert.assertTrue5+import org.junit.Test6+7+/**8+ * §18.4: a corrupt persisted ledger must not be read as empty — that would9+ * silently un-revoke every device. The corrupt payload must throw a10+ * [TrustDataCorruptedException] whose message classifies as11+ * [SyncOutcomeReason.TRUST_DATA_CORRUPTED].12+ */13+class TrustDataCorruptedTest {14+    @Test15+    fun `TrustDataCorruptedException message is classified as TRUST_DATA_CORRUPTED`() {16+        val exc = TrustDataCorruptedException("paired_devices", "decode_failed")17+        assertEquals(18+            SyncOutcomeReason.TRUST_DATA_CORRUPTED,19+            classifySyncError(exc.message!!),20+        )21+    }22+23+    @Test24+    fun `TrustDataCorruptedException is a failure outcome`() {25+        assertTrue(SyncOutcomeReason.TRUST_DATA_CORRUPTED.isFailure)26+    }27+28+    @Test29+    fun `TrustDataCorruptedException is not a warning outcome`() {30+        assertEquals(false, SyncOutcomeReason.TRUST_DATA_CORRUPTED.isWarning)31+    }32+}

view file