Skip to content

fix(import): de-duplicate same-date Google Health records and robustly detect uniqueness violations - #68

Merged
kabaka merged 1 commit into
mainfrom
claude/integration-data-uniqueness-errors-g2omqy
Jun 23, 2026
Merged

kabaka merged 1 commit into
mainfrom
claude/integration-data-uniqueness-errors-g2omqy

Conversation

@kabaka

@kabaka kabaka commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the Google Health (Fitbit) import errors of the form:

temperature/2025-09-30
Storage failed: Failed to add integration daily summary in "integration_data" (key: ...): Unable to add key to index 'source_dataType_date': at least one key does not satisfy the uniqueness requirements.

These appeared whenever an export contained more than one record for the same data type and calendar date (note that several dates, e.g. 2025-09-30 and 2026-06-01, appeared twice in the failing run).

Root causes

  1. Intra-import duplicate dates. The dedup guard only queried the database, so two records sharing the same (source, dataType, date) compound key within a single import both passed the check on a clean DB, both got queued into one batch, and the unique source_dataType_date index rejected the second insert.
  2. Fragile constraint detection. The one-by-one fallback only treated an error as a skippable duplicate when its message included Constraint or duplicate. The actual ConstraintError message ("…at least one key does not satisfy the uniqueness requirements") matched neither, so genuine duplicates surfaced as user-facing errors.

Changes

  • Add a per-call seenKeys set in processDailyRecords and processTimeseriesRecords so intra-import duplicates are skipped before queueing (first occurrence wins), independent of the skipDuplicates flag.
  • Add isConstraintError(), which detects uniqueness violations via the DOMException name (including when wrapped in StorageError.originalCause), replacing the fragile substring matching in both batch-insert fallbacks.
  • Add regression tests covering intra-import same-date de-duplication and ConstraintError classification in the one-by-one fallback.
  • Update CHANGELOG.md.

Quality gates

🤖 Generated with Claude Code

https://claude.ai/code/session_01Lxg2xoW33zAzE8N7WB8K1P


Generated by Claude Code

…y detect uniqueness violations

Google Health imports surfaced errors like "Storage failed: ... Unable to
add key to index 'source_dataType_date': at least one key does not satisfy
the uniqueness requirements" whenever an export contained more than one
record for the same data type and calendar date (e.g. two temperature
readings on the same day).

Two root causes:
- The dedup guard only queried the database, so two records sharing the
  same (source, dataType, date) compound key within a single import were
  both queued into one batch and the second violated the unique index. Add
  a per-call seenKeys set so intra-import duplicates are skipped before
  queueing, independent of the skipDuplicates flag (first occurrence wins).
- The batch-insert fallback classified duplicates via fragile message
  substring matching that missed the real ConstraintError message, so
  genuine duplicates were reported as errors. Add isConstraintError(), which
  detects uniqueness violations via the DOMException name (including when
  wrapped in StorageError.originalCause).

Add regression tests covering intra-import same-date de-duplication and
ConstraintError classification in the one-by-one fallback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lxg2xoW33zAzE8N7WB8K1P
@kabaka
kabaka merged commit 6732d29 into main Jun 23, 2026
13 checks passed
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.

2 participants