Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: preserve executive drill compatibility (#4445)

[._.]/ Adam Eivydc36305449bc
diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
index b4e1ff4344..b68d6dc55e 100644
--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
@@ -191,8 +191,8 @@ export function getDrillTutorial(drill) {
goal: 'Respond to go signals and withhold your response to no-go lures.',
steps: [
'A symbol appears briefly on every trial.',
- 'Tap or press Space for a green go signal.',
- 'Do nothing for a no-go lure; the next trial advances at the deadline.',
+ 'Tap or press Space for the filled-circle go signal.',
+ 'Do nothing for a square or ringed-circle lure; the next trial advances at the deadline.',
],
controls: 'Tap the signal, or press Space / Enter. Withhold on no-go.',
};
@@ -1704,6 +1704,7 @@ function GoNoGoRunner({ drill, drillIndex, drillCount, onComplete, isTraining })
}, []);
const trial = trials[trialIdx];
+ const symbolLabel = { '●': 'filled circle', '◉': 'ringed circle', '■': 'filled square' }[trial?.symbol] || 'signal';
const toneClass = trial?.tone === 'red' ? 'text-port-error' : trial?.tone === 'amber' ? 'text-port-warning' : 'text-port-success';
const progressPct = trials.length ? (trialIdx / trials.length) * 100 : 0;
return (
@@ -1712,7 +1713,7 @@ function GoNoGoRunner({ drill, drillIndex, drillCount, onComplete, isTraining })
<p className="text-center text-sm text-gray-400">Press for <span className="text-port-success font-medium">green go</span>. Withhold for red or amber no-go lures.</p>
<button
type="button"
- aria-label={trial?.kind === 'no-go' ? 'No-go lure — withhold' : 'Go signal — respond'}
+ aria-label={symbolLabel}
onClick={() => recordRef.current(true)}
disabled={!accepting}
className="mx-auto w-48 h-48 rounded-2xl border border-port-border bg-port-card flex items-center justify-center disabled:opacity-70 motion-reduce:transition-none"
diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
index 57a247b54f..a09243ee15 100644
--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
@@ -715,9 +715,9 @@ describe('executive-control runners', () => {
onComplete={onComplete}
isTraining={false}
/>);
- fireEvent.click(screen.getByRole('button', { name: /go signal.*respond/i }));
+ fireEvent.click(screen.getByRole('button', { name: 'filled circle' }));
act(() => vi.advanceTimersByTime(251));
- expect(screen.getByRole('button', { name: /no-go lure.*withhold/i })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'filled square' })).toBeInTheDocument();
act(() => vi.advanceTimersByTime(501));
act(() => vi.advanceTimersByTime(251));
expect(onComplete).toHaveBeenCalledTimes(1);
diff --git a/server/lib/postValidation.js b/server/lib/postValidation.js
index ee83ab81a1..89700a7388 100644
--- a/server/lib/postValidation.js
+++ b/server/lib/postValidation.js
@@ -325,9 +325,12 @@ export const postConfigUpdateSchema = z.object({
drillTypes: z.record(z.enum(LLM_DRILL_TYPES), llmDrillTypeConfigSchema).optional()
}).optional(),
// Deterministic cognitive drills — no provider, so no provider/model fields.
+ // Partial so an older browser's complete pre-executive-control map remains a
+ // valid patch after newer drill types are added to the enum (Zod 4 records
+ // with enum keys are otherwise exhaustive).
cognitive: z.object({
enabled: z.boolean().optional(),
- drillTypes: z.record(z.enum(COGNITIVE_DRILL_TYPES), drillTypeConfigSchema).optional()
+ drillTypes: z.partialRecord(z.enum(COGNITIVE_DRILL_TYPES), drillTypeConfigSchema).optional()
}).optional(),
// Memory practice (issue #3252). Mirrors the other module blocks, plus an
// `items` map so an INDIVIDUAL memorized text — e.g. the seeded Elements Song
diff --git a/server/lib/postValidation.test.js b/server/lib/postValidation.test.js
index fa2f76db8e..9b4355fc78 100644
--- a/server/lib/postValidation.test.js
+++ b/server/lib/postValidation.test.js
@@ -73,6 +73,15 @@ describe('postConfigUpdateSchema llmDrills', () => {
});
});
+describe('postConfigUpdateSchema cognitive compatibility', () => {
+ it('accepts a legacy six-drill map after newer cognitive types are added', () => {
+ const legacyTypes = ['n-back', 'digit-span', 'stroop', 'schulte-table', 'mental-rotation', 'reaction-time'];
+ const drillTypes = Object.fromEntries(legacyTypes.map(type => [type, { enabled: true }]));
+ const parsed = postConfigUpdateSchema.parse({ cognitive: { enabled: true, drillTypes } });
+ expect(Object.keys(parsed.cognitive.drillTypes)).toEqual(legacyTypes);
+ });
+});
+
describe('Morse drill types stay scoped to the training log', () => {
// Regression: MORSE_DRILL_TYPES must never be spliced into the shared
// DRILL_TYPES array — that array also backs the *scored* session submit
diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.js
index 54e8558c00..4a4605a284 100644
--- a/server/services/meatspacePost.js
+++ b/server/services/meatspacePost.js
@@ -730,7 +730,9 @@ function trainingEntryTask(entry) {
const correctCount = Number.isFinite(rawCorrectCount)
? Math.max(0, Math.min(questionCount, rawCorrectCount))
: 0;
- const accuracy = questionCount > 0 ? correctCount / questionCount : null;
+ const accuracy = typeof entry?.accuracy === 'number'
+ ? entry.accuracy
+ : questionCount > 0 ? correctCount / questionCount : null;
return {
id: entry?.id,
module: entry?.module,
@@ -740,7 +742,9 @@ function trainingEntryTask(entry) {
score: Number.isFinite(entry?.score) ? entry.score : (accuracy == null ? null : accuracy * 100),
accuracy,
completion: typeof entry?.completion === 'number' ? entry.completion : (questionCount > 0 ? 1 : null),
- avgResponseMs: questionCount > 0 ? (entry?.totalMs || 0) / questionCount : null,
+ avgResponseMs: typeof entry?.avgResponseMs === 'number'
+ ? entry.avgResponseMs
+ : questionCount > 0 ? (entry?.totalMs || 0) / questionCount : null,
totalMs: entry?.totalMs || 0,
totalCount: questionCount,
};
diff --git a/server/services/meatspacePost.test.js b/server/services/meatspacePost.test.js
index 0d113e2e95..1a01440e89 100644
--- a/server/services/meatspacePost.test.js
+++ b/server/services/meatspacePost.test.js
@@ -2031,10 +2031,11 @@ describe('progressive cognitive drills', () => {
};
}
- function mockSessions(sessions, configOverride) {
+ function mockSessions(sessions, configOverride, training = []) {
readJSONFile.mockImplementation((path, defaultValue) => {
const p = String(path);
if (p.includes('post-sessions')) return Promise.resolve({ sessions });
+ if (p.includes('post-training-log')) return Promise.resolve({ entries: training });
if (p.includes('post-config')) return Promise.resolve(configOverride ?? defaultValue);
return Promise.resolve(defaultValue);
});
@@ -2189,6 +2190,29 @@ describe('progressive cognitive drills', () => {
expect(Object.keys(progress).sort()).toEqual(['digit-span', 'flanker', 'go-no-go', 'mental-rotation', 'n-back', 'schulte-table', 'stroop', 'task-switching']);
});
+ it('uses authoritative training accuracy and latency instead of raw totals', async () => {
+ const training = Array.from({ length: 3 }, (_, index) => ({
+ id: `go-no-go-${index}`,
+ runId: `run-${index}`,
+ date: today,
+ timestamp: `${today}T12:00:00.000Z`,
+ module: 'cognitive',
+ drillType: 'go-no-go',
+ difficulty: { level: 0 },
+ questionCount: 20,
+ correctCount: 16,
+ accuracy: 0.5,
+ completion: 1,
+ avgResponseMs: 300,
+ totalMs: 30000,
+ }));
+ mockSessions([], undefined, training);
+
+ const progress = await getCognitiveProgress();
+ expect(progress['go-no-go'].level).toBe(0);
+ expect(progress['go-no-go'].levels[0]).toMatchObject({ accuracy: 0.5, avgResponseMs: 300, mastered: false });
+ });
+
it('difficulty stamp survives submitPostSession (stored task carries config.level)', async () => {
mockSessions([]);
const { config } = await resolveDrillConfig('schulte-table', {});
diff --git a/server/services/meatspacePostTraining.js b/server/services/meatspacePostTraining.js
index 83f89aa293..6fe6b95152 100644
--- a/server/services/meatspacePostTraining.js
+++ b/server/services/meatspacePostTraining.js
@@ -19,7 +19,8 @@ function trainingAttempt(runId, attempt, position, localDay, startedAt) {
// Training uses the same server-authoritative deterministic scorer as scored
// sessions. The client sends drillData + raw answers for immediate feedback,
// but its correctness, score, error counts, and cost metrics are advisory.
- const scored = COGNITIVE_DRILL_TYPES.includes(attempt.drillType)
+ const hasAnswerKey = attempt.drillData?.type === attempt.drillType;
+ const scored = COGNITIVE_DRILL_TYPES.includes(attempt.drillType) && hasAnswerKey
? scoreCognitiveDrill(attempt.drillType, attempt.drillData, attempt.questions || [])
: null;
const normalized = scored ? { ...attempt, ...scored, scorerProvenance: 'server-deterministic' } : attempt;
@@ -120,9 +121,11 @@ export async function submitTrainingRun(input) {
config: attempt.difficulty || {},
questions: attempt.data?.questions || [],
score: attempt.score,
- accuracy: attempt.data?.questionCount > 0
- ? attempt.data.correctCount / attempt.data.questionCount
- : null,
+ accuracy: typeof attempt.data?.accuracy === 'number'
+ ? attempt.data.accuracy
+ : attempt.data?.questionCount > 0
+ ? attempt.data.correctCount / attempt.data.questionCount
+ : null,
completion: attempt.completion,
})),
}, new Date(saved.run.completedAt || now));
diff --git a/server/services/meatspacePostTraining.test.js b/server/services/meatspacePostTraining.test.js
index 70458e4e4a..b877a3370a 100644
--- a/server/services/meatspacePostTraining.test.js
+++ b/server/services/meatspacePostTraining.test.js
@@ -201,6 +201,29 @@ describe('submitTrainingRun (#4441)', () => {
expect(stored.entries[0].latencyDistributionMs).toHaveLength(6);
expect(stored.entries[0].questions.every(question => question.correct)).toBe(true);
});
+
+ it('preserves legacy cognitive results when no generated answer key is present', async () => {
+ const saved = await submitTrainingRun({
+ id: '33333333-3333-4333-8333-333333333333',
+ attempts: [{
+ id: 'legacy-stroop',
+ module: 'cognitive',
+ drillType: 'stroop',
+ questionCount: 2,
+ correctCount: 1,
+ latencyMs: 1500,
+ score: 50,
+ questions: [{ answered: 'red', correct: true }, { answered: 'blue', correct: false }],
+ }],
+ });
+
+ expect(saved.attempts[0]).toMatchObject({
+ id: 'legacy-stroop',
+ correctCount: 1,
+ score: 50,
+ scorerProvenance: 'post-client',
+ });
+ });
});
describe('getTrainingStats', () => {