From f9bf2ba81dbcce6feb90d0d15dd28a3750a1e8ff Mon Sep 17 00:00:00 2001 From: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:31:34 +0000 Subject: [PATCH] fix(quiz): keep the stored grade when a re-judge is unsure A non-final verdict on a typed answer resolved to is_correct=false, and the judge PATCH then stored result=incorrect, turning a judged-correct answer back into a mistake. Send only the judgment and verdict for an unsure verdict; only a final verdict re-grades. Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com> --- web/components/quiz/QuizViewer.tsx | 10 +++-- web/tests/quiz/QuizViewer.smoke.spec.tsx | 56 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/web/components/quiz/QuizViewer.tsx b/web/components/quiz/QuizViewer.tsx index c39506853..404621deb 100644 --- a/web/components/quiz/QuizViewer.tsx +++ b/web/components/quiz/QuizViewer.tsx @@ -742,11 +742,13 @@ export default function QuizViewer({ const assessment = q ? getAssessment(q, answer, verdict) : null; void updateNotebookEntry(eId, { ai_judgment: finalText, - // Always send an explicit result so a re-judge replaces the - // previous one; the server derives ``resolved`` from it. - ...(verdict && assessment + // A final verdict sends an explicit result so a re-judge + // replaces the previous one; the server derives ``resolved`` + // from it. An unsure verdict is no grade: it keeps the stored + // one instead of turning a judged-correct answer into a mistake. + ...(verdict ? { ai_verdict: verdict } : {}), + ...(verdict?.final && assessment ? { - ai_verdict: verdict, is_correct: assessment.is_correct, result: assessment.result ?? diff --git a/web/tests/quiz/QuizViewer.smoke.spec.tsx b/web/tests/quiz/QuizViewer.smoke.spec.tsx index fcc2b04da..64d35f440 100644 --- a/web/tests/quiz/QuizViewer.smoke.spec.tsx +++ b/web/tests/quiz/QuizViewer.smoke.spec.tsx @@ -406,6 +406,62 @@ describe("QuizViewer smoke", () => { ]); }); + it("keeps the stored grade when a re-judge is unsure (mock API)", async () => { + const user = userEvent.setup(); + renderViewer([shortAnswerQuestion], { + sessionId: "session-1", + turnId: "turn-1", + }); + await user.type( + screen.getByPlaceholderText("Type your answer..."), + "Light becomes sugar.", + ); + await user.click(screen.getByRole("button", { name: /Check Answer/ })); + await waitFor(() => expect(mocks.upsertNotebookEntry).toHaveBeenCalled()); + + const judged = { + result: "correct" as const, + is_correct: true, + final: true, + confidence: 0.92, + steps: [], + }; + await user.click(screen.getByRole("button", { name: /AI Judge/ })); + act(() => { + mocks.judgeHandlers!.onVerdict!(judged); + mocks.judgeHandlers!.onDone("Right."); + }); + await waitFor(() => { + expect(mocks.updateNotebookEntry).toHaveBeenLastCalledWith(11, { + ai_judgment: "Right.", + ai_verdict: judged, + is_correct: true, + result: "correct", + }); + }); + + // An unsure verdict is no grade: it must not turn the judged-correct + // answer back into a mistake. + const unsure = { + result: "ungraded" as const, + is_correct: null, + final: false, + confidence: 0.4, + steps: [], + }; + await user.click(screen.getByRole("button", { name: /Re-judge/ })); + act(() => { + mocks.judgeHandlers!.onVerdict!(unsure); + mocks.judgeHandlers!.onDone("Hard to tell."); + }); + await waitFor(() => { + expect(mocks.updateNotebookEntry).toHaveBeenLastCalledWith(11, { + ai_judgment: "Hard to tell.", + ai_verdict: unsure, + }); + }); + }); + it("shows one result badge when exact matching and the judge disagree", async () => { const user = userEvent.setup(); renderViewer([choiceQuestion]);