fix(cli): queue /plan, /interview, /review mid-turn instead of interrupting - #1256
Open
kavish-19 wants to merge 1 commit into
Open
fix(cli): queue /plan, /interview, /review mid-turn instead of interrupting#1256kavish-19 wants to merge 1 commit into
kavish-19 wants to merge 1 commit into
Conversation
…upting
/plan <text>, /interview <text>, and /review <text> (and their input-mode
counterparts when submitted without inline args) called sendMessage()
directly with no check for whether a run was already in progress. Firing
one of these while a previous message was still streaming registered a new
active-run owner, which force-stops the in-flight run ('user-interrupt')
instead of queuing behind it -- so the current job was interrupted and lost
rather than queued, matching what CodebuffAI#1211 describes.
/skill:<name> already gets this right via dispatchSkillPrompt, which checks
isStreaming/streamMessageIdRef/isChainInProgressRef and falls back to
addToQueue when busy. Extract that logic into a shared sendOrQueuePrompt()
helper and route all six call sites (three in command-registry.ts, three in
router.ts) through it so they can't drift out of sync with the busy check
again.
Added a failing-first regression test covering both entry paths (input mode
and inline slash-command args) for all three commands, confirmed red
against the unfixed code, green after.
Claude-Session: https://claude.ai/code/session_018vPhyqaaoKa8cgs7GEnyq5
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.
What
/plan <text>,/interview <text>, and/review <text>— and their input-mode counterparts when submitted without inline args — calledsendMessage()directly with no check for whether a run was already in progress.Why this is a bug
Every other mid-turn submit path in this file (plain text via the composer,
/skill:<name>) checksisStreaming || streamMessageIdRef.current || isChainInProgressRef.currentand falls back toaddToQueue()when busy, so a message typed while the agent is still working waits its turn./plan,/interview, and/reviewnever got that treatment. Firing one of them while a previous message is still streaming callssendMessage()immediately, which registers a new active-run owner inregisterActiveRun— and that force-stops the in-flight run ('user-interrupt') to make room for the new one. The current job is interrupted and lost instead of being queued behind it. Related: #1211, where a user reports a follow-up message "overwriting" the job in progress instead of queuing.Repro (no race required — deterministic):
/plan add dark mode(or/interview ...,/review ...) and submit.Fix
dispatchSkillPrompt(used by/skill:<name>) already implements the correct pattern. Extracted its busy-check-then-queue-else-send logic into a sharedsendOrQueuePrompt()helper incommand-registry.ts, and routed all six call sites through it:command-registry.ts: the/interview,/plan,/reviewcommand handlers (inline-args form)router.ts: theplan,interview,reviewinput-mode submit handlersdispatchSkillPromptitself is now a thin wrapper oversendOrQueuePrompt, so there's one place that owns "send now vs. queue" for every prompt-dispatching command going forward.Testing
Added regression tests in
router-steering.test.tscovering both entry paths (input mode and inline slash-command args) for all three commands, mid-turn and idle:sendMessagewas called, run interrupted) by temporarily reverting the source changes and re-running.Also ran the full
cli/src/commands/suite (198/199 pass; the one pre-existing failure — an OSC 52 clipboard test — reproduces identically on unmodifiedmainand is untouched by this change) andtsc --noEmiton theclipackage (no new errors; the only typecheck errors present are pre-existing environment issues — missing@types/react-domand thetarpackage types — unrelated to the files this PR touches).