aw-sync: no stored cursor — resume-from-destination silently never syncs late-arriving events
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- rust
- Domain
- backend, databases, distributed-systems
Research direction
Start at sync_one and trace the current destination-based resume logic, including get_events pagination and boundary_ts handling. Design the per-source cursor and migration behavior described in the proposal, then verify that late-arriving events are picked up and separate source buckets do not share progress. Done means the timestamp boundary loop is no longer needed and existing installs retain a usable resume point.
Written by the indexing model from the issue text.
Description
sync_one has no stored cursor. It infers where to resume by reading the newest event already in the destination:
let most_recent_events = ds_to.get_events(bucket_to.id.as_str(), None, None, Some(1))?;
let resume_sync_at = most_recent_events
.first()
.map(|e| e.timestamp + e.duration)
.or(sync_spec.start);
then fetches only events newer than that. The destination copy is being used as its own progress marker.
Consequence 1: events that arrive late never sync, silently
Events are not always appended in timestamp order. An importer (aw-import-*, screentime imports), a retroactively edited stopwatch entry, or any backfill writes events with timestamps older than the bucket's current newest. Those events are permanently invisible to sync: the cursor is already past them, and nothing ever looks back. No error, no warning — the pass reports ✓ Already up to date!.
Consequence 2: it is the mechanism behind #683
Because the cursor lives in the destination rather than being per-source, two folders for one device write into the same destination bucket and the first one to be imported sets the resume point for the second. That is how a 4,068-event partial slice silently suppressed 1,027,343 events of real history. #686 fixes the trigger (duplicate folders) but the amplifier is this cursor design.
Consequence 3: it forces the fragile pagination
Because the cursor is a timestamp, sync_one has to reason carefully about events sharing an identical timestamp at page boundaries — the boundary_ts tie-handling loop, with a documented pathological case it explicitly declines to handle. A monotonic source-side cursor removes that reasoning entirely.
Proposal
Store an explicit cursor per (source_device_id, source_bucket_id) on the destination, keyed by the source's events.id rowid, which is monotonic in insertion order:
sync_cursor(source_device_id, source_bucket_id, last_source_rowid, updated)
- Fetch
WHERE id > last_source_rowid ORDER BY id LIMIT n— no timestamp ties, no boundary loop, and late-arriving events are picked up because they get a new rowid even though their timestamp is old. - Initialise from today's resume-from-newest so existing installs migrate with no re-import.
- Per-source keying means two folders for one device cannot contaminate each other's progress.
Caveat worth designing around: rowids are only monotonic within one source database. If a peer's staging db is rebuilt from scratch its rowids restart, so the cursor needs to be invalidated when the source's identity or generation changes — which is another argument for per-device metadata in the folder (ActivityWatch/activitywatch#302, #691). A cheap interim guard is to store the source's event count alongside the cursor and reset if it goes backwards.
Credit: found in a design review of aw-sync.
Related: #683, #686, #691, ActivityWatch/activitywatch#302.
cc @TimeToBuildBob
- Dominant language
- Rust
- Stars
- 322
- Forks
- 105
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ActivityWatch/aw-server-rust
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ActivityWatch/aw-server-rust#798 · 1 comment ·
Maintainers usually reply within 1 day
-
Allow configuring sync dir in the `aw-sync/config.toml` filePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 58/100
ActivityWatch/aw-server-rust#853 · 1 comment ·
Maintainers usually reply within 1 day
-
Correctness bugs: heartbeat cache, query cache invalidation, commit rollback statePossibly taken A pull request linked to this issue is open or already merged. Openenhancement
Difficulty 4/5 3-5 days Newbie friendliness 25/100
ActivityWatch/aw-server-rust#825 · 2 comments ·
Maintainers usually reply within 1 day
-
aw-sync: rowid upgrade bootstrap does not recover backfills lost under the old timestamp cursorOpen
Difficulty 5/5 Over a week Newbie friendliness 25/100
ActivityWatch/aw-server-rust#793 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
ActivityWatch/aw-server-rust#790 ·
Maintainers usually reply within 1 day
All issues in ActivityWatch/aw-server-rust
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
symposium-dev/symposium#530 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
topgrade-rs/topgrade#2540 ·
Maintainers usually reply within 1 day
-
Invalid JSON options for ngram and edge_ngram silently use defaultsPossibly taken @Tilendlesa claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
noemaforge/vimanam#153 ·
Maintainers usually reply within 1 day