Skip to content

fix(coding-agent): clear pending plan-model switch on plan-mode exit#820

Open
metaphorics wants to merge 2 commits intocan1357:mainfrom
metaphorics:fix/plan-exit-clear-pending-model-switch
Open

fix(coding-agent): clear pending plan-model switch on plan-mode exit#820
metaphorics wants to merge 2 commits intocan1357:mainfrom
metaphorics:fix/plan-exit-clear-pending-model-switch

Conversation

@metaphorics
Copy link
Copy Markdown
Contributor

Closes #816.

Fix

Clear this.#pendingModelSwitch = undefined immediately 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

  • Sanity (red/green): regression test FAILS without fix (setModelTemporary called once on flush, expected 0); PASSES with fix (setModelTemporary not called, session.model stays 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 #pendingModelSwitch is already undefined in that path.

metaphorics and others added 2 commits April 27, 2026 03:53
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plan-mode exit fails to clear deferred #pendingModelSwitch, stranding next turn on plan-model

1 participant