Skip to content

fix: reset thinking flag on agent switch to prevent leaking into non-thinking agents#2161

Closed
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:fix-thinking-ctrl-4
Closed

fix: reset thinking flag on agent switch to prevent leaking into non-thinking agents#2161
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:fix-thinking-ctrl-4

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 18, 2026

When switching agents via Ctrl+N in the TUI, the session's Thinking flag was carried over from the previous agent. This caused Anthropic API errors when switching from a thinking-enabled agent (e.g. Opus with thinking_budget) to one without (e.g. Sonnet with max_tokens=8192), because the thinking budget default (8192) conflicted with max_tokens.

Assisted-By: docker-agent

…thinking agents

When switching agents via Ctrl+N in the TUI, the session's Thinking flag
was carried over from the previous agent. This caused Anthropic API errors
when switching from a thinking-enabled agent (e.g. Opus with thinking_budget)
to one without (e.g. Sonnet with max_tokens=8192), because the thinking
budget default (8192) conflicted with max_tokens.

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner March 18, 2026 15:48
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

This PR correctly fixes a bug where the thinking flag leaked from one agent to another during agent switches, which could cause Anthropic API errors when switching from a thinking-enabled agent to one without thinking configured.

Code Review:

  • ✅ The fix properly resets sess.Thinking to match the new agent's configuration on agent switch
  • ✅ Comprehensive test coverage added (TestAgentSwitch_ResetsThinkingFlag) that validates the fix
  • ✅ The test correctly simulates switching from Opus (with thinking) to Sonnet (without thinking)
  • ✅ The reset behavior is intentional and necessary to prevent API errors

No issues found in the changed code.

@dgageot dgageot closed this Mar 18, 2026
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.

2 participants