Skip to content

Fix the implicit state machines (S1 to S23, N1 to N11) - #63

Merged
sayed0am merged 37 commits into
developfrom
fix/state-machines
Nov 11, 2026
Merged

sayed0am merged 37 commits into
developfrom
fix/state-machines

Conversation

@sayed0am

Copy link
Copy Markdown
Owner

Fixes the implicit state machines from the 2026-11-07 review (findings S1 to S23, plus N1 to N11 from the Zepp parity rewrite). State spread over flags and side fields now has one owner and one set of transitions, and the ones that touch the strap follow Zepp 10.10.5.

Two waves of fix groups, merged here, with develop and main (3.0.4) merged in.

Connection and strap

  • A key the strap turned down is not retried by every background trigger (S1).
  • Live heart rate is one coroutine that follows the reasons, the connection and firmware updates (S9).
  • A background connect never clears the user's Disconnect. Only opening the app does (S13).
  • Bluetooth off is its own state on the Strap page, the notification and the widgets, with Turn on (S12).
  • Connection facts are per connection, and Forget clears them (S22).
  • N1: the workout goes to the strap again only on a new login, not on every battery change, as Zepp.
  • N8: step notify goes off on a background step push with no workout, as Zepp's yt00.

Workouts

  • A failed End says "Not saved yet" with Try again, and saves are tracked per part (S2).
  • Recording resources are owned in one place, Discard is one transaction, and start and restore can't half fail (S3, S4).
  • Notifications follow the session state through one notifier, and "a workout is in progress" has one answer (S10).
  • A STOP or ABANDON that didn't reach the strap goes on the next connect with nothing recording (S11). Without it the strap kept the session running and its frames led the live heart rate. This is the one place unstrap sends more than Zepp, and only after a failed send.
  • A restart keeps the rest time added and the live kcal (S23).

Sync and history

  • One sync queue and worker, one persisted sync status read by the app and the widgets, and only a full sync moves Synced (S5, S6, S19).
  • N3: a history type cut off part way fails the sync, as Zepp's l59.f.

Screens and navigation

  • One day state per picked day, and the picked day survives a restore (S7). A day switch keeps the last day dimmed for at most 300 ms, then the placeholder. This replaces the 4 s undimmed hold from Fix/UI day switch and polish #56.
  • Notification and widget extras are read once, not replayed after process death (S8).
  • You and Strap replace each other instead of stacking (S21).
  • Permissions: one answer runs every waiter, Location and Notifications get the "turned down for good" dialog, and call access is re-read on resume (S16, S17).
  • Health Connect auto sync turns on only after its first export, and calories can be offered again (S18).
  • App update and firmware install state is reconciled after process death (S14, S20).
  • Alarms, share card, sleep edits, backups, the weekly recap and deleted workouts (S15, S23).

Checked

  • Unit tests, lint, detektDebug and protocol:detektMain pass.
  • On the Fold with the strap (3.27.0.1), as a 3.0.5 test build: workout start, reconnect resend, process death restore, End from the notification, N8, Bluetooth off and Turn on, call access on resume, picked day after restore, widget extras after process death, Disconnect holding until Connect, the day swipe, and S11 and S21 before and after their fixes.
  • Not run on a device: the Location and Notifications dialogs, Health Connect's calories offer, the failed End notice, the +10 s rest restore, and N1's battery path. These have unit tests.

🤖 Generated with Claude Code

sayed0am and others added 30 commits November 7, 2026 02:41
A wrong or protected key failed the same way on every presence event,
Bluetooth restart and phone alert. ConnectErrors.isFinal now counts it,
so only the user's own connect or opening the app tries again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, deleted workout page

S8: MainActivity reads notification and widget extras in onCreate (fresh launch only) and onNewIntent, not onResume. S16: onResume refreshes phoneAlerts. S23: workout detail is Loading, Found or Missing by key; Missing shows a deleted message.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…uto sync on after first export, one write lock

