Coach: the create schema requires a routine id and a week
CREATE_SCHEMA is handed to OpenAI-compatible endpoints as a grammar to decode against, and it left both `routines[].id` and `week` optional. Small local models take that offer: llama3.2:3b and qwen2.5:3b both answer with routines that carry no id, and a week naming what they wrote into `name` instead. Nothing in the week then resolves, validate.js reports "the week schedules 0 days but 3 were asked for", the repair round produces the same answer again, and the job ends as `unusable` — "The Coach answered with something the app couldn't use." Requiring the two fields the week resolves through is enough. With them in the schema, llama3.2:3b produces a plan that passes validatePlan on the first attempt, against the payload that failed twice before. The validator is untouched; this only stops the grammar from offering an answer it can never accept.
This commit is contained in:
2 files changed
+27
-2
No files matched your search
@@ -59,6 +59,11 @@ const EX_SCHEMA = {
|
||||
required: ['id', 'sets']
|
||||
};
|
||||
|
||||
// `week` and `routines[].id` are required, not optional: the week is the only thing that says
|
||||
// which day trains which routine, and it points at a routine by id. A schema that leaves either
|
||||
// out lets a small local model answer with routines that have no id and a week naming "r1" —
|
||||
// grammar-valid, and something validate.js can only ever reject ("the week schedules 0 days but
|
||||
// 3 were asked for"), through the repair round and out as a failed job.
|
||||
export const CREATE_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -75,7 +80,7 @@ export const CREATE_SCHEMA = {
|
||||
id: STR, name: STR, emoji: STR, prog: STR, why: STR,
|
||||
ex: { type: 'array', items: EX_SCHEMA }
|
||||
},
|
||||
required: ['name', 'ex']
|
||||
required: ['id', 'name', 'ex']
|
||||
}
|
||||
},
|
||||
customEx: {
|
||||
@@ -83,7 +88,7 @@ export const CREATE_SCHEMA = {
|
||||
items: { type: 'object', properties: { id: STR, n: STR, bp: STR, desc: STR }, required: ['id', 'n'] }
|
||||
}
|
||||
},
|
||||
required: ['coach_contract', 'routines']
|
||||
required: ['coach_contract', 'week', 'routines']
|
||||
};
|
||||
|
||||
export const DEBRIEF_SCHEMA = {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { buildPrompt, buildPromptParts, taskOf } from '../coach/core/prompt.js';
|
||||
import { SCHEMAS } from '../coach/core/schemas.js';
|
||||
import { build, FULL_DETAIL_SESSIONS } from '../coach/core/payload.js';
|
||||
import { chatCompletionsSpec } from '../coach/core/adapters/openai.js';
|
||||
import { validatePlan } from '../coach/core/validate.js';
|
||||
|
||||
const S = (workouts = []) => ({
|
||||
lang: 'en', unit: 'kg', routines: [{ id: 'r1', name: 'A', ex: [{ id: '0001', sets: 3, reps: 8 }] }],
|
||||
@@ -48,6 +49,25 @@ test('every task has a flat schema — no $ref, no anyOf/oneOf (llama.cpp gramma
|
||||
assert.equal(taskOf('create', { refine: 'x' }), 'refine');
|
||||
});
|
||||
|
||||
test('the create schema requires what the week resolves through: a routine id, and a week', () => {
|
||||
// A schema handed to a grammar-constrained decoder is the only thing standing between a small
|
||||
// local model and an answer the validator can only reject. These two fields are where that
|
||||
// showed: llama3.2:3b and qwen2.5:3b both answer with routines that carry no `id` and a week
|
||||
// naming what they put in `name`, which costs a job and a repair round to find out.
|
||||
assert.ok(SCHEMAS.create.properties.routines.items.required.includes('id'));
|
||||
assert.ok(SCHEMAS.create.required.includes('week'));
|
||||
assert.equal(SCHEMAS.refine, SCHEMAS.create); // refine reuses it, same guarantee
|
||||
|
||||
const noId = {
|
||||
coach_contract: 1,
|
||||
routines: [{ name: 'r1', ex: [{ id: '0001', sets: 3, reps: 8 }] }],
|
||||
week: { 1: 'r1' }
|
||||
};
|
||||
const checked = validatePlan(noId, { daysPerWeek: 1 });
|
||||
assert.ok(!checked.ok);
|
||||
assert.ok(checked.errors.some(e => e.includes('week[1] points at "r1"')));
|
||||
});
|
||||
|
||||
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' });
|
||||
|
||||
Reference in new issue
Block a user