fix(coding-agent): clear pending plan-model switch on plan-mode exit#820
Open
metaphorics wants to merge 2 commits intocan1357:mainfrom
Open
fix(coding-agent): clear pending plan-model switch on plan-mode exit#820metaphorics wants to merge 2 commits intocan1357:mainfrom
metaphorics wants to merge 2 commits intocan1357:mainfrom
Conversation
When plan mode is entered mid-stream (session.isStreaming === true), #applyPlanModeModel defers the model switch by queuing #pendingModelSwitch. On plan-mode exit via #exitPlanMode, #planModePreviousModelState was cleared but #pendingModelSwitch was not. A subsequent flushPendingModelSwitch() call (fired by agent_end in EventController) would then apply the queued switch, stranding the session on the plan model after exit. Fix: clear #pendingModelSwitch immediately after the early-out guard in #exitPlanMode, before any tool/model state restoration.
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.
Closes #816.
Fix
Clear
this.#pendingModelSwitch = undefinedimmediately after the early-return guard in#exitPlanMode. The queued switch from the deferred entry path no longer survives plan exit.The remaining restore logic (lines 783-795) then correctly evaluates the post-exit model based on actual current state.
Files
packages/coding-agent/src/modes/interactive-mode.ts— 1 line addition in#exitPlanMode.packages/coding-agent/test/interactive-mode-plan-exit-model-switch.test.ts— new regression test (131 lines) covering the deferred-switch scenario end-to-end.Verification
setModelTemporarycalled once on flush, expected 0); PASSES with fix (setModelTemporarynot called,session.modelstays on default after#exitPlanMode).bun --cwd=packages/coding-agent test: full suite — 2632 pass, 10 pre-existing failures (unrelated to plan-mode/model-switching).bun --cwd=packages/coding-agent run check: tsgo + biome clean.Risk
Very low. Single field clear inside
#exitPlanMode. Existing restore logic handles the rest. The negative case (immediate-switch path, plan entered while not streaming) is unaffected because#pendingModelSwitchis already undefined in that path.