Repository navigation
Clear deleted history out of the database files, not just the tables - #324
Merged
Merged
Conversation
A delete left the rows readable in the files. Android's SQLite zeroes a deleted row, but in WAL mode that happens in the log: until a checkpoint the main file keeps the old pages and the -wal keeps the frames that inserted the rows. The checkpoint #315 added after VACUUM never ran, because a PRAGMA query closed unread is never executed. DatabaseCompaction now holds both steps, with the checkpoint's row read so it runs. A period chosen in Settings and a removed tag get VACUUM and the checkpoint; the prune at every app start gets the checkpoint alone, which is what clears the rows and writes only the changed pages. CompactingAfterDeletingHistoryTest reads both files byte for byte for text only the deleted reports carried; both tests fail with the checkpoint unread, and the start test fails with it removed. HistoryRetentionSettingTest's fake now records when prune() is called rather than when it is subscribed, so save.andThen(prune) fails the ordering test, and a new test covers a failed save: nothing is deleted and the old period is shown again. Both fail with onlyAfter replaced by andThen. AGENTS.md rule 24 records the WAL remnants and the unread cursor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
parawanderer
temporarily deployed
to
Android Build
November 28, 2026 10:45 — with
GitHub Actions
Inactive
parawanderer
temporarily deployed
to
Android Build
November 28, 2026 10:45 — with
GitHub Actions
Inactive
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #321 (location history retention) and #315 (removing a tag's data), both by @lazzurs. Deleted reports were still readable in the database files after either.
Cause
Android's SQLite has
secure_deleteandauto_vacuumon (measured on the managed device:secure_delete=1,auto_vacuum=1), so a delete zeroes the row. In WAL mode that happens in the log: until a checkpoint, the main file keeps the pages from before the delete and-walkeeps the frames that inserted the rows.#315's
compactBestEffortranVACUUMand thensqlite.query("PRAGMA wal_checkpoint(TRUNCATE)").close(). An Android cursor runs when first read, so that checkpoint never executed. After VACUUM, the deleted text was still in the files; after a checkpoint whose row is read, in neither. #321's prune did no checkpoint at all.Change
db/repo/DatabaseCompaction:checkpointreads the pragma's row, and logs when a reader kept it from finishing;nowrunsVACUUMthencheckpoint. ReplacesBeaconRepository.compactBestEffort.LocationHistoryRetention.prune(Settings, shorter period):nowwhen something was deleted.LocationHistoryRetention.pruneAtStart(every app start):checkpointonly, which clears the rows and writes only the changed pages, instead of rewriting the whole file at every start.OpenAirTagApplicationcalls it.VACUUMplus the now-working checkpoint.Tests
CompactingAfterDeletingHistoryTest(new, instrumented): a database file of its own, 300 padded reports carrying a marker, prune, then searches the main file and-walbyte for byte. Asserts the marker was there before, is gone after, and that the kept report's marker is still found. One test per path (prune,pruneAtStart).HistoryRetentionSettingTest: the fake pruner recorded the stored period insideSingle.fromCallable, i.e. at subscription, sosave.andThen(prune)passed the ordering test as well asRxFlows.onlyAfterdid. It now records whenprune()is called. NewaFailedSaveDeletesNothingAndPutsThePeriodBackhosts the row onTestHostActivitywith a repository whose save fails, and asserts the pruner is never called and the subtitle returns to Forever.Negative controls, each run on the managed device and reverted:
pruneAtStartRxFlows.onlyAfterreplaced withsave.andThen(prune)Verified
aosp-atdAPI 34):CompactingAfterDeletingHistoryTest,PruningOldLocationHistoryTest,HistoryRetentionSettingTest,RemovingATagForgetsItsKeysTest, 31 tests, all pass.:app:testDebugUnitTestandcheck_java_imports.pypass. The full emulator suite was not run locally; CI runs it.Not verified
secure_delete.VACUUMstays on the user-initiated paths for that case; the app-start checkpoint alone would leave deleted rows in free space there until the next Settings change or tag removal.VACUUMtakes on a large real history.🤖 Generated with Claude Code