Repository navigation
Conversation
…open A WHOOP 4.0 can answer SEND_HISTORICAL_DATA with PENDING and then never start the type-47 record stream. The strap still emits a fresh EVENT (type 48) roughly every 15 s, and EVENT is an offload frame, so each one re-armed the 60 s backfill idle watchdog. The session never completed and never timed out; `backfilling` stayed true, so every later sync trigger (periodic, foreground, manual, strap) was refused for the rest of the connection and no history landed. Add offloadFrameShowsProgress on both platforms: every offload frame is still routed to the drain, but on WHOOP 4.0 an EVENT no longer counts as progress for the watchdog. Type 47 records and METADATA (49) still re-arm, so a real offload is unaffected. 5/MG behaviour is unchanged. Refs ryanbr#2780
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.
What this PR does
Fixes a WHOOP 4.0 sync hang. A stalled history offload could stay open forever, and while it was open the app refused every new sync. History and stats stopped updating until the app was killed or the strap reconnected.
The core problem
A history sync works like this:
SEND_HISTORICAL_DATA.backfillingistrue. A 60 s idle watchdog (armBackfillTimeout,backfillIdleTimeoutSeconds) ends the session if the strap goes quiet.isOffloadFrameaccepts: types 47, 48, 49, 50 and 56.The bad case: a WHOOP 4.0 answers PENDING but never starts the type-47 stream. It is not silent, though. It keeps sending its normal EVENT frames (type 48) about every 15 s. EVENT is in the offload set, so each one re-arms the 60 s watchdog. 15 s is always less than 60 s, so:
backfillingstaystruefor the whole connection;requestSyncrefuses every later trigger whilebackfillingis set. That covers periodic, connect, foreground, manual and strap-initiated syncs.So one stalled PENDING blocked all history for the life of the connection. Pull-to-refresh did nothing. The app looked connected and healthy.
Evidence (WHOOP 4.0, iPhone, strap log)
To see it, I added a temporary per-type frame counter to the keep-alive log while
backfillingwas set. It is not part of this PR. A hung session showed only EVENT frames, and nothing else, for minutes:Strap backlog pages behind: 25811. On a healthy day this reads 18–70.With the fix on the same phone and strap, the next session went PENDING, then
historical records use layout v245 s later. It drained 500+ chunks and saved heart-rate rows for the missing days.The fix
New helper on both platforms, next to
isOffloadFrame:BLEManager.offloadFrameShowsProgress(_:family:)WhoopBleClient.offloadFrameShowsProgress(frame, family)It answers one question: does this offload frame show that history is still moving? Only those frames re-arm the watchdog.
It is used at the one re-arm site on each platform:
What changes and what doesn't:
routeBackfillFrame. Events are still stored, and the real-time gesture path (Strap log: surface WHERE offloaded rows landed + WHY (stale-RTC "missed sleep", #67) #69) still fires. Only the watchdog re-arm is filtered.backfilling. The durablestrap_trimcursor means the next session resumes where it left off.armBackfillTimeoutare updated to say it re-arms on progress frames.Risk
The case to think about: a backlog that is truly EVENT-only on WHOOP 4.0, with no type-47 at all. That stream would now depend on its METADATA (49) frames to keep the watchdog alive. A gap of over 60 s with only EVENTs would end the session early. That costs nothing: the trim cursor is durable, and the next sync trigger resumes it. Today the same case hangs every future sync for the connection, which is worse.
Type of change
How it was tested
Hardware (WHOOP 4.0, iPhone, iOS build):
Unit tests, twins on both platforms:
StrandTests/OffloadProgressWatchdogTests.swiftandroid/app/src/test/java/com/noop/ble/OffloadProgressWatchdogTest.ktThey cover:
Local runs:
xcodebuild -scheme Strand -destination 'platform=macOS' build: succeeded.xcodebuild ... test-without-building -only-testing:StrandTests/OffloadProgressWatchdogTests: 5 tests, 0 failures.Tools/doc_comment_lint.py: no new detached doc comments.Whoop5OffloadTestpattern. I'm relying onandroid.ymlto compile and run it.Checklist
Packages/changes)android/(not run locally, no JDK; see above, CI will run them)StrandDesigntokens (no UI changes)isOffloadFramealready usesdocs/CONTRIBUTING.mdStrand.xcodeproj/) or any secrets/keystoresRelated issues
Refs #2780