Skip to content

Apple Health export re-import duplicates workouts, and export workouts are missing distance, energy and heart rate #1414

Open

Description

@camiracode

Version: v1.48.x, Apple Health export importer parser revision 4, self-hosted.

Bug 1: workout external IDs change between imports. Re-uploading a fresh full export inserted 969 of 1,003 workouts that were already stored, and only 34 were updated. Each import gives the same workout a different sample: externalId, so it isn't recognised as already present. After three sources (live iPhone sync, an earlier export, and the latest export), 967 workouts have duplicate APPLE_HEALTH rows, 935 of them with 3 to 6 copies. Workouts that Strava also syncs directly get another copy under the STRAVA source.

Expected: the externalId for an export workout stays the same across imports and parser revisions (for example derived from source, workoutActivityType, startDate and endDate, or the HK UUID when present), so re-imports update rows instead of inserting new ones. Ideally it also matches the live-sync row for the same workout.

Bug 2: <WorkoutStatistics> is ignored. Current iOS exports store a workout's totals in <WorkoutStatistics> child elements, not in attributes on <Workout>. The importer logs element::WorkoutStatistics as unknown, so export-created workouts have NULL distance and active energy. Only 20 of 2,930 Apple Health workouts in my DB have an average heart rate.

Expected: read HKQuantityTypeIdentifierActiveEnergyBurned (sum), HKQuantityTypeIdentifierDistance* (sum), and HKQuantityTypeIdentifierHeartRate (average, minimum, maximum) from <WorkoutStatistics>.

Impact: the UI may collapse the duplicates, but anything that queries workouts directly over-counts, and workout totals are empty for exported history.

Happy to provide anonymised sample XML or test a fix.

Activity

  1. MBombeck commented on Nov 19, 2026

    @MBombeck
    Owner

    @camiracode Thanks for the counts, they make this clear. Both parts are real.

    The export importer builds a workout's identity from the raw startDate, endDate and duration strings, so when two exports write the same workout slightly differently (offset or duration precision), it looks new and gets inserted again. I'll change the identity to the normalised start and end instants plus the activity type, and merge the duplicates that are already there. <WorkoutStatistics> is currently ignored, which is why distance, energy and heart rate stay empty; that gets read too.

    This goes into the next patch. To be sure the new identity matches your exports, could you paste the same workout's <Workout …> line from two different exports (the attributes are enough, you can blank out the device name)?

  2. added
    bug
    on Nov 19, 2026
  3. camiracode commented on Nov 20, 2026

    @camiracode
    ContributorAuthor

    Here's the same workout from two full exports (source name blanked). First line is a 2026-09-28 export; second is a 2026-11-18 export:

    <Workout workoutActivityType="HKWorkoutActivityTypeWalking" duration="55.26666666666667" durationUnit="min" sourceName="" sourceVersion="54910" creationDate="2026-09-14 19:06:03 -0600" startDate="2026-08-21 10:36:16 -0600" endDate="2026-08-21 11:31:32 -0600">
    <Workout workoutActivityType="HKWorkoutActivityTypeWalking" duration="55.26666666666667" durationUnit="min" sourceName="" sourceVersion="54910" creationDate="2026-09-14 18:06:03 -0700" startDate="2026-08-21 09:36:16 -0700" endDate="2026-08-21 10:31:32 -0700">
    

    The start, end, and creation dates are the same instants written with a different offset (-0600 vs -0700); duration is unchanged. Normalized start and end instants plus activity type would match these two.

  4. MBombeck commented on Nov 20, 2026

    @MBombeck
    Owner

    @camiracode Fixed in 1.48.3, out now (https://github.com/MBombeck/HealthLog/releases/tag/v1.48.3). A workout is now recognised by its activity type and start and end time, and the update merges the copies you already have (the oldest stays, a route or heart rate curve moves over if it had none). Distance, energy and heart rate from <WorkoutStatistics> fill the fields the workout left empty; for multisport workouts only the top-level statistics count.

    Could you check your workout count after the update, and whether a re-import of the same export now adds nothing? The two <Workout> lines I asked for are no longer needed unless something still doubles.

  5. added
    waiting-on-reporter
    on Nov 20, 2026
  6. camiracode commented on Nov 20, 2026

    @camiracode
    ContributorAuthor

    Thanks! I re-ran the same Nov 18 export (1,003 workouts) on 1.48.4 with #1416 built in.

    • The update merged 955 copies: 4,080 → 3,125 workouts (Apple Health 2,930 → 1,975, Strava 1,150 unchanged). No sessions were lost.
    • First re-import: 1,003 read, 969 updated, 34 duplicate, 0 inserted.
    • Second re-import of the same export: 0 inserted again. I changed only the zip comment so it fully re-parsed instead of hitting the upload-hash shortcut. The identical file just returned the earlier job.
    • <WorkoutStatistics> filled in totals: Apple workouts without energy dropped from 1,275 to 607.

    One thing is still doubled. For 934 sessions, the export row sits next to one or more Apple Health rows from the iPhone app (HealthKit UUID ids) with the same activity type and start and end time. 902 of them have exactly one of each. 0513 only groups export-keyed rows, so these pairs stay. Is that intended, or should an export workout also match an existing HealthKit row?

  7. MBombeck commented on Nov 22, 2026

    @MBombeck
    Owner

    @camiracode Thanks for the numbers. 955 copies merged and nothing inserted on two re-imports is the result I hoped for.

    To your question: yes, that pair is expected with the current design. The row from the iPhone app is keyed on its HealthKit UUID, and an export doesn't carry that UUID, so the export row gets its own key and both are stored. The reads don't count it twice, though. The workout list and detail, the activity calendar, the doctor report, the Coach and the insights all go through one pick that treats two rows from the same source with the same sport, start and duration as one session and keeps the one with more data. So the pair only shows up when you query the workouts table directly.

    Whether an export workout should fold into the HealthKit row when it is written, so that storage holds one row as well, is a fair question. I'll come back to you on it here.

  8. removed
    waiting-on-reporter
    on Nov 22, 2026
  9. MBombeck commented on Nov 22, 2026

    @MBombeck
    Owner

    A short update, as promised. The pairs stay stored, and every reading path already counts each one once. Merging an export workout into its HealthKit row when it is written is planned for the next minor release, together with a one-time cleanup of the pairs already stored. I'll post here when it is on its way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions