Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

The same exercise in two routines progresses on two lines, not one that zigzags between them (#216)

Duarte Santosab0c586b14f6
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js
index 2ebbc0683..8695cc775 100644
--- a/frontend/src/lib/history.js
+++ b/frontend/src/lib/history.js
@@ -231,10 +231,46 @@ export function entryExcluded(w, entry) {
return w?.excludeFromProgression === true || entry?.noProg === true
}
-export function lastEntryFor(S, exId) {
- for (let i = S.workouts.length - 1; i >= 0; i--) {
- const w = S.workouts[i]
- const en = w.entries.find(e => e.id === exId)
+/**
+ * Which routine a saved entry was planned by — the "slot" its numbers belong to (issue #216).
+ *
+ * Every entry of a session started since combined days carries its own `rid`. A session saved
+ * before that has none, and there the workout's routine stands in for all of its entries. The one
+ * exception is a newer session in which some entries carry a `rid` and this one does not: that is
+ * an exercise added to a freestyle session, and it belongs to no routine at all.
+ */
+export function entryRoutineId(w, en) {
+ if (en?.rid) return en.rid
+ if ((w?.entries || []).some(e => e && e.rid)) return null
+ return [].concat(w?.routineIds ?? [])[0] ?? w?.routineId ?? null
+}
+
+// The entry for one exercise in one saved workout. With a routine id it is that routine's own
+// entry — a combined A+B day can hold the same exercise twice, and the second one is not the
+// first one's history. Without, the first one, as it always was.
+const entryIn = (w, exId, rid) => (w.entries || []).find(e => e && e.id === exId && (!rid || entryRoutineId(w, e) === rid))
+
+/**
+ * The last counting session of an exercise: `{ d, sets, target, rid?, planned? }`, or null.
+ *
+ * Given a routine id, the routine's own last session of it (issue #216): the same bench press in
+ * a heavy day and a light day is two lines of progress, not one that zigzags between them. A
+ * routine that has never trained the exercise falls back to its last session anywhere, so a new
+ * or copied routine starts from what you actually lift rather than from nothing.
+ */
+export function lastEntryFor(S, exId, rid) {
+ if (rid) {
+ const own = lastEntryIn(S, exId, rid)
+ if (own) return own
+ }
+ return lastEntryIn(S, exId, null)
+}
+
+function lastEntryIn(S, exId, rid) {
+ const workouts = S.workouts || []
+ for (let i = workouts.length - 1; i >= 0; i--) {
+ const w = workouts[i]
+ const en = entryIn(w, exId, rid)
if (!en) continue
// A session that does not count — a planned deload, or a rehab block merged into a real
// session — is not "last time" for the next regular prescription: its reps and durations
@@ -250,7 +286,10 @@ export function lastEntryFor(S, exId) {
// `target` is what the session prescribed; finished workouts carry it so labels and the
// progression engine can read a session back the way it was logged. Older workouts have
// none — modeOf() falls back to the body part for them, which is what they were.
- if (done.length) return { d: w.d, sets: done, target: en.target || null }
+ if (done.length) {
+ const slot = entryRoutineId(w, en)
+ return { d: w.d, sets: done, target: en.target || null, ...(slot ? { rid: slot } : {}), ...(en.planned ? { planned: en.planned } : {}) }
+ }
}
return null
}
@@ -380,8 +419,9 @@ function buildWorkSets(S, cfg, options = {}) {
const useTarget = !!options.useTarget
// `lastEntryFor` now skips any entry that does not count — a planned deload, or a rehab
// block merged into a real session (entryExcluded) — so the rows seed from the last
- // *counting* session without this function pre-filtering the history itself.
- const last = lastEntryFor(S, cfg.id)
+ // *counting* session without this function pre-filtering the history itself. `options.rid`
+ // is the routine the rows are for: its own last session of the exercise comes first (#216).
+ const last = lastEntryFor(S, cfg.id, options.rid)
const n = Math.max(1, cfg.sets || 1)
const mode = modeOf(cfg)
const sets = []
@@ -406,18 +446,20 @@ function buildWorkSets(S, cfg, options = {}) {
}
return sets
}
- const conf = S.exWeights[cfg.id]
+ const conf = (S.exWeights || {})[cfg.id]
for (let i = 0; i < n; i++) {
const prev = prevAt(i)
const usable = prev && prev.r > 0 ? prev : null
- // Planned sessions may use the confirmed working weight, while freestyle should reproduce
- // the load of each matching set when that option is requested.
+ // The weight comes from the last session this routine trained (or any, for a routine that
+ // never has). The confirmed working weight is keyed by exercise alone, so it is only the
+ // fallback once there is no session to read: taken first, it handed a light day the heavy
+ // day's number (#216). A progression policy overwrites this anyway (applyPrescription).
// A deload uses the routine's target weight; a routine that never set one (weight 0) falls
// back to the last regular load rather than prescribing an empty bar.
const lastRegular = last ? (last.sets[i] || last.sets[last.sets.length - 1]) : null
const w = useTarget
? (cfg.weight > 0 ? cfg.weight : (lastRegular && lastRegular.r > 0 ? lastRegular.w : cfg.weight))
- : preferLast && usable ? usable.w : (conf && conf.w > 0 ? conf.w : (usable ? usable.w : cfg.weight))
+ : usable ? usable.w : (conf && conf.w > 0 ? conf.w : cfg.weight)
const row = { w, r: usable ? usable.r : cfg.reps, done: false }
// A unilateral exercise logs each side on its own (issue #60): the row splits into L/R,
// each seeded with half the total reps at the same weight. When "last time" was itself a
diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js
index 5fd3edae5..f49eadb99 100644
--- a/frontend/src/lib/history.test.js
+++ b/frontend/src/lib/history.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, setsDone, setsDoneActive, setUnits, doneUnits, setUnitsTotal, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor, effectiveRoutineIds, effectiveRoutines, effectiveRoutineId, effectiveRoutine, lastEntryFor, entryExcluded } from './history.js'
+import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, setsDone, setsDoneActive, setUnits, doneUnits, setUnitsTotal, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor, effectiveRoutineIds, effectiveRoutines, effectiveRoutineId, effectiveRoutine, lastEntryFor, entryExcluded, entryRoutineId } from './history.js'
import { makeSideSet, setSideField, toggleSide } from './workout-model.js'
import { EXDB } from './exercises.js'
@@ -481,9 +481,12 @@ describe('buildSets', () => {
.toEqual([{ w: 40, r: 8, done: false }])
})
- it('still prefers the confirmed working weight for reps sets', () => {
+ it('seeds the weight from the last session, and the confirmed working weight only when there is none', () => {
+ // The confirmed weight is keyed by exercise alone — a heavy day's number — so it no longer
+ // beats the session the rows are read from (#216). It still fills in without history.
const S = { exWeights: { [LIFT]: { w: 75 } }, workouts: [{ d: '2026-01-01', entries: [{ id: LIFT, sets: [{ w: 60, r: 10, done: true }] }] }] }
- expect(buildSets(S, { id: LIFT, sets: 1, reps: 8, weight: 50 })).toEqual([{ w: 75, r: 10, done: false }])
+ expect(buildSets(S, { id: LIFT, sets: 1, reps: 8, weight: 50 })).toEqual([{ w: 60, r: 10, done: false }])
+ expect(buildSets({ ...S, workouts: [] }, { id: LIFT, sets: 1, reps: 8, weight: 50 })).toEqual([{ w: 75, r: 8, done: false }])
})
it('can preserve each last set weight for freestyle instead of using the working-weight hint', () => {
@@ -1162,6 +1165,57 @@ describe('lastEntryFor / buildSets skip a noProg entry', () => {
})
})
+// Issue #216: the same exercise in two routines — a heavy day and a light day — is two lines of
+// history. Each routine reads its own, and one that has none reads the exercise's.
+describe('routine slots: lastEntryFor / buildSets read the routine\'s own history (#216)', () => {
+ const LIFT3 = EXDB.find(e => e.bp !== 'cardio' && e.eq !== 'body weight').id
+ const session = (d, rid, w, r, extra = {}) => ({ id: LIFT3, ...(rid ? { rid } : {}), target: { sets: 2, reps: r, weight: w }, sets: [{ w, r, done: true }, { w, r, done: true }], ...extra })
+ const S = {
+ exWeights: { [LIFT3]: { w: 60 } },
+ workouts: [
+ { d: '2026-01-01', routineIds: ['A'], entries: [session('2026-01-01', 'A', 60, 10)] },
+ { d: '2026-01-03', routineIds: ['B'], entries: [session('2026-01-03', 'B', 40, 15)] },
+ ],
+ }
+
+ it('takes the routine\'s own last session, not the latest one of the exercise', () => {
+ expect(lastEntryFor(S, LIFT3, 'A')).toMatchObject({ d: '2026-01-01', rid: 'A' })
+ expect(lastEntryFor(S, LIFT3, 'B')).toMatchObject({ d: '2026-01-03', rid: 'B' })
+ expect(lastEntryFor(S, LIFT3).d).toBe('2026-01-03')
+ })
+
+ it('falls back to the exercise\'s last session for a routine that never trained it', () => {
+ expect(lastEntryFor(S, LIFT3, 'C')).toMatchObject({ d: '2026-01-03', rid: 'B' })
+ })
+
+ it('reads a combined day by the entry that belongs to the routine, not the first one', () => {
+ const combined = { exWeights: {}, workouts: [{ d: '2026-01-05', routineIds: ['A', 'B'], entries: [session('', 'A', 60, 10), session('', 'B', 40, 15)] }] }
+ expect(lastEntryFor(combined, LIFT3, 'B').sets.map(s => [s.w, s.r])).toEqual([[40, 15], [40, 15]])
+ expect(lastEntryFor(combined, LIFT3, 'A').sets.map(s => [s.w, s.r])).toEqual([[60, 10], [60, 10]])
+ })
+
+ it('opens each routine\'s rows from its own line', () => {
+ const cfg = { id: LIFT3, sets: 2, reps: 10, weight: 0 }
+ expect(buildSets(S, cfg, { rid: 'A' }).map(s => s.w)).toEqual([60, 60])
+ expect(buildSets(S, cfg, { rid: 'B' }).map(s => s.w)).toEqual([40, 40])
+ })
+
+ it('gives a session saved before per-entry routine ids to the workout\'s routine', () => {
+ const legacy = { d: '2026-01-01', routineId: 'A', entries: [session('', null, 60, 10)] }
+ expect(entryRoutineId(legacy, legacy.entries[0])).toBe('A')
+ expect(entryRoutineId({ routineIds: ['B'], entries: [] }, { id: LIFT3 })).toBe('B')
+ expect(lastEntryFor({ workouts: [legacy] }, LIFT3, 'A')).toMatchObject({ rid: 'A' })
+ })
+
+ it('leaves an exercise added to a freestyle session without a routine', () => {
+ // "Add routine" on a freestyle session: the routine's entries carry its id, the exercise
+ // picked before it does not — it was never part of that routine's plan.
+ const w = { routineIds: ['A'], entries: [{ id: LIFT3 }, { id: 'x', rid: 'A' }] }
+ expect(entryRoutineId(w, w.entries[0])).toBeNull()
+ expect(entryRoutineId({ routineIds: [], entries: [{ id: LIFT3 }] }, { id: LIFT3 })).toBeNull()
+ })
+})
+
describe('per-side volume and legacy timed sets (QA round 2026-09-12)', () => {
it('sums each side of a unilateral set on its own instead of max weight × total reps', () => {
const w = { entries: [{ id: 'x', sets: [
diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js
index 712ed03f3..88477c1f1 100644
--- a/frontend/src/lib/progression.js
+++ b/frontend/src/lib/progression.js
@@ -16,7 +16,7 @@
// · fewer sets than prescribed → miss
// So a session that fell apart can never advance the load as though it had succeeded.
-import { modeOf, repStep, rerampWarmups, isBw, isPerSide, entryExcluded } from './history.js'
+import { modeOf, repStep, rerampWarmups, isBw, isPerSide, entryExcluded, entryRoutineId } from './history.js'
import { EXIDX, isAssisted } from './exercises.js'
import { isWarmupRow, isSideSet, syncSideAggregate, makeSideSet } from './workout-model.js'
import { normalizeRepRange } from './rep-range.js'
@@ -262,11 +262,28 @@ export function readSession(entry, fallback) {
}
}
-/** Every past session for one exercise, oldest first. `fallback` — see readSession. */
-export function sessionsFor(S, exId, fallback) {
+/**
+ * Every past session for one exercise, oldest first. `fallback` — see readSession.
+ *
+ * With a routine id, the sessions that routine trained (issue #216): a heavy day and a light day
+ * of the same lift each progress on their own line, and a combined day that holds the lift twice
+ * is read by the entry that belongs to the routine, not by whichever comes first. A routine with
+ * no session of its own reads the exercise's whole history instead, so a new or copied routine
+ * continues from where you are. Each session carries the routine it came from (`rid`) and the
+ * plan it was built from (`planned`), so the caller can tell a borrowed or outdated baseline.
+ */
+export function sessionsFor(S, exId, fallback, rid) {
+ if (rid) {
+ const own = sessionsIn(S, exId, fallback, rid)
+ if (own.length) return own
+ }
+ return sessionsIn(S, exId, fallback, null)
+}
+
+function sessionsIn(S, exId, fallback, rid) {
const out = []
;(S.workouts || []).forEach(w => {
- const entry = w.entries.find(e => e.id === exId)
+ const entry = (w.entries || []).find(e => e && e.id === exId && (!rid || entryRoutineId(w, e) === rid))
if (!entry) return
// A session that does not count for this exercise cannot become the baseline for its next
// prescription. Exclusion is per-entry now (ENG-11): a legacy whole-workout
@@ -274,7 +291,9 @@ export function sessionsFor(S, exId, fallback) {
// only its own. `noProg` is frozen onto the entry at build time, so later routine edits
// never rewrite it. This is the only progression-exclusion path in the file.
if (entryExcluded(w, entry)) return
- if (entry.sets.some(s => s.done && !isWarmupRow(s))) out.push({ d: w.d, ...readSession(entry, fallback) })
+ if (!entry.sets.some(s => s.done && !isWarmupRow(s))) return
+ const slot = entryRoutineId(w, entry)
+ out.push({ d: w.d, ...(slot ? { rid: slot } : {}), ...(entry.planned ? { planned: entry.planned } : {}), ...readSession(entry, fallback) })
})
return out
}
@@ -331,7 +350,9 @@ export function nextPrescription(S, cfg, routine) {
const easier = weight => (assisted ? addStep(weight, inc, inc) : deloadTo(weight, inc))
- const sessions = sessionsFor(S, cfg.id, cfg).filter(s => s.mode === mode)
+ // The routine's own sessions of this exercise, or the exercise's whole history when the
+ // routine has none yet (issue #216) — see sessionsFor.
+ const sessions = sessionsFor(S, cfg.id, cfg, routine?.id).filter(s => s.mode === mode)
const last = sessions[sessions.length - 1]
if (!last) return { policy, kind: 'first', why: ['Nothing logged yet — this session sets the baseline.'] }
diff --git a/frontend/src/lib/progression.test.js b/frontend/src/lib/progression.test.js
index 83d56bd9b..742cc7cd8 100644
--- a/frontend/src/lib/progression.test.js
+++ b/frontend/src/lib/progression.test.js
@@ -580,6 +580,54 @@ describe('sessionsFor', () => {
})
})
+// Issue #216: a heavy day and a light day of the same lift progress on their own lines. The
+// routine's own sessions decide; a routine without any reads the exercise's whole history.
+describe('routine slots (#216)', () => {
+ const entry = (rid, w, r, extra = {}) => ({ id: LIFT, rid, target: { sets: 2, reps: r, weight: w }, sets: [{ w, r, done: true }, { w, r, done: true }], ...extra })
+ const S = {
+ unit: 'kg',
+ workouts: [
+ { d: '2026-03-01', routineIds: ['heavy'], entries: [entry('heavy', 60, 10)] },
+ { d: '2026-03-03', routineIds: ['light'], entries: [entry('light', 40, 15)] },
+ ],
+ }
+ const heavy = { id: 'heavy', prog: 'linear', ex: [] }
+ const light = { id: 'light', prog: 'linear', ex: [] }
+
+ it('reads only the routine\'s own sessions, each marked with its routine', () => {
+ expect(sessionsFor(S, LIFT, null, 'heavy').map(s => [s.d, s.rid, s.weight])).toEqual([['2026-03-01', 'heavy', 60]])
+ expect(sessionsFor(S, LIFT, null, 'light').map(s => [s.d, s.rid, s.weight])).toEqual([['2026-03-03', 'light', 40]])
+ expect(sessionsFor(S, LIFT)).toHaveLength(2)
+ })
+
+ it('progresses each routine from its own last session', () => {
+ expect(nextPrescription(S, { id: LIFT, sets: 2, reps: 10, weight: 60 }, heavy).weight).toBe(62.5)
+ expect(nextPrescription(S, { id: LIFT, sets: 2, reps: 15, weight: 40 }, light).weight).toBe(42.5)
+ })
+
+ it('falls back to the exercise\'s history for a routine that never trained it', () => {
+ expect(sessionsFor(S, LIFT, null, 'new').map(s => s.rid)).toEqual(['heavy', 'light'])
+ })
+
+ it('reads a combined day by the routine\'s own entry, not the first one', () => {
+ const combined = { unit: 'kg', workouts: [{ d: '2026-03-05', routineIds: ['heavy', 'light'], entries: [entry('heavy', 60, 10), entry('light', 40, 15)] }] }
+ expect(sessionsFor(combined, LIFT, null, 'light').map(s => s.weight)).toEqual([40])
+ expect(nextPrescription(combined, { id: LIFT, sets: 2, reps: 15, weight: 40 }, light).weight).toBe(42.5)
+ })
+
+ it('does not let a stall on one routine deload the other', () => {
+ const miss = (d, rid, w) => ({ d, routineIds: [rid], entries: [{ id: LIFT, rid, target: { sets: 2, reps: 10, weight: w }, sets: [{ w, r: 6, done: true }, { w, r: 6, done: true }] }] })
+ const st = { unit: 'kg', workouts: [miss('2026-03-01', 'heavy', 60), S.workouts[1], miss('2026-03-05', 'heavy', 60), miss('2026-03-07', 'heavy', 60)] }
+ expect(nextPrescription(st, { id: LIFT, sets: 2, reps: 10, weight: 60 }, heavy).kind).toBe('deload')
+ expect(nextPrescription(st, { id: LIFT, sets: 2, reps: 15, weight: 40 }, light).kind).toBe('up')
+ })
+
+ it('reads a session saved before per-entry routine ids by the workout\'s routine', () => {
+ const legacy = { unit: 'kg', workouts: [{ d: '2026-03-01', routineId: 'heavy', entries: [{ id: LIFT, target: { sets: 2, reps: 10, weight: 60 }, sets: [{ w: 60, r: 10, done: true }, { w: 60, r: 10, done: true }] }] }] }
+ expect(sessionsFor(legacy, LIFT, null, 'heavy').map(s => s.rid)).toEqual(['heavy'])
+ })
+})
+
// "Excluded from progression" is per-entry now (ENG-11): a rehab routine combined with real
// work must exclude only its own exercises, not the whole session.
describe('per-entry noProg (combine routines)', () => {
diff --git a/frontend/src/lib/session-merge.test.js b/frontend/src/lib/session-merge.test.js
index 23acce69f..4a10fa0c2 100644
--- a/frontend/src/lib/session-merge.test.js
+++ b/frontend/src/lib/session-merge.test.js
@@ -1,6 +1,8 @@
import { describe, it, expect } from 'vitest'
import { buildCombinedEntries, deriveSessionName } from './session-merge.js'
import { buildSessionEntries } from './session-start.js'
+import { buildCompletedWorkout } from './finish-workout.js'
+import { isWarmupRow } from './workout-model.js'
const st = {
unit: 'kg', workouts: [], exWeights: {},
@@ -42,6 +44,26 @@ describe('buildCombinedEntries', () => {
})
})
+// A combined day that holds the same exercise twice — a heavy block and a light block — saves
+// two entries for it. Each routine's next session reads its own one (#216); it used to read only
+// the first, so the light block came back at the heavy block's numbers.
+describe('the same exercise in two routines of one combined day', () => {
+ const work = e => e.sets.filter(s => !isWarmupRow(s))
+ const A = { id: 'A', name: 'Heavy', ex: [{ id: '0025', sets: 2, reps: 10, weight: 60 }] }
+ const B = { id: 'B', name: 'Light', ex: [{ id: '0025', sets: 2, reps: 15, weight: 40 }] }
+
+ it('opens each routine from its own entry of the saved workout', () => {
+ const state = { unit: 'kg', exWeights: {}, routines: [A, B], workouts: [] }
+ const { entries, routineIds } = buildCombinedEntries(state, ['A', 'B'])
+ const active = { id: 'w1', d: '2026-08-01', start: 1, routineIds, name: 'Heavy + Light', entries: entries.map(e => ({ ...e, sets: e.sets.map(s => ({ ...s, done: true })) })) }
+ state.workouts.push(buildCompletedWorkout(active, { end: 2 }))
+
+ const next = buildCombinedEntries(state, ['A', 'B']).entries
+ expect(work(next[0]).map(s => [s.w, s.r])).toEqual([[62.5, 10], [62.5, 10]])
+ expect(work(next[1]).map(s => [s.w, s.r])).toEqual([[42.5, 15], [42.5, 15]])
+ })
+})
+
describe('deriveSessionName', () => {
it('is null for an empty list', () => {
expect(deriveSessionName([])).toBe(null)
diff --git a/frontend/src/lib/session-start.js b/frontend/src/lib/session-start.js
index 855764e3b..6da1f1fe4 100644
--- a/frontend/src/lib/session-start.js
+++ b/frontend/src/lib/session-start.js
@@ -9,8 +9,8 @@ import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement
// Returns a bare array of session entries. "Excluded from progression" is per-entry now
// (`entry.noProg`, written only when true) rather than a wrapper flag — a rehab routine merged
// into real work must exclude only its own exercises. The merge helper (lib/session-merge.js)
-// stamps `entry.rid`; this builder is unaware of which routine it serves, so the single-routine
-// and combined paths share it unchanged.
+// stamps `entry.rid`, so the single-routine and combined paths share this builder unchanged; it
+// only reads the routine's id, to start each exercise from that routine's own history (#216).
export function buildSessionEntries(st, r) {
// The prescription is applied as the session is built, so you walk up to the bar with the
// right weight already on the screen instead of being told about it afterwards. `plan` is
@@ -22,7 +22,7 @@ export function buildSessionEntries(st, r) {
// plates exist), not the unit default; a timed exercise's `inc` is seconds, so it keeps the
// default for its optional load.
const step = modeOf(cfg) === 'reps' ? weightIncrement(cfg, st.unit) : defaultIncrement(cfg.id, st.unit)
- const sets = applyIntensifierPlan(applyPrescription(buildSets(st, cfg, { step, useTarget: plan.kind === 'off' }), plan, step), cfg)
+ const sets = applyIntensifierPlan(applyPrescription(buildSets(st, cfg, { step, rid: r?.id, useTarget: plan.kind === 'off' }), plan, step), cfg)
const target = { ...cfg }
if (plan.weight != null) target.weight = plan.weight
if (plan.reps != null) target.reps = plan.reps
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index e484bdf87..725b43eff 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -1026,7 +1026,7 @@ export function swapActiveWorkoutExercise(index) {
// prescription — swapping barbell for dumbbell bench must not start you at an empty bar.
const step = modeOf(full) === 'reps' ? weightIncrement(full, st.unit) : defaultIncrement(ex.id, st.unit)
const plan = freestyle ? null : nextPrescription(st, full, slotRoutine)
- const built = buildSets(st, full, { step, ...(freestyle ? { preferLast: true } : {}), ...(plan?.kind === 'off' ? { useTarget: true } : {}) })
+ const built = buildSets(st, full, { step, ...(freestyle ? { preferLast: true } : { rid: current.rid }), ...(plan?.kind === 'off' ? { useTarget: true } : {}) })
const replacement = {
id: ex.id,
target: { ...cfg },
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index bed11c5e8..6ae1413d9 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -128,7 +128,9 @@ function ExerciseBlock({ entryIdx, compact, dense, onToggle, onToggleSide, onFie
const mode = modeOf({ ...(entry.target || {}), id: entry.id })
const cardio = mode === 'cardio'
const timed = mode === 'time'
- const last = lastEntryFor(S, entry.id)
+ // The routine's own last session of this exercise (or any, for a routine that has none), the
+ // same one the rows and the progression line were built from (#216).
+ const last = lastEntryFor(S, entry.id, entry.rid)
const standingNote = exNoteFor(S, entry.id)
// Only worth surfacing while there is still work left: once the exercise is finished, a note
// telling you what to do in it is behind you, and the block is already long.
@@ -801,7 +803,7 @@ function ActiveWorkout() {
// The sheet edits sets, reps, weight and warm-ups as well as the rule — so the rows are
// rebuilt from the new config the way the session was, and only what you already logged
// is kept in place (done warm-ups first, then done work sets, then the fresh remainder).
- const fresh = applyIntensifierPlan(applyPrescription(buildSets(s, full, { step, useTarget: plan.kind === 'off' }), plan, step), full)
+ const fresh = applyIntensifierPlan(applyPrescription(buildSets(s, full, { step, rid: activeEntry.rid, useTarget: plan.kind === 'off' }), plan, step), full)
const doneWarm = activeEntry.sets.filter(x => x.done && isWarmupRow(x))
const doneWork = activeEntry.sets.filter(x => x.done && !isWarmupRow(x))
const freshWarm = fresh.filter(isWarmupRow)
@@ -1080,7 +1082,7 @@ function ActiveWorkout() {
const plan = freestyle ? null : nextPrescription(s, full, routine)
const sets = buildSets(s, full, {
step: modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(ex.id, s.unit),
- ...(freestyle ? { preferLast: true } : {}),
+ ...(freestyle ? { preferLast: true } : { rid: curRid }),
...(plan?.kind === 'off' ? { useTarget: true } : {})
})
const progressed = freestyle ? sets : applyPrescription(sets, plan, modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(ex.id, s.unit))