Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(mastery): name the picked option next to its letter in the grade seed (#1993)

drakeo33805f302e3559e
diff --git a/deeptutor/capabilities/mastery/loop.py b/deeptutor/capabilities/mastery/loop.py
index 0ed181d02..d019236bc 100644
--- a/deeptutor/capabilities/mastery/loop.py
+++ b/deeptutor/capabilities/mastery/loop.py
@@ -807,11 +807,11 @@ class MasteryLoopCapability:
{**result, "is_correct": result.get("is_correct", grade.get("is_correct"))}
)
learner_answer = str(result.get("learner_answer") or "").strip()
+ learner_body = str(result.get("learner_body") or "").strip()
+ picked = f"{learner_answer}: {learner_body}" if learner_body else learner_answer
lines = [
"[Mastery] The learner answered the open question on its card and the "
- f"engine reports: {outcome}"
- + (f' (they answered "{learner_answer}")' if learner_answer else "")
- + ".",
+ f"engine reports: {outcome}" + (f' (they answered "{picked}")' if picked else "") + ".",
str(result.get("feedback") or ""),
]
if result.get("final") is False or outcome == "ungraded":
diff --git a/deeptutor/learning/question_card.py b/deeptutor/learning/question_card.py
index 60f47566f..f527461db 100644
--- a/deeptutor/learning/question_card.py
+++ b/deeptutor/learning/question_card.py
@@ -112,6 +112,7 @@ def build_grade_result(
it is graded — which is exactly when they are worth reading.
"""
label = str(correct_label or "").strip()
+ picked = str(learner_answer or "").strip()
payload = {
"question_id": str(question_id or ""),
"is_correct": is_correct,
@@ -120,6 +121,10 @@ def build_grade_result(
"feedback": feedback,
"confidence": confidence,
"learner_answer": str(learner_answer or ""),
+ # The option text behind the picked letter: the card may show the
+ # options in a different order than the tutor registered them, so the
+ # letter alone does not say what the learner chose.
+ "learner_body": str(choice_options.get(picked) or "") if picked else "",
"correct_label": label,
"correct_body": str(choice_options.get(label) or "") if label else "",
"explanation": str(explanation or ""),
diff --git a/tests/capabilities/test_mastery_capability.py b/tests/capabilities/test_mastery_capability.py
index 95578d960..45d27d6e1 100644
--- a/tests/capabilities/test_mastery_capability.py
+++ b/tests/capabilities/test_mastery_capability.py
@@ -815,3 +815,35 @@ def test_kb_seed_is_left_alone_outside_mastery_mode() -> None:
metadata={"mastery_card_answered": True},
)
assert MasteryLoopCapability().skip_kb_seed(context) is False
+
+
+def test_seed_names_the_option_the_learner_picked_not_just_its_letter():
+ """A bare letter is ambiguous once the card shuffles the options.
+
+ The tutor registered the options in its own order; the card shows (and the
+ engine persists) a shuffled one. "D" therefore means a different option in
+ the tutor's context than on the learner's screen (HKUDS/DeepTutor#1993),
+ so the picked option's body has to travel with the letter.
+ """
+ from deeptutor.learning.question_card import build_grade_result
+
+ shuffled = {
+ "A": "Each instance remembers request ids in local memory",
+ "B": "Disable the send button while waiting",
+ "C": "SELECT first, then INSERT",
+ "D": "Idempotency key plus an atomic claim in the backend",
+ }
+ result = build_grade_result(
+ question_id="q-1",
+ is_correct=True,
+ learner_answer="D",
+ correct_label="D",
+ choice_options=shuffled,
+ explanation="why",
+ )
+ context = _context()
+ context.metadata["mastery_card_grade"] = {"is_correct": True, "result": result}
+
+ seed = MasteryLoopCapability()._grade_seed(context)
+
+ assert "Idempotency key plus an atomic claim in the backend" in seed