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([issue-2094]): claude-review findings — n-back legacy derive parity, metric-field sanitization, completion-floor ease-through

Adam Eivyc6bb00953e92
diff --git a/client/src/components/meatspace/post/PostSessionResults.jsx b/client/src/components/meatspace/post/PostSessionResults.jsx
index cbcc4032e9..ab822c17eb 100644
--- a/client/src/components/meatspace/post/PostSessionResults.jsx
+++ b/client/src/components/meatspace/post/PostSessionResults.jsx
@@ -79,8 +79,11 @@ export default function PostSessionResults({ session, tags = {}, onSaved, onBack
// the session hasn't been scored server-side yet. n-back is a go/no-go
// task: a withheld press ("answered: null") is a deliberate no-match
// decision, not an unreached trial — so every trial counts as reached
- // (completion 100%) and accuracy spans all trials, matching the server
- // scorer that stamps completion=1 for n-back.
+ // (completion 100%, matching the server's completion=1). Note: the
+ // pre-save fallback accuracy here is raw position accuracy over all
+ // trials — a close stand-in for (not identical to) the balanced
+ // signal-detection accuracy the server persists on save (#2093 owns
+ // the deeper results UI).
const questions = result.questions || [];
const noGo = result.type === 'n-back';
const reached = noGo ? questions : questions.filter(q => q.answered !== null);
diff --git a/server/lib/postAdaptive.js b/server/lib/postAdaptive.js
index bd36137b2f..ed1ded8093 100644
--- a/server/lib/postAdaptive.js
+++ b/server/lib/postAdaptive.js
@@ -90,10 +90,14 @@ export function adaptDrillConfig(type, baseConfig = {}, signal = {}, opts = {})
return out;
}
- if (completion != null && completion < options.minCompletion) {
+ const lowCompletion = completion != null && completion < options.minCompletion;
+ if (lowCompletion && scoreToDirection(score, options) !== -1) {
// The user barely reached this drill (timed out on most of it) — accuracy off
- // a handful of answers isn't a trustworthy difficulty signal, so hold the
- // manual config until they complete more of it (issue #2094).
+ // a handful of answers isn't a trustworthy signal to HOLD or go HARDER on, so
+ // keep the manual config until they complete more of it (issue #2094). The
+ // EASIER direction is deliberately allowed through: chronic low completion is
+ // itself evidence the drill is too hard/long, and blocking the ease would
+ // deadlock difficulty (low completion → no adaptation → completion stays low).
out.reason = 'insufficient-completion';
return out;
}
diff --git a/server/lib/postAdaptive.test.js b/server/lib/postAdaptive.test.js
index c1c3dd100a..20309719e6 100644
--- a/server/lib/postAdaptive.test.js
+++ b/server/lib/postAdaptive.test.js
@@ -59,6 +59,16 @@ describe('adaptDrillConfig', () => {
expect(res.config.maxDigits).toBe(2);
});
+ it('still EASES under the completion floor — chronic time-outs must not deadlock difficulty', () => {
+ // Low completion + low accuracy: the drill is too hard/long. Blocking the
+ // ease would freeze difficulty forever (low completion → no adaptation →
+ // completion stays low), so the easier direction passes the floor.
+ const res = adaptDrillConfig('multiplication', { maxDigits: 3 }, { score: 30, samples: 5, completion: 0.3 });
+ expect(res.applied).toBe(true);
+ expect(res.reason).toBe('easier');
+ expect(res.config.maxDigits).toBe(2);
+ });
+
it('adapts normally once completion clears the floor', () => {
const res = adaptDrillConfig('multiplication', { maxDigits: 2 }, { score: 95, samples: 5, completion: 0.8 });
expect(res.applied).toBe(true);
diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.js
index e0b463b8c4..567658f1e2 100644
--- a/server/services/meatspacePost.js
+++ b/server/services/meatspacePost.js
@@ -156,10 +156,20 @@ export async function submitPostSession(sessionData) {
const data = await loadSessions();
const now = new Date().toISOString();
- // Strip client-provided score/correct and recompute server-side (math drills only)
+ // Strip client-provided score/correct — plus every separated metric field
+ // (issue #2094) — and recompute server-side. Stripping up front means the
+ // LLM/memory branches (which trust the client `score` but never carry these
+ // metrics) can't persist stale client-sent values that stats aggregation
+ // would then prefer over a questions[] derivation.
const rawTasks = Array.isArray(sessionData.tasks) ? sessionData.tasks : [];
const rescoredTasks = rawTasks.map(t => {
- const { score: _score, correct: _correct, ...rest } = t || {};
+ const {
+ score: _score, correct: _correct,
+ accuracy: _acc, completion: _comp, avgResponseMs: _avg,
+ answeredCount: _ac, totalCount: _tc, medianMs: _med, bestMs: _best, span: _span,
+ hits: _h, misses: _m, falseAlarms: _fa, correctRejections: _cr,
+ ...rest
+ } = t || {};
// LLM drills: score was computed server-side via /post/score-llm and
// passed back by the client. Re-scoring here would add latency + cost.
@@ -309,19 +319,24 @@ export function computePostStreaks(sessions, todayStr) {
export function deriveTaskAccuracy(task) {
if (typeof task?.accuracy === 'number' && !Number.isNaN(task.accuracy)) return task.accuracy;
const qs = Array.isArray(task?.questions) ? task.questions : [];
- const answered = qs.filter(q => q?.answered != null);
- if (!answered.length) return null;
- return answered.filter(q => q?.correct).length / answered.length;
+ // n-back is go/no-go: a withheld press (answered == null) is a deliberate
+ // "no-match" decision, not an unreached trial — so accuracy spans ALL trials,
+ // mirroring the client fallbacks in PostHistory/PostSessionResults.
+ const reached = task?.type === 'n-back' ? qs : qs.filter(q => q?.answered != null);
+ if (!reached.length) return null;
+ return reached.filter(q => q?.correct).length / reached.length;
}
/**
* Completion (answered / total) for a scored task, with the same legacy fallback
* as deriveTaskAccuracy. `null` when there are no questions to derive from.
+ * n-back legacy tasks are always fully reached — every trial gets a decision.
*/
export function deriveTaskCompletion(task) {
if (typeof task?.completion === 'number' && !Number.isNaN(task.completion)) return task.completion;
const qs = Array.isArray(task?.questions) ? task.questions : [];
if (!qs.length) return null;
+ if (task?.type === 'n-back') return 1;
return qs.filter(q => q?.answered != null).length / qs.length;
}
@@ -713,7 +728,9 @@ export function computeExpectedFromPrompt(prompt) {
}
export function scoreDrill(type, questions, timeLimitMs, config = {}) {
- if (!questions?.length) return { score: 0, questions };
+ if (!questions?.length) {
+ return { score: 0, questions, accuracy: null, completion: null, avgResponseMs: null, answeredCount: 0, totalCount: 0 };
+ }
// Recompute expected from the prompt server-side — never trust client-provided expected
const recomputed = questions.map(q => {
@@ -748,7 +765,7 @@ export function scoreDrill(type, questions, timeLimitMs, config = {}) {
// so the headline gamification number is unchanged for existing sessions and
// fully-answered tasks (back-compat). The separated metrics below are what
// reporting and the adaptive signal now consume (issue #2094).
- const correctRatio = correctCount / totalCount;
+ const correctRatio = totalCount ? correctCount / totalCount : 0;
// Clamp responseMs to [0, timeLimitMs] to prevent inflated speed bonuses
const totalResponseMs = answered.reduce((sum, q) => sum + Math.min(Math.max(q.responseMs || 0, 0), timeLimitMs), 0);
diff --git a/server/services/meatspacePost.test.js b/server/services/meatspacePost.test.js
index 33518e0087..47998ae288 100644
--- a/server/services/meatspacePost.test.js
+++ b/server/services/meatspacePost.test.js
@@ -883,6 +883,23 @@ describe('deriveTaskAccuracy / deriveTaskCompletion — legacy-session fallback'
expect(deriveTaskCompletion({ questions: [] })).toBe(null);
expect(deriveTaskCompletion({})).toBe(null);
});
+
+ it('legacy n-back: withheld presses are decisions, not skips — accuracy spans all trials, completion is 1', () => {
+ // 10-trial legacy n-back run: 2 presses (1 correct hit, 1 false alarm) and 8
+ // withheld (all correct rejections). Answered-only filtering would report
+ // accuracy 0.5 / completion 0.2; go/no-go semantics say 9/10 and fully reached.
+ const task = {
+ type: 'n-back',
+ questions: [
+ { answered: 'match', correct: true },
+ { answered: 'match', correct: false },
+ ...Array.from({ length: 8 }, () => ({ answered: null, correct: true })),
+ ],
+ };
+ expect(deriveTaskAccuracy(task)).toBeCloseTo(0.9, 5);
+ expect(deriveTaskCompletion(task)).toBe(1);
+ expect(deriveTaskCompletion({ type: 'n-back', questions: [] })).toBe(null);
+ });
});
describe('getPostStats — accuracy/completion aggregation', () => {