DeepTutor icon indicating copy to clipboard operation
DeepTutor copied to clipboard

[Bug]: mastery_grade keeps re-grading a stale clarification request; a later composer answer to a free-text question is never graded

Open BenjiAvH opened this issue 3 weeks ago • 2 comments

Bug description

Free-text follow-up to #1004 (which was fixed for choice cards only).

On a Mastery Path, the tutor poses a short-answer/procedure question with mastery_quiz. The learner's first composer reply is a request for help ("I don't understand, please explain the task with the solution"). mastery_grade correctly returns result: "ungraded", final: false, needs_clarification: true, and the interaction stays ANSWERED with that request stored as user_answer.

After the explanation, the learner answers in the composer with a correct calculation. Every subsequent mastery_grade call (with the new answer, the correct question_id, and the new _learner_message) still grades the old help request: the tool result shows learner_answer = the original request and needs_clarification: true again. The question can never be graded; the gate stays at mastery 0.0. In our session this repeated four times until the tutor called mastery_skip_question itself.

Root cause (current dev)

deeptutor/capabilities/mastery/tools.py, MasteryGradeTool.execute:

if interaction is not None and interaction.status == InteractionStatus.ANSWERED:
    ...
    if question.question_type != "choice" or is_readable_choice_answer(stored, question.choice_map):
        answer = stored

For every non-choice question the stored user_answer always replaces the new reply, even when the stored reply was already ruled non-final. LearningService.grade_interaction_semantic does the same (answers = {qid: interaction.user_answer if ANSWERED ...}).

LearningService.record_question_answer already supports revising an ANSWERED interaction whose result.final is False (emits assessment.revised), but that path only runs from the card-commit adapter (_commit_mastery_card_answer). A reply typed in the composer never reaches it, so the stale answer is reused forever.

Steps to reproduce (synthetic)

  1. register_question with a leaf PendingQuestion (expected_answer="photosynthesis").
  2. MasteryGradeTool().execute(_mastery_path_id=..., question_id="q1", _learner_message="I don't get it, explain") with a judge returning ungraded → needs_clarification: true, status ANSWERED.
  3. MasteryGradeTool().execute(..., _learner_message="photosynthesis").

Expected: graded correct. Actual: is_correct: None, needs_clarification: true, judge receives the old text again.

Proposed fix

In MasteryGradeTool.execute, before the stored-answer replacement: if the single (non-group) interaction is ANSWERED, its result.final is False, and the new non-empty reply differs from the stored one, call the existing service.record_question_answer(path_id, answer, interaction_id=...) revision path, re-read the interaction, then continue. A repeated identical or empty message does not revise. I have a ~20-line patch plus two regression tests (red before, green after; tests/capabilities + tests/services/session pass locally) and can open a PR against dev if this direction is acceptable.

Environment

DeepTutor 1.7.2 (pip), code path unchanged on current dev. Tracking: #1940.

BenjiAvH avatar Nov 10 '26 12:11 BenjiAvH

I reproduced the free-text stall on freshly fetched dev@60fb3bdf using #2605's submitted tool-level regression unchanged: after the help request is recorded and judged non-final, the later photosynthesis reply still returns is_correct: null. At the draft's current head 3ee8efe24, the same test grades it correct and persists the new learner answer.

The repeated-help and model-only-answer negative controls pass on both versions. The current tool, semantic-assessment, question-group and private-kwarg test files pass together (162 passed). This is controlled-judge/durable-store verification; it does not establish how a live model classifies a second clarification question.

I also found and posted an additional regression on #2605: the new global underscore filter removes valid MCP inputs such as a declared _id, so unrelated tools either fail dispatch or lose an optional argument. The comment includes a small test that passes on dev and fails on the draft. The original recovery works in the tested case, but the shared-dispatcher change and the author's already-noted follow-up-question behavior still need review before treating this issue as resolved.

Taz33m avatar Nov 10 '26 20:11 Taz33m

Verified fixed on the current local dev branch (ebd0f11083c0), with regression checks.

will be fixed in the next releases!

pancacake avatar Nov 14 '26 16:11 pancacake