Skip to content

Manual "Next Set" on a held Set Summary is rejected (AUTHORITY_REJECTED) — workout frozen after first completed set (Set summary duration = Manual) #1413

Closed

Description

@9thLevelSoftware

Summary

With Profile → Set summary duration = Manual, the Set Summary card holds as designed after a completed set, but every tap on its visible Next Set button is rejected app-side: the screen stays frozen and each tap logs

WORKOUT_PERSISTENCE level=WARNING message=Rest transition install failed details=reason=AUTHORITY_REJECTED

Observed in-app on the iPad simulator with the Phantom provider through the ordinary UI (no harness taps into internals). 50 consecutive taps over ~24 minutes were each rejected; the summary never advanced. This was found while capturing the #1394 boundary acceptance on current main (9ae2124d); PR #1396 is not the cause — its diff does not touch this code path.

Steps to reproduce

  1. Profile → Set summary duration → Manual (ordinary Settings UI).
  2. Start a routine on the Phantom provider (simulator build), complete the first working set (simulated reps are fine).
  3. The Set Summary holds (correct). Tap Next Set.

Expected: the explicit continue installs the rest transition from the claimed set completion and the workout proceeds to the next set's readiness — exactly what the engine contract test autoplay off keeps manual readiness at duplicate boundary (Issue1394ConsecutiveDuplicateAutoAdvanceTest) asserts when it calls proceedFromSummary() at +1 s.

Actual: every tap logs Rest transition install failed reason=AUTHORITY_REJECTED and the screen stays frozen (byte-identical screenshots across taps).

Call chain (source at 9ae2124d)

SetSummaryCard "Next Set" Button(onClick = onContinue) → WorkoutTab onProceedFromSummary → MainViewModel.proceedFromSummary → DefaultWorkoutSessionManager.proceedFromSummary() / proceedFromSummaryFor → ActiveSessionEngine.startRestTimer(completion) / startRestTimerFor (the hasExpectedAuthority gate passes — a false result returns silently and logs transition=suppressed, which never appears) → installInitialRestPlan → hasCompletionRestAuthority returns false → InitialRestPlanInstallResult.AuthorityRejected → the observed WARNING.

One of hasCompletionRestAuthority's identity-coordinate conjuncts (profileId / routineId / routineSessionId / exerciseIndex / setIndex / routineExerciseId vs completion.routineIdentity) no longer matches the coordinator at tap time. The rest plan is installed successfully by the completion job at set-completion time (no install warning at completion in the captured log), so the coordinates drift silently while the summary is held. The exact drifting conjunct is not yet instrumented (Kermit Logger.d never reaches the unified log in this build; only the connection-log PHX-CAPTURE-LOG channel is observable).

Note the stale-completion guards are load-bearing and must survive any fix: installInitialRestPlan deliberately re-checks hasCompletionRestAuthority around replaceRuntimeDocument, and the executionGuard lease/claim machinery rejects superseded completions.

Evidence

From the #1394 boundary-capture run (issue-1394-boundary-capture-t_4538cc25):

  • logs/12-runR4-test04-findings.md — full symptom write-up and call-chain trace.
  • logs/runR4-test04-autoplay-off-console.log — timeline: execution begun 17:50:43.368 → activated 17:50:43.414 → completion claimed + machine teardown begun/ready (elapsedMs=0) 17:50:54.0x → summary holds → first genuine tap ~17:51:43 produces WARNING id=431; all 50 taps (ids 431–480) produce one AUTHORITY_REJECTED each, with zero intervening app log entries between teardown-ready and the first rejection (the drift is silent).
  • results/runR4-test04-config-frames.txt, pngs/runR4-test04-autoplay-off/.

Scope notes

