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): fill-blank element attribution + sync sessionScore to server weight
Adam Eivyddb3db3a33e0
diff --git a/client/src/hooks/usePostSession.js b/client/src/hooks/usePostSession.jsindex f772543256..96186474e6 100644--- a/client/src/hooks/usePostSession.js+++ b/client/src/hooks/usePostSession.js@@ -151,6 +151,11 @@ export function usePostSession() {// For estimation drills, check within tolerancelet correct;let answered;+ // Fill-blank element attribution: which specific answers[] entry the+ // user's guess matched (if any) — set only on an unambiguous correct+ // match, since a wrong guess against a multi-blank prompt can't be+ // attributed to any one blank/element (issue #2099 codex review).+ let matchedElement;if (hasFillBlankAnswers) {answered = value;const normalized = value !== null ? String(value).toLowerCase().trim() : '';@@ -160,7 +165,9 @@ export function usePostSession() {// fill-blank answer wrong (issue #2116). Compare against the object's// `.word` (falling back to the raw value for a plain-string entry, for// forward/backward compatibility with any other producer).- correct = q.answers.some(a => String(a?.word ?? a).toLowerCase().trim() === normalized);+ const matched = q.answers.find(a => String(a?.word ?? a).toLowerCase().trim() === normalized);+ correct = !!matched;+ matchedElement = matched?.element ?? null;} else if (isTextAnswer) {answered = value;correct = value !== null && String(value).toLowerCase().trim() === String(q.expected).toLowerCase().trim();@@ -181,7 +188,12 @@ export function usePostSession() {answered,correct,responseMs,- ...memoryAttribution(q)+ ...memoryAttribution(q),+ // Fill-blank's per-answer element (see matchedElement above) takes+ // priority over memoryAttribution(q)'s question-level element field+ // (which fill-blank questions never carry — only memory-element-flash+ // does), so mergeMasteryFromSession can credit the matched element.+ ...(matchedElement != null ? { element: matchedElement } : {})};const newAnswers = [...answers, answer];@@ -357,6 +369,14 @@ export function usePostSession() {});if (!session) return null;setSavedSession(session);+ // Replace the pre-save estimate (computeSessionScoreFromResults, a plain+ // per-domain average) with the server's authoritative score — which now+ // additionally honors configured per-module scoring.weights (issue+ // #2099). Without this, PostSessionResults keeps showing the local+ // estimate even in the SAVED state, silently diverging from the score+ // that was actually persisted/toasted whenever weights aren't uniform+ // (issue #2099 codex review).+ setSessionScore(session.score);toast.success(`POST complete — score: ${session.score}`);setState(STATES.SAVED);return session;diff --git a/client/src/hooks/usePostSession.test.js b/client/src/hooks/usePostSession.test.jsindex 245a15622a..2932894eaf 100644--- a/client/src/hooks/usePostSession.test.js+++ b/client/src/hooks/usePostSession.test.js@@ -335,6 +335,110 @@ describe('usePostSession — memory-fill-blank scoring (issue #2099/#2116)', ()expect(result.current.drillResults[0].questions[0].correct).toBe(false);});++ // Regression (codex review of issue #2099): a correct fill-blank match on+ // an element-name blank must carry that element through to the answer so+ // mergeMasteryFromSession can credit item.mastery.elements — previously+ // only chunkId (question-level) survived; the per-answer element was+ // silently dropped because memoryAttribution(q) only reads q.element,+ // which fill-blank questions never carry (only answers[i].element does).+ it('attributes the matched answer\'s element on a correct match', async () => {+ generatePostDrill.mockResolvedValue(+ fillBlankDrill([+ { index: 1, word: 'hydrogen', element: 'H' },+ { index: 3, word: 'fox', element: null },+ ])+ );++ const { result } = renderHook(() => usePostSession());+ await act(async () => {+ await result.current.startSession([{ type: 'memory-fill-blank', config: {}, timeLimitSec: 60 }]);+ });+ act(() => {+ result.current.submitAnswer('hydrogen');+ });++ const q = result.current.drillResults[0].questions[0];+ expect(q.correct).toBe(true);+ expect(q.element).toBe('H');+ });++ it('omits element on an incorrect match — which blank was intended is ambiguous', async () => {+ generatePostDrill.mockResolvedValue(+ fillBlankDrill([{ index: 1, word: 'hydrogen', element: 'H' }])+ );++ const { result } = renderHook(() => usePostSession());+ await act(async () => {+ await result.current.startSession([{ type: 'memory-fill-blank', config: {}, timeLimitSec: 60 }]);+ });+ act(() => {+ result.current.submitAnswer('nope');+ });++ const q = result.current.drillResults[0].questions[0];+ expect(q.correct).toBe(false);+ expect(q).not.toHaveProperty('element');+ });++ it('omits element when the matched answer has none (a plain-word blank)', async () => {+ generatePostDrill.mockResolvedValue(+ fillBlankDrill([{ index: 1, word: 'quick', element: null }])+ );++ const { result } = renderHook(() => usePostSession());+ await act(async () => {+ await result.current.startSession([{ type: 'memory-fill-blank', config: {}, timeLimitSec: 60 }]);+ });+ act(() => {+ result.current.submitAnswer('quick');+ });++ const q = result.current.drillResults[0].questions[0];+ expect(q.correct).toBe(true);+ expect(q).not.toHaveProperty('element');+ // chunkId still comes through via memoryAttribution(q) regardless.+ expect(q.chunkId).toBe('verse-1');+ });+});++// Regression (codex review of issue #2099): saveSession's returned session+// score (now module-weighted server-side, see meatspacePost.js+// computeSessionScore) must replace the pre-save local estimate+// (computeSessionScoreFromResults — a plain per-domain average that never+// reads config.scoring.weights), or the results screen keeps showing the+// stale unweighted estimate even after the weighted score was toasted/saved.+describe('usePostSession — sessionScore syncs to the server score on save (issue #2099)', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it('replaces the local pre-save score estimate with the server-computed session.score', async () => {+ generatePostDrill.mockResolvedValue({+ type: 'doubling-chain',+ config: { startValue: 2, steps: 1 },+ questions: [{ prompt: '2 x 2', expected: 4 }],+ });+ // Server's weighted score (e.g. a de-emphasized module) diverges from+ // whatever the client's local per-domain estimate computed pre-save.+ submitPostSession.mockResolvedValue({ id: 'session-1', score: 37 });++ const { result } = renderHook(() => usePostSession());+ await act(async () => {+ await result.current.startSession([{ type: 'doubling-chain', config: {}, timeLimitSec: 60 }]);+ });+ act(() => {+ result.current.submitAnswer('4');+ });++ expect(result.current.sessionScore).not.toBe(37); // the local estimate, pre-save++ await act(async () => {+ await result.current.saveSession({});+ });++ expect(result.current.sessionScore).toBe(37);+ });});describe('usePostSession — LLM training-log correctCount (issue #2097)', () => {