Skip to content

Don't lose the answer when validation replaces the practiced word - #761

Merged
mircealungu merged 1 commit into
masterfrom
wt/sr-lost-answer
Sep 25, 2026
Merged

mircealungu merged 1 commit into
masterfrom
wt/sr-lost-answer

Conversation

@mircealungu

Copy link
Copy Markdown
Member

The bug

/report_exercise_outcome fails with Instance <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_outcome had already created the Exercise bound to that original, so the commit fails.

The fix

report_exercise_outcome now 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_create and 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.py replaces the word the way _fix_bookmark does; 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

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>
@github-actions

Copy link
Copy Markdown

ArchLens - No architecturally relevant changes to the existing views

@mircealungu
mircealungu merged commit e6a4ebb into master Sep 25, 2026
3 checks passed
@mircealungu
mircealungu deleted the wt/sr-lost-answer branch September 25, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant