fix(google-health): bound the backfill by progress and a horizon, not pages

A resumable collection counted the pages it had written across every
backfill attempt and stopped at its ceiling (10,000 for heart rate). A
watch that records heart rate every few seconds reaches that count two to
three years back, and since it never reset, every later slice stopped at
the same place, failed as stuck, and the backfill was never stamped
complete.

A walk is now stopped only when it stops moving: 20 pages in a row that
reach no further back than the pages before them end it. A history
backfill reads back at most GOOGLE_HEALTH_BACKFILL_HORIZON_YEARS (20 when
unset). A data type that ends either way counts as finished, and where and
why it ended is kept in backfillProgress past the completion stamp. An
oldest-first list is read whole, as before. The slice chain's ceiling is
derived from sixty days of back-to-back slices instead of the old page
count. An account left at the old ceiling continues from its edge with
the next slice.

Refs #1220
This commit is contained in:
Marc-André Bombeck committed 2026-10-19 17:25:48 +02:00
1 parent 01bf8fbb64
commit 72c259d85c
13 files changed
+1351 -108

No files matched your search

+8 -5
View File
@@ -4463,11 +4463,14 @@ model GoogleHealthConnection {
/// repair pending (or the connection predates the fix).
sleepRepairedAt DateTime? @map("sleep_repaired_at")
/// How far the in-flight history backfill has got
/// (`{ done: string[], cursors: { [collection]: { at, order, pages } } }`):
/// the collections it walked to the end, and for each collection read page
/// by page the edge it has written up to, so the next slice resumes there
/// instead of starting over. Null once the backfill completes, and reset
/// on every reconnect.
/// (`{ done: string[], cursors: { [collection]: { at, order, pages } },
/// ended?: { [collection]: { type, at, reason } } }`): the collections it
/// walked to the end, for each collection read page by page the edge it has
/// written up to, so the next slice resumes there instead of starting over,
/// and the collections it ended short of their history's start (the
/// horizon, or a walk that stopped getting anywhere). Once the backfill
/// completes only `ended` is kept, or null when nothing ended short; the
/// status routes publish it as `backfillEnded`. Reset on every reconnect.
backfillProgress Json? @map("backfill_progress")
/// One bounded, owner-scoped current sync run. This is replaced at the start
/// of every run and never retains provider payloads or historical runs.