Skip to content

Finish a workout the app was recording when it was closed - #80

Merged
gabrielbr merged 2 commits into
mainfrom
ccr-67ccb970-dqwwqd
Nov 16, 2026
Merged

gabrielbr merged 2 commits into
mainfrom
ccr-67ccb970-dqwwqd

Conversation

@gabrielbr

@gabrielbr gabrielbr commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

The owner started workouts with Record in PulseLoop (confirmed), and they never showed up on the Activity tab. Workouts recorded by Google Health did show up, because they come in through Health Connect, a separate path.

Cause

If the app's process ends during a workout, that workout stays "recording" in the database forever. The process can end because an update is installed, Android reclaims memory, or the app crashes. Three things combine:

  • Nothing saves the live workout itself, only its samples.
  • ActivitySessionDao.active() has no caller, so nothing ever looks for a workout left running.
  • The Activity tab lists finished workouts only.

So the workout never appears, and nothing ever finishes it. Today alone had four release installs, and each install ends any workout in progress.

There is a second way to get stuck in the same state. finish() saved the workout only after recomputing its summary. If that recompute failed, the workout stayed "recording".

Fix

  • WorkoutRecovery runs when the workout manager starts. It finds each workout still marked as running that started before that moment, and closes it:
    • Normally: it ends at the workout's own last live heart-rate sample or GPS point. A gap of more than 10 minutes counts as the end, and a workout is capped at 6 hours. All-day history samples don't count, because they keep arriving after the workout. The workout is then recomputed and credited to the day like a normal finish.
    • If it was paused: it ends where it was paused.
    • If it recorded nothing: it is marked cancelled, rather than given an invented duration.
    • A workout started while this runs is never touched.
  • finish() now saves the workout as finished before computing its summary. If the summary or the day's credit fails, the workout still appears.

WorkoutRecoveryTest covers these cases: a quiet stretch, no evidence, a paused workout, the 6-hour cap, and "now".

The diagnostics export the owner attached (11 Nov, v2.16.0) contains no workout data, since exports carry no database rows by design, so it could not confirm the cause either way.

No UI change, so there is no audit file and no canvas update.

🤖 Generated with Claude Code

https://claude.ai/code/session_01P1t1aUqSUPd3whKXmgVm7w

A workout in progress when the process died (an update install, Android reclaiming memory, a
crash) stayed "recording" in the database forever: nothing persisted the live workout but its
samples, ActivitySessionDao.active() had no caller, and the Activity tab lists finished workouts
only, so it never appeared.

WorkoutRecovery runs when the workout manager comes up: each workout still marked active that
started before then is closed at its own last live heart-rate sample or GPS point (before a
10-minute silence, at most 6 h), recomputed and credited like a normal finish. A paused one ends
where it was paused; one with nothing recorded is cancelled rather than given an invented
duration. A workout started while this runs is never touched.

Claude-Session: https://claude.ai/code/session_01P1t1aUqSUPd3whKXmgVm7w
If the summary failed, finish() threw before the session was saved, leaving it "recording"
for good. It is now saved as finished first; the summary and the day's credit can't take it
down with them.

Claude-Session: https://claude.ai/code/session_01P1t1aUqSUPd3whKXmgVm7w
@gabrielbr
gabrielbr merged commit 4541f44 into main Nov 16, 2026
1 check passed
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.

2 participants