Skip to content

Fix outage data loss with per-target fetch cursors; audit cleanups; 1.8.1#55

Merged
sturimcode merged 1 commit into
mainfrom
code-quality-sweep
Jul 24, 2026
Merged

Fix outage data loss with per-target fetch cursors; audit cleanups; 1.8.1#55
sturimcode merged 1 commit into
mainfrom
code-quality-sweep

Conversation

@sturimcode

Copy link
Copy Markdown
Owner

An Opus 4-lens audit (correctness, quality, security, UX/docs) found one real bug and a handful of cleanups. This ships all of it.

The bug: a Garmin outage permanently lost measurements

sync_user fetched only measurements newer than the latest synced timestamp across all targets. With Garmin auth down and Strava healthy, Strava kept advancing that shared cursor. After --reauth garmin, the fetch started past the outage window, so those weigh-ins never reached Garmin and nothing ever retried them.

Fix: each target keeps its own cursor and the fetch reaches back to the oldest one. The healthy target skips re-fetched measurements through the existing is_synced dedup. A target with no rows yet gets a 7-day cursor, which replaces the old new-target backfill branch.

Also in here

  • Same-date guard loophole: with two weigh-ins in one day and an external Garmin entry for that date, the first skip row used to flip the guard off and let the second upload a duplicate. Skip rows no longer count as uploads.
  • has_synced_on_date / weight_only_syncs_on_date narrow the scan with a SQL date window instead of reading every row.
  • Extracted the copy-pasted result-tally loop and target-label join in app.py.
  • --install-agent refuses on a machine with no config instead of scheduling an agent that fails every few hours.
  • --status now suggests --reauth garmin like every other surface.
  • README documents --history; pyproject gains Homepage and Ko-fi Funding links for PyPI.

Security lens came back clean. 332 tests pass, 5 new.

🤖 Generated with Claude Code

….8.1

The fetch cursor was the latest synced timestamp across ALL targets. If
Garmin auth broke while Strava kept syncing, Strava kept advancing that
shared cursor, and once Garmin recovered the fetch started after the
outage window: those weigh-ins never reached Garmin and nothing retried
them. The cursor is now per target and the fetch starts from the oldest
one; the up-to-date target skips re-fetched measurements via is_synced.
This also subsumes the new-target 7-day backfill branch (a target with
no rows gets a 7-day cursor), so has_any_syncs is gone.

Also from the audit:
- Same-date guard: a skipped-because-already-in-Garmin row no longer
  counts as "we uploaded on this date", so a second measurement that day
  can't slip past the guard and duplicate an external entry.
- Date lookups narrow the scan with a SQL two-day window before the
  exact local-date check in Python.
- app.py: extract _tally_run and _target_label (each was copy-pasted).
- --install-agent now requires a config, so a fresh machine can't
  schedule an agent that fails every few hours.
- --status Garmin hint now says --reauth garmin like everywhere else.
- README documents --history; pyproject gains Homepage and Funding URLs.
- Flatten the keep-db conditional in --uninstall.

332 tests, 5 new (outage recovery, new-target backfill, per-target
cursor, skip-row guard at both state and sync level).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sturimcode
sturimcode merged commit 8c4d920 into main Jul 24, 2026
6 checks passed
@sturimcode
sturimcode deleted the code-quality-sweep branch July 24, 2026 20:47
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.

1 participant