Skip to content

perf(import): bound Google Health import memory + PHI-safe parser logging - #67

Merged
kabaka merged 2 commits into
mainfrom
claude/import-stream-store-phi-hygiene
Jun 23, 2026
Merged

kabaka merged 2 commits into
mainfrom
claude/import-stream-store-phi-hygiene

Conversation

@kabaka

@kabaka kabaka commented Jun 23, 2026

Copy link
Copy Markdown
Owner

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 memory

For 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, ImportAbortedError unwinds; 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 failed JSON.parse can 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 a warnParseIssue() helper that logs only [GoogleHealth] <context> <fileName> (<errorName>) — error name only, never the message/stack/object or any parsed content — gated behind import.meta.env.DEV (works in main + worker contexts). Centralizes the single no-console suppression, dropping 23 lint warnings to 0.

Reviews

  • QA: approved — no blockers, no should-fix. All 7 streaming invariants verified; both changes green.
  • Security: clean — LOW-1 resolved (no PHI reaches the console, DEV-gated both contexts); streaming refactor introduces no new privacy/consistency issue (cancellation still leaves consistent storage; dedup idempotent; test exercises real safety checks).

Testing

  • typecheck 0 errors; eslint 0 errors (warnings 36 → 13, the 23 parser no-console eliminated); vitest 3708 passed; build OK.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG


Generated by Claude Code

claude added 2 commits June 23, 2026 04:17
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
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