Repository navigation
Don't lose the answer when validation replaces the practiced word - #761
Merged
Merged
Conversation
Scheduling a word for the first time validates its translation through the LLM. A correction moves the learner's bookmark to a UserWord for the corrected meaning and deletes the original -- but report_exercise_outcome had already bound the Exercise to that original, so the commit failed with 'Instance <UserWord> has been deleted' and the answer was lost: 7 times in the 9 days of production logs (Sep 2026). Schedule first, then record the answer against the word that survived: the original, or the replacement the bookmark now points to. The new test reproduces the production error on the old ordering. #738's comments about the savepoint no longer assume the Exercise is added before scheduling. Replaces the remaining part of #679 (closed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
ArchLens - No architecturally relevant changes to the existing views |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
/report_exercise_outcomefails withInstance <UserWord> has been deleted— 7 times in the last 9 days of production logs, each a learner's answer lost.Scheduling a word for the first time validates its translation through the LLM (
FourLevelsPerWord.find_or_create→validate_and_fix). When the LLM corrects the translation, validation moves the learner's bookmark to a UserWord for the corrected meaning and deletes the original.UserWord.report_exercise_outcomehad already created the Exercise bound to that original, so the commit fails.The fix
report_exercise_outcomenow schedules first, then records the answer against the word that survived — the original, or (if it was deleted) the one its preferred bookmark now points to.find_or_createand its five other callers are unchanged.Also: the comments #738 added about its savepoint assumed the Exercise is added before scheduling; reworded (the savepoint itself stays — other callers can have pending work).
Tests
New test in
test_scheduling_lost_answers.pyreplaces the word the way_fix_bookmarkdoes; it reproduces the production error on the old ordering and passes with the fix.zeeguu/api/test+ scheduling/exercise/bookmark/badge/streak core tests: 230 pass.Replaces the remaining part of #679 (closed — its other two fixes landed differently in #738; its move of validation off the request path can come back as its own design).
🤖 Generated with Claude Code