Repository navigation
Write workout routes and heartbeat series as file-backed recordings - #160
Open
PSchmiedmayer wants to merge 7 commits into
Open
PSchmiedmayer wants to merge 7 commits into
PSchmiedmayer wants to merge 7 commits into
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
A workout route or heartbeat series was exported from an array of its samples, encoded in memory. HealthKitRecordingFile writes either one from an asynchronous sequence directly into a recording file, requiring the series' complete sample count, and Record.fileRecording exports it as the same DocumentReference as the inline recording, referencing the file at a relative path. The disclosure options apply to it as to every other record.
`HealthKitRecordingFile.RecordingError.incompleteSeries` is thrown for too few and for too many elements, so it becomes `elementCountMismatch`.
RecordingError.invalidRelativePath names every case the shared relative attachment path check refuses.
PSchmiedmayer
force-pushed
the
healthkit-file-recordings
branch
from
November 28, 2026 00:17
e68c004 to
3869db9
Compare
PSchmiedmayer
changed the base branch from
recording-files
to
fhir-measurement-catalog
November 28, 2026 00:17
This was referenced Nov 28, 2026
PSchmiedmayer
marked this pull request as ready for review
December 6, 2026 06:24
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.
♻️ Current situation & Problem
This PR builds on #161.
The exporter converts a workout route or heartbeat series from an array of all its samples (
Record.workoutRoute(_:locations:),Record.heartbeatSeries(_:beats:)) and embeds the encoded CSV in the DocumentReference. A long route or beat series therefore holds every sample and the complete CSV in memory, and the CSV travels inside the record.Trove reads routes and beats with
HKWorkoutRouteQueryDescriptorandHKHeartbeatSeriesQueryDescriptor, writes each series into a recording file under a byte limit atrecordings/<sample UUID>.csv, and uploads the bytes separately from the event that carries the record. That needs a recording written from the query results as they arrive and referenced by a relative URL. The change reuses the registered CSV formats, row encoding and DocumentReference of the inline path; only the attachment changes from embedded data to a URL with the same size and SHA-1 hash.⚙️ Release Notes
HealthKitRecordingFileholds a complete route or beat series written into aRecordingFile, with itsrelativePathand registeredformat. It has no public initializer; two@concurrentfactories build one from aSendableAsyncSequence, so the synchronous file writes never run on the caller's actor:Rows go through
RecordingCSVFileWriterwith the row mapping the inline path uses, so a file holds exactly the bytes of the inline CSV for the same samples.The sequence must deliver exactly
HKSeriesSample.countelements, otherwiseRecordingError.elementCountMismatchis thrown; a sample that states no elements throwsemptyRecordingSeries. This keeps a truncated query result from becoming a complete-looking record.No partial recording is returned: query errors, cancellation, invalid rows and an exceeded
maximumByteCount(1 toInt32.max, inclusive) all throw. ArelativePaththat fails the shared relative path check throwsRecordingError.invalidRelativePathbefore anything is written.Record.fileRecording(_:)exports the same DocumentReference as the inline recording, with a relative URL in place of embedded data. A file-backed route still requiresoptions.route = .authorized. The array-based cases are unchanged.The file is a temporary snapshot. The caller copies it into persistent storage before advancing its query anchor and uploads it with
recording.file.readChunks(_:)orrecording.file.chunks.Breaking:
HealthKitFHIRExporter.Recordgains the casefileRecording(_:), so an exhaustiveswitchoverRecordneeds a new branch.📚 Documentation
GroveHealthKitFHIR.md has a new "File-backed recordings" section and lists
HealthKitRecordingFilein the exporter topic group. The new type, its factories,RecordingErrorandRecord.fileRecording(_:)have symbol documentation.✅ Testing
HealthKitRecordingFileTests(new): route and heartbeat files match the inline bytes, hash, size and DocumentReference envelope, and a route is omitted under the default route option; query failure and cancellation return no recording; the exact byte limit is accepted and one byte less fails; a non-finite beat time throws; 0, 1 and 3 locations for a two-location route throwelementCountMismatch; absolute, parent, empty-segment, URL, percent-encoded and query paths throwinvalidRelativePath.HealthKitDisclosureOptionsTests.everyOutputKindFollowsThePoliciesadds a file-backed heartbeat series as an output kind.StoredSampleFixturescan restate a series sample'scountandnumberOfDataPoints, andAssemblyFixturesconverts a.fileRecordingrecord.Code of Conduct & Contributing Guidelines
By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines: