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

feat([issue-2093]): per-question mistake review in POST session results

Adam Eivy833f736924f7
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 894946cf08..39328be1b8 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,6 +6,7 @@
## MeatSpace POST
+- **[issue-2093] Session results now teach from mistakes on every drill, not just AI ones.** Expanding a math, memory, or cognitive (n-back, digit-span, Stroop, Schulte table, mental rotation, reaction time) drill row on the results screen used to do nothing — only AI-scored drills showed a review. Every drill row now expands into a per-question/per-trial breakdown: a "missed items" summary up top, then a type-appropriate view — a prompt/answer/expected table for math and memory, letter-sequence hit/miss/false-alarm marks for n-back, shown-vs-recalled digits for digit span, word/ink/your-answer for Stroop, and per-trial timing with slow-response outliers flagged for the pure speed drills. Unanswered questions are shown distinctly from wrong ones. The same review now also appears when you expand a past session in History.
- **Multiplication drills now ramp up instead of starting hard.** The mental-math multiplication drill used to open at a fixed 2-digit × 2-digit difficulty (e.g. `566 × 191`) for everyone. It now climbs a mastery-gated ladder — `1×1` → `1×2` → `1×1×1` → `2×2` → … — starting at single-digit × single-digit and advancing to the next rung only after you answer a level quickly *and* accurately (≥90% correct within a per-rung speed target). The drill header and the config page show your current rung and per-level mastery. On by default; turn off "Progressive difficulty" on the Multiplication card to go back to the manual Max Digits setting.
- **Morse trainer audio now works on mobile Safari.** iOS Safari starts the Web Audio context suspended and only unlocks it once `resume()` fully settles. The trainer fired `resume()` without awaiting it, so the first tones were scheduled against a still-suspended clock and never sounded on iPhone/iPad. It now awaits the resume before scheduling any tone (matching the app's other audio modules), so Copy, Head Copy, and Send-mode keying all produce sound on mobile Safari.
- **The Elements Song trainer is now mobile-friendly and speed-readable.** The periodic-table memorization view no longer overflows off the right edge of a phone screen: the mastery summary, search box, and Mastery/Category toggle now stack and stretch to full width on small screens, the periodic table uses smaller cells (with a scroll-hint fade so it's clear the grid pans horizontally), and the header shrinks to fit. It also gained a **Rapid Read** practice mode that RSVP-flashes the lyrics one word at a time (reusing the app's speed reader) — run the whole song from the Practice list, or tap the gauge icon on any verse to speed-read just that section.
diff --git a/client/src/components/meatspace/post/DrillQuestionReview.jsx b/client/src/components/meatspace/post/DrillQuestionReview.jsx
new file mode 100644
index 0000000000..e6ba59e481
--- /dev/null
+++ b/client/src/components/meatspace/post/DrillQuestionReview.jsx
@@ -0,0 +1,365 @@
+import { Check, X, MinusCircle, AlertTriangle } from 'lucide-react';
+
+// Sub-second precision — most drill response times are under a few seconds,
+// so the shared `formatDurationMs` (client/src/utils/formatters.js), which
+// floors to whole seconds and shows "0s" for anything under 1000ms, is too
+// coarse for a per-question review. This is a deliberately separate,
+// narrower formatter for that reason.
+const fmtMs = (ms) => `${(Math.max(0, ms || 0) / 1000).toFixed(1)}s`;
+
+const isUnanswered = (q) => q.answered === null || q.answered === undefined;
+
+function ResultIcon({ correct, unanswered }) {
+ if (unanswered) return <MinusCircle size={13} className="text-gray-500 shrink-0" />;
+ return correct
+ ? <Check size={13} className="text-port-success shrink-0" />
+ : <X size={13} className="text-port-error shrink-0" />;
+}
+
+const rowTint = (correct, unanswered) => {
+ if (unanswered) return 'bg-port-bg/40 text-gray-500';
+ return correct === false ? 'bg-port-error/10' : '';
+};
+
+function TableShell({ children }) {
+ return (
+ <div className="overflow-x-auto -mx-1 px-1">
+ <table className="w-full text-xs min-w-[420px]">{children}</table>
+ </div>
+ );
+}
+
+// Leads every review with the misses so a mistake is visible before scrolling
+// through the full per-question list (issue #2093 acceptance criterion #3).
+function MissedSummary({ missed, formatPrompt }) {
+ if (!missed.length) {
+ return (
+ <div className="flex items-center gap-1.5 text-xs text-port-success mb-3">
+ <Check size={13} />
+ No misses
+ </div>
+ );
+ }
+ const shown = missed.slice(0, 8);
+ const extra = missed.length - shown.length;
+ return (
+ <div className="mb-3">
+ <div className="flex items-center gap-1.5 text-xs text-port-error font-medium mb-1.5">
+ <X size={13} />
+ {missed.length} missed
+ </div>
+ <div className="flex flex-wrap gap-1.5">
+ {shown.map((q, i) => (
+ <span
+ key={i}
+ className="text-xs px-1.5 py-0.5 rounded bg-port-error/10 text-port-error border border-port-error/20 font-mono"
+ >
+ {formatPrompt(q)}
+ </span>
+ ))}
+ {extra > 0 && <span className="text-xs text-gray-500 self-center">+{extra} more</span>}
+ </div>
+ </div>
+ );
+}
+
+// =============================================================================
+// GENERIC — math, memory, mental-rotation (and any future non-cognitive/LLM
+// drill type): prompt / your answer / expected / result / time.
+// =============================================================================
+function formatGenericValue(type, value) {
+ if (value === null || value === undefined || value === '') return '—';
+ if (type === 'mental-rotation' && Number.isInteger(value)) return `Option ${value + 1}`;
+ return String(value);
+}
+
+function GenericReview({ questions, missed, type }) {
+ return (
+ <div>
+ <MissedSummary missed={missed} formatPrompt={(q) => q.prompt} />
+ <TableShell>
+ <thead>
+ <tr className="text-gray-500 text-left border-b border-port-border">
+ <th className="py-1 pr-2 font-medium">Prompt</th>
+ <th className="py-1 pr-2 font-medium">Your answer</th>
+ <th className="py-1 pr-2 font-medium">Expected</th>
+ <th className="py-1 pr-2 font-medium text-center">Result</th>
+ <th className="py-1 pl-2 font-medium text-right">Time</th>
+ </tr>
+ </thead>
+ <tbody>
+ {questions.map((q, i) => {
+ const unanswered = isUnanswered(q);
+ return (
+ <tr key={i} className={`border-b border-port-border/30 ${rowTint(q.correct, unanswered)}`}>
+ <td className="py-1 pr-2 font-mono text-white">{q.prompt}</td>
+ <td className="py-1 pr-2 font-mono">
+ {unanswered
+ ? <span className="italic text-gray-500">skipped</span>
+ : formatGenericValue(type, q.answered)}
+ </td>
+ <td className="py-1 pr-2 font-mono text-port-success">{formatGenericValue(type, q.expected)}</td>
+ <td className="py-1 pr-2 text-center"><ResultIcon correct={q.correct} unanswered={unanswered} /></td>
+ <td className="py-1 pl-2 text-right text-gray-400 font-mono">{fmtMs(q.responseMs)}</td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </TableShell>
+ </div>
+ );
+}
+
+// =============================================================================
+// N-BACK — a letter sequence rendered as chips, colored by signal-detection
+// outcome (hit / false alarm / miss / correct rejection). Derived purely from
+// `answered`/`correct` — no separate `isTarget` field is stored on the
+// question, so this classification IS the answer-key reconstruction.
+// =============================================================================
+const NBACK_STYLES = {
+ hit: 'bg-port-success/20 border-port-success/50 text-port-success',
+ falseAlarm: 'bg-port-warning/20 border-port-warning/50 text-port-warning',
+ miss: 'bg-port-error/20 border-port-error/50 text-port-error',
+ reject: 'bg-port-bg border-port-border/50 text-gray-500',
+};
+const NBACK_LABELS = { hit: 'Hit', falseAlarm: 'False alarm', miss: 'Miss', reject: 'Correct reject' };
+
+function classifyNBack(q) {
+ const pressed = q.answered === 'match';
+ if (pressed && q.correct) return 'hit';
+ if (pressed && !q.correct) return 'falseAlarm';
+ if (!pressed && q.correct) return 'reject';
+ return 'miss';
+}
+
+function NBackReview({ questions, missed }) {
+ const counts = questions.reduce((acc, q) => {
+ const cls = classifyNBack(q);
+ acc[cls] = (acc[cls] || 0) + 1;
+ return acc;
+ }, {});
+
+ return (
+ <div>
+ <MissedSummary missed={missed} formatPrompt={(q) => q.prompt} />
+ <div className="flex flex-wrap gap-1 mb-2">
+ {questions.map((q, i) => {
+ const cls = classifyNBack(q);
+ return (
+ <span
+ key={i}
+ title={`${NBACK_LABELS[cls]} · ${fmtMs(q.responseMs)}`}
+ className={`w-7 h-7 flex items-center justify-center rounded border font-mono text-xs font-semibold ${NBACK_STYLES[cls]}`}
+ >
+ {q.prompt}
+ </span>
+ );
+ })}
+ </div>
+ <div className="flex flex-wrap gap-3 text-xs text-gray-500">
+ {['hit', 'falseAlarm', 'miss', 'reject'].filter((k) => counts[k]).map((k) => (
+ <span key={k} className="flex items-center gap-1.5">
+ <span className={`w-2.5 h-2.5 rounded-sm border ${NBACK_STYLES[k]}`} />
+ {NBACK_LABELS[k]} ({counts[k]})
+ </span>
+ ))}
+ </div>
+ </div>
+ );
+}
+
+// =============================================================================
+// DIGIT SPAN — shown digits vs recalled digits, per round.
+// =============================================================================
+function DigitSpanReview({ questions, missed }) {
+ return (
+ <div>
+ <MissedSummary missed={missed} formatPrompt={(q) => q.prompt} />
+ <TableShell>
+ <thead>
+ <tr className="text-gray-500 text-left border-b border-port-border">
+ <th className="py-1 pr-2 font-medium">Round</th>
+ <th className="py-1 pr-2 font-medium">Shown</th>
+ <th className="py-1 pr-2 font-medium">Recalled</th>
+ <th className="py-1 pr-2 font-medium text-center">Result</th>
+ <th className="py-1 pl-2 font-medium text-right">Time</th>
+ </tr>
+ </thead>
+ <tbody>
+ {questions.map((q, i) => {
+ const unanswered = isUnanswered(q);
+ return (
+ <tr key={i} className={`border-b border-port-border/30 ${rowTint(q.correct, unanswered)}`}>
+ <td className="py-1 pr-2 text-gray-400">{q.prompt}</td>
+ <td className="py-1 pr-2 font-mono text-white tracking-widest">{q.expected ?? '—'}</td>
+ <td className="py-1 pr-2 font-mono tracking-widest">
+ {unanswered ? <span className="italic text-gray-500 tracking-normal">skipped</span> : q.answered}
+ </td>
+ <td className="py-1 pr-2 text-center"><ResultIcon correct={q.correct} unanswered={unanswered} /></td>
+ <td className="py-1 pl-2 text-right text-gray-400 font-mono">{fmtMs(q.responseMs)}</td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </TableShell>
+ </div>
+ );
+}
+
+// =============================================================================
+// STROOP — word vs ink color vs your answer, with a color swatch per name.
+// The swatch hex map comes from `drillData.options` (the drill's generated
+// STROOP_COLORS mirror) — falls back to plain text if drillData is absent.
+// =============================================================================
+function StroopReview({ questions, missed, drillData }) {
+ const colorHex = {};
+ for (const opt of drillData?.options || []) colorHex[opt.name] = opt.hex;
+
+ const Swatch = ({ name }) => (
+ name && colorHex[name]
+ ? <span className="inline-block w-2.5 h-2.5 rounded-full mr-1 align-middle" style={{ backgroundColor: colorHex[name] }} />
+ : null
+ );
+
+ return (
+ <div>
+ <MissedSummary missed={missed} formatPrompt={(q) => q.prompt} />
+ <TableShell>
+ <thead>
+ <tr className="text-gray-500 text-left border-b border-port-border">
+ <th className="py-1 pr-2 font-medium">Word</th>
+ <th className="py-1 pr-2 font-medium">Ink color</th>
+ <th className="py-1 pr-2 font-medium">Your answer</th>
+ <th className="py-1 pr-2 font-medium text-center">Result</th>
+ <th className="py-1 pl-2 font-medium text-right">Time</th>
+ </tr>
+ </thead>
+ <tbody>
+ {questions.map((q, i) => {
+ const unanswered = isUnanswered(q);
+ return (
+ <tr key={i} className={`border-b border-port-border/30 ${rowTint(q.correct, unanswered)}`}>
+ <td className="py-1 pr-2 font-mono text-white uppercase">{q.prompt}</td>
+ <td className="py-1 pr-2 capitalize"><Swatch name={q.expected} />{q.expected || '—'}</td>
+ <td className="py-1 pr-2 capitalize">
+ {unanswered
+ ? <span className="italic text-gray-500 normal-case">skipped</span>
+ : <><Swatch name={q.answered} />{q.answered}</>}
+ </td>
+ <td className="py-1 pr-2 text-center"><ResultIcon correct={q.correct} unanswered={unanswered} /></td>
+ <td className="py-1 pl-2 text-right text-gray-400 font-mono">{fmtMs(q.responseMs)}</td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </TableShell>
+ </div>
+ );
+}
+
+// =============================================================================
+// SCHULTE TABLE / REACTION TIME — pure speed drills: per-trial time with
+// outliers flagged (response time > mean + 1.5 SD over the genuinely-timed
+// trials — false starts and skips are excluded from the baseline so one
+// anomalous trial can't skew the threshold for the rest).
+// =============================================================================
+function computeOutlierIndices(questions) {
+ const timed = questions
+ .map((q, i) => ({ i, ms: q.responseMs || 0 }))
+ .filter(({ i }) => !questions[i].falseStart && questions[i].answered != null);
+ const outliers = new Set();
+ if (timed.length < 3) return outliers;
+ const mean = timed.reduce((s, t) => s + t.ms, 0) / timed.length;
+ const variance = timed.reduce((s, t) => s + (t.ms - mean) ** 2, 0) / timed.length;
+ const stddev = Math.sqrt(variance);
+ if (stddev <= 0) return outliers;
+ const threshold = mean + 1.5 * stddev;
+ timed.forEach(({ i, ms }) => { if (ms > threshold) outliers.add(i); });
+ return outliers;
+}
+
+function TimingReview({ questions, missed, type }) {
+ const isReaction = type === 'reaction-time';
+ const outlierIdx = computeOutlierIndices(questions);
+
+ return (
+ <div>
+ <MissedSummary missed={missed} formatPrompt={(q) => q.prompt} />
+ <TableShell>
+ <thead>
+ <tr className="text-gray-500 text-left border-b border-port-border">
+ <th className="py-1 pr-2 font-medium">#</th>
+ <th className="py-1 pr-2 font-medium">Status</th>
+ <th className="py-1 pl-2 font-medium text-right">Time</th>
+ </tr>
+ </thead>
+ <tbody>
+ {questions.map((q, i) => {
+ const isOutlier = outlierIdx.has(i);
+ let statusText;
+ let statusCls;
+ let StatusIcon;
+ if (isReaction && q.falseStart) {
+ statusText = 'False start'; statusCls = 'text-port-warning'; StatusIcon = AlertTriangle;
+ } else if (q.correct) {
+ statusText = isReaction ? 'Correct' : 'Found'; statusCls = 'text-port-success'; StatusIcon = Check;
+ } else {
+ statusText = q.answered == null ? 'No response' : 'Wrong'; statusCls = 'text-port-error'; StatusIcon = X;
+ }
+ // Not reusing the shared `rowTint` helper here: a false start is
+ // "answered: null" like a skip, but should read as a distinct
+ // warning (via the Status column) rather than the muted
+ // unanswered-row treatment the other reviews use.
+ return (
+ <tr key={i} className={`border-b border-port-border/30 ${q.correct === false && !q.falseStart ? 'bg-port-error/10' : ''}`}>
+ <td className="py-1 pr-2 text-gray-400 font-mono">{i + 1}</td>
+ <td className="py-1 pr-2">
+ <span className={`inline-flex items-center gap-1 ${statusCls}`}>
+ <StatusIcon size={12} />
+ {statusText}
+ </span>
+ </td>
+ <td className="py-1 pl-2 text-right font-mono">
+ <span className={isOutlier ? 'text-port-warning' : 'text-gray-400'}>{fmtMs(q.responseMs)}</span>
+ {isOutlier && <AlertTriangle size={11} className="inline-block ml-1 mb-0.5 text-port-warning" aria-label="Outlier response time" />}
+ </td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </TableShell>
+ </div>
+ );
+}
+
+/**
+ * Per-question / per-trial mistake review, shared by PostSessionResults (the
+ * just-finished session) and PostHistory (a past session's expanded detail).
+ * Dispatches on drill `type` — math/memory/mental-rotation share a generic
+ * prompt/answered/expected table; n-back, digit-span, stroop, and the two
+ * pure-speed drills (schulte-table/reaction-time) each get a type-appropriate
+ * view because their `questions[]` capture different things per trial.
+ *
+ * `drillData` is the generated drill (only used by Stroop, to look up each
+ * color's swatch hex) — optional, and safely ignored by every other type.
+ */
+export default function DrillQuestionReview({ type, questions, drillData }) {
+ const list = questions || [];
+ if (!list.length) return null;
+
+ const missed = list.filter((q) => q.correct === false);
+
+ switch (type) {
+ case 'n-back':
+ return <NBackReview questions={list} missed={missed} />;
+ case 'digit-span':
+ return <DigitSpanReview questions={list} missed={missed} />;
+ case 'stroop':
+ return <StroopReview questions={list} missed={missed} drillData={drillData} />;
+ case 'schulte-table':
+ case 'reaction-time':
+ return <TimingReview questions={list} missed={missed} type={type} />;
+ default:
+ return <GenericReview questions={list} missed={missed} type={type} />;
+ }
+}
diff --git a/client/src/components/meatspace/post/DrillQuestionReview.test.jsx b/client/src/components/meatspace/post/DrillQuestionReview.test.jsx
new file mode 100644
index 0000000000..9a046757c4
--- /dev/null
+++ b/client/src/components/meatspace/post/DrillQuestionReview.test.jsx
@@ -0,0 +1,162 @@
+import { describe, it, expect } from 'vitest';
+import { render, screen, within } from '@testing-library/react';
+import DrillQuestionReview from './DrillQuestionReview';
+
+// Shared per-question/per-trial mistake review (issue #2093). Covers the
+// generic math/memory table, and the type-appropriate cognitive views —
+// each drill family's `questions[]` shape captures different things per
+// trial, so the dispatch-by-type behavior is the load-bearing contract here.
+//
+// The missed-items summary chip re-renders each missed question's `prompt`,
+// so table assertions are scoped with `within(table)` to avoid ambiguous
+// double-matches against that chip.
+
+describe('DrillQuestionReview — generic (math/memory/fallback)', () => {
+ const questions = [
+ { prompt: '6 x 7', expected: 42, answered: 41, correct: false, responseMs: 2200 },
+ { prompt: '3 x 3', expected: 9, answered: 9, correct: true, responseMs: 900 },
+ { prompt: '8 x 8', expected: 64, answered: null, correct: false, responseMs: 0 },
+ ];
+
+ it('renders every question with prompt, answered, and expected', () => {
+ const { container } = render(<DrillQuestionReview type="multiplication" questions={questions} />);
+ const table = within(container.querySelector('table'));
+ expect(table.getByText('6 x 7')).toBeInTheDocument();
+ expect(table.getByText('41')).toBeInTheDocument();
+ expect(table.getByText('42')).toBeInTheDocument();
+ expect(table.getAllByText('9')).toHaveLength(2); // correct row: answered === expected
+ });
+
+ it('leads with a missed-items summary counting only the incorrect questions', () => {
+ render(<DrillQuestionReview type="multiplication" questions={questions} />);
+ expect(screen.getByText('2 missed')).toBeInTheDocument();
+ });
+
+ it('shows "No misses" when every question is correct', () => {
+ render(<DrillQuestionReview type="multiplication" questions={[questions[1]]} />);
+ expect(screen.getByText('No misses')).toBeInTheDocument();
+ });
+
+ it('renders an unanswered question as "skipped", distinct from a wrong answer', () => {
+ const { container } = render(<DrillQuestionReview type="multiplication" questions={questions} />);
+ const table = within(container.querySelector('table'));
+ expect(table.getByText('skipped')).toBeInTheDocument();
+ // The wrong-but-answered question still shows its actual (incorrect) value.
+ expect(table.getByText('41')).toBeInTheDocument();
+ });
+
+ it('formats mental-rotation option indices as human-readable option numbers', () => {
+ render(
+ <DrillQuestionReview
+ type="mental-rotation"
+ questions={[{ prompt: 'shape L', expected: 1, answered: 0, correct: false, responseMs: 650 }]}
+ />
+ );
+ expect(screen.getByText('Option 2')).toBeInTheDocument(); // expected (index 1)
+ expect(screen.getByText('Option 1')).toBeInTheDocument(); // answered (index 0)
+ });
+
+ it('renders nothing when there are no questions', () => {
+ const { container } = render(<DrillQuestionReview type="multiplication" questions={[]} />);
+ expect(container).toBeEmptyDOMElement();
+ });
+});
+
+describe('DrillQuestionReview — n-back', () => {
+ // Classification is derived purely from answered+correct (no isTarget field
+ // is stored on the question) — this is the reconstruction under test.
+ const questions = [
+ { prompt: 'A', index: 2, expected: 'match', answered: 'match', correct: true, responseMs: 400 }, // hit
+ { prompt: 'C', index: 3, expected: 'no-match', answered: 'match', correct: false, responseMs: 300 }, // false alarm
+ { prompt: 'B', index: 4, expected: 'match', answered: null, correct: false, responseMs: 0 }, // miss
+ { prompt: 'D', index: 5, expected: 'no-match', answered: null, correct: true, responseMs: 0 }, // correct reject
+ ];
+
+ it('classifies every trial as hit / false alarm / miss / correct reject', () => {
+ render(<DrillQuestionReview type="n-back" questions={questions} />);
+ expect(screen.getByText(/Hit \(1\)/)).toBeInTheDocument();
+ expect(screen.getByText(/False alarm \(1\)/)).toBeInTheDocument();
+ expect(screen.getByText(/Miss \(1\)/)).toBeInTheDocument();
+ expect(screen.getByText(/Correct reject \(1\)/)).toBeInTheDocument();
+ });
+
+ it('counts the false alarm and the miss as the 2 "missed" trials', () => {
+ render(<DrillQuestionReview type="n-back" questions={questions} />);
+ expect(screen.getByText('2 missed')).toBeInTheDocument();
+ });
+});
+
+describe('DrillQuestionReview — digit-span', () => {
+ it('shows the shown digits (expected) alongside the recalled digits (answered)', () => {
+ const questions = [
+ { prompt: '3-digit (forward)', index: 0, expected: '123', answered: '124', correct: false, responseMs: 1500, length: 3 },
+ ];
+ render(<DrillQuestionReview type="digit-span" questions={questions} />);
+ expect(screen.getByText('123')).toBeInTheDocument();
+ expect(screen.getByText('124')).toBeInTheDocument();
+ });
+
+ it('renders a skipped round distinctly, not as a wrong recall', () => {
+ const questions = [
+ { prompt: '3-digit (forward)', index: 0, expected: '123', answered: null, correct: false, responseMs: 0, length: 3 },
+ ];
+ render(<DrillQuestionReview type="digit-span" questions={questions} />);
+ expect(screen.getByText('skipped')).toBeInTheDocument();
+ expect(screen.getByText('123')).toBeInTheDocument();
+ });
+});
+
+describe('DrillQuestionReview — stroop', () => {
+ it('renders the word, the ink color (expected), and the picked answer', () => {
+ const questions = [
+ { prompt: 'RED', index: 0, expected: 'blue', answered: 'red', correct: false, responseMs: 800 },
+ ];
+ const drillData = { options: [{ name: 'blue', hex: '#3b82f6' }, { name: 'red', hex: '#ef4444' }] };
+ const { container } = render(<DrillQuestionReview type="stroop" questions={questions} drillData={drillData} />);
+ const table = within(container.querySelector('table'));
+ expect(table.getByText('RED')).toBeInTheDocument();
+ expect(table.getByText('blue')).toBeInTheDocument();
+ expect(table.getByText('red')).toBeInTheDocument();
+ });
+
+ it('does not crash when drillData is absent (falls back to plain text, no swatch)', () => {
+ const questions = [
+ { prompt: 'GREEN', index: 0, expected: 'green', answered: 'green', correct: true, responseMs: 400 },
+ ];
+ render(<DrillQuestionReview type="stroop" questions={questions} />);
+ expect(screen.getByText('GREEN')).toBeInTheDocument();
+ });
+});
+
+describe('DrillQuestionReview — schulte-table / reaction-time timing review', () => {
+ it('flags a response time far above the others as an outlier', () => {
+ const questions = [
+ { prompt: '1', index: 0, expected: 1, answered: 1, correct: true, responseMs: 500 },
+ { prompt: '2', index: 1, expected: 2, answered: 2, correct: true, responseMs: 520 },
+ { prompt: '3', index: 2, expected: 3, answered: 3, correct: true, responseMs: 510 },
+ { prompt: '4', index: 3, expected: 4, answered: 4, correct: true, responseMs: 6000 },
+ ];
+ const { container } = render(<DrillQuestionReview type="schulte-table" questions={questions} />);
+ expect(container.querySelector('[aria-label="Outlier response time"]')).toBeInTheDocument();
+ });
+
+ it('does not flag anything as an outlier when times are all similar', () => {
+ const questions = [
+ { prompt: '1', index: 0, expected: 1, answered: 1, correct: true, responseMs: 500 },
+ { prompt: '2', index: 1, expected: 2, answered: 2, correct: true, responseMs: 520 },
+ { prompt: '3', index: 2, expected: 3, answered: 3, correct: true, responseMs: 510 },
+ ];
+ const { container } = render(<DrillQuestionReview type="schulte-table" questions={questions} />);
+ expect(container.querySelector('[aria-label="Outlier response time"]')).not.toBeInTheDocument();
+ });
+
+ it('flags a false start distinctly from a wrong pick in reaction-time', () => {
+ const questions = [
+ { prompt: 'react', index: 0, answered: null, correct: false, responseMs: 0, falseStart: true },
+ { prompt: 'react', index: 1, answered: 'react', correct: true, responseMs: 300 },
+ ];
+ render(<DrillQuestionReview type="reaction-time" questions={questions} />);
+ expect(screen.getByText('False start')).toBeInTheDocument();
+ expect(screen.getByText('Correct')).toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
index 38d9c8a9f3..89a5b82778 100644
--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
@@ -114,6 +114,11 @@ export function buildNBackQuestions(seq, n, answers) {
return {
prompt: letter,
index: i,
+ // Mirrors the server's scoreNBack recompute exactly ('match'/'no-match')
+ // so the results-review UI (DrillQuestionReview) reads one consistent
+ // field regardless of whether it's showing the just-finished client
+ // result or a server-rescored history record.
+ expected: isTarget ? 'match' : 'no-match',
answered: a.answered ?? null,
correct: answeredMatch === isTarget,
responseMs: a.responseMs || 0,
@@ -135,6 +140,10 @@ export function scoreDigitSpanRecall({ digits, direction, index, answeredStr, re
question: {
prompt: `${digits.length}-digit (${direction})`,
index,
+ // Shown digits in recall order — matches the server's scoreDigitSpan
+ // recompute so the review UI shows "shown vs recalled" from either the
+ // client's local result or a server-rescored history record.
+ expected,
answered: answeredRaw.length ? answeredRaw : null,
correct: answeredRaw.length > 0 && answeredRaw === expected,
responseMs,
@@ -152,6 +161,8 @@ export function scoreStroopTrial({ trial, index, colorName, responseMs }) {
return {
prompt: trial.word,
index,
+ // Ink color is the answer key — mirrors the server's scoreStroop recompute.
+ expected: trial.inkColor,
answered: colorName,
correct: colorName === trial.inkColor,
responseMs,
@@ -166,6 +177,8 @@ export function scoreMentalRotationTrial({ trial, index, optionIndex, responseMs
return {
prompt: `shape ${trial.shape || ''}`,
index,
+ // Mirrors the server's scoreMentalRotation recompute.
+ expected: trial.correctIndex,
answered: optionIndex,
correct: optionIndex === trial.correctIndex,
responseMs,
diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
index c2a62f2005..482b60ec9c 100644
--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
@@ -117,6 +117,7 @@ describe('scoreDigitSpanRecall', () => {
expect(question).toEqual({
prompt: '3-digit (forward)',
index: 0,
+ expected: '123',
answered: '123',
correct: true,
responseMs: 1500,
@@ -182,6 +183,7 @@ describe('scoreStroopTrial', () => {
expect(question).toEqual({
prompt: 'RED',
index: 0,
+ expected: 'blue',
answered: 'blue',
correct: true,
responseMs: 800,
@@ -210,6 +212,7 @@ describe('scoreMentalRotationTrial', () => {
expect(question).toEqual({
prompt: 'shape L',
index: 0,
+ expected: 1,
answered: 1,
correct: true,
responseMs: 650,
diff --git a/client/src/components/meatspace/post/PostHistory.jsx b/client/src/components/meatspace/post/PostHistory.jsx
index b7bd3a2589..5f370a63bd 100644
--- a/client/src/components/meatspace/post/PostHistory.jsx
+++ b/client/src/components/meatspace/post/PostHistory.jsx
@@ -6,6 +6,7 @@ import {
import { getPostSessions, getPostStats } from '../../../services/api';
import useChartColors from '../../../hooks/useChartColors.js';
import { LLM_DRILL_TYPES, DRILL_LABELS, DRILL_TO_DOMAIN, domainLabel } from './constants';
+import DrillQuestionReview from './DrillQuestionReview';
const RANGES = [
{ label: '7d', days: 7 },
@@ -277,6 +278,22 @@ export default function PostHistory({ onBack }) {
</td>
</tr>
);
+
+ // Per-question mistake review — same shared component as
+ // PostSessionResults, reused here so a past session teaches
+ // from mistakes exactly like the just-finished one (#2093).
+ // LLM drills are unchanged (the summary line above is all
+ // history shows for them, matching PostSessionResults).
+ if (!isLlm && task.questions?.length > 0) {
+ rows.push(
+ <tr key={`${s.id}-${i}-review`} className="bg-port-bg/30">
+ <td></td>
+ <td className="px-4 pb-3 pt-0" colSpan={4}>
+ <DrillQuestionReview type={task.type} questions={task.questions} drillData={task.drillData} />
+ </td>
+ </tr>
+ );
+ }
}
}
diff --git a/client/src/components/meatspace/post/PostHistory.test.jsx b/client/src/components/meatspace/post/PostHistory.test.jsx
index 2cb5c76d86..57f47a00ae 100644
--- a/client/src/components/meatspace/post/PostHistory.test.jsx
+++ b/client/src/components/meatspace/post/PostHistory.test.jsx
@@ -86,3 +86,50 @@ describe('PostHistory analytics dashboard', () => {
expect(screen.queryByText('Drill Breakdown')).toBeNull();
});
});
+
+// Issue #2093 — expanding a past session must reuse DrillQuestionReview so
+// history teaches from mistakes exactly like the just-finished session does.
+describe('PostHistory expanded session review', () => {
+ const REVIEW_SESSIONS = [
+ {
+ id: 'c', date: '2026-06-03', score: 70, durationMs: 60000, modules: ['mental-math'],
+ tasks: [
+ {
+ module: 'mental-math', type: 'multiplication', score: 50,
+ questions: [
+ { prompt: '6 x 7', expected: 42, answered: 41, correct: false, responseMs: 2000 },
+ { prompt: '3 x 3', expected: 9, answered: 9, correct: true, responseMs: 1200 },
+ ],
+ },
+ { module: 'llm-drills', type: 'pun-wordplay', score: 64, responses: [{}] },
+ ],
+ },
+ ];
+
+ it('reuses DrillQuestionReview inside an expanded session for a non-LLM task', async () => {
+ getPostSessions.mockResolvedValue(REVIEW_SESSIONS);
+ render(<PostHistory onBack={() => {}} />);
+ await waitFor(() => expect(screen.getByText('2026-06-03')).toBeTruthy());
+
+ fireEvent.click(screen.getByText('2026-06-03'));
+
+ // The missed-item summary + per-question table (shared with PostSessionResults).
+ // "6 x 7" appears twice once expanded: once in the missed-items chip,
+ // once in the per-question table row.
+ await waitFor(() => expect(screen.getByText('1 missed')).toBeTruthy());
+ expect(screen.getAllByText('6 x 7').length).toBe(2);
+ expect(screen.getByText('42')).toBeTruthy();
+ });
+
+ it('does not render a review for an LLM task (unchanged summary-only behavior)', async () => {
+ getPostSessions.mockResolvedValue(REVIEW_SESSIONS);
+ render(<PostHistory onBack={() => {}} />);
+ await waitFor(() => expect(screen.getByText('2026-06-03')).toBeTruthy());
+
+ fireEvent.click(screen.getByText('2026-06-03'));
+
+ await waitFor(() => expect(screen.getByText('1 responses')).toBeTruthy());
+ // No missed-item summary rendered twice — only the one math task produces it.
+ expect(screen.getAllByText(/missed/).length).toBe(1);
+ });
+});
diff --git a/client/src/components/meatspace/post/PostSessionResults.jsx b/client/src/components/meatspace/post/PostSessionResults.jsx
index 98d012e56b..2cb3842ca9 100644
--- a/client/src/components/meatspace/post/PostSessionResults.jsx
+++ b/client/src/components/meatspace/post/PostSessionResults.jsx
@@ -1,6 +1,7 @@
import { useState } from 'react';
import { CheckCircle, Save, ArrowLeft, ChevronDown, ChevronUp, Dumbbell } from 'lucide-react';
import { LLM_DRILL_TYPES, DRILL_TO_DOMAIN, DOMAINS, DRILL_LABELS } from './constants';
+import DrillQuestionReview from './DrillQuestionReview';
export default function PostSessionResults({ session, tags = {}, onSaved, onBack }) {
const { drillResults, sessionScore, state, saveSession, isTraining } = session;
@@ -100,7 +101,7 @@ export default function PostSessionResults({ session, tags = {}, onSaved, onBack
<span className={`font-mono font-medium ${drillScoreColor}`}>
{result.score || 0}
</span>
- {isLlm && (isExpanded ? <ChevronUp size={14} className="text-gray-500" /> : <ChevronDown size={14} className="text-gray-500" />)}
+ {isExpanded ? <ChevronUp size={14} className="text-gray-500" /> : <ChevronDown size={14} className="text-gray-500" />}
</div>
</button>
@@ -127,6 +128,13 @@ export default function PostSessionResults({ session, tags = {}, onSaved, onBack
)}
</div>
)}
+
+ {/* Math / Memory / Cognitive per-question review */}
+ {!isLlm && isExpanded && (result.questions?.length > 0) && (
+ <div className="mt-2 ml-2 bg-port-bg border border-port-border rounded p-3">
+ <DrillQuestionReview type={result.type} questions={result.questions} drillData={result.drillData} />
+ </div>
+ )}
</div>
);
})}
diff --git a/client/src/components/meatspace/post/PostSessionResults.test.jsx b/client/src/components/meatspace/post/PostSessionResults.test.jsx
new file mode 100644
index 0000000000..dae5e583cb
--- /dev/null
+++ b/client/src/components/meatspace/post/PostSessionResults.test.jsx
@@ -0,0 +1,92 @@
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen, fireEvent, within } from '@testing-library/react';
+import PostSessionResults from './PostSessionResults';
+
+// Issue #2093 — the drill-breakdown expansion previously only ever showed
+// data for LLM drills (`isLlm && isExpanded && result.evaluation`); math and
+// cognitive drills rendered a dead, chevron-less button. These tests guard
+// both the fix (per-question review for non-LLM drills) and the regression
+// (LLM behavior stays exactly as it was).
+
+function makeSession(overrides = {}) {
+ return {
+ drillResults: [
+ {
+ type: 'multiplication',
+ score: 60,
+ questions: [
+ { prompt: '6 x 7', expected: 42, answered: 41, correct: false, responseMs: 2000 },
+ { prompt: '3 x 3', expected: 9, answered: 9, correct: true, responseMs: 900 },
+ ],
+ },
+ {
+ type: 'word-association',
+ score: 80,
+ evaluation: { summary: 'Nice variety', scores: [{ score: 80, feedback: 'Good range' }] },
+ responses: [{ response: 'apple, banana' }],
+ },
+ ],
+ sessionScore: 70,
+ state: 'complete',
+ saveSession: vi.fn(),
+ isTraining: false,
+ ...overrides,
+ };
+}
+
+function renderResults(overrides = {}) {
+ return render(
+ <PostSessionResults session={makeSession(overrides)} tags={{}} onSaved={() => {}} onBack={() => {}} />
+ );
+}
+
+describe('PostSessionResults drill breakdown', () => {
+ it('renders a chevron on every drill row — including non-LLM ones (regression: dead expand affordance)', () => {
+ const { container } = renderResults();
+ // Both rows start collapsed, so both show ChevronDown. Previously this
+ // icon was gated behind `isLlm &&`, so a math/cognitive row (like
+ // "multiplication" here) rendered no chevron at all.
+ expect(container.querySelectorAll('.lucide-chevron-down')).toHaveLength(2);
+ });
+
+ it('expanding a math drill row reveals its per-question review (regression for the isLlm-only gate)', () => {
+ const { container } = renderResults();
+ fireEvent.click(screen.getByText('Multiplication'));
+ const table = within(container.querySelector('table'));
+ expect(table.getByText('6 x 7')).toBeInTheDocument();
+ expect(table.getByText('41')).toBeInTheDocument();
+ expect(table.getByText('42')).toBeInTheDocument();
+ });
+
+ it('leads the math review with a missed-items summary', () => {
+ renderResults();
+ fireEvent.click(screen.getByText('Multiplication'));
+ expect(screen.getByText('1 missed')).toBeInTheDocument();
+ });
+
+ it('expanding an LLM drill row still shows its evaluation, unchanged', () => {
+ renderResults();
+ // "Nice variety" is already visible pre-expansion (it's the row subtitle);
+ // expanding adds a second copy in the evaluation block, plus the
+ // per-response feedback text which only exists once expanded.
+ expect(screen.getAllByText('Nice variety')).toHaveLength(1);
+ fireEvent.click(screen.getByText('Word Association'));
+ expect(screen.getAllByText('Nice variety')).toHaveLength(2);
+ expect(screen.getByText('Good range')).toBeInTheDocument();
+ });
+
+ it('does not render the per-question table for an LLM row', () => {
+ renderResults();
+ fireEvent.click(screen.getByText('Word Association'));
+ expect(screen.queryByText('6 x 7')).not.toBeInTheDocument();
+ });
+
+ it('collapses the review again on a second click', () => {
+ const { container } = renderResults();
+ const row = screen.getByText('Multiplication');
+ fireEvent.click(row);
+ expect(within(container.querySelector('table')).getByText('6 x 7')).toBeInTheDocument();
+ fireEvent.click(row);
+ expect(container.querySelector('table')).not.toBeInTheDocument();
+ });
+});