Repository navigation
perf(import): bound Google Health import memory + PHI-safe parser logging - #67
Merged
Merged
Conversation
The Google Health parsers logged caught errors directly
(console.warn(`... ${file.name}:`, e)). A failed JSON.parse can carry a
fragment of file content in its message, so this wrote health-data-adjacent
content into the devtools console (on-device only, never transmitted, but
poor PHI hygiene — security finding LOW-1).
Route all 23 parser warn sites through a new warnParseIssue() helper that
logs only "[GoogleHealth] <context> <fileName> (<errorName>)" — error name
only, never the message, stack, error object, or any parsed content. The
helper is gated behind import.meta.env.DEV (works in both main-thread and
worker contexts, with a try/catch fallback to silence) and centralizes the
single no-console suppression, dropping 23 pre-existing lint warnings to 0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG
… heap For worker-parsed heavy data types (intraday heart rate, SpO2, HRV, snoring), the import accumulated every parsed record for the whole data type in memory before storing, so peak main-thread heap was O(all files in the type) — a multi-year wearable export could reach hundreds of MB and OOM the tab on low-RAM devices. (The earlier worker move bounded the parse footprint; this bounds the accumulated-results footprint.) Replace parseDataTypeViaWorker with parseAndStoreDataTypeViaWorker, which stores each file's daily + timeseries records immediately after it is parsed and releases them before the next file, capping peak heap at ~O(one file) regardless of file/year count. The inline light-type path is unchanged. Behavior is preserved exactly: identical stored output; de-duplication (DB-keyed on source/dataType/date, shared across per-file stores, so within-import duplicates are still skipped); monotonic progress counters and identical totals (via explicit baseStored/baseSkipped); per-record trackDate and date-range; recoverable per-file errors; and end-to-end abort semantics (checkpoint between files, ImportAbortedError unwinds the import; partial per-file commits stay durable and idempotent). Adds a regression test covering identical output, cross-file dedup, monotonic counters, recoverable per-file errors, and the store-before-last-parse streaming property. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG
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.
Overview
Two follow-ups flagged during the import-redesign reviews (#66), both confined to the Google Health/Fitbit import path.
1.
perf(import): stream-to-store heavy types — bound peak memoryFor worker-parsed heavy data types (intraday heart rate, SpO₂, HRV, snoring), the import accumulated every parsed record for a whole data type in memory before storing — peak main-thread heap was O(all files in the type). A multi-year wearable export could reach hundreds of MB and OOM the tab on low-RAM devices. (ADR 0027's worker move bounded the parse footprint; this bounds the accumulated-results footprint.)
parseDataTypeViaWorker→parseAndStoreDataTypeViaWorker, which stores each file's records immediately after parsing and releases them before the next file. Peak heap is now ~O(one file) regardless of file/year count. The inline light-type path is untouched.Behavior preserved exactly (QA-verified, 7 invariants): identical stored output; de-duplication (DB-keyed on source/dataType/date, shared across per-file stores, so within-import duplicates are still skipped); monotonic progress counters + identical totals; per-record
trackDate; recoverable per-file errors; and end-to-end abort (checkpoint between files,ImportAbortedErrorunwinds; partial commits stay durable + idempotent). New regression test covers identical output, cross-file dedup, monotonic counters, recoverable per-file errors, and the store-before-last-parse streaming property.2.
refactor(import): PHI-safe parser logging (security finding LOW-1)The parsers logged caught errors directly (
console.warn('… ${file.name}:', e)); a failedJSON.parsecan embed a fragment of file content in its message, writing health-data-adjacent content to the devtools console (on-device only, never transmitted, but poor hygiene). All 23 sites now route through awarnParseIssue()helper that logs only[GoogleHealth] <context> <fileName> (<errorName>)— error name only, never the message/stack/object or any parsed content — gated behindimport.meta.env.DEV(works in main + worker contexts). Centralizes the singleno-consolesuppression, dropping 23 lint warnings to 0.Reviews
Testing
typecheck0 errors;eslint0 errors (warnings 36 → 13, the 23 parserno-consoleeliminated);vitest3708 passed;buildOK.🤖 Generated with Claude Code
https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG
Generated by Claude Code