One Bluetooth answer runs the queued workout and the Strap action. The location follow-up is a saved tag.
Granted for Health Connect writes means the required permissions only. Auto sync turns on only after its first
export succeeds. All Health Connect writes share one Mutex.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
S6: requests go through one channel and worker, a Sync now waits for a session or a firmware update, stale auto and type requests are dropped, only an auto failure triggers an immediate retry, dumpRaw takes its turn and never leaves Running. S19: widget refreshes run one at a time, the snapshot reads sync state once, bump uses update.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Update: failures after process death are shown from the saved tag, the tag is reconciled with installer sessions at start and on resume, Installing times out, one Check type, PendingAction.Install always cleared with feedback when installs are denied. Firmware: stale or illegal events are ignored per step, one AccountMode, token kept out of saved state, fields keyed on the account.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ngs after End

Discard is one DAO transaction. Start rolls back if it fails half way and honours a missing GPS. Readings after the last flush are dropped, the loop flushes under the lock, and a failed restore is retried. Starting a workout no longer overrides Disconnect.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…cap sent flag (S15, S23)

Alarms: write results close the sheet only on success, queued refresh, Loading/Failed/Loaded read state.
Share card: photo state, saveable result. Sleep detail: saveable sheets, Undo only after delete shows.
Backups: one DataJobs lock and a snapshot file per call. Recap marked sent only after it is shown.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…connection facts, find strap start order

Background connects never clear the user's Disconnect and read it on the lane. Live HR follows reasons, the connection and firmwareUpdating in one ordered coroutine. NotPaired follows the paired flow, Forget clears the old strap's facts, and Find strap is set before its start goes out.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Two overrides returned Boolean where the interface wants Unit, a connect
test counted log lines after virtual time while the connect reads the
paired strap on a real thread, the share photo test built a Compose
bitmap Robolectric can't, and detekt's new findings (long lines, three
LaunchedEffects that only set state, and two complexity rules).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Develop's Zepp parity work rewrote sync, connect, live heart rate and workout traffic.

- SyncCoordinator: develop's version, which already queues and runs one sync at a time. Group C's SyncPlan and its test are dropped.
- LiveHeartRateStream: keeps the single coroutine that owns the stream, with develop's per-screen consumers in place of the effort watch.
- StrapManager: develop's connect order plus clearing the last connection's battery and firmware. The wear poll is gone as on develop.
- StrapCommands: develop's per-connection alarm caps, still cleared on Forget.
- Chinese strings for the five strings wave 1 added.
- The firmware install state test is ignored while firmware updates are off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reconnect resend acted on every Connected value, and a battery or charging change is a new one, so each sent
the config and state again. Zepp sends it at the workout start (xbc.k) and then only on AUTH_SUCCESS (rbc via
yfk); its battery callback sends nothing. It now follows the change into Connected, which the start still sends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A type whose retries ran out, or that hit the cyclic stop, after some chunks counted as ok, so the sync ended Done
with that type short. Zepp's type result is its last exchange's status (l59.f, ixi.a), so the type fails and the
sync ends with an error. The chunks that came first are still stored and the cursor moves past them, as in Zepp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wn for good, Offer calories again

Location and notifications turned down for good get the Bluetooth dialog with its settings button. A notifications denial is now recorded from the Bluetooth ask and checked at workout start. The Health Connect page offers calories again, asking for just those permissions, only while they are not granted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed per part, start returns a result

A failed End sets Recording.endFailed and the live screen shows Not saved yet with Try again (End again).
saveFailed is now derived from endFailed and a per-part set (Workout, Sets, Rounds, HeartRate), so one
success no longer clears another failure. start() returns Deferred<StartResult>, WorkoutSession and the
layer share inProgress, the tile no longer sends Ready during a summary or reads the sport back from
its subtitle, and a GpsState flow says Off, Searching, Fixed or Unavailable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he picked day is saved

