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.

Coach: cardio keeps its mode, minutes and pace (#640)

Duarte Santos9c30183c9de1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3a9bcec75..4ce4f2566 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,11 @@ with the muscles it works lit up. No more opening Leg Day to remember it is, in
GitHub Sponsors, and on the iPhone a straight line to writing an App Store review. No pop-ups
asking for anything, promise.
+**Fixes**
+- Cardio the Coach prescribes on a non-cardio exercise (kettlebell swings for 15 minutes) stays
+ 15 minutes instead of turning into sets with no target, in new plans, in review additions and
+ in shared plan files (#640, thanks @rudycelekli for spotting the review side).
+
## v1.4.2 (2026-10-18)
openGym comes to the App Store, with an Apple Watch app in tow. Plus everything you asked for
diff --git a/api/coach/core/validate.js b/api/coach/core/validate.js
index 4fa4fe42c..b15bbb412 100644
--- a/api/coach/core/validate.js
+++ b/api/coach/core/validate.js
@@ -55,6 +55,12 @@ const isStr = v => typeof v === 'string' && v.trim().length > 0;
const isNum = v => typeof v === 'number' && Number.isFinite(v);
const isInt = (v, lo, hi) => Number.isInteger(v) && v >= lo && v <= hi;
const clampStr = (v, n) => String(v == null ? '' : v).slice(0, n);
+// The minutes and pace of a cardio exercise a review adds, in the bounds the 'cardio' change
+// holds them to. Without them the app fell back to 20 min at 8 km/h whatever was shown (#640).
+const cardioTarget = e => (e.mode !== 'cardio' ? {} : {
+ ...(isInt(e.min, 1, 180) ? { min: e.min } : {}),
+ ...(isNum(e.speed) && e.speed > 0 && e.speed <= MAX_SPEED ? { speed: e.speed } : {})
+});
// Routine icons: an icon key the app knows or a legacy emoji, never free text (#311).
export { ROUTINE_GLYPHS } from './glyphs.js';
@@ -128,6 +134,10 @@ export function validatePlan(data, ctx = {}) {
const mode = MODES.includes(e.mode) ? e.mode : 'reps';
const perSide = !!e.side;
if (mode === 'cardio') {
+ // Written out like 'time' below: without it every reader falls back to the catalogue,
+ // and a cardio finisher on a non-cardio exercise (kettlebell swings) comes out as reps
+ // with no target at all (#640).
+ clean.mode = 'cardio';
clean.min = isInt(e.min, 1, 180) ? e.min : 20;
clean.speed = isNum(e.speed) && e.speed > 0 && e.speed <= MAX_SPEED ? e.speed : 8;
} else if (mode === 'time') {
@@ -345,6 +355,7 @@ export function validateReview(data, plan, ctx = {}) {
...(MODES.includes(a.mode) ? { mode: a.mode } : { mode: 'reps' }),
...(isInt(a.reps, 1, 100) ? { reps: a.reps } : {}),
...(isInt(a.sec, 5, 3600) ? { sec: a.sec } : {}),
+ ...cardioTarget(a),
...(isNum(a.weight) && a.weight > 0 && a.weight <= MAX_WEIGHT ? { weight: a.weight } : {}),
...(POLICIES.includes(a.prog) ? { prog: a.prog } : {}),
...(isInt(a.repsMin, 1, 100) ? { repsMin: a.repsMin } : {}),
@@ -454,6 +465,7 @@ export function validateReview(data, plan, ctx = {}) {
mode: MODES.includes(e.mode) ? e.mode : 'reps',
...(isInt(e.reps, 1, 100) ? { reps: e.reps } : {}),
...(isInt(e.sec, 5, 3600) ? { sec: e.sec } : {}),
+ ...cardioTarget(e),
...(isInt(e.repsMin, 1, 100) ? { repsMin: e.repsMin } : {}),
...(isInt(e.repsMax, 1, 100) ? { repsMax: e.repsMax } : {}),
...(isInt(e.setsMax, 1, 10) ? { setsMax: e.setsMax } : {}),
diff --git a/api/test/validate.test.js b/api/test/validate.test.js
index 6953109d7..dfe4a8b1c 100644
--- a/api/test/validate.test.js
+++ b/api/test/validate.test.js
@@ -206,6 +206,25 @@ test('values are type-checked per change type', () => {
assert.equal(review([change({ type: 'inc', after: -5 })]).ok, false);
});
+test('cardio on a non-cardio exercise keeps its mode, minutes and pace (#640)', () => {
+ // 0001 is a reps exercise in the catalogue: without the mode written out, every reader falls
+ // back to reps and the 15 minutes at 10 km/h are gone.
+ const plan = validatePlan({ routines: [{ name: 'Finisher', ex: [{ id: '0001', sets: 2, mode: 'cardio', min: 15, speed: 10 }] }] });
+ assert.equal(plan.ok, true);
+ assert.deepEqual(plan.bundle.routines[0].ex[0], { id: '0001', sets: 2, mode: 'cardio', min: 15, speed: 10 });
+ const added = review([change({ type: 'add-exercise', target: { routineId: 'r1' }, after: { id: '0009', sets: 2, mode: 'cardio', min: 15, speed: 10 } })]);
+ assert.equal(added.ok, true);
+ assert.deepEqual([added.proposal.changes[0].after.min, added.proposal.changes[0].after.speed], [15, 10]);
+ const routine = review([change({ type: 'add-routine', target: {}, after: { name: 'C', ex: [{ id: '0009', sets: 2, mode: 'cardio', min: 15, speed: 99 }] } })]);
+ assert.equal(routine.ok, true);
+ const ex = routine.proposal.changes[0].after.ex[0];
+ assert.equal(ex.min, 15);
+ assert.equal(ex.speed, undefined, 'a pace past the cap is dropped, the app then uses its default');
+ // Minutes on a reps exercise mean nothing and stay out.
+ const reps = review([change({ type: 'add-exercise', target: { routineId: 'r1' }, after: { id: '0009', sets: 3, reps: 10, min: 15 } })]);
+ assert.equal(reps.proposal.changes[0].after.min, undefined);
+});
+
test('adding an exercise requires a real library id', () => {
const ok = review([change({ type: 'add-exercise', target: { routineId: 'r1' }, after: { id: '0009', sets: 3, reps: 12 } })]);
assert.equal(ok.ok, true);
diff --git a/frontend/src/lib/coach.js b/frontend/src/lib/coach.js
index 8680e6851..58a7351b1 100644
--- a/frontend/src/lib/coach.js
+++ b/frontend/src/lib/coach.js
@@ -523,7 +523,9 @@ const CHANGE_APPLY = {
...(POLICIES.includes(a.prog) ? { prog: a.prog } : {}),
ex: a.ex.map(e => ({
id: canonicalExId(e.id), sets: e.sets || 3, mode: e.mode || 'reps',
- ...(e.mode === 'time' ? { sec: e.sec || 45 } : { reps: e.reps || 10 }),
+ // The same targets and defaults as 'add-exercise': a cardio entry used to get reps (#640).
+ ...(e.mode === 'cardio' ? { min: e.min || 20, speed: e.speed || 8 }
+ : e.mode === 'time' ? { sec: e.sec || 45 } : { reps: e.reps || 10 }),
...(Number.isInteger(e.repsMax) ? { repsMax: e.repsMax } : {}),
...(Number.isInteger(e.setsMax) ? { setsMax: e.setsMax } : {}),
...(e.bodyweight != null ? { bodyweight: !!e.bodyweight } : {}),
diff --git a/frontend/src/lib/coach.test.js b/frontend/src/lib/coach.test.js
index e41063884..ac76414b5 100644
--- a/frontend/src/lib/coach.test.js
+++ b/frontend/src/lib/coach.test.js
@@ -299,6 +299,17 @@ describe('applying changes', () => {
expect(out.routines[0].ex[1].sg).toBeUndefined()
})
+ it('an added routine keeps a cardio exercise as minutes and pace, not reps (#640)', () => {
+ const out = apply(state(), proposal([change({
+ type: 'add-routine', target: {}, before: null,
+ after: { name: 'Finisher', ex: [{ id: '0001', sets: 2, mode: 'cardio', min: 15, speed: 10 }, { id: '0007', sets: 1, mode: 'cardio' }] }
+ })]), ['c1'])
+ const [swings, other] = out.routines[2].ex
+ expect(swings).toMatchObject({ mode: 'cardio', min: 15, speed: 10 })
+ expect(swings.reps).toBeUndefined()
+ expect(other).toMatchObject({ mode: 'cardio', min: 20, speed: 8 })
+ })
+
it('adds, renames and removes routines, clearing any day that pointed at one', () => {
const added = apply(state(), proposal([change({
type: 'add-routine', target: {}, before: null,
diff --git a/frontend/src/lib/plan-share.js b/frontend/src/lib/plan-share.js
index 9754e8758..93a0cddc3 100644
--- a/frontend/src/lib/plan-share.js
+++ b/frontend/src/lib/plan-share.js
@@ -74,6 +74,9 @@ function cleanEx(e) {
const o = { id: e.id, sets: e.sets }
const mode = modeOf(e)
if (mode === 'cardio') {
+ // Written out for the same reason as 'time' below: swings set to cardio would otherwise
+ // arrive as reps with no target (#640).
+ o.mode = 'cardio'
if (e.min != null) o.min = e.min
if (e.speed != null) o.speed = e.speed
} else if (mode === 'time') {
diff --git a/frontend/src/lib/plan-share.test.js b/frontend/src/lib/plan-share.test.js
index 22a27a7fc..3a3cad2f5 100644
--- a/frontend/src/lib/plan-share.test.js
+++ b/frontend/src/lib/plan-share.test.js
@@ -69,6 +69,11 @@ describe('what survives a shared plan', () => {
expect(cardio.side).toBeUndefined()
})
+ it('carries cardio set on a non-cardio exercise, mode and all (#640)', () => {
+ expect(roundTrip({ mode: 'cardio', min: 15, speed: 10, sets: 2, reps: undefined, weight: undefined }))
+ .toMatchObject({ mode: 'cardio', min: 15, speed: 10, sets: 2 })
+ })
+
it('carries a drop-set prescription', () => {
expect(roundTrip({ intensifier: { type: 'dropset', count: 2, pct: 20 } }).intensifier)
.toEqual({ type: 'dropset', count: 2, pct: 20 })