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: cap the plan arrays in the schema, not only in the prompt

Konstantinos Thermos673054984510
diff --git a/api/coach/core/schemas.js b/api/coach/core/schemas.js
index 072c58fda..163b4570b 100644
--- a/api/coach/core/schemas.js
+++ b/api/coach/core/schemas.js
@@ -72,13 +72,20 @@ export const CREATE_SCHEMA = {
summary: STR,
basedOn: STR,
week: { type: 'object' },
+ // The caps are the validator's own (MAX_ROUTINES, MAX_EX_PER_ROUTINE), stated here as well
+ // because "1-7 routines, each 3-12 exercises" in create.md is only a request. A small model
+ // that starts repeating itself does not stop at a request: qwen2.5:3b walks the library id by
+ // id, three sets of eight apiece, until it hits the output limit — twelve minutes for an
+ // answer that arrives cut in half and cannot be parsed. maxItems ends that run at seven
+ // routines instead.
routines: {
type: 'array',
+ maxItems: 7,
items: {
type: 'object',
properties: {
id: STR, name: STR, emoji: STR, prog: STR, why: STR,
- ex: { type: 'array', items: EX_SCHEMA }
+ ex: { type: 'array', maxItems: 20, items: EX_SCHEMA }
},
required: ['id', 'name', 'ex']
}
diff --git a/api/test/prompt-split.test.js b/api/test/prompt-split.test.js
index aea87c9e3..deb80c373 100644
--- a/api/test/prompt-split.test.js
+++ b/api/test/prompt-split.test.js
@@ -68,6 +68,13 @@ test('the create schema requires what the week resolves through: a routine id, a
assert.ok(checked.errors.some(e => e.includes('week[1] points at "r1"')));
});
+test('the create schema caps the two arrays the validator caps, so a repeating model stops', () => {
+ // validate.js slices at MAX_ROUTINES / MAX_EX_PER_ROUTINE; a model that never stops emitting
+ // otherwise runs to the output limit first and the answer arrives truncated and unparseable.
+ assert.equal(SCHEMAS.create.properties.routines.maxItems, 7);
+ assert.equal(SCHEMAS.create.properties.routines.items.properties.ex.maxItems, 20);
+});
+
test('older sessions in a review window are compacted, the recent ones keep full sets', () => {
const many = Array.from({ length: FULL_DETAIL_SESSIONS + 4 }, (_, i) => workout('2026-08-' + String(i + 1).padStart(2, '0')));
const p = build(S(many), { handle: 'h1', kind: 'review' });