Skip to content

feat(import): background imports, multi-stage progress, and off-thread Fitbit parsing - #66

Merged
kabaka merged 4 commits into
mainfrom
claude/charming-cerf-yu8yvk
Jun 23, 2026
Merged

kabaka merged 4 commits into
mainfrom
claude/charming-cerf-yu8yvk

Conversation

@kabaka

@kabaka kabaka commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Overview

Reworks the data-import experience end to end, addressing the three reported pain points and several adjacent improvements. Designed and reviewed by the specialist agent team (ux, ui-design, performance) before implementation, then gated through qa and security.

Problems solved

  1. "One progress bar that keeps changing purpose." Replaced with a multi-stage progress list — every stage is shown from the start (CPAP: Scan → Parse → Build sessions → Store; Google Health/Fitbit: Scan → per-data-type Import), each with its own pending / active / done / warning / error state (icon shape + text word + colour, never colour alone).
  2. Navigating away discarded the import. Import lifecycle is lifted out of the React tree into a module-level ImportController singleton backed by a dedicated useImportStore. Imports now run in the background and survive navigation, surfaced by a persistent bottom-left status pill (expandable detail panel, confirmed cancel, completion toast) mounted app-wide.
  3. Fitbit intraday heart-rate import froze the UI for minutes. The heavy intraday parsers (HR, SpO₂, HRV, snoring) were moved into a dedicated fitbitParser.worker.ts with chunked, determinate per-file/per-chunk progress — the intraday-HR sub-stage now shows a live bar instead of a multi-minute freeze.

Also included

  • Unified, serializable ImportJobProgress model (stages + sub-items + throughput/ETA + capped errors).
  • End-to-end cancellation via an AbortSignal + checkpoint() threaded through both import services; cancel stops work at safe boundaries and leaves IndexedDB/OPFS consistent (per-day/per-batch + de-dup idempotent).
  • rAF-coalesced progress writes (one store update per frame); throughput/ETA via EWMA.
  • Accessibility: one quantized polite live region + an assertive region for terminals, indeterminate bars omit aria-valuenow, reduced-motion fallbacks, ≥44px targets, theme-correct.

Architecture decisions

  • ADR 0026 — Background import controller outside the React tree
  • ADR 0027 — Move Fitbit (Google Health) parsing to Web Workers

Correctness & safety

  • Fitbit parser equivalence gate: the moved parsers are verbatim; golden-fixture tests assert byte-identical output vs. the legacy path, plus chunk-size invariance. parseFitbitLegacyDateTime (timezone-load-bearing) is untouched.
  • Security review: clean. No new network surface (privacy upheld), same-origin static worker, no XSS sinks (React-escaped), devtools DEV-gated, fits existing CSP, 50 MB/file cap preserved.
  • QA review: no blockers. Both SHOULD-FIX items addressed (E2E coverage of the cross-route journeys; per-job toast tracking so concurrent CPAP+Fitbit terminals each announce once).

Testing

  • Unit/integration: full Vitest suite green (3672 tests), including new coverage for the controller, store, checkpoint/abort, throughput/ETA, worker equivalence, and the new UI.
  • E2E: tests/e2e/import-redesign.spec.ts covers multi-stage progress, background-survives-navigation, confirmed cancel, completion toast, and reduced-motion (Chromium + Firefox; one documented skip). Pre-existing import spec migrated to the new summary copy.
  • typecheck, eslint (0 errors), and build (worker emitted as its own chunk) all green.

Follow-ups (non-blocking, noted by review)

  • Console PHI hygiene on malformed-parse console.warn (pre-existing).
  • Stream-to-store per file for Google Health to bound per-type memory (pre-existing; future performance work).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG


Generated by Claude Code

claude added 4 commits June 23, 2026 01:47
…oundation

Lay the groundwork for the import-experience redesign:

- ImportController singleton outside the React tree owns the import
  lifecycle (services, worker pool, per-job AbortController), so imports
  survive navigation instead of being discarded on unmount.
- useImportStore (Zustand) holds per-job progress; controller writes are
  rAF-coalesced (one store write per frame) with a test-env fallback.
- Unified, serializable ImportJobProgress model (multi-stage + sub-items
  + throughput/ETA + capped errors) alongside the existing per-service
  progress shapes.
- End-to-end cancellation: AbortSignal threaded through both services via
  a checkpoint() helper at existing yield points; cancel leaves IDB/OPFS
  consistent (per-day/per-batch + dedup idempotent).
- useImport/useGoogleHealthImport refactored to thin subscribe+dispatch
  hooks that preserve their existing public API.
- Design-system primitives: status/disclosure icons (check-circle,
  alert-triangle, x-circle, circle-dashed, circle-dot, spinner,
  chevron-up/down), import-stage status tokens (both themes), and
  ProgressBar size/tone variants.
- ADRs 0026 (background import controller) and 0027 (Fitbit parsing in
  Web Workers).

Refs: docs/decisions/0026, docs/decisions/0027

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG
…f-thread Fitbit parsing

Build the redesigned import experience on the new background architecture.

Fitbit/Google Health parsing (ADR 0027):
- Extract pure parser cores (intraday HR, SpO2, HRV, snoring) and move the
  heavy work into a dedicated fitbitParser.worker.ts, ending the multi-minute
  main-thread freeze. Parsing is chunked (~2,000 entries) with determinate
  per-file and per-chunk progress; ArrayBuffers are transferred in, one file
  per pool task to bound memory; the job AbortSignal cancels queued work.
- Output proven byte-identical to the legacy path via golden-fixture and
  chunk-invariance tests. Storage path unchanged.
- Granular per-data-type progress flows into ImportJobProgress.subItems so the
  intraday-HR substage shows a live determinate bar.

Import UI:
- ImportStageList: all stages visible from the start, each with its own
  pending/active/done/warning/error state (icon shape + text word + colour,
  never colour alone); indeterminate when totals are unknown (no fake 0%);
  expandable Fitbit sub-stages; throughput/ETA on the active stage.
- ImportStatusDock: persistent bottom-left pill (mounted at RootLayout) that
  survives navigation, expands to a non-modal panel, shows overall weighted
  progress, confirmed cancel, and fires a completion toast.
- ImportSummary: success / partial / error variants with per-file error
  disclosure and elapsed time.
- ImportWizard adopts an active or terminal background job on mount, adds
  "Continue in background", surfaces a busy second-import attempt, and drops
  all emoji glyphs for themeable Icons.

a11y: one quantized polite live region + an assertive region for terminals,
indeterminate bars omit aria-valuenow, reduced-motion fallbacks, ≥44px
targets, focus management.

Refs: docs/decisions/0026, docs/decisions/0027

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG
…ff-thread Fitbit parsing

- CHANGELOG: populate [Unreleased] with the user-facing import changes
  (background imports + persistent indicator, multi-stage progress,
  off-thread intraday parsing, safe immediate cancellation, tab-close
  behavior).
- Help: expand the "Importing Data" article (background import and the
  progress indicator, cancelling, de-duplication, closing the tab) and
  add "Background Import" and "Intraday" glossary entries.
- Dev docs: point data-architecture user-flow at ADRs 0026/0027.

Refs: docs/decisions/0026, docs/decisions/0027

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG
- Add tests/e2e/import-redesign.spec.ts covering the headline journeys:
  multi-stage progress list, background import surviving navigation (dock
  persists across routes), confirmed cancel, completion toast on another
  route, and reduced-motion spinner fallback (Chromium + Firefox).
- Fix dropped completion feedback when a CPAP and a Fitbit import finish
  concurrently: track toasted/announced job ids in Sets so each terminal
  transition toasts and announces exactly once (QA SHOULD-FIX).
- Migrate the pre-existing import-wizard E2E spec to the redesigned summary
  ("Import complete" / "Import finished with issues") with strengthened
  stat assertions.
- Add stable data-testid/data-animated hooks to the dock pill icon and use
  them in E2E instead of hashed-class selectors.
- NITs: 44px panel-close target, inline style moved to CSS module,
  documented the test-only IndexedDBService cast in __resetForTests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qn5jBf8f5u1bXnC2ioq8pG
@kabaka
kabaka merged commit bc59d41 into main Jun 23, 2026
13 checks passed
kabaka added a commit that referenced this pull request Jun 23, 2026
…ging (#67)

Two import follow-ups from the #66 reviews: (1) perf — stream Google Health heavy types to storage per file, bounding peak heap to ~O(one file) instead of O(whole data type) and fixing OOM risk on large multi-year Fitbit imports, with all 7 behavior invariants preserved; (2) refactor — route the 23 parser warn sites through a DEV-gated, error-name-only logging helper so no file-content fragments reach the console (security LOW-1). QA approved; security clean.
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