Skip to content

aw-sync: add --mode to daemon, fix unrespected --start-date#620

Open
0xbrayo wants to merge 3 commits into
ActivityWatch:masterfrom
0xbrayo:aw-sync-daemon-mode-and-start-date
Open

aw-sync: add --mode to daemon, fix unrespected --start-date#620
0xbrayo wants to merge 3 commits into
ActivityWatch:masterfrom
0xbrayo:aw-sync-daemon-mode-and-start-date

Conversation

@0xbrayo

@0xbrayo 0xbrayo commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds --mode push|pull|both to aw-sync daemon (previously hardcoded to Both), matching the option already available on aw-sync sync. Closes Add more options to aw-sync daemon #485.
  • Fixes --start-date, which was parsed into SyncSpec.start but never read. It's now used as the resume point on the first sync of a bucket (when the destination has no events yet), with subsequent runs resuming from the last-synced event as before.

Test plan

  • cargo build -p aw-sync --features cli
  • cargo test -p aw-sync --features cli (3 passed)
  • cargo clippy -p aw-sync --features cli (no new warnings)
  • aw-sync daemon --help shows the new --mode flag

0xbrayo added 2 commits June 13, 2026 15:44
The daemon previously hardcoded SyncMode::Both, requiring users to
run "aw-sync sync" in a loop to get push-only or pull-only behavior.
Adds the same --mode push|pull|both flag already available on the
sync subcommand.

Closes ActivityWatch#485
SyncSpec.start was parsed from the CLI but never read by sync_one,
so --start-date had no effect. Now used as the resume point when a
destination bucket has no events yet (first sync), falling back to
the last-synced event's end time on subsequent runs as before.
@greptile-apps

greptile-apps Bot commented Jun 13, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a --mode push|pull|both argument to the aw-sync daemon subcommand (previously hardcoded to Both) and fixes --start-date, which was stored in SyncSpec but never forwarded into sync_one where it could actually be used as the initial fetch offset.

  • --mode for daemon: SyncMode is threaded through the daemon() call and passed directly to sync_run, mirroring the flag that sync already exposed. The default value (Both) is set both in the clap definition and in the unwrap_or fallback when no subcommand is provided.
  • --start-date fix: sync_one now receives a &SyncSpec reference and uses sync_spec.start as the lower bound for get_events only when the destination bucket has no events yet (first sync of that bucket). Subsequent daemon iterations resume from the last-synced event's end time as before.

Confidence Score: 4/5

Safe to merge; the daemon now respects --mode and --start-date is correctly applied only to empty destination buckets.

Both changes are small and well-scoped. The --mode wiring is a direct pass-through with no new logic. The --start-date fix is correct: sync_spec.start is used as a fallback only when the destination bucket has no events, so repeat daemon iterations naturally skip it once events exist. No data loss or duplicate-event scenarios are introduced.

aw-sync/src/sync.rs — verify the get_events ordering assumption (limit=1 returns most-recent) holds for all AccessMethod implementations, since sync_one relies on it for the resume point.

Important Files Changed

Filename Overview
aw-sync/src/main.rs Adds mode field to Daemon variant, threads it through the daemon() call, and adds it as a parameter to the daemon() function itself; straightforward and correct.
aw-sync/src/sync.rs Passes sync_spec down to sync_one and uses sync_spec.start as a fallback when the destination bucket is empty; logic is correct but the fallback applies on every daemon iteration until the bucket receives its first event.
aw-sync/README.md Adds two example invocations for the new --mode push and --mode pull daemon flags; accurate and clear.

Sequence Diagram

sequenceDiagram
    participant CLI
    participant DaemonFn as daemon()
    participant SyncRun as sync_run()
    participant SyncDS as sync_datastores()
    participant SyncOne as sync_one()

    CLI->>DaemonFn: "--mode push|pull|both, --start-date"
    loop every 5 minutes
        DaemonFn->>SyncRun: sync_spec, mode
        alt mode is Pull or Both
            SyncRun->>SyncDS: ds_remote to ds_local
            SyncDS->>SyncOne: bucket_from, bucket_to, sync_spec
            SyncOne->>SyncOne: get_events dest limit 1
            alt destination has events
                SyncOne->>SyncOne: resume from last event end time
            else destination is empty
                SyncOne->>SyncOne: resume from sync_spec.start
            end
            SyncOne->>SyncOne: fetch and insert events
        end
        alt mode is Push or Both
            SyncRun->>SyncDS: ds_local to ds_sync_folder
            SyncDS->>SyncOne: bucket_from, bucket_to, sync_spec
        end
        SyncRun-->>DaemonFn: Ok
    end
Loading

Comments Outside Diff (1)

  1. aw-sync/src/main.rs, line 201-241 (link)

    P2 --mode silently ignored for sync in the simple path

    When sync is invoked without --start-date, --buckets, or --sync-db, the code falls into the legacy sync_wrapper branch and the mode value is never consulted — aw-sync sync --mode push will still perform both a pull and a push. This pre-dates the PR but is now more likely to confuse users who see --mode documented for both daemon and sync. A minimal guard (or a note in --help) would prevent silent mismatch between the flag's appearance and its effect in the simple path.

Reviews (1): Last reviewed commit: "fix(aw-sync): respect --start-date on in..." | Re-trigger Greptile

Previously, "aw-sync sync --mode push" with no other flags fell
through to the legacy host-based sync path, which always does both
a pull and a push regardless of --mode. Make mode an Option so an
explicit --mode opts into the advanced sync path (where it's
respected), matching the documented behavior.
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.09%. Comparing base (656f3c9) to head (b064eae).
⚠️ Report is 63 commits behind head on master.

Files with missing lines Patch % Lines
aw-sync/src/main.rs 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #620      +/-   ##
==========================================
+ Coverage   70.81%   77.09%   +6.28%     
==========================================
  Files          51       62      +11     
  Lines        2916     4956    +2040     
==========================================
+ Hits         2065     3821    +1756     
- Misses        851     1135     +284     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more options to aw-sync daemon

1 participant