fix: flush _repCount before WORKOUT_COMPLETE handles set completion (#703) - #704
Conversation
…703) When the Nth rep notification triggers WORKOUT_COMPLETE, handleSetCompletion reads coordinator._repCount.value which was still stale (N-1) because the StateFlow write at handleRepNotification line 1334 occurs AFTER repCounter.process() returns. The fix flushes _repCount.value inside the WORKOUT_COMPLETE handler before calling handleSetCompletion, ensuring captureExitSnapshot sees the correct rep count. Also adds a targeted test exercising the full repNotification -> handleRepNotification -> WORKOUT_COMPLETE -> handleSetCompletion -> captureExitSnapshot -> persistence path with reps=7 warmupReps=3. Fixes #703
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
Code Review Roast 🔥Verdict: 0 Issues Found | Recommendation: Merge Overview
Incremental Update (commit 5893a27)The follow-up commit resolves all three findings from the previous review:
No new issues introduced in this incremental commit. The race-condition explanation in Ponytail: Lean already. Ship. 🏆 Best part: Deleting the private 💀 Worst part: It took an extra commit to fix the three nits from the previous review. Three small issues, all copy-paste-driven, all caught by the first review, all left in place for a round-trip. The first commit should have shipped clean. 📊 Overall: PR is mergeable. The behavioral fix is correct, the regression test exercises the right path, and the housekeeping is now actually housekept. Two commits to land what should have been one, but the landed diff is solid. Files Reviewed (2 files)
Previous Review Summaries (2 snapshots, latest commit f77aaee)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit f77aaee)Verdict: 3 Issues Found | Recommendation: Address before merge Overview
Incremental Update (commit f77aaee)The follow-up commit swaps
The three findings from the prior review are unresolved — none of the lines they cite were touched in this incremental commit. Issue Details (click to expand)
🏆 Best part: The fix itself is dead-on. 💀 Worst part: Three places — two in code, one in the test — confidently cite "line 1334" as where 📊 Overall: The follow-up commit is a clean compile-fix; no new findings. The original PR still needs the three documented nits resolved before merge. Files Reviewed (2 files)
Fix these issues in Kilo Cloud Previous review (commit d381652)Verdict: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)
🏆 Best part: The fix itself is dead-on. 💀 Worst part: Three places — two in code, one in the test — confidently cite "line 1334" as where 📊 Overall: Solid bug-fix PR — the actual logic change is minimal, correct, and well-commented. The new regression test exercises the exact reproduction scenario. The only smell is a private Files Reviewed (2 files)
Reviewed by minimax-m3 · Input: 30.1K · Output: 3.3K · Cached: 291.6K Review guidance: REVIEW.md from base branch |
- Drop brittle line-1334 reference from WORKOUT_COMPLETE flush comment in ActiveSessionEngine.kt (the actual write is at line 1340; line numbers rot). - Drop same wrong line reference from the WorkoutExitPersistenceTest KDoc. - Replace the duplicate private nowMs() helper with the existing harness.nowMs from DWSMTestHarness (which advances with the testScheduler), so future tests that care about scheduler-relative timing remain correct.
Summary
Fixes off-by-one rep count when ROM reps precede the working set (Issue #703).
Root Cause
When the Nth rep notification triggers
WORKOUT_COMPLETE,handleSetCompletionreadscoordinator._repCount.valuewhich was still stale (N-1) because the StateFlow write athandleRepNotificationline 1334 occurs AFTERrepCounter.process()returns.The race:
repCounter.process()updates internalworkingRepsto Nprocess()firesWORKOUT_COMPLETEviaonRepEventcallbackhandleSetCompletion(eventLease)handleSetCompletionreadscoordinator._repCount.value-> still N-1captureExitSnapshotpersistsworkingReps = N-1instead of NFix
Flush
coordinator._repCount.value = repCounter.getRepCount()inside theWORKOUT_COMPLETEhandler before callinghandleSetCompletion, ensuring the snapshot sees the correct rep count.Changes
ActiveSessionEngine.kt: Added_repCount.valueflush in WORKOUT_COMPLETE handlerWorkoutExitPersistenceTest.kt: Added targeted test for the full repNotification -> handleRepNotification -> WORKOUT_COMPLETE -> handleSetCompletion -> captureExitSnapshot -> persistence pathRCA Reference
Fixes #703