Skip to content

Sync staging db: reset/re-stage to drop pre-ActivityWatch/aw-server-rust#713 duplicate copies (item 2 of ActivityWatch/aw-server-rust#717) #296

Description

@TimeToBuildBob

Follow-up to ActivityWatch/aw-server-rust#717, item 2. Item 1 (aw-sync dedupe for -synced-from- buckets on desktops) merged in ActivityWatch/aw-server-rust#718. This is the phone side.

Problem

The phone's push staging db ({sync_dir}/{hostname}/{device_id}/test.db) still holds the copies written by pre-ActivityWatch/aw-server-rust#713 pushes: 293 of one finished stopwatch event, plus the counts from the desktop dry run on erb-m2 (android-test 155,316 of 306,738, android-unlock 4,797, android 2,349). #295 (bump to 70ba50d) stops the growth, but every fresh desktop import of this phone still pulls the existing copies once.

aw-sync dedupe does not reach this: it deliberately refuses non--synced-from- buckets, goes over the aw-server HTTP API (ms precision), and staging is a separate sqlite file that no server serves.

Proposal

The staging db is derived data (the local datastore is the source of truth), so drop it and re-stage rather than dedupe it in place:

  1. JNI SyncInterface.resetStaging(hostname) in aw-sync/src/android.rs: delete test.db, test.db-wal, test.db-shm for the own device dir only. Resolve the path from the same get_sync_dir() + hostname/device id the push uses and refuse anything not under that dir. Never touch a peer's dir.
  2. Kotlin: run it under the existing syncInFlight guard (never concurrent with a push), once, before the first push after upgrading to a build carrying fix(aw-sync): dedup boundary events on resume to prevent cursor re-imports (#711) aw-server-rust#713. Gate with a SharedPreferences flag so it doesn't repeat.
  3. The next push rebuilds staging from the local datastore. Push resume is derived from the staging bucket's last event, so an empty staging means one full re-push (small on a phone).

Trigger choice for Erik: automatic one-shot (nobody has to know) versus a "Reset sync staging" button in Sync Settings. I lean automatic one-shot since there is no reason a user would ever decline it.

Verify before building

  • Confirm the phone's local android-test / android-unlock buckets are not themselves duplicated. If they are, re-staging reproduces the copies and the local buckets need the cleanup instead. Erik's dry run only proved the staging db matches the desktop counts.
  • After reset, pull on erb-m2 should add zero events (the end_time + data fingerprint from fix(aw-sync): dedup boundary events on resume to prevent cursor re-imports (#711) aw-server-rust#713 covers re-imported rows). Worth one check on the real pair before calling it done.

Out of scope: sync v2 makes this class impossible by construction (idempotency by source event id).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions