fix(datastore): merge disjoint aw-watcher-android-test events on name collision - #661
Conversation
UPDATE OR IGNORE skipped the collision case where both the legacy aw-watcher-android-test_* bucket and the canonical aw-watcher-android_* bucket exist, leaving years of history stranded after upgrades (ActivityWatch/aw-android#243). Move non-overlapping legacy events into the canonical bucket, leave overlapping events in the legacy bucket, and delete the legacy bucket only once it is empty. Replace the in-memory bucket cache from SQLite after the rewrite so deleted buckets disappear. Refs: ActivityWatch/aw-android#149, ActivityWatch/aw-android#150
Greptile SummaryThe PR safely completes the Android legacy-bucket migration fix by retaining mutually overlapping legacy events while moving disjoint history into the canonical bucket.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the updated predicate keeps mutually overlapping legacy events together, resolving the previously reported migration defect. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Legacy Android bucket] --> B{Canonical bucket exists?}
B -- No --> C[Rename legacy bucket]
B -- Yes --> D[Inspect each legacy event]
D --> E{Overlaps destination or another legacy event?}
E -- No --> F[Move event to canonical bucket]
E -- Yes --> G[Keep event in legacy bucket]
F --> H{Legacy bucket empty?}
G --> H
H -- Yes --> I[Delete legacy bucket]
H -- No --> J[Retain partially merged bucket]
C --> K[Rebuild bucket cache]
I --> K
J --> K
Reviews (2): Last reviewed commit: "fix(datastore): retain overlapping legac..." | Re-trigger Greptile |
|
Windows |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #661 +/- ##
==========================================
+ Coverage 70.81% 79.40% +8.58%
==========================================
Files 51 66 +15
Lines 2916 5603 +2687
==========================================
+ Hits 2065 4449 +2384
- Misses 851 1154 +303 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Set a 5-second busy_timeout after opening SQLite connections to allow the database to wait for locks rather than immediately failing with DatabaseBusy errors. This fixes test failures on Windows where multiple connections to the same database file can create lock contention. Fixes windows-latest CI failure in sync_roundtrip tests.
|
Fixed Greptile's P1 in |
|
@greptileai review |
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
Summary
migrate_test_bucket_names()(from #628) renamedaw-watcher-android-test*buckets withUPDATE OR IGNORE. That no-ops when the canonicalaw-watcher-android_*bucket already exists — exactly the post-upgrade state in ActivityWatch/aw-android#243, where years of history sit in the old bucket and the Activity view queries the new empty-ish one.This replaces the rename-only path with:
A single overlapping cutover heartbeat no longer strands the rest of the history.
Also rebuilds the in-memory bucket cache from SQLite after the rewrite so deleted buckets disappear (the previous insert-only refresh kept stale IDs).
Why not skip the whole bucket on any overlap?
Erik's constraint in ActivityWatch/aw-android#243 is merge when it is safe/non-overlapping. Skipping the entire legacy bucket because one event overlaps at the upgrade boundary would leave years of disjoint history invisible. Partial merge matches that constraint without throwing away the rest.
Tests
test_migrate_test_bucket_names_renames_bucket_and_preserves_eventstest_migrate_test_bucket_names_merges_non_overlapping_bucketstest_migrate_test_bucket_names_keeps_overlapping_buckets_separatetest_migrate_test_bucket_names_merges_interleaved_non_overlapping_eventstest_migrate_test_bucket_names_moves_disjoint_events_when_some_overlap(new)cargo test -p aw-datastore --test datastore— 16 passed.Follow-up
ActivityWatch/aw-android still never calls this JNI. Companion PR will wire
migrateWatcherAndroidBucketNames()fromBackgroundServicestartup.Refs: ActivityWatch/aw-android#149, ActivityWatch/aw-android#150, ActivityWatch/aw-android#243