Health import endpoint with a durable rejection trace #13
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What to build
An endpoint that accepts a day's metrics from an external provider — iOS Shortcuts reading HealthKit, Tasker, a cron script — authenticated by the scoped API token from #3.
Partial payloads are normal and expected. Providers differ in what they can supply, and a payload carrying three of the eight kinds is valid, not an error.
Partial validity is the important behaviour. If one metric in a payload of twenty fails validation, the nineteen valid ones are stored and the invalid one is rejected and recorded in a durable trace the User can see. Rejecting the whole payload would mean one bad field costs every night's data from a client that cannot show the User an error — a trivial units bug silently costing months of otherwise-good data. Clamping would be worse still: a 970% blood oxygen becoming 100% fabricates a measurement and hides the bug permanently.
The rejection trace is the same surface that receives unreadable stored rows from #8. One place the User looks to find data that could not be used.
Re-posting a date upserts —
(User, Date, MetricKind)uniqueness and the Manual-never-clobbered rule from #8 already define the semantics, so imports are naturally idempotent.Backfill needs a bound on how many dates one request may carry.
Acceptance criteria
Manualvalue is not overwritten by an importBlocked by