fix(healthkit): count a type as arrived only when the batch brought something new

A batch that carried a type with duplicates only moved its
lastReceivedAt, lastTrigger and lastBackgroundAt, so a type whose live
delivery had stalled kept reading as freshly arrived for as long as a
replay, a retry or an older client re-sent its old samples.

The arrival ledger now moves those stamps only for a type the batch
brought at least one new or changed row for. An unchanged stats:
re-post and an hour posted again with its stored value count as
duplicates here; the wire keeps answering updated for them. A
duplicates-only type stamps the new last_seen_duplicate_at column on
its existing row and nothing else. The intake bulk route's dose entry
follows the same rule through the shared recorder. lastSyncedAt and
healthKitLastSyncedAt are unchanged.

GET /api/integrations/healthkit serves the stamp additively as
metricFreshness[].lastSeenDuplicateAt, and the Apple Health card names a
re-send that came after the last arrival.

Refs #1259
This commit is contained in:
Marc-André Bombeck committed 2026-10-22 10:34:45 +02:00
1 parent 703c92c776
commit 6a2247e422
25 files changed
+547 -84

No files matched your search

@@ -617,6 +617,7 @@ describe("GET /api/integrations/healthkit — sync health", () => {
lastNewSampleAt: null,
lastBackgroundAt: backgroundAt.toISOString(),
lastBackfillAt: null,
lastSeenDuplicateAt: null,
});
expect(byType.PULSE).toMatchObject({ lastBackgroundAt: null });
});