fix(qwen): make Stop actually stop instead of replaying the prompt - #351
Merged
Merged
Conversation
The qwen provider interrupted a turn via Query.interrupt(). In qwen-code that control request aborts a session-wide controller the CLI never resets, so the CLI exits with code 1 on its next stdin read. The consumer treats "exited with code 1" as a missing backing session and recovers by replaying the last prompt into a fresh session, so every Stop restarted the task from scratch. Interrupt now hard-aborts (marking codeoid's controller aborted, so no recovery fires) and clears pending tool state. The next send rebuilds the loop with `resume`, keeping context. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
rsharath
approved these changes
Oct 4, 2026
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.
Summary
On the qwen backend, pressing Stop did not stop the task: the agent restarted the same prompt from scratch a few seconds later, and repeated Stops just kept restarting it.
Cause. The qwen provider interrupted a turn with
Query.interrupt(). In qwen-code, that control request aborts a session-wideAbortControllerthat the CLI never resets. The in-flight turn stops, but the CLI then exits withCLI process exited with code 1on its next stdin read. The consumer'sisBackingSessionMissing()heuristic matches that message and "recovers" by resetting to a fresh backing session and replaying the last prompt viaonRecoveryNeeded. So an interrupt turned into a full restart that also lost the backing session's history.Fix.
interruptnow goes straight to the hard abort that was previously only the fallback path: it aborts codeoid's own controller, closes the input queue, and clears pending tool state. Because codeoid's controller is marked aborted, the consumer's catch skips recovery. The nextsend()finds the input queue closed, rebuilds the loop withresume: <backingId>, and keeps context.The Claude provider's "keep-warm"
Query.interrupt()is unaffected; this is specific to how qwen-code handles that request.Test plan
src/tests/provider-qwen-interrupt.test.ts(mocks@qwen-code/sdk, modelling the CLI dying after a soft interrupt):interrupt(), emits no error, and does not fireonRecoveryNeededresumeon the same backing idbacking session missing — scheduling recovery)bun test src/tests/provider-qwen*.test.ts,bun run typecheck, biome clean on changed files🤖 Generated with Claude Code