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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve questionIndex through POST drill schema so scoring pairs to correct prompt
Adam Eivydbf19260444f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdnew file mode 100644index 0000000000..2e42c5b9f6--- /dev/null+++ b/.changelog/NEXT.md@@ -0,0 +1,3 @@+## Fixed++- **POST drill scoring paired every answer to the first prompt** — `llmResponseSchema` in `postValidation.js` didn't list `questionIndex`, so Zod's default strip mode dropped the field on its way to the scorer. The scorer's `r.questionIndex ?? i` fallback then resolved to the response-array index — always 0 for the single-response submits the trainer makes — and every answer was evaluated against the FIRST prompt of the drill. Affected bridge-word, idiom-twist, double-meaning, and every other LLM-scored POST drill (the v1.43.0 client-side fix wired up `questionIndex` on the request but it never reached the scorer). Schema now declares `questionIndex` and a regression test in `postValidation.test.js` covers the round-trip.diff --git a/server/lib/postValidation.js b/server/lib/postValidation.jsindex 944ce4732f..487f0d68e9 100644--- a/server/lib/postValidation.js+++ b/server/lib/postValidation.js@@ -20,6 +20,11 @@ const questionResultSchema = z.object({// LLM drill response (text-based)const llmResponseSchema = z.object({+ // questionIndex pairs the response with the correct prompt in drillData.+ // Without it Zod's default strip would drop the field, the scorer would fall+ // back to the array index (always 0 for single-response submits), and every+ // answer would be evaluated against the first prompt.+ questionIndex: z.number().int().min(0).optional(),prompt: z.string().optional(),response: z.string().optional(),answers: z.array(z.string()).optional(),diff --git a/server/lib/postValidation.test.js b/server/lib/postValidation.test.jsnew file mode 100644index 0000000000..56544a8ecf--- /dev/null+++ b/server/lib/postValidation.test.js@@ -0,0 +1,38 @@+import { describe, it, expect } from 'vitest';+import { postLlmScoreRequestSchema } from './postValidation.js';++describe('postLlmScoreRequestSchema', () => {+ // Regression: Zod's default strip mode dropped `questionIndex` from each+ // response, so the server scorer fell back to the response-array index+ // (always 0 for single-response submits) and every answer was scored against+ // the FIRST prompt of the drill. Affected bridge-word, idiom-twist,+ // double-meaning, etc.+ it('preserves questionIndex on each response', () => {+ const parsed = postLlmScoreRequestSchema.parse({+ type: 'bridge-word',+ drillData: { puzzles: [{ answer: 'a' }, { answer: 'b' }] },+ responses: [{ questionIndex: 1, response: 'b', responseMs: 1000 }],+ timeLimitMs: 120000+ });+ expect(parsed.responses[0].questionIndex).toBe(1);+ });++ it('accepts responses without questionIndex (back-compat)', () => {+ const parsed = postLlmScoreRequestSchema.parse({+ type: 'idiom-twist',+ drillData: { challenges: [{ idiom: 'x' }] },+ responses: [{ response: 'twist', responseMs: 1000 }],+ timeLimitMs: 60000+ });+ expect(parsed.responses[0].questionIndex).toBeUndefined();+ });++ it('rejects negative questionIndex', () => {+ expect(() => postLlmScoreRequestSchema.parse({+ type: 'bridge-word',+ drillData: {},+ responses: [{ questionIndex: -1, responseMs: 0 }],+ timeLimitMs: 60000+ })).toThrow();+ });+});