LifeMate — Personal, Family & Learning Companion
test: recognize an empty committed SQLite truncate journal
Quinn White committed
Oct 23, 2026 at 06:37 UTC
a26d2524c48be957f57a92868600c149bc837eb2
3 files changed
+191
-4
apps/lifemate/tool/test_personal_recovery_android.py
+8
-3
@@ -251,15 +251,20 @@ class Harness:
251
# A terminated read-only Android WAL connection can leave a zero-byte
252
# WAL plus SHM cache. Only a strictly empty WAL has no frames to replay.
253
wal, shm, journal = (DATABASE + suffix for suffix in ('-wal', '-shm', '-journal'))
254
- query = (f'if [ -e {journal} ]; then printf SIDECAR; '
254
+ # Android TRUNCATE mode also retains a regular zero-byte journal after
255
+ # a committed transaction. It has no rollback record to recover.
256
+ query = (f'if [ -L {wal} ] || [ -L {shm} ] || [ -L {journal} ]; then printf SIDECAR; '
257
+ f'elif [ -e {journal} ]; then '
258
+ f'if [ -f {journal} ] && [ ! -s {journal} ] && [ ! -e {wal} ] && [ ! -e {shm} ]; '
259
+ 'then printf EMPTY_JOURNAL; else printf SIDECAR; fi; '
260
f'elif [ ! -e {wal} ] && [ ! -e {shm} ]; then printf CLEAN; '
261
f'elif [ -f {wal} ] && [ ! -s {wal} ]; then '
262
f'if [ -e {shm} ]; then printf EMPTY_WAL_SHM; else printf EMPTY_WAL; fi; '
263
'else printf SIDECAR; fi')
264
output = self.adb.shell('run-as', package, 'sh', '-c', query).strip()
260
- if output not in ('CLEAN', 'EMPTY_WAL', 'EMPTY_WAL_SHM'):
265
+ if output not in ('CLEAN', 'EMPTY_WAL', 'EMPTY_WAL_SHM', 'EMPTY_JOURNAL'):
266
self._diagnose_cold_files(package)
262
- require(output in ('CLEAN', 'EMPTY_WAL', 'EMPTY_WAL_SHM'), 'database_sidecar_present')
267
+ require(output in ('CLEAN', 'EMPTY_WAL', 'EMPTY_WAL_SHM', 'EMPTY_JOURNAL'), 'database_sidecar_present')
268
return output
269
270
def _diagnose_cold_files(self, package):
apps/lifemate/tool/test_personal_recovery_android_test.py
+85
-1
@@ -132,7 +132,7 @@ class RecoveryBoundaryTest(unittest.TestCase):
132
h.install(subject.ORIGINAL)
133
raw = subject.create_sample_database()
134
h.binary = lambda command, data=None: raw
135
- for shape in ('CLEAN', 'EMPTY_WAL', 'EMPTY_WAL_SHM'):
135
+ for shape in ('CLEAN', 'EMPTY_WAL', 'EMPTY_WAL_SHM', 'EMPTY_JOURNAL'):
136
self.adb.sidecars = shape
137
self.assertEqual(h.capture(subject.ORIGINAL), raw)
138
self.adb.sidecars = 'EMPTY_WAL_SHM'
@@ -169,6 +169,90 @@ class RecoveryBoundaryTest(unittest.TestCase):
169
self.assertEqual(h.receipt['lastColdFileObservation'], 'UNAVAILABLE')
170
self.assertNotIn('untrusted', json.dumps(h.receipt))
171
172
+ def test_actual_committed_truncate_journal_is_safe_after_process_exit(self):
173
+ source = self.directory / subject.DATABASE
174
+ source.parent.mkdir()
175
+ fixture = subject.create_sample_database()
176
+ source.write_bytes(fixture)
177
+ script = ("import os,sqlite3,sys; d=sqlite3.connect(sys.argv[1]); "
178
+ "d.execute('PRAGMA journal_mode=TRUNCATE'); "
179
+ "d.execute('CREATE TABLE android_metadata (locale TEXT)'); "
180
+ "d.execute(\"INSERT INTO android_metadata VALUES ('en_US')\"); "
181
+ "d.commit(); os._exit(0)")
182
+ subprocess.run(['python3', '-c', script, str(source)], check=True)
183
+ journal = Path(str(source) + '-journal')
184
+ self.assertTrue(journal.is_file())
185
+ self.assertEqual(journal.stat().st_size, 0)
186
+ before = {p: p.read_bytes() for p in (source, journal)}
187
+ h = self.make()
188
+ h.preflight()
189
+ h.install(subject.ORIGINAL)
190
+ previous_shell = self.adb.shell
191
+ def shell(*parts, **kwargs):
192
+ if parts[0] == 'run-as':
193
+ return subprocess.run(['sh', '-c', parts[-1]], cwd=self.directory,
194
+ capture_output=True, text=True, check=True, timeout=2).stdout
195
+ return previous_shell(*parts, **kwargs)
196
+ self.adb.shell = shell
197
+ h.binary = lambda command, data=None: source.read_bytes()
198
+ try:
199
+ captured = h.capture(subject.ORIGINAL)
200
+ except subject.AcceptanceError as error:
201
+ self.fail('Committed TRUNCATE journal is empty, but capture refused: ' + str(error))
202
+ self.assertEqual(h.receipt['coldCaptureStates'][subject.ORIGINAL], 'EMPTY_JOURNAL')
203
+ copy = self.directory / 'captured-main.sqlite'
204
+ copy.write_bytes(captured)
205
+ reference = self.directory / 'reference.sqlite'
206
+ reference.write_bytes(fixture)
207
+ actual = subject.normalized_snapshot(copy, self.directory / 'normalized.sqlite')
208
+ self.assertEqual(actual, subject.export_fixture(reference))
209
+ self.assertEqual(subject.independent_sql(reference),
210
+ subject.independent_sql(self.directory / 'normalized.sqlite'))
211
+ self.assertEqual({p: p.read_bytes() for p in before}, before)
212
+
213
+ def test_actual_shell_rejects_unsafe_journal_shapes(self):
214
+ h = self.make()
215
+ h.preflight()
216
+ h.install(subject.ORIGINAL)
217
+ previous_shell = self.adb.shell
218
+ with tempfile.TemporaryDirectory() as root:
219
+ db = Path(root) / subject.DATABASE
220
+ db.parent.mkdir()
221
+ journal = Path(str(db) + '-journal')
222
+ wal = Path(str(db) + '-wal')
223
+ shm = Path(str(db) + '-shm')
224
+ def shell(*parts, **kwargs):
225
+ if parts[0] == 'run-as':
226
+ return subprocess.run(['sh', '-c', parts[-1]], cwd=root,
227
+ capture_output=True, text=True, check=True, timeout=2).stdout
228
+ return previous_shell(*parts, **kwargs)
229
+ self.adb.shell = shell
230
+ for kind in ('byte', 'directory', 'fifo', 'symlink', 'dangling', 'with_wal', 'with_shm'):
231
+ with self.subTest(kind=kind):
232
+ if kind == 'byte':
233
+ journal.write_bytes(b'x')
234
+ elif kind == 'directory':
235
+ journal.mkdir()
236
+ elif kind == 'fifo':
237
+ subject.os.mkfifo(journal)
238
+ elif kind in ('symlink', 'dangling'):
239
+ target = Path(root) / 'empty-target'
240
+ if kind == 'symlink':
241
+ target.write_bytes(b'')
242
+ journal.symlink_to(target if kind == 'symlink' else Path(root) / 'missing')
243
+ else:
244
+ journal.write_bytes(b'')
245
+ (wal if kind == 'with_wal' else shm).write_bytes(b'')
246
+ with self.assertRaisesRegex(subject.AcceptanceError, 'database_sidecar_present'):
247
+ h._cold(subject.ORIGINAL)
248
+ if journal.is_dir():
249
+ journal.rmdir()
250
+ else:
251
+ journal.unlink()
252
+ for extra in (wal, shm):
253
+ if extra.exists():
254
+ extra.unlink()
255
+
256
def test_actual_exited_sqlite_reader_leaves_empty_wal_cache_only(self):
257
source = self.directory / 'real-closed-reader.sqlite'
258
fixture = subject.create_sample_database()
docs/audits/evidence/personal-recovery-cold-diagnostic-2026-10-23.json
new
+98
@@ -0,0 +1,98 @@
1
+{
2
+ "schemaVersion": 1,
3
+ "status": "FAILED_ACTUAL_ANDROID_ACCEPTANCE",
4
+ "sourceCommit": "c5942f4d06f9df87ee5874553309b75aa658d27d",
5
+ "runId": 39848561580,
6
+ "artifactId": 12457246607,
7
+ "artifactZipSha256": "1851ec108b74ff4ff480ec83452729c73a0f26a9bc345f766608a9347c8866b7",
8
+ "rootVerifiedArtifactDigest": true,
9
+ "receipt": {
10
+ "apks": {
11
+ "original": {
12
+ "package": "ir.lifeguide.app.device",
13
+ "sha256": "c24ff6e75a987945399b0d96129f5d1a72525fa0270f31b0c481f9780f84db8e",
14
+ "versionCode": 9,
15
+ "versionName": "0.7.2-personal.1"
16
+ },
17
+ "qaNeverDistribute": {
18
+ "package": "ir.lifeguide.app.personal",
19
+ "sha256": "8fdb87aae0b36a28a08652ab718642f6c89858e8ec9154525f7541cf2f3a697b",
20
+ "versionCode": 10,
21
+ "versionName": "0.7.2-recovery-qa.10"
22
+ },
23
+ "upgradeNeverDistribute": {
24
+ "package": "ir.lifeguide.app.personal",
25
+ "sha256": "30c3842fca73de639c33921c04f862754c35c119d024dc4d13ecc840bdfc4fcd",
26
+ "versionCode": 11,
27
+ "versionName": "0.7.2-recovery-qa.11"
28
+ }
29
+ },
30
+ "canonicalSnapshotSha256": "f64bf8f30e41dc4eddca18629f2ca950839fdb11f489c85889a40500739c06f9",
31
+ "certificatesSha256": [
32
+ "4ef990d647fc98ac41113d5dbe7ee476ba80bf95b71b5f219b7863fa95263391",
33
+ "f559aa4d6af8596f837694840ccb27af73a899626efdde5e3a2b43bc791495a0",
34
+ "f559aa4d6af8596f837694840ccb27af73a899626efdde5e3a2b43bc791495a0"
35
+ ],
36
+ "checks": {
37
+ "allApksAndFreshEmulatorGatedBeforeInstall": "PASS"
38
+ },
39
+ "coldCaptureStates": {
40
+ "ir.lifeguide.app.device": "CLEAN"
41
+ },
42
+ "counts": {
43
+ "local_occurrences": 4,
44
+ "local_plans": 4,
45
+ "local_profiles": 1,
46
+ "local_weekly_slots": 3
47
+ },
48
+ "currentPhase": "original_seed_and_ordinary_ui",
49
+ "errorCode": "database_sidecar_present",
50
+ "fictionalScreenshotsSha256": {
51
+ "personal-recovery-android.png": "65117bbda7e93f3812824c4328a9f635b0e86ffdb25a711e4189a06c65944ba0"
52
+ },
53
+ "lastColdFileObservation": {
54
+ "journal": {
55
+ "bytes": 0,
56
+ "kind": "FILE"
57
+ },
58
+ "main": {
59
+ "bytes": 49152,
60
+ "kind": "FILE"
61
+ },
62
+ "shm": {
63
+ "kind": "ABSENT"
64
+ },
65
+ "wal": {
66
+ "kind": "ABSENT"
67
+ }
68
+ },
69
+ "lastUiObservation": {
70
+ "exactContentDescriptionMatch": true,
71
+ "exactTextMatch": false,
72
+ "nodeCount": 30,
73
+ "ownedPackageNodeCount": 30,
74
+ "package": "ir.lifeguide.app.device"
75
+ },
76
+ "limitations": {
77
+ "Doze": "UNVERIFIED",
78
+ "USB": "UNVERIFIED",
79
+ "Windows": "UNVERIFIED",
80
+ "distributionApk": "UNVERIFIED",
81
+ "originalNotificationsEnabled": "UNVERIFIED",
82
+ "ownerData": "UNVERIFIED",
83
+ "ownerSigningKey": "UNVERIFIED",
84
+ "physicalDevice": "UNVERIFIED",
85
+ "powerLossOrFullDisk": "UNVERIFIED",
86
+ "reboot": "UNVERIFIED",
87
+ "soundOrVibration": "UNVERIFIED"
88
+ },
89
+ "result": "FAIL",
90
+ "schemaVersion": 1,
91
+ "syntheticDataOnly": true
92
+ },
93
+ "diagnosis": {
94
+ "actualObservation": "PID absent; main49152bytes; WAL absent; SHM absent; regular journal0bytes",
95
+ "rootCause": "Test classifier rejected an inert zero-byte TRUNCATE journal, not an observed nonempty WAL",
96
+ "fixScope": "Only regular zero-byte journal with no WAL/SHM after process absence; compare shape before/after; never delete/checkpoint any source; nonempty journal/WAL still refused"
97
+ }
98
+}