fix(exam-checker): casual mention no longer hijacks chat; always give an exit (bd-2484) - #142
Open
mah-noor1 wants to merge 1 commit into
Open
fix(exam-checker): casual mention no longer hijacks chat; always give an exit (bd-2484)#142mah-noor1 wants to merge 1 commit into
mah-noor1 wants to merge 1 commit into
Conversation
…an exit A plain-text question — "Can you grade exam papers for me?" — silently started a real exam-grading session because shouldTriggerExamChecker matched the phrase "grade exam" ANYWHERE via .includes(). Once in that session every subsequent plain-text message was captured with no reply, and there was no timeout and no text way out (handleExamCancel was dead code, and a slash command bypassed the checker but left the session active, so the next message was recaptured — the same trap fixed for coaching in bd-2508). Fixes, all TDD (red-first, 14 new tests): - Anchored trigger: the message must BE or LEAD with a trigger phrase, not merely contain one. "grade exams" still starts it; a question mentioning it does not. - Explicit exit words (stop/cancel/exit + Urdu/Arabic) end the session and confirm; a slash command ends it silently then runs (mirrors bd-2508). - Accidental sessions (collecting_images, zero images, untouched >1h) auto- expire so they cannot linger and recapture chat. Baseline suite unchanged (44 pre-existing env failures before and after); +14 passing tests. Refs: bd-2484 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
A plain-text question — "Can you grade exam papers for me?" — silently started a real exam-grading session, then captured every following plain-text message so normal chat stopped working. Only slash commands escaped, and there was no timeout and no way to type your way out.
Two stacked faults, both confirmed from source (not the report):
shouldTriggerExamCheckermatched a keyword anywhere in the text via.includes(), so"grade exam"buried inside a question started the feature.handleExamCancelwas dead code (never wired). A slash command bypassed the checker but left the session active in Supabase (which persists indefinitely — the 24h Redis TTL just re-hydrates from the DB), so the next plain text was recaptured. This is the exact trap already fixed for coaching in bd-2508 ("held for 269 hours").The fix
"grade exams"still starts it; a question that mentions grading does not.stop/cancel/exit(+ Urdu/Arabic) ends the session and confirms it; any slash command ends it silently then runs (mirrors the bd-2508 coaching fix — bypassing without ending lets the next message get recaptured).collecting_images, zero images, untouched > 1h) auto-expires so it can't linger. Never touches a grading that's actually in progress.Files
bot/shared/handlers/exam-checker.handler.jsshouldTriggerExamChecker; newisExamExitText+endActiveExamSession;handleExamCancelnow delegatesbot/shared/handlers/text-message.handler.jsbot/shared/services/exam-checker/exam-session.service.js_isStaleCollectingSession+_expireIfStale, wired intogetActiveTests (TDD, red-first)
2 new suites, 14 tests, each written to fail against current code first:
tests/exam-checker/bd-2484-trigger-and-exit.test.jstests/exam-checker/bd-2484-session-staleness.test.jsFull
npm test: 44 failing suites at baseline == 44 after (all pre-existing environmentaldotenv/dep failures in a fresh checkout), +14 passing, zero new failures.Not covered here / follow-ups
stop(or after 1h) once this is live.🤖 Generated with Claude Code