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>
This commit is contained in:
Benjamin Schwing
2026-11-25 01:31:34 +00:00
parent 66b33e29f2
commit f9bf2ba81d
2 changed files with 62 additions and 4 deletions

View File

@@ -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 ??

View File

@@ -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]);