Skip to content

fix(quiz): let the AI judge grade objective items whose key names no option - #3204

Open
BenjiAvH wants to merge 4 commits into
HKUDS:devfrom
BenjiAvH:up/exam-d-quiz-fix
Open

BenjiAvH wants to merge 4 commits into
HKUDS:devfrom
BenjiAvH:up/exam-d-quiz-fix

Conversation

@BenjiAvH

@BenjiAvH BenjiAvH commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to the judge-verdict PR (#2952, merged). In a quiz, a choice or true/false item whose key resolves to no option or truth value (e.g. a key such as "Richtig, weil …", or an empty key) was failed by exact matching, and that exact-match result also overruled any AI-judge verdict, because choice and true/false items are treated as objective.

Such items are now left to the judge, like open answers: an item counts as objective only when its key names one of its options (choice) or a truth value (true/false). Items with a readable key are graded exactly as before.

Related Issues

Module(s) Affected

  • web (Frontend)
  • tests

Checklist

  • This PR targets dev (not main — see the base-branch selector above).
  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards (tsc, eslint).
  • I have run pre-commit run --all-files and fixed any issues (ran tsc, eslint, vitest, npm run i18n:check and npm run contracts:check individually).
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary). Not needed.
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

  • Test: web/tests/quiz/QuizViewer.smoke.spec.tsx › "lets the judge grade a true/false item whose key names no truth value". It fails without the change (exact matching marks the judged-correct answer wrong) and passes with it.
  • vitest run tests/quiz: 36 passed; tsc --noEmit clean.

…option

A choice or true/false key that resolves to no option or truth value
("Richtig, weil ...", an empty key) made exact matching fail the item and
overrule any judge verdict. Such items are now graded by the judge, like
open answers.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

@MohammadHijjawi97 MohammadHijjawi97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this fills a real gap left by #2952. vitest run tests/quiz gives 37 passed, tsc --noEmit and eslint on the two files are clean, and the new test fails with QuizViewer.tsx reverted to dev.

One case seems off. hasObjectiveKey() is stricter than isAnswerCorrect(), so some keys that exact matching can read lose their authority. isAnswerCorrect() accepts the first letter of the key (correct.charAt(0)), so a key like "B) Paris" or "B. Paris" still marks B as correct. But resolveChoiceAnswerKey("B) Paris", options) returns "B) PARIS", which is not in options, so the item now counts as non-objective. A wrong pick then takes the judge's verdict.

I checked this with a temporary test next to yours: choiceQuestion with correct_answer: "B) Paris", the learner picks Madrid, and the judge returns correct. On this head updateNotebookEntry gets is_correct: true. On dev it gets is_correct: false. The backend normalizer leaves such keys as they are (_normalize_quiz_payload only maps an exact key or an exact label), so they can reach the viewer.

A simple fix is to make hasObjectiveKey() use the same resolution as isAnswerCorrect(). For example, also treat the item as objective when key.charAt(0).toUpperCase() is an option key, or move the key resolution into one helper that both functions call. Either way, "readable for a correct answer" and "authoritative for a wrong answer" would always match.

Comment thread web/components/quiz/QuizViewer.tsx Outdated
const key = question.correct_answer.trim();
if (!key) return false;
if (isMultipleChoice(question)) {
return resolveChoiceAnswerKey(key, question.options) in question.options!;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isAnswerCorrect() also accepts correct.charAt(0), so for a key like "B) Paris" exact matching marks B correct, but this returns false and a wrong pick can be flipped by the judge. Could this share the same resolution?

@github-actions
github-actions Bot removed the request for review from pancacake December 4, 2026 23:49
@github-actions github-actions Bot added bug Something isn't working web Web frontend (Next.js UI & components) labels Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working web Web frontend (Next.js UI & components)

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants