Skip to content

Keep workout payloads under Tidepool's 4 KB limit - #53

Open
ps2 wants to merge 1 commit into
next-devfrom
fix/workout-payload-size
Open

ps2 wants to merge 1 commit into
next-devfrom
fix/workout-payload-size

Conversation

@ps2

@ps2 ps2 commented Dec 1, 2026

Copy link
Copy Markdown

Tidepool rejects a datum whose payload is over 4 KB of JSON (tidepool-org/platform metadata/metadata.go), and with it the whole upload (datasets_data_create.go returns 400). Loop retries a failed exercise upload without moving on, so one long workout with many lap or segment events would stop every later workout from reaching Tidepool.

The workout payload now drops detail until it fits:

  1. events other than pause and resume (laps, segments, markers)
  2. sub-activities
  3. the remaining events
  4. the HealthKit metadata

The activity type code and the heart rate summary always stay. The limit used is 3800 bytes, leaving room for small differences between the app's JSON encoding and the server's.

Follows #48.

Testing:

  • Two new tests in StoredWorkoutDatumTests: a 2 h run with 120 segment events plus a pause/resume pair, and a workout with 5 KB of third-party metadata. Both fail without the fix.
  • All 78 TidepoolServiceKitTests pass.
  • On a Tidepool integration account, the datum built for the 2 h run was rejected without the fix (400, "size 7366 is not less than or equal to 4096"). With the fix it was accepted with a 286-byte payload that keeps the pause/resume events, time zone, indoor flag and heart rate summary.

Tidepool rejects a datum whose payload is over 4 KB of JSON, and with it
the whole upload. Loop retries a failed exercise upload without moving
on, so one long workout with many lap or segment events would stop all
later workouts from reaching Tidepool.

The payload now drops detail until it fits: first the events other than
pause and resume, then the sub-activities, then the remaining events,
then the HealthKit metadata. The activity type code and heart rate
summary always stay.
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.

1 participant