[native] Bound FIT import memory with native streaming

Merged
AS
4mo ago
+4382-1584

Summary

  • Replace whole-file JavaScript FIT parsing with Garmin's official C++ decoder, built through CMake, Ninja, and vcpkg in Docker and CI.
  • Stream validated activity or weight messages through 250-record, 512 KiB backpressured batches while bounding classification telemetry and hashing files without buffering them.
  • Route Garmin dumps and Wahoo, COROS, and Suunto downloads through the canonical FIT import queue with correct worker lifecycle, retry cleanup, progress, and unsupported-file handling.
  • Add native protocol coverage, provider/job regressions, exact incident-file validation, package documentation, and the production RCA.

Summary by cubic

Replaced whole‑file JS FIT parsing with a native C++ streaming decoder to bound memory and backpressure large imports. Also gated sync/upload/webhook work behind worker startup and tightened the import lifecycle to finish in‑process decoding before cleanup.

  • New Features

    • Added native/fit-decoder (CMake + vcpkg, Garmin FIT C++ SDK) emitting NDJSON with per‑batch acks (max 250 messages / 512 KiB); CI job, Docker stage, and a build:fit-decoder script.
    • Unified FIT imports: Garmin dumps and Wahoo, COROS, Suunto now use the fit-file-import workflow via enqueueFitFileImportAndWait with retries, progress, and aggregation.
    • Targeted webhook syncs can start the worker when needed (requiresWorkerForWebhookSync); FIT external IDs can fall back to a streaming SHA‑256 without buffering files.
  • Bug Fixes

    • Prevented partial metric‑stream replacement on decoder errors by writing to a temp scope and swapping on success; validated replacement publishers before mutation.
    • Avoided provider self‑deadlocks by running FIT imports inline in provider workers; uploads still use the queue.
    • Gated enqueues behind worker startup and surfaced failures to callers; start-worker now resolves only after Docker confirms the worker is running.
    • Awaited in‑process decoding before deleting staged files; added tests enforcing worker‑start awaiting and protocol size limits.

Summary by CodeRabbit

  • New Features

    • Added native, streaming Garmin FIT decoding with bounded batches, backpressure acknowledgements, and support for both activity and weight files.
    • Routed all provider FIT handling through a unified “fit-file import” workflow with staged replay and consistent aggregated results.
    • FIT external IDs can now be derived directly from file content when needed.
  • Bug Fixes

    • Prevented duplicate background worker startup during targeted webhook sync.
    • Improved reliability by awaiting worker startup in sync and upload flows.
  • Documentation

    • Updated FIT importing documentation and Docker build instructions for the new native decoder pipeline.