Repository navigation
fix(import): de-duplicate same-date Google Health records and robustly detect uniqueness violations - #68
Merged
Conversation
…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
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
Fixes the Google Health (Fitbit) import errors of the form:
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-30and2026-06-01, appeared twice in the failing run).Root causes
(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 uniquesource_dataType_dateindex rejected the second insert.Constraintorduplicate. The actualConstraintErrormessage ("…at least one key does not satisfy the uniqueness requirements") matched neither, so genuine duplicates surfaced as user-facing errors.Changes
seenKeysset inprocessDailyRecordsandprocessTimeseriesRecordsso intra-import duplicates are skipped before queueing (first occurrence wins), independent of theskipDuplicatesflag.isConstraintError(), which detects uniqueness violations via the DOMExceptionname(including when wrapped inStorageError.originalCause), replacing the fragile substring matching in both batch-insert fallbacks.ConstraintErrorclassification in the one-by-one fallback.CHANGELOG.md.Quality gates
tsc --noEmit, ESLint, Prettier: clean🤖 Generated with Claude Code
https://claude.ai/code/session_01Lxg2xoW33zAzE8N7WB8K1P
Generated by Claude Code