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 plan that changes the weight with the reps opens at the new weight (#275)

Duarte Santos16209969ea65
diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js
index 2d4a5d8bd..23b796a37 100644
--- a/frontend/src/lib/progression.js
+++ b/frontend/src/lib/progression.js
@@ -210,7 +210,8 @@ export function selectDeloadCandidate({ currentWeight, targetWeight, targetReps,
* 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.
+ * The weight never starts one on its own — history decides it — but once the sets or reps were
+ * edited, a weight edited with them is the one the new plan opens at (nextPrescription).
*/
export function plannedOf(cfg) {
const c = cfg || {}
@@ -395,19 +396,26 @@ export function nextPrescription(S, cfg, 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).
+ // routine no longer asks for. 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 && climbsReps(cfg)) return { policy, kind: 'hold', weight: 0, reps: cfg.reps || undefined, why }
+ // The weight holds at what was last lifted, unless the plan's own weight is not the one the
+ // session was built from: the same edit that turned 3 × 5 @ 100 into 3 × 10 @ 70 set 70,
+ // and 102.5 × 10 is a load never lifted for those reps. A routine whose weight nobody
+ // touched still carries the one it was created with, so there the history decides.
+ const set = cfg.weight > 0 && last.planned && (last.planned.weight ?? null) !== cfg.weight ? { weight: cfg.weight } : null
+ if (mode === 'time') return { policy, kind: 'hold', ...set, sec: cfg.sec || last.goal || undefined, why }
+ if (!set && last.weight <= 0 && climbsReps(cfg)) return { policy, kind: 'hold', weight: 0, reps: cfg.reps || undefined, why }
// A loaded lift logged at 0 had no weight typed in (see below): the plan's, if it has one.
- const held = last.weight > 0 ? { weight: last.weight } : cfg.weight > 0 ? { weight: cfg.weight } : {}
+ const held = set || (last.weight > 0 ? { weight: last.weight } : cfg.weight > 0 ? { weight: cfg.weight } : {})
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)))
+ // A new weight starts at the bottom of the range, the way a raise does: the reps managed
+ // were managed at another load.
+ const aim = set ? range.repsMin : Math.min(range.reps, Math.max(range.repsMin, last.low + repStep(cfg)))
return { policy, kind: 'hold', ...held, reps: aim, why }
}
return { policy, kind: 'hold', ...held, reps: cfg.reps || undefined, why }
diff --git a/frontend/src/lib/progression.test.js b/frontend/src/lib/progression.test.js
index a4b1e2d1e..8b985c165 100644
--- a/frontend/src/lib/progression.test.js
+++ b/frontend/src/lib/progression.test.js
@@ -718,6 +718,27 @@ describe('an edited plan restarts progression (#275)', () => {
expect(nextPrescription(S, { id: LIFT, sets: 2, reps: 15, weight: 40, prog: 'linear' }, R)).toMatchObject({ kind: 'up', weight: 42.5 })
})
+ // The weight is history's call — unless the same edit that changed the sets or reps changed the
+ // plan's weight too. 102.5 × 10 after 3 × 5 @ 100 was rewritten as 3 × 10 @ 70 is a load never
+ // lifted for those reps, and "starting from your new target" would not be true of it.
+ it('opens at the plan\'s new weight when the edit changed it along with the reps', () => {
+ const five = logged(LIFT, { sets: 3, reps: 5, weight: 100 }, { sets: 3, reps: 5, weight: 102.5 }, 102.5, [5, 5, 5])
+ const S = { unit: 'kg', workouts: [five] }
+ const p = nextPrescription(S, { id: LIFT, sets: 3, reps: 10, weight: 70, prog: 'linear' }, R)
+ expect(p).toMatchObject({ kind: 'hold', weight: 70, reps: 10 })
+ expect(p.why[0]).toBe('Plan changed — starting from your new target.')
+ // Only the reps edited, the weight the routine was created with left alone: what was lifted.
+ expect(nextPrescription(S, { id: LIFT, sets: 3, reps: 10, weight: 100, prog: 'linear' }, R)).toMatchObject({ kind: 'hold', weight: 102.5, reps: 10 })
+ // A weight edit alone restarts nothing: the sets and reps are the plan's, the history moves on.
+ expect(nextPrescription(S, { id: LIFT, sets: 3, reps: 5, weight: 70, prog: 'linear' }, R)).toMatchObject({ kind: 'up', weight: 105 })
+ })
+
+ it('starts a new weight at the bottom of a double-progression range', () => {
+ const twelve = logged(LIFT, { sets: 3, reps: 12, weight: 40 }, { sets: 3, reps: 12, weight: 40 }, 40, [12, 12, 12])
+ const p = nextPrescription({ unit: 'kg', workouts: [twelve] }, { id: LIFT, sets: 3, reps: 12, repsMin: 8, weight: 60, prog: 'double' }, R)
+ expect(p).toMatchObject({ kind: 'hold', weight: 60, reps: 8 })
+ })
+
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)
@@ -763,6 +784,15 @@ describe('an edited plan restarts progression (#275)', () => {
expect(p.why[0]).toBe('First time in this routine — starting from its own target.')
})
+ // A heavy day and a light day of the same lift (#216): the heavy day's first session opens at
+ // its own weight, not at the light day's.
+ it('starts a routine at its own weight when the routine it borrows from planned another', () => {
+ const B = { d: '2026-04-01', routineIds: ['b'], entries: [{ id: LIFT, rid: 'b', planned: { sets: 2, reps: 15, weight: 40 }, target: { sets: 2, reps: 15, weight: 40 }, sets: [{ w: 40, r: 15, done: true }, { w: 40, r: 15, done: true }] }] }
+ const p = nextPrescription({ unit: 'kg', workouts: [B] }, { id: LIFT, sets: 2, reps: 10, weight: 60, prog: 'linear' }, { id: 'a', ex: [] })
+ expect(p).toMatchObject({ kind: 'hold', weight: 60, reps: 10 })
+ expect(p.why[0]).toBe('First time in this routine — starting from its own target.')
+ })
+
it('opens a loaded lift logged at 0 kg at the plan\'s weight when the plan changed', () => {
const BENCH = '0025' // barbell bench press: a load nobody typed in, not a bodyweight set
const S = { unit: 'kg', workouts: [logged(BENCH, { sets: 2, reps: 15, weight: 0 }, { sets: 2, reps: 15, weight: 0 }, 0, [15, 15])] }
diff --git a/frontend/src/lib/session-start.plan.test.js b/frontend/src/lib/session-start.plan.test.js
index 7e5867873..705d58cbe 100644
--- a/frontend/src/lib/session-start.plan.test.js
+++ b/frontend/src/lib/session-start.plan.test.js
@@ -46,15 +46,27 @@ 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])
+ // A has no session of its own, so it starts from its own sets × reps (#216), and says so. Its
+ // plan asks 60 where B's asked 40 — a heavy day and a light day — so it opens at its own 60,
+ // not at the light day's load.
+ expect(work(a).map(s => s.w)).toEqual([60, 60])
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]])
+ expect(work(again).map(s => [s.w, s.r])).toEqual([[62.5, 10], [62.5, 10]])
+ })
+
+ it('from the exercise\'s last weight when the other routine planned the same one', () => {
+ const st = state([
+ { id: 'A', name: 'Plan A', ex: [{ id: BENCH, sets: 2, reps: 10, weight: 40 }] },
+ { id: 'B', name: 'Plan B', ex: [{ id: BENCH, sets: 2, reps: 15, weight: 40 }] },
+ ])
+ train(st, ['B'])
+ train(st, ['B'])
+ const [a] = start(st, ['A'])
+ expect(work(a).map(s => [s.w, s.r])).toEqual([[42.5, 10], [42.5, 10]])
})
for (const prog of [undefined, 'linear', 'greyskull', 'off']) {
@@ -160,6 +172,21 @@ describe('an edited routine starts again from its new plan', () => {
expect(start(st, ['A'])[0].plan.kind).toBe('up') // and progresses from there
})
+ // The same edit that changed the reps changed the weight: 3 × 5 @ 100 rewritten as 3 × 10 @ 70
+ // opens at 70 × 10, not at the 102.5 progression reached for fives.
+ it('opens at the plan\'s new weight when the edit changed it too', () => {
+ const st = state([{ id: 'A', name: 'A', ex: [{ id: BENCH, sets: 3, reps: 5, weight: 100 }] }])
+ train(st, ['A'])
+ train(st, ['A'])
+ expect(work(start(st, ['A'])[0]).map(s => s.w)).toEqual([105, 105, 105])
+ Object.assign(cfgOf(st, 'A'), { reps: 10, weight: 70 })
+ const [e] = start(st, ['A'])
+ expect(work(e).map(s => [s.w, s.r])).toEqual([[70, 10], [70, 10], [70, 10]])
+ expect(e.plan.why[0]).toBe('Plan changed — starting from your new target.')
+ train(st, ['A'])
+ expect(work(start(st, ['A'])[0]).map(s => [s.w, s.r])).toEqual([[72.5, 10], [72.5, 10], [72.5, 10]])
+ })
+
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'])
diff --git a/frontend/src/sheets.plan-session.test.jsx b/frontend/src/sheets.plan-session.test.jsx
index 81089d8bd..63b33c767 100644
--- a/frontend/src/sheets.plan-session.test.jsx
+++ b/frontend/src/sheets.plan-session.test.jsx
@@ -78,13 +78,14 @@ describe('what you plan is what you train', () => {
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
+ // B's first time: B's own plan, the light day's 40 at its 15 reps — not the heavy day's 60
+ expect(rowsOf('B')).toEqual(['40x15', '40x15'])
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
+ expect(rowsOf('B')).toEqual(['40x15', '40x15']) // B holds after its own miss
})
it('"Your last session" still carries the 15s over', () => {