aw-sync: no stored cursor — resume-from-destination silently never syncs late-arriving events

Open
#696 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@TimeToBuildBob is already working on this.

Since Oct 6, 2026.

  • #789 by @TimeToBuildBob — open

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

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

bug

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ActivityWatch/aw-server-rust

All issues in ActivityWatch/aw-server-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.