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.

An edited routine starts again from its new sets and reps, under every policy (#275)

Duarte Santosc86add5e31d1
diff --git a/frontend/src/lib/active-exercise-swap.js b/frontend/src/lib/active-exercise-swap.js
index 57fc94548..3b22710bc 100644
--- a/frontend/src/lib/active-exercise-swap.js
+++ b/frontend/src/lib/active-exercise-swap.js
@@ -20,7 +20,7 @@ export function swapActiveExercise(active, index, replacement, {
const current = active.entries[index]
if (!hasLoggedSet(current)) {
const metadata = Object.fromEntries(Object.entries(current).filter(([key]) => (
- !['id', 'target', 'plan', 'sets', 'sg'].includes(key)
+ !['id', 'target', 'plan', 'planned', 'sets', 'sg'].includes(key)
)))
active.entries[index] = { ...metadata, ...replacement, ...(current.sg ? { sg: current.sg } : {}) }
active.cur = index
diff --git a/frontend/src/lib/finish-workout.js b/frontend/src/lib/finish-workout.js
index 47390b62a..6be02c4a0 100644
--- a/frontend/src/lib/finish-workout.js
+++ b/frontend/src/lib/finish-workout.js
@@ -15,6 +15,9 @@ export function buildCompletedWorkout(active, { end = Date.now(), prs = [], snap
// shape it always was. Without this the whitelist drops both at finish.
...(entry.rid ? { rid: entry.rid } : {}),
...(entry.noProg === true ? { noProg: true } : {}),
+ // What the routine asked for when the session was built (session-start.js), next to the
+ // target the prescription moved — how the next session tells an edited plan (#275).
+ ...(entry.planned ? { planned: entry.planned } : {}),
}
const snapshot = typeof snapshotFor === 'function' ? snapshotFor(entry) : null
if (snapshot && typeof snapshot === 'object' && !Array.isArray(snapshot) && Object.keys(snapshot).length) {
diff --git a/frontend/src/lib/finish-workout.test.js b/frontend/src/lib/finish-workout.test.js
index cb9439483..b90870661 100644
--- a/frontend/src/lib/finish-workout.test.js
+++ b/frontend/src/lib/finish-workout.test.js
@@ -49,6 +49,19 @@ describe('completed workout boundary', () => {
expect(b.noProg).toBe(true)
})
+ it('keeps the plan each entry was built from, next to the target the prescription moved', () => {
+ const active = {
+ id: 'w', d: '2026-08-08', start: 1, routineIds: ['strength'],
+ entries: [
+ { id: '0025', rid: 'strength', planned: { sets: 2, reps: 10, weight: 60 }, sets: [{ done: true, w: 62.5, r: 10 }], target: { sets: 2, reps: 10, weight: 62.5 } },
+ { id: '0031', sets: [{ done: true, w: 10, r: 12 }], target: { sets: 1, reps: 12 } },
+ ],
+ }
+ const [a, b] = buildCompletedWorkout(active).entries
+ expect(a.planned).toEqual({ sets: 2, reps: 10, weight: 60 })
+ expect('planned' in b).toBe(false)
+ })
+
it('derives topW from the highest completed non-warm-up work set, not stale entry data', () => {
const active = {
id: 'active-1', d: '2026-08-08', start: 1000,
diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js
index c1674a807..3828c3a31 100644
--- a/frontend/src/lib/progression.js
+++ b/frontend/src/lib/progression.js
@@ -205,6 +205,30 @@ export function selectDeloadCandidate({ currentWeight, targetWeight, targetReps,
return { ...candidates[0], target1RM, factor: deloadFactorOf({ deloadFactor: factor }), upper, bottom }
}
+/**
+ * What a routine's exercise asks for — its sets and reps (the range, under double progression;
+ * the seconds, for a hold) — as stamped on every entry a session builds (`entry.planned`, issue
+ * #275). A prescription moves the session's `target`; this keeps what the routine said, which
+ * is the only way the next session can tell a plan that was edited from one that progressed.
+ * The weight rides along for reference and never restarts anything: history decides it.
+ */
+export function plannedOf(cfg) {
+ const c = cfg || {}
+ const mode = modeOf(c)
+ const out = { sets: Math.max(1, c.sets || 1) }
+ if (mode === 'reps' && c.reps > 0) out.reps = c.reps
+ if (mode === 'reps' && c.repsMin > 0) out.repsMin = c.repsMin
+ if (mode === 'time' && c.sec > 0) out.sec = c.sec
+ if (c.weight != null) out.weight = c.weight
+ return out
+}
+const PLAN_KEYS = ['sets', 'reps', 'repsMin', 'sec']
+const samePlan = (a, b) => PLAN_KEYS.every(k => (a[k] ?? null) === (b[k] ?? null))
+/** Did the routine's sets or reps change since the session that stamped `planned`? */
+export function planChanged(planned, cfg) {
+ return !!planned && !samePlan(planned, plannedOf(cfg))
+}
+
/**
* Reduce one finished workout entry to what a policy needs to judge it.
*
@@ -308,6 +332,9 @@ export function stallCount(sessions, policy) {
for (let i = sessions.length - 1; i >= 0; i--) {
if (sessions[i].ok) break
if (i < sessions.length -1 && sessions[i].weight !== sessions[i+1].weight) break
+ // So does an edit of the plan (issue #275): misses against the old sets × reps say nothing
+ // about the new ones. Only sessions that both carry their plan can show one.
+ if (i < sessions.length - 1 && sessions[i].planned && sessions[i + 1].planned && !samePlan(sessions[i].planned, sessions[i + 1].planned)) break
// Next part limits policy to double. Why? Double is the only policy that deliberately asks for less than it grades against
// (Since it is geared towards climbing through a rep range).
// Specifically, `aim` (see `const aim`) climbs from the bottom of the range while `ok` needs the top.
@@ -358,6 +385,27 @@ export function nextPrescription(S, cfg, routine) {
const last = sessions[sessions.length - 1]
if (!last) return { policy, kind: 'first', why: ['Nothing logged yet — this session sets the baseline.'] }
+ // Start again from the plan (issue #275) when the last session was built from a different one:
+ // the routine's sets or reps were edited since, or the session is borrowed from another routine
+ // (this one has none of its own yet, see sessionsFor) whose plan was not this one's. Its
+ // numbers were judged against the old target, so they cannot say where the new one stands —
+ // a bodyweight goal climbing from the old count, or a deload aimed at reps and sets the
+ // routine no longer asks for. The weight holds at what was last lifted; the sets and reps are
+ // the routine's own (double progression aims inside its new range, from what you managed).
+ // A borrowed session saved before plans were stamped is taken as a different plan.
+ const borrowed = !!routine?.id && last.rid !== routine.id
+ if (last.planned ? planChanged(last.planned, cfg) : borrowed) {
+ const why = borrowed ? ['First time in this routine — starting from its own target.'] : ['Plan changed — starting from your new target.']
+ if (mode === 'time') return { policy, kind: 'hold', sec: cfg.sec || last.goal || undefined, why }
+ if (last.weight <= 0 && isBw(cfg)) return { policy, kind: 'hold', weight: 0, reps: cfg.reps || undefined, why }
+ if (policy === 'double') {
+ const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin, repStep(cfg))
+ const aim = Math.min(range.reps, Math.max(range.repsMin, last.low + repStep(cfg)))
+ return { policy, kind: 'hold', weight: last.weight, reps: aim, why }
+ }
+ return { policy, kind: 'hold', weight: last.weight, reps: cfg.reps || undefined, why }
+ }
+
const stalls = stallCount(sessions, policy)
const deloadAt = DELOAD_AFTER[policy] || 3
@@ -413,7 +461,9 @@ export function nextPrescription(S, cfg, routine) {
weight: previous.weight ?? cfg.weight,
reps: previous.reps ?? cfg.reps,
repsMin: previous.repsMin ?? cfg.repsMin,
- sets: previous.sets ?? cfg.sets,
+ // The sets are always the plan's: a loaded lift never gets a set count from progression,
+ // so an older one here can only be a plan since edited — and would grow the session back.
+ sets: cfg.sets ?? previous.sets,
bodyweight: previous.bodyweight ?? cfg.bodyweight,
side: previous.side ?? cfg.side,
intensifier: previous.intensifier ?? cfg.intensifier
@@ -452,11 +502,11 @@ export function nextPrescription(S, cfg, routine) {
const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin, repStep(cfg))
const top = range.reps
const bottom = range.repsMin
- // `last.ok` only means "matched whatever was recorded as this session's target" - the
- // first session for a fresh exercise (or one mid-climb) is seeded below the top of the
- // range, so hitting that recorded target is compliance with the plan, not "reached the
- // top". Double progression must not add weight until every set actually reaches the top
- // of the range (issue #278).
+ // `last.ok` only means "matched whatever was recorded as this session's target" - and that
+ // target can sit below the top of the range: the bottom stamped after a raise, or a count
+ // from before the exercise moved to double progression. Hitting it is compliance with that
+ // session, not "reached the top". Double progression must not add weight until every set
+ // actually reaches the top of the range (issue #278).
if (last.ok && last.low >= top) return {
policy, kind: 'up', weight: harder(w, inc), reps: bottom,
why: assisted
diff --git a/frontend/src/lib/progression.test.js b/frontend/src/lib/progression.test.js
index d6b2aa0ab..856ff6d0e 100644
--- a/frontend/src/lib/progression.test.js
+++ b/frontend/src/lib/progression.test.js
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest'
import {
- readSession, sessionsFor, stallCount, nextPrescription, applyPrescription,
+ readSession, sessionsFor, stallCount, nextPrescription, applyPrescription, plannedOf, planChanged,
policyFor, defaultIncrement, weightIncrement, epley1RM, deloadTarget1RM,
deloadFactorOf, DELOAD_FACTOR, POLICIES_FOR, DELOAD_AFTER, MAX_BW_SETS
} from './progression.js'
@@ -628,6 +628,103 @@ describe('routine slots (#216)', () => {
})
})
+// Issue #275: every session entry carries the plan it was built from (`planned`). When the
+// routine's sets or reps have changed since, or the last session is borrowed from another
+// routine with another plan, the next session starts again from the plan — the old target
+// cannot say where the new one stands.
+describe('an edited plan restarts progression (#275)', () => {
+ const PUSH = EXDB.find(e => e.eq === 'body weight' && e.bp !== 'cardio').id
+ const logged = (id, planned, target, w, reps, extra = {}) => ({
+ d: '2026-04-01', routineIds: ['r'],
+ entries: [{ id, planned, target, sets: reps.map(r => ({ w, r, done: true })), ...extra }],
+ })
+ const R = { id: 'r', ex: [] }
+
+ it('stamps only what the routine asks for, and tells an edit from a progression', () => {
+ expect(plannedOf({ id: LIFT, sets: 2, reps: 10, weight: 60, prog: 'linear', note: 'x' })).toEqual({ sets: 2, reps: 10, weight: 60 })
+ expect(plannedOf({ id: LIFT, sets: 3, reps: 12, repsMin: 8, weight: 40 })).toEqual({ sets: 3, reps: 12, repsMin: 8, weight: 40 })
+ expect(plannedOf({ id: LIFT, mode: 'time', sets: 2, sec: 45, weight: 0 })).toEqual({ sets: 2, sec: 45, weight: 0 })
+ const planned = plannedOf({ id: LIFT, sets: 2, reps: 10, weight: 60 })
+ expect(planChanged(planned, { id: LIFT, sets: 2, reps: 10, weight: 80 })).toBe(false) // weight: history's call
+ expect(planChanged(planned, { id: LIFT, sets: 2, reps: 12, weight: 60 })).toBe(true)
+ expect(planChanged(planned, { id: LIFT, sets: 3, reps: 10, weight: 60 })).toBe(true)
+ expect(planChanged(planned, { id: LIFT, sets: 2, reps: 12, repsMin: 10, weight: 60 })).toBe(true)
+ expect(planChanged(undefined, { id: LIFT, sets: 2, reps: 12 })).toBe(false)
+ })
+
+ it('holds the weight at the new sets × reps when a loaded lift\'s plan was edited', () => {
+ const S = { unit: 'kg', workouts: [logged(LIFT, { sets: 2, reps: 15, weight: 40 }, { sets: 2, reps: 15, weight: 40 }, 40, [15, 15])] }
+ const p = nextPrescription(S, { id: LIFT, sets: 2, reps: 10, weight: 40, prog: 'linear' }, R)
+ expect(p).toMatchObject({ kind: 'hold', weight: 40, reps: 10 })
+ expect(p.why[0]).toBe('Plan changed — starting from your new target.')
+ // The same session under an unchanged plan progresses as usual.
+ expect(nextPrescription(S, { id: LIFT, sets: 2, reps: 15, weight: 40, prog: 'linear' }, R)).toMatchObject({ kind: 'up', weight: 42.5 })
+ })
+
+ it('restarts a bodyweight goal from the new reps instead of climbing from the old ones', () => {
+ const S = { unit: 'kg', workouts: [logged(PUSH, { sets: 2, reps: 15, weight: 0 }, { sets: 2, reps: 15, weight: 0 }, 0, [15, 15])] }
+ const p = nextPrescription(S, { id: PUSH, sets: 2, reps: 10, weight: 0, bodyweight: true }, R)
+ expect(p).toMatchObject({ kind: 'hold', weight: 0, reps: 10 })
+ })
+
+ it('does not deload toward the old target after three misses and an edit', () => {
+ const miss = { d: '2026-04-01', routineIds: ['r'], entries: [{ id: LIFT, planned: { sets: 3, reps: 15, weight: 50 }, target: { sets: 3, reps: 15, weight: 50 }, sets: [12, 12, 12].map(r => ({ w: 50, r, done: true })) }] }
+ const S = { unit: 'kg', workouts: [miss, miss, miss] }
+ expect(nextPrescription(S, { id: LIFT, sets: 3, reps: 15, weight: 50, prog: 'linear' }, R).kind).toBe('deload')
+ const p = nextPrescription(S, { id: LIFT, sets: 2, reps: 10, weight: 50, prog: 'linear' }, R)
+ expect(p).toMatchObject({ kind: 'hold', weight: 50, reps: 10 })
+ expect(p.sets).toBeUndefined()
+ })
+
+ it('ends a stall streak at the edit — misses against the old plan do not count', () => {
+ const at = (planned, reps) => ({ d: '2026-04-01', routineIds: ['r'], entries: [{ id: LIFT, planned, target: { ...planned }, sets: reps.map(r => ({ w: 50, r, done: true })) }] })
+ const old = { sets: 3, reps: 15, weight: 50 }
+ const now = { sets: 3, reps: 10, weight: 50 }
+ const S = { unit: 'kg', workouts: [at(old, [12, 12, 12]), at(old, [12, 12, 12]), at(now, [9, 9, 9])] }
+ expect(stallCount(sessionsFor(S, LIFT, null, 'r'))).toBe(1)
+ expect(nextPrescription(S, { id: LIFT, ...now, prog: 'linear' }, R).kind).toBe('hold')
+ })
+
+ it('aims inside the new range under double progression, from what you managed', () => {
+ // History at 3 × 8 under linear, then the exercise switched to double 8–12 (the #278 path):
+ // a restart at the same weight, aiming one rep up — not a raise off a bottom stamped as hit.
+ const S = { unit: 'kg', workouts: [logged(LIFT, { sets: 3, reps: 8, weight: 36 }, { sets: 3, reps: 8, weight: 36 }, 36, [8, 8, 8])] }
+ const p = nextPrescription(S, { id: LIFT, sets: 3, reps: 12, repsMin: 8, weight: 36, prog: 'double' }, R)
+ expect(p).toMatchObject({ kind: 'hold', weight: 36, reps: 9 })
+ })
+
+ it('restarts a timed hold at its new duration', () => {
+ const S = { unit: 'kg', workouts: [logged(LIFT, { sets: 2, sec: 60, weight: 0 }, { mode: 'time', sets: 2, sec: 60 }, 0, [], { sets: [{ sec: 60, done: true }, { sec: 60, done: true }] })] }
+ const p = nextPrescription(S, { id: LIFT, mode: 'time', sets: 2, sec: 30, weight: 0, prog: 'time' }, R)
+ expect(p).toMatchObject({ kind: 'hold', sec: 30 })
+ })
+
+ it('starts a routine from its own target when the only history is another routine\'s', () => {
+ const B = { d: '2026-04-01', routineIds: ['b'], entries: [{ id: PUSH, rid: 'b', planned: { sets: 2, reps: 15, weight: 0 }, target: { sets: 2, reps: 15, weight: 0 }, sets: [{ w: 0, r: 15, done: true }, { w: 0, r: 15, done: true }] }] }
+ const p = nextPrescription({ unit: 'kg', workouts: [B] }, { id: PUSH, sets: 2, reps: 10, weight: 0, bodyweight: true }, { id: 'a', ex: [] })
+ expect(p).toMatchObject({ kind: 'hold', reps: 10 })
+ expect(p.why[0]).toBe('First time in this routine — starting from its own target.')
+ })
+
+ it('continues another routine\'s progression when its plan is the same one (a copied routine)', () => {
+ const B = { d: '2026-04-01', routineIds: ['b'], entries: [{ id: LIFT, rid: 'b', planned: { sets: 2, reps: 10, weight: 60 }, target: { sets: 2, reps: 10, weight: 60 }, sets: [{ w: 60, r: 10, done: true }, { w: 60, r: 10, done: true }] }] }
+ expect(nextPrescription({ unit: 'kg', workouts: [B] }, { id: LIFT, sets: 2, reps: 10, weight: 60, prog: 'linear' }, { id: 'copy', ex: [] }))
+ .toMatchObject({ kind: 'up', weight: 62.5 })
+ })
+
+ it('leaves history saved before plans were stamped to progress as it always did', () => {
+ const S = { unit: 'kg', workouts: [{ d: '2026-04-01', routineIds: ['r'], entries: [{ id: LIFT, target: { sets: 2, reps: 15, weight: 40 }, sets: [{ w: 40, r: 15, done: true }, { w: 40, r: 15, done: true }] }] }] }
+ expect(nextPrescription(S, { id: LIFT, sets: 2, reps: 10, weight: 40, prog: 'linear' }, R)).toMatchObject({ kind: 'up', weight: 42.5 })
+ })
+
+ it('aims an Epley deload at the plan\'s set count even for history saved before plans were stamped', () => {
+ const miss = { d: '2026-04-01', routineIds: ['r'], entries: [{ id: LIFT, target: { sets: 3, reps: 8, weight: 60 }, sets: [6, 6, 6].map(r => ({ w: 60, r, done: true })) }] }
+ const p = nextPrescription({ unit: 'kg', workouts: [miss, miss, miss] }, { id: LIFT, sets: 2, reps: 8, weight: 60, prog: 'linear' }, R)
+ expect(p.kind).toBe('deload')
+ expect(p.sets).toBe(2)
+ })
+})
+
// "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-start.js b/frontend/src/lib/session-start.js
index 2816cdb79..a71b49942 100644
--- a/frontend/src/lib/session-start.js
+++ b/frontend/src/lib/session-start.js
@@ -4,7 +4,7 @@
// Imports both history.js and progression.js (which itself imports history.js); nothing in
// either imports this file, so there is no cycle.
import { buildSets, applyIntensifierPlan, modeOf } from './history.js'
-import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement } from './progression.js'
+import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement, plannedOf } from './progression.js'
/**
* Where a planned session's reps come from (Settings → During a workout). 'plan', the default:
@@ -37,7 +37,9 @@ export function buildPlannedEntry(st, cfg, routine, { noProg = false } = {}) {
if (plan.reps != null) target.reps = plan.reps
if (plan.sec != null) target.sec = plan.sec
if (plan.sets != null) target.sets = plan.sets
- return { target, plan, sets }
+ // `planned` is what the routine asked for, kept apart from the target the prescription moved,
+ // so the next session can tell an edited plan from a progressed one (nextPrescription).
+ return { target, plan, sets, planned: plannedOf(cfg) }
}
// Returns a bare array of session entries. "Excluded from progression" is per-entry now
@@ -50,7 +52,7 @@ export function buildSessionEntries(st, r) {
// right weight already on the screen instead of being told about it afterwards.
const noProg = r?.excludeFromProgression === true
return (r ? r.ex : []).map(cfg => {
- const { target, plan, sets } = buildPlannedEntry(st, cfg, r, { noProg })
- return { id: cfg.id, sg: cfg.sg, target, plan, sets, ...(noProg ? { noProg: true } : {}) }
+ const { target, plan, sets, planned } = buildPlannedEntry(st, cfg, r, { noProg })
+ return { id: cfg.id, sg: cfg.sg, target, plan, sets, planned, ...(noProg ? { noProg: true } : {}) }
})
}
diff --git a/frontend/src/lib/session-start.plan.test.js b/frontend/src/lib/session-start.plan.test.js
index abf10230b..69a2dc337 100644
--- a/frontend/src/lib/session-start.plan.test.js
+++ b/frontend/src/lib/session-start.plan.test.js
@@ -46,6 +46,15 @@ describe('a planned session opens at the plan\'s reps', () => {
expect(work(a)).toHaveLength(2)
expect(reps(a)).toEqual([10, 10])
expect(a.target.reps).toBe(10)
+ // A has no session of its own, so it starts from the exercise's last weight (#216) at its own
+ // sets × reps, and says so.
+ expect(work(a).map(s => s.w)).toEqual([40, 40])
+ expect(a.plan.why[0]).toBe('First time in this routine — starting from its own target.')
+ // From then on A progresses on its own line, whatever B does.
+ train(st, ['A'])
+ train(st, ['B'], { r: 9 })
+ const [again] = start(st, ['A'])
+ expect(work(again).map(s => [s.w, s.r])).toEqual([[42.5, 10], [42.5, 10]])
})
for (const prog of [undefined, 'linear', 'greyskull', 'off']) {
@@ -129,6 +138,61 @@ describe('a planned session opens at the plan\'s reps', () => {
}
})
+describe('an edited routine starts again from its new plan', () => {
+ it('holds the weight at the new reps under the default policy', () => {
+ const st = state([{ id: 'A', name: 'A', ex: [{ id: BENCH, sets: 2, reps: 15, weight: 50 }] }])
+ train(st, ['A'])
+ cfgOf(st, 'A').reps = 10
+ const [e] = start(st, ['A'])
+ expect(work(e).map(s => [s.w, s.r])).toEqual([[50, 10], [50, 10]])
+ expect(e.plan.why[0]).toBe('Plan changed — starting from your new target.')
+ train(st, ['A'])
+ expect(start(st, ['A'])[0].plan.kind).toBe('up') // and progresses from there
+ })
+
+ it('aims inside the new range under double progression', () => {
+ const st = state([{ id: 'A', name: 'A', ex: [{ id: BENCH, sets: 2, reps: 15, repsMin: 13, weight: 50, prog: 'double' }] }])
+ train(st, ['A'])
+ Object.assign(cfgOf(st, 'A'), { reps: 10, repsMin: 8 })
+ const [e] = start(st, ['A'])
+ expect(e.plan.kind).toBe('hold')
+ expect(reps(e)).toEqual([10, 10])
+ })
+
+ it('restarts a bodyweight rep goal from the new count, not from the old one plus a rep', () => {
+ const ARCHER = '3294' // archer push-up — body-weight equipment
+ const st = state([{ id: 'A', name: 'A', ex: [{ id: ARCHER, sets: 2, reps: 15, weight: 0, mode: 'reps' }] }])
+ train(st, ['A'])
+ cfgOf(st, 'A', ARCHER).reps = 10
+ const [e] = start(st, ['A'])
+ expect(reps(e)).toEqual([10, 10])
+ train(st, ['A'])
+ expect(reps(start(st, ['A'])[0])).toEqual([11, 11])
+ })
+
+ it('does not deload toward the old reps, or grow back a removed set, after three misses', () => {
+ const st = state([{ id: 'A', name: 'A', ex: [{ id: BENCH, sets: 3, reps: 15, weight: 50 }] }])
+ for (let i = 0; i < 3; i++) train(st, ['A'], { r: 12 })
+ Object.assign(cfgOf(st, 'A'), { sets: 2, reps: 10 })
+ const [e] = start(st, ['A'])
+ expect(e.plan.kind).toBe('hold')
+ expect(work(e).map(s => [s.w, s.r])).toEqual([[50, 10], [50, 10]])
+ })
+
+ it('does not raise the weight off a bottom stamped after switching to double (#278)', () => {
+ const A = { id: 'A', name: 'A', ex: [{ id: BENCH, sets: 3, reps: 8, weight: 36, inc: 6 }] }
+ const st = state([A])
+ train(st, ['A']) // 3 × 8 @ 36 under linear
+ st.routines[0].ex[0] = { ...st.routines[0].ex[0], reps: 12, repsMin: 8, prog: 'double' }
+ const [e] = start(st, ['A'])
+ expect(e.plan).toMatchObject({ kind: 'hold', weight: 36, reps: 9 })
+ train(st, ['A'], { r: 8, w: 42 }) // the user overrides to 42, does 3 × 8
+ const [next] = start(st, ['A'])
+ expect(next.plan.kind).not.toBe('up')
+ expect(work(next).map(s => s.w)).toEqual([42, 42, 42])
+ })
+})
+
describe('"Your last session" keeps the old carry-over', () => {
it('opens at the reps logged last time, judged against the plan', () => {
const st = state([{ id: 'A', name: 'A', ex: [{ id: BENCH, sets: 2, reps: 10, weight: 50 }] }], { startFrom: 'last' })
diff --git a/frontend/src/lib/session-start.test.js b/frontend/src/lib/session-start.test.js
index 6b85b122b..b94feec6c 100644
--- a/frontend/src/lib/session-start.test.js
+++ b/frontend/src/lib/session-start.test.js
@@ -27,7 +27,7 @@ describe('buildSessionEntries', () => {
const st = {
unit: 'kg', exWeights: {}, routines: [],
workouts: [1, 2, 3].map((n) => ({
- d: `2026-01-0${n}`,
+ d: `2026-01-0${n}`, routineIds: ['r'],
entries: [{
id: cfg.id,
target: { sets: 3, reps: 8, weight: 60 },
@@ -52,7 +52,7 @@ describe('buildSessionEntries', () => {
// plan's, so a routine edited from 15 to 10 opened at 15 and read 15 ≥ 10 as a hit forever.
const history = (reps, extra = {}) => ({
unit: 'kg', exWeights: {}, routines: [],
- workouts: [{ d: '2026-01-01', entries: [{ id: '0025', target: { sets: 2, reps: 15, weight: 40 }, sets: reps.map(r => ({ w: 40, r, done: true })) }] }],
+ workouts: [{ d: '2026-01-01', routineIds: ['r'], entries: [{ id: '0025', target: { sets: 2, reps: 15, weight: 40 }, sets: reps.map(r => ({ w: 40, r, done: true })) }] }],
...extra,
})
// Greyskull has no hold: one failure resets it, so its miss case is a (non-Epley) deload.
@@ -87,7 +87,7 @@ describe('buildSessionEntries', () => {
const side = (w, r) => ({ w, r, done: true })
const st = {
unit: 'kg', exWeights: {}, routines: [],
- workouts: [{ d: '2026-01-01', entries: [{ id: '0025', target: { sets: 1, reps: 10, weight: 20, side: true }, sets: [
+ workouts: [{ d: '2026-01-01', routineIds: ['r'], entries: [{ id: '0025', target: { sets: 1, reps: 10, weight: 20, side: true }, sets: [
{ w: 22.5, r: 10, done: true, sides: { L: side(22.5, 5), R: side(20, 5) } },
] }] }],
}
@@ -98,6 +98,25 @@ describe('buildSessionEntries', () => {
expect(row.r).toBe(entry.target.reps)
})
+ it('stamps what the routine asked for on every entry, apart from the target it progressed', () => {
+ const cfg = { id: '0025', sets: 2, reps: 10, weight: 40, prog: 'linear' }
+ const [entry] = buildSessionEntries(history([15, 15]), { id: 'r', prog: 'linear', ex: [cfg] })
+ expect(entry.planned).toEqual({ sets: 2, reps: 10, weight: 40 })
+ expect(entry.target.weight).toBe(42.5)
+ })
+
+ it('opens an edited plan at its new numbers, and completing them reads as a hit', () => {
+ const st = history([15, 15])
+ st.workouts[0].entries[0].planned = { sets: 2, reps: 15, weight: 40 }
+ const cfg = { id: '0025', sets: 3, reps: 10, weight: 40, prog: 'linear' }
+ const [entry] = buildSessionEntries(st, { id: 'r', prog: 'linear', ex: [cfg] })
+ const work = entry.sets.filter(s => !isWarmupRow(s))
+ expect(entry.plan.kind).toBe('hold')
+ expect(work.map(s => [s.w, s.r])).toEqual([[40, 10], [40, 10], [40, 10]])
+ expect(entry.target).toMatchObject({ sets: 3, reps: 10, weight: 40 })
+ expect(readSession({ ...entry, sets: entry.sets.map(s => ({ ...s, done: true })) }, cfg).ok).toBe(true)
+ })
+
it('returns a bare array — no { entries, excluded } wrapper', () => {
const r = { id: 'r', prog: 'off', ex: [{ id: '0025', sets: 3, reps: 5, weight: 60 }] }
const out = buildSessionEntries(st, r)
diff --git a/frontend/src/lib/unilateral-integration.test.js b/frontend/src/lib/unilateral-integration.test.js
index 146987d9b..7b5e5b559 100644
--- a/frontend/src/lib/unilateral-integration.test.js
+++ b/frontend/src/lib/unilateral-integration.test.js
@@ -42,7 +42,7 @@ describe('unilateral sets across session boundaries', () => {
it('uses progressed side weights when building a routine session and its planned drops', () => {
const cfg = { id: '0025', mode: 'reps', side: true, bodyweight: false, sets: 1, reps: 16, weight: 20, policy: 'linear', inc: 2.5, intensifier: { type: 'dropset', count: 1, pct: 20 } }
- const S = { unit: 'kg', exWeights: {}, workouts: [{ id: 'w', d: '2026-09-01', entries: [{ ...entry(done(row())), target: cfg }] }] }
+ const S = { unit: 'kg', exWeights: {}, workouts: [{ id: 'w', d: '2026-09-01', routineIds: ['r'], entries: [{ ...entry(done(row())), target: cfg }] }] }
const [built] = buildSessionEntries(S, { id: 'r', policy: 'linear', ex: [cfg] })
expect(built.plan.kind).toBe('up')
expect(built.sets[0].sides.L.w).toBe(built.plan.weight)
diff --git a/frontend/src/sheets.plan-session.test.jsx b/frontend/src/sheets.plan-session.test.jsx
index c3307538d..81089d8bd 100644
--- a/frontend/src/sheets.plan-session.test.jsx
+++ b/frontend/src/sheets.plan-session.test.jsx
@@ -57,7 +57,7 @@ describe('what you plan is what you train', () => {
upd(s => { s.routines[0].ex[0] = { ...s.routines[0].ex[0], reps: 10 } })
startOn('2026-09-14', ['A'])
expect(S().active.entries[0].target.reps).toBe(10)
- expect(rowsOf('A').map(r => r.split('x')[1])).toEqual(['10', '10'])
+ expect(rowsOf('A')).toEqual(['50x10', '50x10'])
})
it('logging 15 once on a 2 × 10 plan does not turn every later session into 15s', () => {
@@ -69,6 +69,24 @@ describe('what you plan is what you train', () => {
expect(rowsOf('A')).toEqual(['52.5x10', '52.5x10'])
})
+ it('a routine trains its own line: Plan B on Wednesday does not move Plan A on Monday (#216)', () => {
+ install([
+ { id: 'A', name: 'Plan A', emoji: 'dumbbell', ex: [{ id: BENCH, sets: 2, reps: 10, weight: 60, mode: 'reps' }] },
+ { id: 'B', name: 'Plan B', emoji: 'dumbbell', ex: [{ id: BENCH, sets: 2, reps: 15, weight: 40, mode: 'reps' }] },
+ ])
+ startOn('2026-09-07', ['A'])
+ expect(rowsOf('A')).toEqual(['60x10', '60x10'])
+ trainActive('2026-09-07')
+ startOn('2026-09-09', ['B'])
+ expect(rowsOf('B')).toEqual(['60x15', '60x15']) // B's first time: the last weight, B's reps
+ trainActive('2026-09-09', 12)
+ startOn('2026-09-14', ['A'])
+ expect(rowsOf('A')).toEqual(['62.5x10', '62.5x10']) // A's own line, not B's miss
+ trainActive('2026-09-14')
+ startOn('2026-09-16', ['B'])
+ expect(rowsOf('B')).toEqual(['60x15', '60x15']) // B holds after its own miss
+ })
+
it('"Your last session" still carries the 15s over', () => {
install([{ id: 'A', name: 'Plan A', emoji: 'dumbbell', ex: [{ id: BENCH, sets: 2, reps: 10, weight: 50, mode: 'reps' }] }], { startFrom: 'last' })
startOn('2026-09-07', ['A'])
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index be5f2b5fe..f4e6bd85d 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -811,6 +811,7 @@ function ActiveWorkout() {
const freshWork = fresh.filter(x => !isWarmupRow(x))
activeEntry.target = built.target
activeEntry.plan = built.plan
+ activeEntry.planned = built.planned
activeEntry.sets = [...doneWarm, ...freshWarm.slice(doneWarm.length), ...doneWork, ...freshWork.slice(doneWork.length)]
})
}, null, routine)
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx
index 0f235b901..4d6638826 100644
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@ -761,6 +761,8 @@ describe('progression settings rebuild the rows like a session start', () => {
expect(saved.sets.map(s => [s.w, s.r])).toEqual([[42.5, 10], [42.5, 10]])
expect(saved.target).toMatchObject({ id: 'plain-bench', sets: 2, reps: 10, weight: 42.5 })
expect(saved.plan.kind).toBe('up')
+ // The plan this session now follows, so the next one can tell it apart from the routine's.
+ expect(saved.planned).toEqual({ sets: 2, reps: 10, weight: 40 })
})
it('carries last session\'s reps when the profile starts from the last session', async () => {
diff --git a/mcp/src/tools.js b/mcp/src/tools.js
index b748e32e4..dd4600aa8 100644
--- a/mcp/src/tools.js
+++ b/mcp/src/tools.js
@@ -426,7 +426,9 @@ function sourceOf(S, cfg, plan, field, routine) {
// exactly as session-start.js does with useTarget — history and the confirmed weight are ignored.
if (!plan || plan.kind === 'off') return 'routine_plan'
const decided = plan.kind !== 'first' && plan[field] != null
- if (decided) return 'progression'
+ // A policy that settles on the routine's own reps or hold — a restart after the plan was
+ // edited, a bodyweight hold at the plan's count — is the plan speaking, not an override.
+ if (decided) return field !== 'weight' && plan[field] === cfg[field] ? 'routine_plan' : 'progression'
const last = lastEntryFor(S, cfg.id, routine && routine.id)
if (field === 'reps') return startsFromLast(S) && last ? 'last_session' : 'routine_plan'
if (last) return 'last_session'
diff --git a/mcp/test/tools.test.js b/mcp/test/tools.test.js
index dbabaab25..e7aecc9dd 100644
--- a/mcp/test/tools.test.js
+++ b/mcp/test/tools.test.js
@@ -797,6 +797,26 @@ describe('preview_session', () => {
expect(e.weight_source).toBe('progression')
})
+ test('an edited routine restarts from its new reps, and says why (#275)', () => {
+ only({ id: '0025', sets: 2, reps: 10, weight: 60 }, {
+ workouts: [{
+ id: 'w1', d: '2026-07-20', routineIds: ['r-preview'], name: 'Preview',
+ entries: [{
+ id: '0025', rid: 'r-preview',
+ planned: { sets: 2, reps: 15, weight: 60 },
+ target: { sets: 2, reps: 15, weight: 60 },
+ sets: [{ w: 60, r: 15, done: true }, { w: 60, r: 15, done: true }]
+ }]
+ }]
+ })
+ const e = call('preview_session').exercises[0]
+ expect(e.prescription.kind).toBe('hold')
+ expect(e.prescription.why).toBe('Plan changed — starting from your new target.')
+ expect(e.opening_sets.map(s => [s.w, s.r])).toEqual([[60, 10], [60, 10]])
+ expect(e.reps_source).toBe('routine_plan')
+ expect(e.differs_from_plan).toBe(false)
+ })
+
test('planned drop sets show up on the opening rows', () => {
only({ id: '0025', sets: 2, reps: 10, weight: 50, intensifier: { type: 'dropset', count: 1, pct: 20 } })
const e = call('preview_session').exercises[0]