Activity

  1. 9thLevelSoftware commented on Nov 18, 2026

    @9thLevelSoftware
    OwnerAuthor

    Status update — diagnosis, instrumentation and fix PR

    What the capture evidence pins down (runR4-test04):

    • The AUTHORITY_REJECTED at every tap comes from hasCompletionRestAuthority — but the same check passed when the completion job installed the rest plan at set-completion time (no install warning at completion in the connection log; the plan is installed while the summary is held).
    • The rejection appears only after a silent drift during the hold: zero connection-log entries between teardown-ready (17:50:54.036, elapsedMs=0) and the first rejection (17:51:43.568), and zero transition=suppressed entries in the entire run — so every hasExpectedAuthority lease gate passed and executionGuard.isCurrent(completion.lease) held for the full 24 minutes. That also proves no successor execution ever started — the drift is not a workout advance.
    • Delaying the tap alone does not reproduce it in the engine harness (green at +30 s virtual time), so the drift writer is app-side and not modelled by DWSMTestHarness.

    Instrumentation (this PR): hasCompletionRestAuthority now emits a privacy-safe PHX-CAPTURE-LOG line naming the rejecting conjunct (conjunct=lease_not_current | profile_id | live_routine_position with index values), and a second line fires when the raw mirror flows drifted but the anchored position still accepted the transition (Rest transition live mirror drifted; entered position still authoritative, with identity/current/entered coordinates). The next simulator run names the drifting coordinate directly — even though the flow now proceeds.

    Fix (this PR): the rest-transition authority's live-position check no longer trusts the raw mirror flows (currentRoutineId / currentRoutineSessionId / _currentExerciseIndex / _currentSetIndex) — exactly what drifts silently — and instead anchors on the loaded routine (id + exercise-id at the source index) and the last explicitly entered RoutineFlowState.SetReady position, which every legitimate position transition writes atomically with the index flows. Lease currency, the completion claim, plan/document source coherence, cleanup fences and terminal supersession are unchanged and still reject stale completions (regression test: a genuine SetReady(1, 0) successor transition still rejects the superseded completion). The same anchor is applied at the duplicated raw-coordinate blocks in hasRestTransitionAuthorityIgnoringReadyProfile, hasPersistedRestTimerDispatchAuthorityLocked and consumeNormalTransitionAndDispatchAwait, and startNextSetOrExerciseFor now classifies entry boundaries from the anchored position (a drifted exercise-index mirror otherwise mis-classifies the boundary and strands the summary).

    Likely shared root cause with #1360: the dead +30s / Pause rest controls run through mutatePlanOwnedRest → hasRestTransitionAuthority, the same live-coordinate gates that die under this drift. If the instrumentation names the drift, #1360's remaining symptom should be re-tested against this fix.

    PR opened: #1414 (head f040282) with Fixes #1413. Not merged by design — the merge gate is phoenix-rca. Full CI unit gate green on the exact head (6024 tests, 0 failures), including the #1398 Issue1360RestControlOutcomeTest suite (the PostWriteDrift contract is preserved — the drift tolerance is scoped to the held-SetSummary context only).

  2. 9thLevelSoftware commented on Nov 18, 2026

    @9thLevelSoftware
    OwnerAuthor

    RCA — #1413 Manual "Next Set" frozen / AUTHORITY_REJECTED (phoenix-rca)

    Conclusion (high confidence, verified by execution): The first Next Set tap on a held Manual summary succeeds, and that success is the "silent drift". It advances the routine coordinates and enters RoutineFlowState.SetReady, but it never publishes WorkoutState.Idle. ActiveWorkoutScreen navigates to SetReady only when workoutState is not SetSummary, so the Set Summary card stays on screen. Every later tap re-enters proceedFromSummary with the same claimed completion, whose identity is still at the completed set. hasCompletionRestAuthority then fails its _currentSetIndex conjunct and logs AUTHORITY_REJECTED, forever. The authority check is doing its job. The defect is the missing state publication on the manual successor path.

    PR #1414 (head f0402823) does not fix this mechanism. Details and execution evidence are below.

    Evidence used

    • Report: owner-filed issue body plus the 2026-11-18 status comment. No reporter clarification was needed.
    • Recreation: REPRODUCED, deterministic.
      • Live iPad simulator with Phantom: 51 taps. Tap 1 at 17:51:14.045 logged nothing (silent success). Taps 2–51 each logged Rest transition install failed reason=AUTHORITY_REJECTED (ids 431–480). Zero transition=suppressed entries. Pre- and post-tap screenshots are byte-identical.
      • Host test Issue1413ManualNextSetReproTest (:shared:testAndroidHostTest), on a 2-set entry: tap 1 → routineFlowState=SetReady(0,1) while WorkoutState stays SetSummary. Tap 2 → AuthorityRejected, conjunct setIndex (coordinator=1, identity=0).
      • Delay-only control: taps at +1 s to +25 min, plus a 50-tap loop on a 1-set-entry boundary, gave 0 rejections.
    • How this squares with the status comment. The comment notes zero log entries between teardown (17:50:54) and the first rejection (17:51:43), and no successor execution. Both are consistent with this RCA. The writer the comment is looking for is tap 1's own startNextSetOrExerciseFor. It writes _currentSetIndex and RoutineFlowState.SetReady without starting an execution and without logging.

    Call chain (main ca2fefe1)

    1. SettingsManager.kt:140: autoplayEnabled = summaryCountdownSeconds != 0, so Manual means autoplay is off.
    2. DefaultWorkoutSessionManager.proceedFromSummaryFor (~1361–1374): for a routine completion with a routineIdentity, this is the install-first branch. It calls activeSessionEngine.startRestTimer(completion) and then return@launch. That bypasses the legacy autoplay-off branch (~1453–1497), which writes WorkoutState.Idle before enterSetReady (the Set Summary (unlimited) + per-set rest times: "Next Set" stuck on first set, then jumps to End Routine #656 fix).
    3. ActiveSessionEngine.startRestTimerFor (12502+): installInitialRestPlan → Installed(NormalAdvance), and the plan is dispatched immediately because it is a NormalAdvance. Then startNextSetOrExerciseFor:
      • It sets _currentExerciseIndex / _currentSetIndex to the successor (13587–13588).
      • Within-entry arm (13733–13744) and distinct-exercise arm with !deferManualStart (13692–13712): both call startWorkoutOrSetReady(lease, autoplay=false) (13464–13471), which only calls flowDelegate.enterSetReady(...).
      • Neither arm writes WorkoutState.Idle.
      • Only the deferManualStart same-exercise arm (13713–13731) does. Its comment documents this exact strand: "ActiveWorkoutScreen only navigates to SetReady when workoutState is Idle. Leaving Resting/SetSummary after SetReady setup strands the user on the rest/summary UI."
    4. ActiveWorkoutScreen.kt (phoneMain, 383–404): isWorkoutActive includes SetSummary, so the SetReady navigation never fires.
    5. Retry tap: state is still SetSummary, and claimedCompletion still has identity (0,0). In installInitialRestPlan (13150+), hasCompletionRestAuthority (13302–13315) runs before the idempotent already-installed short-circuit. It fails on _currentSetIndex(1) != identity.setIndex(0) → AuthorityRejected → the WARNING at 13232. startRestTimerFor then returns silently.

    Why the #1394 contract test passes: its entries have 1 set each, so the boundary is a same-exercise entry change with autoplay off. That takes the deferManualStart arm, which does write Idle. The bug shows up on every other Manual-summary routine progression: the next set within an entry, and a distinct-exercise boundary.

    Blast radius: every Manual ("Set summary duration = Manual") routine progression except adjacent same-exercise entries. The workout freezes after the first completed set. Severity: high. advanceToNextSetInSingleExercise is not affected, because it always calls startWorkout and never enters SetReady. The other enterSetReady sites (2522, 3932, 11570) already publish Idle next to the call.

    PR #1414 does not resolve this (executed at head f0402823)

    I ran the recreation's Issue1413ManualNextSetReproTest against the PR head. Result: 7 tests, 1 failure.

    • manual next set after multi-set first entry advances to the second set still fails with "the tap at +48s on a multi-set entry must advance out of the summary".
    • The second-tap AUTHORITY_REJECTED signature still reproduces.

    Why: after tap 1, both the raw indices and the entered SetReady are at the successor (0,1). The PR's anchor still disagrees with identity (0,0), so the rejection stands, and the missing Idle write is untouched. The PR's own tests use 1-set entries (the healthy deferManualStart arm) and inject synthetic mirror drift, so they never exercise the failing arm. The PR also relaxes the live-position authority while a summary is held. That weakens a stale-completion guard to tolerate a drift whose writer turns out to be the legitimate tap-1 transition. Separately, its iOS Test Target Compile check is failing.

    Fix direction (binding for the fixer)

    1. Primary. In ActiveSessionEngine.startNextSetOrExerciseFor, in both !autoplay manual arms (the isChangingExercise && !deferManualStart arm and the within-entry else arm), publish coordinator._workoutState.value = WorkoutState.Idle after enterSetReady and applyPendingRestRackSelection(nextExIdx to nextSetIdx). Guard the write with hasExpectedAuthority(lease, ...), mirroring 13729–13731. Doing it in startWorkoutOrSetReady is acceptable only if Idle is still published after the rack-selection application.
      • Scratch probe: I applied exactly this (6 lines) on main ca2fefe1. The RED test passes, and these suites stay green: Issue1394ConsecutiveDuplicateAutoAdvanceTest (27/27), Issue1360RestControlOutcomeTest (10/10), Issue1360RestTimerControlsTest (4/4), Issue1360RestTimerUiTest, DropSetRestTransitionTest (13/13), DWSMRoutineFlowTest (14/14), Issue656ReproTest, and the SetReady wiring tests.
      • With the fix, the old second-tap signature no longer occurs: the second tap sees non-SetSummary and is ignored.
    2. Secondary hardening (optional, same PR). In installInitialRestPlan, an idempotent retry for the same executionId + logicalSetKey whose plan was already installed and consumed should be a quiet no-op, not a WARNING. Do not loosen hasCompletionRestAuthority for genuinely stale completions.
    3. Do not ship the PR fix(workout): publish Idle on manual summary continue so SetReady can navigate (#1413) #1414 approach of anchoring authority to the entered/loaded routine position as the fix for this issue. Rework fix(workout): publish Idle on manual summary continue so SetReady can navigate (#1413) #1414 to the direction above, or replace it.

    Acceptance criteria

    Regression test target

    Add Issue1413ManualNextSetReproTest-style host tests in shared/src/commonTest/.../presentation/manager/ using DWSMTestHarness with setActiveSummaryCountdownSeconds(0). Cover the 2-set entry case, the distinct-exercise boundary, and a second tap producing no warning. These tests must fail on main without the fix (verified: they do).

    Non-goals

    Scratch probe diff and test runs: local RCA artifacts (phoenix-rca). Issue state is unchanged; it closes only via the fix PR's Fixes #1413.

  3. 9thLevelSoftware commented on Nov 18, 2026

    @9thLevelSoftware
    OwnerAuthor

    Architecture review: #1413 (Manual Set Summary, Next Set rejected with AUTHORITY_REJECTED)

    Verdict: APPROVED, subject to the binding constraints below. I checked the RCA fix direction against main@ca2fefe1.

    What I checked

    • ActiveSessionEngine.startNextSetOrExerciseFor: both manual successor arms call startWorkoutOrSetReady(lease, autoplay=false). That only calls enterSetReady and never publishes WorkoutState.Idle. One arm handles a distinct exercise without deferManualStart (~13692-13712). The other handles a later set inside the same entry (~13732-13744). Only the deferManualStart arm (13713-13731) writes Idle, and its comment describes this exact strand.
    • hasCompletionRestAuthority (13302-13315) compares the frozen completion identity with the live _currentSetIndex. After the first tap moves the index, every retry tap fails this check by design. The check is correct; the stranded SetSummary is what keeps it firing.
    • advanceToNextSetInSingleExercise (13391+) always auto-starts, so it does not have this gap. No change is needed there.
    • Probe issue-1413-idle-probe.diff (6 lines, both arms, hasExpectedAuthority-guarded) is the right fix shape.

    Architectural assessment

    • Scope is minimal and stays inside one KMP shared-engine function. There are no schema, Supabase, edge-function, portal, migration or persisted-state changes, and no BLE command changes. Publishing Idle only changes navigation: it triggers the SetReady route that ActiveWorkoutScreen already expects.
    • It follows the existing convention: the same pattern as the deferManualStart arm and the legacy DWSM autoplay-off branch from Set Summary (unlimited) + per-set rest times: "Next Set" stuck on first set, then jumps to End Routine #656.
    • Risk is low. Idle is published only after the lease has been re-checked, so a superseded execution cannot overwrite a newer state.

    Binding constraints for the fix

    1. Publish WorkoutState.Idle at the two call sites, AFTER enterSetReady and applyPendingRestRackSelection(nextExIdx to nextSetIdx), guarded by hasExpectedAuthority(lease, ...). Do not move the write into startWorkoutOrSetReady ahead of the rack-selection apply, because SetReady must see rest-screen edits first.
    2. Do NOT relax hasCompletionRestAuthority or executionGuard. The anchored-position authority change in PR fix(workout): publish Idle on manual summary continue so SetReady can navigate (#1413) #1414 is not an acceptable fix for this mechanism. Rework fix(workout): publish Idle on manual summary continue so SetReady can navigate (#1413) #1414 to this direction (or replace it), keep Fixes #1413, and drop the authority relaxation unless it is proven independently necessary with its own RED test.
    3. Optional hardening: an idempotent retry for a plan already installed or consumed with the same executionId + logicalSetKey can become a quiet no-op. If you do this, it must stay ordered so stale or superseded completions are still rejected. Do not move the idempotent check ahead of the authority check for genuinely different completions.
    4. Leave the autoplay arms and the deferManualStart arm unchanged.
    5. Tests: the recreation RED test (Issue1413ManualNextSetReproTest, covering a 2-set entry and a distinct-exercise boundary) must fail on main and pass with the fix. Issue1394 (27), Issue656Repro, DropSetRestTransition, DWSMRoutineFlow and the [TestFlight] Rest timer controls not working — Pause and +30s unresponsive — iPhone17_1 #1360 rest-control/PostWriteDrift suites must stay green. New commonTest names must be valid for Kotlin/Native (no , in backtick names), so iOS Test Target Compile passes.
    6. Acceptance evidence: simulator/Phantom evidence of a Manual-summary routine with an entry of 2 or more sets advancing on the first Next Set tap, with no Rest transition install failed warning on later taps, is sufficient.
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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions