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]): scale reaction-time headline score by valid-trial rate (codex round 2)

Adam Eivy7970ce126e6e
diff --git a/server/services/meatspacePostCognitive.js b/server/services/meatspacePostCognitive.js
index 6ece85b643..313eb438ac 100644
--- a/server/services/meatspacePostCognitive.js
+++ b/server/services/meatspacePostCognitive.js
@@ -559,13 +559,21 @@ function scoreReactionTime(drillData, questions) {
// median RT vs a reference curve drives the score (issue #2094). A false start
// (pressing before the stimulus) invalidates its trial; in choice mode a wrong
// target also invalidates it. In simple mode "correct" == a clean, timed press.
+ // The latency score is then scaled by the VALID-TRIAL RATE — otherwise one
+ // lucky 200ms press among a run of false starts would persist a perfect 100
+ // headline score. Mirrors the blended-score convention everywhere else, where
+ // completion/invalid trials fold into the headline number while the separated
+ // medianMs/accuracy metrics stay pure.
const valid = recomputed.filter(q => q.correct && !q.falseStart && q.responseMs > 0);
const latencies = valid.map(q => q.responseMs);
const medianMs = median(latencies);
const bestMs = latencies.length ? Math.min(...latencies) : null;
- const score = medianMs == null
+ const totalTrials = recomputed.length;
+ const validRate = totalTrials ? valid.length / totalTrials : 0;
+ const latencyScore = medianMs == null
? 0
- : Math.min(100, Math.max(0, Math.round((100 * (refMs - medianMs)) / (refMs - fastMs))));
+ : Math.min(100, Math.max(0, (100 * (refMs - medianMs)) / (refMs - fastMs)));
+ const score = Math.round(latencyScore * validRate);
// A press attempt is any non-false-start trial with a real latency; accuracy is
// the share of those that were valid (in simple mode every clean press is valid,
diff --git a/server/services/meatspacePostCognitive.test.js b/server/services/meatspacePostCognitive.test.js
index 4416c986c0..a278aae52f 100644
--- a/server/services/meatspacePostCognitive.test.js
+++ b/server/services/meatspacePostCognitive.test.js
@@ -316,10 +316,28 @@ describe('cognitive drill scorers (recompute the answer key, never trust client)
expect(fast.medianMs).toBe(240);
expect(slow.medianMs).toBe(520);
expect(fast.score).toBeGreaterThan(slow.score);
- // simple-mode reference curve: 200ms→100, 600ms→0. Median 240 → round(100*(600-240)/400)=90.
+ // simple-mode reference curve: 200ms→100, 600ms→0. Median 240, all trials
+ // valid (validRate 1) → round(100*(600-240)/400)=90.
expect(fast.score).toBe(90);
});
+ it('reaction-time: one lucky valid press among false starts cannot score 100 (valid-rate scaling)', () => {
+ const drillData = { type: 'reaction-time', config: { mode: 'simple' }, trials: Array.from({ length: 4 }, () => ({ delayMs: 500 })) };
+ const { score, medianMs, accuracy } = scoreCognitiveDrill('reaction-time', drillData, [
+ { index: 0, answered: 'react', responseMs: 200 }, // perfect latency
+ { index: 1, answered: null, responseMs: 0, falseStart: true },
+ { index: 2, answered: null, responseMs: 0, falseStart: true },
+ { index: 3, answered: null, responseMs: 0, falseStart: true },
+ ]);
+ // Latency component is perfect (200ms → 100) but only 1 of 4 trials is valid →
+ // 100 × 0.25 = 25. The separated medianMs metric stays pure (200).
+ expect(medianMs).toBe(200);
+ expect(score).toBe(25);
+ // accuracy (valid over pressed) is 1 — false starts fold into the headline
+ // score and completion, not into the answered-only accuracy.
+ expect(accuracy).toBe(1);
+ });
+
it('reaction-time scores 0 when every trial is a false start (no valid latency)', () => {
const drillData = { type: 'reaction-time', config: { mode: 'simple' }, trials: [{ delayMs: 500 }, { delayMs: 500 }] };
const { score, medianMs, bestMs } = scoreCognitiveDrill('reaction-time', drillData, [