Skip to content

feat: Heavy Deload scales AMRAP sets from last session reps (issue #1408) - #1410

Merged
9thLevelSoftware merged 2 commits into
mainfrom
feat/1408-deload-amrap-history
Nov 18, 2026
Merged

9thLevelSoftware merged 2 commits into
mainfrom
feat/1408-deload-amrap-history

Conversation

@9thLevelSoftware

Copy link
Copy Markdown
Owner

Heavy Deload scales AMRAP sets from last session's reps (#1408)

Fixes #1408

Problem

When a routine launches with Heavy Deload at P%, working reps are cut to the offered percentages — but AMRAP sets have no programmed reps to cut, so they passed through the deload transform untouched (null setReps entries are never scaled).

Behavior (reporter's example: 45 lb curls, AMRAP 10 reps last week, Heavy Deload 60%)

  • Each AMRAP set on an eligible exercise (not bodyweight, not timed-cable) becomes a session-only fixed-rep set at scaleReps(R, P), where R = the achieved reps of the most recent completed AMRAP-typed set for the same exercise (profile-scoped, latest logical attempt). 10 reps × 60% = 6 reps, weight unchanged.
  • Reference precedence: same routine-exercise + set slot → same routine-exercise → any completed AMRAP set of the exercise (routine or Just Lift).
  • No history → no change: the set stays AMRAP and unscaled; the last-set AMRAP placeholder is no longer pointlessly scaled while it remains AMRAP.
  • With history, the "last set AMRAP" flag is cleared on the session copy only — the saved routine template is never modified, and the deloaded sets record as STANDARD, so deload history can never feed back into later deloads.
  • Bodyweight and timed-cable exercises produce output byte-identical to before (including last-set placeholder scaling).
  • Rounding: (reps * percent / 100).roundToInt().coerceAtLeast(1) — 7 × 60% → 4; 1 × 10% → 1.

Scope

Per the signed-off design (signoff.md, implementation-spec.md): diff limited to exactly 3 files.

  • ApplyRoutineModifierUseCase.kt — applyHeavyDeload becomes suspend + profileId; one bounded history lookup per exercise per launch (getRecentCompletedSetsForExercise, limit 50, filtered to SetType.AMRAP && actualReps > 0). No schema/SQL/sync/DI/UI/portal change, no feature flag, no try/catch.
  • ApplyRoutineModifierUseCaseTest.kt — 11 new Kotlin/Native-safe test cases (conversion, no-history fallback, flag clearing on copy only, placeholder semantics, reference precedence, STANDARD/zero-rep filtering, profile isolation, bodyweight/timed exclusion, rounding, single query per exercise, Active Recovery reads no history).
  • testutil/FakeCompletedSetRepository.kt — the fake now honors profileId and records history-query calls.

Accepted limitations (documented in KDoc): Active Recovery AMRAP rows may serve as a reference; history beyond the 50 most recent sets of an exercise is not consulted.

Verification

  • ./gradlew -Pskip.supabase.check=true :shared:testAndroidHostTest --tests '…ApplyRoutineModifierUseCaseTest' --tests '…DWSMWorkoutLifecycleTest' — 281 tests, 0 failures (32 in ApplyRoutineModifierUseCaseTest incl. the 11 new; 249 in DWSMWorkoutLifecycleTest, all pre-existing cases unchanged).
  • ./gradlew -Pskip.supabase.check=true :shared:compileTestKotlinIosArm64 — BUILD SUCCESSFUL (backtick test names are KN-safe).
  • Required CI (Unit Tests / Build Android / iOS Test Target Compile) tracked on this PR. GitGuardian is not a gate.

Release note (from user-instructions.md)

Heavy Deload now applies to AMRAP sets. When you launch a routine with Heavy Deload, AMRAP sets are automatically set to a fixed rep target based on your last session's AMRAP result and the deload percentage (e.g. 10 reps last session at 60% → 6 reps this session; weight stays the same). If you have no AMRAP history for an exercise, the set stays AMRAP as before. The saved routine is never changed — only the session.

Design artifacts: ~/.hermes/phoenix-enhancements/issue-1408-1572315372235923557/ (implementation-spec.md, user-instructions.md). No UI change (ui_required=false), so no visual evidence is required for this PR.

Heavy Deload previously left AMRAP sets untouched (null setReps entries are
not scaled), so the deload had no effect on them. Eligible exercises (not
bodyweight, not timed-cable) now convert each AMRAP set into a session-only
fixed-rep set at scaleReps(R, P) where R is the achieved reps of the most
recent completed AMRAP-typed set for the same exercise (profile-scoped,
latest logical attempt; precedence same routine-exercise + set slot, then
same routine-exercise, then any). 10 AMRAP reps at 60% -> 6 reps, weight
unchanged. Without AMRAP history the set stays AMRAP and unchanged; bodyweight
and timed-cable rows keep today's exact output. The routine template is never
mutated and deloaded sets record as STANDARD, so no history feedback loop.
Copilot AI balanced review requested due to automatic review settings November 17, 2026 23:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@9thLevelSoftware

Copy link
Copy Markdown
Owner Author

Verification evidence (implementation stage)

Local gates (host: macOS, Android SDK + JDK 21):

  • ./gradlew -Pskip.supabase.check=true :shared:testAndroidHostTest --tests 'com.devil.phoenixproject.domain.usecase.ApplyRoutineModifierUseCaseTest' --tests 'com.devil.phoenixproject.presentation.manager.DWSMWorkoutLifecycleTest' → 281 tests, 0 failures (32 in ApplyRoutineModifierUseCaseTest — 21 pre-existing unchanged + 11 new; 249 in DWSMWorkoutLifecycleTest, green after the fake's profile-scoping change).
  • ./gradlew -Pskip.supabase.check=true :shared:compileTestKotlinIosArm64 → BUILD SUCCESSFUL (Kotlin/Native-safe test names).
  • git diff --name-only origin/main...HEAD → exactly the 3 allowed files from the signed-off spec.

CI status — one failure, PRE-EXISTING ON MAIN, not caused by this PR:

Unit Tests fails with exactly one test: ExerciseMediaWiringTest > noMigrationTouchesExerciseImage (this PR: 6003 tests, 1 failed). This is a source-level migration-count ratchet guard (assertTrue(maxSeen <= 63, ...), ExerciseMediaWiringTest.kt:125) that was not bumped when 64.sqm (issue #1400 per-rep aggregate eligibility) landed — 64.sqm is on origin/main and does not mention ExerciseImage at all, so only the counter guard is stale.

Evidence it is pre-existing: main's own CI run on this PR's exact base commit 6f95247 (run 44193888713, 2026-11-17 22:50Z, before this branch existed) fails with the identical single failure — ExerciseMediaWiringTest > noMigrationTouchesExerciseImage, 5992 tests, 1 failed (5992 + this PR's 11 new tests = 6003). The preceding commit 99c33b7 was green.

The one-line fix (bump the ratchet 63 → 64 in shared/src/commonTest/kotlin/com/devil/phoenixproject/presentation/ExerciseMediaWiringTest.kt) is outside this PR's 3 allowed files (signoff binding #1: any other file → stop and report scope drift), so it must land as a separate main-side fix; after that, a re-run turns Unit Tests green and releases the Build Android / iOS Test Target Compile legs (currently skipping because they gate on Unit Tests — iOS Test Target Compile already passed locally). GitGuardian is not a gate.

@9thLevelSoftware

Copy link
Copy Markdown
Owner Author

CI follow-up: pre-existing Unit Tests failure resolved main-side

The single Unit Tests failure (ExerciseMediaWiringTest > noMigrationTouchesExerciseImage) was the pre-existing stale migration ratchet documented above — it failed main's own CI on base commit 6f95247 (run 44193888713) before this branch existed.

Resolved outside this PR (this PR's diff stays limited to the 3 signed-off files):

  • Landed c28f5094 on main: bumped the T6/AC13 ratchet maxSeen <= 63 → maxSeen <= 64 in ExerciseMediaWiringTest.kt (guard (b) — only 43.sqm may mention ExerciseImage — is unchanged; 64.sqm contains zero ExerciseImage mentions). Verified locally: :shared:testAndroidHostTest --tests ExerciseMediaWiringTest → 12 tests, 0 failures.
  • Merged origin/main into this branch (acf2d485); git diff --name-only origin/main...HEAD still shows exactly ApplyRoutineModifierUseCase.kt, ApplyRoutineModifierUseCaseTest.kt, testutil/FakeCompletedSetRepository.kt.

CI is re-running on acf2d485. This also repairs main's own failing CI and unblocks the same check on other open PRs (e.g. #1407).

@9thLevelSoftware
9thLevelSoftware merged commit a6a659d into main Nov 18, 2026
13 of 14 checks passed
@9thLevelSoftware
9thLevelSoftware deleted the feat/1408-deload-amrap-history branch November 18, 2026 02:05
@9thLevelSoftware

Copy link
Copy Markdown
Owner Author

Merge gate: merged ✅

PR #1410 was squash-merged to main as a6a659d09bfd45ba77c76ebe2f93d9eedebf6f38. This issue was closed automatically by Fixes #1408.

What changed: When Heavy Deload is on, each AMRAP set on a weighted cable exercise now becomes a fixed-rep set for that session only. Its rep target is your reps from the most recent AMRAP set for that exercise, times the deload percent. For example, 10 reps at 60% gives 6 reps, and the weight stays the same. If there is no AMRAP history, the set stays AMRAP with no change. Bodyweight and timed exercises are not affected, and the saved routine is never modified.

Gate audit (head acf2d485):

  • Signoff approved (escalated-model review). The feasibility, architecture, integration-model, spec, signoff and user-instructions artifacts are all present.
  • The PR diff is exactly the 3 signoff-allowed files. I checked it against all 11 signoff bindings: eligibility, placeholder and isAMRAP handling, one memoized query per exercise (limit 50) with an AMRAP && actualReps > 0 filter, no try/catch, Active Recovery untouched, and KDoc limitations.
  • All required checks are green: Unit Tests, Build Android, iOS Test Target Compile, Lint, and iOS Schema Sync. Security Hygiene, native-tv and native-tv-device also pass. The iOS Simulator job is non-blocking and was skipped.
  • PR state was MERGEABLE/CLEAN with 0 review threads. The only bot review was a Copilot quota notice, not a requested change.
  • main moved ahead by 2 commits after follow-up (test(media): real picker-dialog photo-attach forwarding coverage (Refs #1358) #1409, fix: auto-advance equivalent consecutive duplicate routine entries (#1394) #1396). Neither touches the modifier or deload path, and git merge-tree showed a clean merge.
  • No UI change (ui_required=false), so no visual evidence was required.

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.

Feature: Apply deload percentages to AMRAP sets using last session's reps

2 participants