DayViewModel builds one DayScreenState from one flatMapLatest on the shown day, so the
day, Recovery (Loading, Ready or Failed), Healthspan, usual steps and activity carry the
same date and start empty on a switch. The picked day goes in SavedStateHandle. The
per-screen date checks are gone, and Sleep detail no longer shows No night before load.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…fter restore, Ready cleared on start

WorkoutNotifier (app scope) owns Saved and the Keep recording cancel. The notice can no longer be cancelled by the
session's late clear after the service's refusal. Undo only applies to the end it was posted for. End keeps its
confirmation until end() finishes. START_STICKY follows the restored state and drops once nothing is in progress.
Ready and Choose close whenever the session leaves Idle.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…as a state, companion prompt cancel only hides the offer

S5: SyncCoordinator persists the last full sync and the failing-since time. The header, the Strap page and the widgets read that one status. A push sync no longer moves the Synced time, and busy now covers the work after a sync. S12: ConnectionState.BluetoothOff with a Turn on action on the Strap page, the notification and widgets. Companion: Back on Android's prompt hides the offer for now, a real failure falls back to the battery setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sayed0am and others added 7 commits November 10, 2026 11:09
- DayViewModel keeps its profile flow as a property, which the new per-day flows read, and names the 800 ms settle.
- StrapService starts itself with runCatching outside a coroutine, and the sticky check is split for detekt.
- NavRequestsEffect collects with the lifecycle and closes Ready in a SideEffect.
- The two older day tests read the single screen state.
- The sync failure time is left out of backups, as the last sync time is.
- Line length and two suppressions with reasons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A workout that ended with the app behind left the strap pushing steps, since notify was only set on visibility
changes and connects. Zepp's RealtimeStepService turns it off on a step push (07, its mgk event) when the app is
behind and no phone GPS workout runs, at most once per 1.5 s (yt00.a, yt00.j).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both lived only in memory, so a process death cut a rest short by the +10 s taps and dropped the live kcal, which
never goes down. They are kept in settings for the recording workout, keyed on its start, and read back on restore.
The end question and "in a car" still start afresh, so a restart doesn't ask at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DayViewModel: wave 2's per-day activity flow with main's strip dots. ScoreDetail: main's held day page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aceholder

Main's detail pages kept the last day's page up to 4 s, undimmed, so another day's numbers stood under the new date.
One rule now covers Today and the details: a refresh of the same day keeps its value, another day keeps the last one
dimmed for at most 300 ms, then the placeholder, and a failed day holds nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ger stack

S11: a STOP or ABANDON the strap never got (out of range, Bluetooth off) left its session running, and its frames then
led the live heart rate. The session keeps the unsent end and sends it once on the next connect with nothing recording;
a new START replaces it. Seen and fixed on the strap (3.27.0.1) 2026-11-11.

S21: two quick taps on You and the strap pill stacked [You, Strap], so Back went to You. The two root pages now replace
each other; pages opened from a row still stack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
/** Where the day's rows are worked into its state, off the main thread (audit C7). */
private val work: CoroutineDispatcher = Dispatchers.Default,
/** Keeps the day picked, so a restore reopens the same day. */
private val saved: SavedStateHandle = SavedStateHandle(),
/** Where the day's rows are worked into its state, off the main thread (audit C7). */
private val work: CoroutineDispatcher = Dispatchers.Default,
/** Keeps the day picked, so a restore reopens the same day. */
private val saved: SavedStateHandle = SavedStateHandle(),
@sayed0am
sayed0am merged commit 4413a3f into develop Nov 11, 2026
5 checks passed
sayed0am added a commit that referenced this pull request Nov 11, 2026
Brings in the state machine fixes (#63). Health Connect keeps develop's
rule that only the needed permissions decide, with the optional ones now
calories, breathing rate and VO2 max, offered again from the Health
Connect page. Strap workouts are dropped under the same write lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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