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
address review (codex): fix benchmark weighting, legacy tags loss, single-point chart
[._.]/ Adam Eivy6727621baecc
diff --git a/client/src/components/meatspace/post/PostProgress.jsx b/client/src/components/meatspace/post/PostProgress.jsxindex 59e6fa6cae..1be8308d4a 100644--- a/client/src/components/meatspace/post/PostProgress.jsx+++ b/client/src/components/meatspace/post/PostProgress.jsx@@ -281,15 +281,31 @@ export default function PostProgress({ subtab, onBack }) {{benchmark && (<div className="grid grid-cols-1 gap-4 sm:gap-6"><div>- <TrendChart- title={`Benchmark Trend — ${benchmark.protocolId} v${benchmark.protocolVersion}`}- data={benchmarkScoreData}- dataKey="score"- domainRange={[0, 100]}- stroke={chartColors.accent}- chartColors={chartColors}- emptyText="No compatible benchmark runs yet — start one from the launcher."- />+ {/* TrendChart's line needs 2+ points to plot — a single+ compatible run is the common first-use case (issue #4442+ codex review), so show its score directly instead of+ falling into the chart's "no runs yet" empty state, which+ would misreport a real result as none. */}+ {benchmarkScoreData.length === 1 ? (+ <div className="bg-port-card border border-port-border rounded-lg p-4">+ <h3 className="text-sm font-medium text-gray-400 mb-3">+ {`Benchmark Trend — ${benchmark.protocolId} v${benchmark.protocolVersion}`}+ </h3>+ <div className="text-sm text-gray-300">+ Latest compatible run: <span className="font-mono font-bold text-white">{benchmarkScoreData[0].score}</span> on {benchmarkScoreData[0].date}. Complete another benchmark to chart a trend.+ </div>+ </div>+ ) : (+ <TrendChart+ title={`Benchmark Trend — ${benchmark.protocolId} v${benchmark.protocolVersion}`}+ data={benchmarkScoreData}+ dataKey="score"+ domainRange={[0, 100]}+ stroke={chartColors.accent}+ chartColors={chartColors}+ emptyText="No compatible benchmark runs yet — start one from the launcher."+ />+ )}{benchmark.excludedCount > 0 && (<p className="text-xs text-gray-500 mt-2">{benchmark.excludedCount} earlier benchmark {benchmark.excludedCount === 1 ? 'run' : 'runs'} excluded — different protocol/scoring version, not comparable to the current battery.diff --git a/client/src/components/meatspace/post/PostProgress.test.jsx b/client/src/components/meatspace/post/PostProgress.test.jsxindex 664702eec8..c93a34a2b7 100644--- a/client/src/components/meatspace/post/PostProgress.test.jsx+++ b/client/src/components/meatspace/post/PostProgress.test.jsx@@ -137,6 +137,29 @@ describe('PostProgress — benchmark trend', () => {expect(screen.getByText(/post-foundation-battery v1/)).toBeInTheDocument();});+ it('shows a single-point summary instead of the empty state for exactly one compatible run (issue #4442 codex review)', async () => {+ getPostProgress.mockResolvedValue({+ ...PROGRESS,+ series: {+ ...PROGRESS.series,+ benchmark: {+ protocolId: 'post-foundation-battery',+ protocolVersion: 1,+ scorerVersion: 'post-deterministic-v1',+ byDay: [{ date: '2026-06-03', score: 88, sessions: 1 }],+ excludedCount: 0,+ },+ },+ });+ renderProgress();+ await waitFor(() => expect(screen.getByText(/Benchmark Trend/)).toBeInTheDocument());+ // The one real result must be visible, not masked by the "no runs yet" text+ // TrendChart's own multi-point chart would otherwise fall back to.+ expect(screen.getByText('88')).toBeInTheDocument();+ expect(screen.getByText(/2026-06-03/)).toBeInTheDocument();+ expect(screen.queryByText(/No compatible benchmark runs yet/)).not.toBeInTheDocument();+ });+it('surfaces the excluded-legacy-runs note when excludedCount is set', async () => {getPostProgress.mockResolvedValue({...PROGRESS,diff --git a/client/src/hooks/usePostSession.js b/client/src/hooks/usePostSession.jsindex 1d48190368..12c4fd0a8a 100644--- a/client/src/hooks/usePostSession.js+++ b/client/src/hooks/usePostSession.js@@ -173,6 +173,14 @@ export function usePostSession() {// the /post/session/:id results URL — so a saved session's URL === its run id.const [runId, setRunId] = useState(restored?.runId ?? null);const [conditions, setConditions] = useState(restored?.conditions ?? {}); // session conditions captured at launch+ // Read-only carrier for a run resumed from a PRE-upgrade snapshot that still+ // has the legacy free-text `tags` shape (e.g. a mid-session refresh spanning+ // a deploy). Never written by this session — the launcher only ever produces+ // `conditions` now — so it's captured once here and submitted verbatim under+ // the legacy `tags` field on save, rather than silently dropped or coerced+ // into `conditions`'s fixed enums (its free-text values wouldn't validate as+ // enum members anyway).+ const legacyTags = restored?.tags && !restored?.conditions ? restored.tags : null;const [sessionPlan, setSessionPlan] = useState(restored?.sessionPlan ?? null);const [benchmark, setBenchmark] = useState(restored?.benchmark ?? null);const [lastAnswer, setLastAnswer] = useState(null); // { correct, expected, answered } for training feedback@@ -593,6 +601,7 @@ export function usePostSession() {modules,tasks: drillResults,conditions: finalConditions,+ ...(legacyTags ? { tags: legacyTags } : {}),startedAt: new Date(runStartedAtRef.current).toISOString(),...(sessionPlan ? { plan: sessionPlan } : {}),...(benchmark ? { benchmark } : {}),diff --git a/client/src/hooks/usePostSession.test.js b/client/src/hooks/usePostSession.test.jsindex 471986cad2..b9c0c5ac67 100644--- a/client/src/hooks/usePostSession.test.js+++ b/client/src/hooks/usePostSession.test.js@@ -927,6 +927,58 @@ describe('usePostSession — refresh-safe run + idempotent submit (issue #2098)'expect(result.current.drillResults).toHaveLength(1);});+ it('preserves legacy free-text tags from a run resumed after an app upgrade (issue #4442 codex review)', async () => {+ // A snapshot written by a PRE-upgrade build still has the old free-text+ // `tags` shape and no `conditions` key at all — e.g. a mid-session+ // refresh spanning a deploy. Those values must ride through to the+ // submitted payload's legacy `tags` field, not be silently dropped.+ sessionStorage.setItem('post.activeRun', JSON.stringify({+ runId: '22222222-2222-4222-8222-222222222222', state: 'complete', isTraining: false,+ drills: [{ type: 'doubling-chain', config: {}, timeLimitSec: 60 }],+ currentDrillIndex: 0, currentDrill: null, currentQuestionIndex: 0, answers: [],+ drillResults: [{ module: 'mental-math', type: 'doubling-chain', score: 80 }],+ sessionScore: 80,+ tags: { sleep: 'good', caffeine: '1 cup' },+ }));+ submitPostSession.mockResolvedValue({ id: 'session-legacy', score: 80 });++ const { result } = renderHook(() => usePostSession());+ expect(result.current.state).toBe('complete');++ await act(async () => {+ await result.current.saveSession({});+ });++ const payload = submitPostSession.mock.calls[0][0];+ expect(payload.tags).toEqual({ sleep: 'good', caffeine: '1 cup' });+ expect(payload.conditions).toEqual({});+ });++ it('does NOT resurrect legacy tags for a run resumed from a snapshot that already has conditions', async () => {+ sessionStorage.setItem('post.activeRun', JSON.stringify({+ runId: '33333333-3333-4333-8333-333333333333', state: 'complete', isTraining: false,+ drills: [{ type: 'doubling-chain', config: {}, timeLimitSec: 60 }],+ currentDrillIndex: 0, currentDrill: null, currentQuestionIndex: 0, answers: [],+ drillResults: [{ module: 'mental-math', type: 'doubling-chain', score: 80 }],+ sessionScore: 80,+ // Both keys present (shouldn't normally happen, but conditions being+ // set at all is the signal this is a post-upgrade snapshot) — tags+ // must not be treated as the legacy carrier here.+ tags: { sleep: 'good' },+ conditions: { sleepQuality: 'good' },+ }));+ submitPostSession.mockResolvedValue({ id: 'session-new', score: 80 });++ const { result } = renderHook(() => usePostSession());+ await act(async () => {+ await result.current.saveSession({});+ });++ const payload = submitPostSession.mock.calls[0][0];+ expect(payload.tags).toBeUndefined();+ expect(payload.conditions).toEqual({ sleepQuality: 'good' });+ });+it('clears the persisted run on reset (no stale run resumes next mount)', async () => {generatePostDrill.mockResolvedValue({type: 'doubling-chain', config: { startValue: 2, steps: 1 }, questions: [{ prompt: '2 x 2', expected: 4 }],diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.jsindex 3ad31e476e..7ee1f68cae 100644--- a/server/services/meatspacePost.js+++ b/server/services/meatspacePost.js@@ -511,7 +511,12 @@ export async function submitPostSession(sessionData) {cadence: sessionData.cadence || 'daily',modules: sessionData.modules,tasks: rescoredTasks,- score: computeSessionScore(rescoredTasks, config.scoring?.weights),+ // Benchmark scoring is fixed by the protocol, never by the user's live+ // scoring.weights config — otherwise two "compatible" (same protocol/+ // version/scorer) runs scored under different weight configs would land+ // in the same trend as though they were on one scale (issue #4442 codex+ // review). Quick/Test/Train sessions keep the configured weights.+ score: computeSessionScore(rescoredTasks, sessionData.benchmark ? undefined : config.scoring?.weights),tags: sessionData.tags || {},...(sessionData.conditions && Object.keys(sessionData.conditions).length? { conditions: sessionData.conditions }diff --git a/server/services/meatspacePost.test.js b/server/services/meatspacePost.test.jsindex f4b3319548..b7d8f099ff 100644--- a/server/services/meatspacePost.test.js+++ b/server/services/meatspacePost.test.js@@ -57,7 +57,9 @@ import {getSessionSkillContext,getPostReviewReps,getPostBenchmarkProtocol,+ POST_BENCHMARK_PROTOCOL,} from './meatspacePost.js';+import { generateCognitiveDrill } from './meatspacePostCognitive.js';describe('Quick POST config', () => {it('defaults a new install to the five-minute preset', async () => {@@ -104,6 +106,91 @@ describe('Fixed POST benchmark protocol', () => {});});+// A benchmark's score must be comparable across runs regardless of the+// user's live scoring.weights config — otherwise two "compatible" (same+// protocol/version/scorer) runs could land on different scales and the+// benchmark trend (getPostProgress's series.benchmark) would silently+// compare apples to oranges (issue #4442 codex review).+describe('submitPostSession — benchmark scoring ignores config.scoring.weights', () => {+ beforeEach(() => { vi.clearAllMocks(); });++ const FORM_A = POST_BENCHMARK_PROTOCOL.forms.find(f => f.formId === 'a');+ const MATH_TASK_CONFIG = FORM_A.tasks.find(t => t.type === 'doubling-chain').config;+ const COGNITIVE_TASK_CONFIG = FORM_A.tasks.find(t => t.type === 'task-switching').config;++ function benchmarkFormATasks() {+ const cognitiveDrill = generateCognitiveDrill('task-switching', COGNITIVE_TASK_CONFIG);+ return [+ {+ module: 'mental-math',+ type: 'doubling-chain',+ config: MATH_TASK_CONFIG,+ // All 8 answered correctly and fast — deterministically scores ~100.+ questions: Array.from({ length: 8 }, () => ({ prompt: '2 x 2', expected: 4, answered: 4, responseMs: 100 })),+ totalMs: 800,+ },+ {+ module: 'cognitive',+ type: 'task-switching',+ config: COGNITIVE_TASK_CONFIG,+ drillData: cognitiveDrill,+ // Zero trials attempted — deterministically scores 0 (0% completion).+ questions: [],+ totalMs: 1000,+ },+ ];+ }++ function benchmarkSubmission() {+ return {+ modules: ['mental-math', 'cognitive'],+ tasks: benchmarkFormATasks(),+ benchmark: {+ protocolId: POST_BENCHMARK_PROTOCOL.protocolId,+ protocolVersion: POST_BENCHMARK_PROTOCOL.protocolVersion,+ scorerVersion: POST_BENCHMARK_PROTOCOL.scorerVersion,+ formId: 'a',+ },+ };+ }++ it('scores a plain unweighted mean of the two task scores (100 and 0 → 50)', async () => {+ readJSONFile.mockImplementation((path, defaultValue) => Promise.resolve(defaultValue));+ const session = await submitPostSession(benchmarkSubmission());+ expect(session.score).toBe(50);+ });++ it('ignores a configured scoring.weights skew that would otherwise shift the score', async () => {+ readJSONFile.mockImplementation((path, defaultValue) => {+ const p = String(path);+ if (p.includes('post-config')) {+ // Heavily favor cognitive (score 0) over mental-math (score ~100) —+ // if this leaked through, the blended score would collapse toward 0.+ return Promise.resolve({ scoring: { weights: { 'mental-math': 0.1, cognitive: 5 } } });+ }+ return Promise.resolve(defaultValue);+ });+ const session = await submitPostSession(benchmarkSubmission());+ // Same 50 as the uniform-weights case above — the skewed config never applied.+ expect(session.score).toBe(50);+ });++ it('a non-benchmark session with the SAME tasks still honors configured weights', async () => {+ readJSONFile.mockImplementation((path, defaultValue) => {+ const p = String(path);+ if (p.includes('post-config')) {+ return Promise.resolve({ scoring: { weights: { 'mental-math': 0.1, cognitive: 5 } } });+ }+ return Promise.resolve(defaultValue);+ });+ const { benchmark: _benchmark, ...plainSubmission } = benchmarkSubmission();+ const session = await submitPostSession(plainSubmission);+ // (100*0.1 + 0*5) / (0.1+5) ≈ 1.96 → rounds to 2 — confirms the fixed-weights+ // behavior above is benchmark-specific, not a global scoring regression.+ expect(session.score).toBe(2);+ });+});+// Structured session conditions (issue #4442) — sleepQuality/caffeine/stress// enums plus an optional note, persisted independently of the legacy// free-text `tags` map.