fix: prevent ordinary prompt text from being interpreted as a mode switch (#3387)#3491
Conversation
Round-2 review: when StartTurnRequest.mode carries a non-token value, fall back to the thread's persisted mode via parse_mode_opt instead of coercing to Agent, so an invalid override never crosses the mode boundary (#3387). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HzUHiFSX6tAEdQtQGA3hDx
parse_mode's broad catch-all silently coerced any unrecognized string into a valid AppMode, so a stray prompt fragment reaching the runtime turn-start resolver could enter Plan/Agent/YOLO mode with no explicit request (#3387). Split out a strict parse_mode_opt that resolves only the exact explicit tokens (agent/plan/yolo plus the numeric aliases 1/2/3, matching the /mode command's parse_mode_arg) and returns None otherwise; parse_mode stays an infallible wrapper defaulting unknown input to Agent. Adds regression coverage asserting prompt fragments like "plan a trip to Tokyo" and "enter yolo mode" never coerce into a mode. Fixes #3387 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HzUHiFSX6tAEdQtQGA3hDx
|
Claude finished @Hmbown's task in 1m 57s —— View job PR Review: fix: prevent ordinary prompt text from being interpreted as a mode switch (#3387)Tasks
SummaryThe fix is correct and the approach is clean. The split into CorrectnessThe core fix is sound. ( Old: New: The numeric aliases ( Pre-existing follow-up (not introduced here): Provider/Model/Route SafetyNot touched by this PR. No code path infers a provider or model from freeform text. ✅ TestsCoverage is solid:
Minor: the test name The existing Good Choices
Verdict: Approve. The fix is minimal, correct, and well-tested. The |
Rebased, credit-preserving replacement for #3455 (which was red only due to a stale base; the diff itself is clean). Cherry-picked @mvanhorn's two commits onto current
mainso CI runs against the live tree.Closes #3387.
What
RuntimeThreadManagerpreviously coerced any unrecognized per-turn mode override toAgentviaparse_mode. A stray prompt fragment in the mode slot could silently flip the thread's mode. This splits resolution:parse_mode_optresolves only explicit tokens (agent/plan/yolo) and numeric aliases (1/2/3); anything else returnsNone.This aligns with AGENTS.md: route/mode changes must come from explicit user choice, not from interpreting raw prompt text.
Testing
cargo fmt -p codewhale-tui -- --check✅cargo test -p codewhale-tui --bin codewhale-tui -- parse_mode→ 6 passed ✅ (incl. newparse_mode_opt_resolves_explicit_tokens_and_aliases,parse_mode_opt_rejects_prompt_fragments,parse_mode_wrapper_defaults_and_resolves_numeric_aliases)Harvested from #3455.
Co-authored-by: Matt Van Horn 455140+mvanhorn@users.noreply.github.com