Google Health sync toggle, auto-reconnect, and incremental sync#6
Merged
isAdamBailey merged 3 commits intoJul 18, 2026
Merged
Conversation
…ssing data Sync used to require a manual Disconnect/Connect round trip whenever Google's refresh token expired, and every sync re-pulled full history. Now a failed sync during a weight save stashes the entry and redirects straight to Google's consent screen, resuming the save automatically once reconnected. Settings gains a pause/resume toggle that keeps the connection (no re-consent needed to resume), and syncs are bounded to data missing since the last watermark instead of always fetching everything — weight/height never overwrite existing days, while active energy always refreshes today/yesterday since it's the only Google-only, continuously-accumulating metric. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
persistRefreshedToken reused CredentialsRepository.Save to persist a refreshed access/refresh token, but Save's upsert always sets sync_enabled = true (intentional for an explicit connect/reconnect). A token refresh mid-sync could race a user's pause toggle and flip sync_enabled back on. Add a dedicated UpdateGoogleOAuthTokens query/ UpdateTokens repository method that updates only the token columns. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Make the toggle the sole Settings control (connect/resume/pause), auto-open OAuth when enabling hits expired credentials, and use the correct snake_case active-energy filter so post-reconnect backfill can update last-sync. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sync_enabledongoogle_oauth_credentials,POST /api/google/sync-enabled), auto-reconnect handling when a save is blocked on reauthorization, and incremental sync that pulls only missing weight/height/active-energy data (watermark-based) instead of a full backfill on every run.sync_enabled = true— a token refresh could silently re-enable a sync the user had just paused. Added a dedicatedUpdateGoogleOAuthTokensquery/UpdateTokensrepository method used only for token refresh, which never touchessync_enabled, plus a regression test (TestCredentialsRepository_UpdateTokens_DoesNotResumePausedSync).Test plan
go build ./...go test ./...golangci-lint run ./...— 0 issuesnpm run test(vitest) — 18 passednpm run lint(eslint) — clean/code-review(8-angle multi-agent review) run against the full diff vsmain; the one confirmed correctness bug was fixed and covered by a new test. Remaining findings were efficiency/architecture cleanup (N+1 query patterns during backfill/reconnect, sequential Google API calls, minor TOCTOU inSetSyncEnabled) judged non-critical and out of scope for this change.🤖 Generated with Claude Code