[Bug]: Pending Mastery Path quiz card becomes ungradable after KB re-index ("Prepare the lesson again" loop)
Describe the bug
A pending Mastery Path quiz card becomes permanently ungradable once the knowledge base behind its objective is re-indexed (for example after adding a new document to the KB). Every mastery_grade call for that card fails with:
The selected sources or their index changed. Prepare the lesson again.
Following that instruction does not help: mastery_prepare_lesson refreshes the objective's lesson_evidence, but the card keeps the source_evidence snapshot it was created with. validate_question() (deeptutor/learning/semantic_assessment.py) validates that frozen snapshot via validate_evidence(), whose scope_fingerprint now includes the new index version/catalog digest (lesson_evidence.py, scope_snapshot() / check around "The selected sources or their index changed"). The check can therefore never pass again for that card.
Observed effect in a real session: the learner answered a spaced-review card (procedure objective, numeric calculation) correctly. The tutor called mastery_prepare_lesson → mastery_grade → error, repeated this over three turns (each 110–150 s), told the learner the answer was correct, and finally called mastery_skip_question. The answer was never recorded as evidence. Because the objective is still due, next stays on the same review objective, so the route UI keeps highlighting it while the chat has already moved on to new material.
Steps to reproduce
- Mastery Path with a KB source; have a
mastery_quizcard pending (e.g. a due review card) for an objective whosetopic_source_idspoint into that KB. - Add a document to the same KB (
POST /api/knowledge-bases/<kb>/upload) and let indexing finish, so the published index version/catalog digest changes. - Answer the pending card in the path chat.
- Tool trace:
mastery_grade→ "The selected sources or their index changed. Prepare the lesson again.";mastery_prepare_lessonsucceeds;mastery_gradefails again with the same message. Loop until the tutor skips the card.
Code on current dev (checked against 60fb3bdfd): service.py grade path calls validate_question(self._store, tx.progress, interaction.question) and raises MasteryInteractionError on LessonUnavailable; nothing refreshes or reissues the stale card.
Expected behavior
One of:
- Grading re-validates the card against fresh evidence when only the index version changed but the card's cited pages (
document_key,page_index,source_digest) are still present and unchanged, then grades the stored answer; or - the engine voids the stale card itself and reissues an equivalent card, telling the tutor to ask again — instead of an instruction ("Prepare the lesson again") that cannot resolve the error.
In both cases the learner's already submitted answer should not be silently lost.
Environment
- DeepTutor 1.7.2 (pip), same logic on
dev60fb3bdfd - Mastery Path, LlamaIndex KB, incremental KB upload
Additional context
Related to the tracking issue #1940 (Mastery Path reliability). Any workflow that adds material during a semester (weekly slides) hits this for every card created before the upload.
Verified fixed on the current local dev branch (ef44b97564f7), with regression checks.
will be fixed in the next releases!