#10097: fix: add empty thinking blocks to tool call messages when thinking is…
agents
stale
Cluster:
Model Reasoning Fixes
… enabled
When switching from a model with thinking disabled to a model with thinking enabled, API requests would fail with:
"400 thinking is enabled but reasoning_content is missing in assistant tool call message"
This happens because historical assistant messages with tool calls were generated without thinking blocks, but the API requires all assistant tool call messages to have reasoning_content when thinking is enabled.
This fix:
1. Adds `hasHistoryToolCallWithoutThinking()` to detect incompatible history
2. Adds `addEmptyThinkingToToolCallMessages()` to add empty thinking blocks
3. Calls these in `sanitizeSessionHistory()` when thinking is enabled
Fixes #XXXX
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR hardens session history sanitization for “thinking-enabled” models by detecting assistant messages that contain `toolCall` blocks but lack any `thinking` block, and then prepending an empty thinking block to those messages during `sanitizeSessionHistory()`.
The change is implemented in `src/agents/pi-embedded-helpers/openai.ts` (new detection + rewrite helpers) and is wired into the embedded runner’s history sanitization (`src/agents/pi-embedded-runner/google.ts`), with callsites passing `thinkingEnabled` from the run/compaction flows. A new vitest suite covers the helper functions’ behavior.
<h3>Confidence Score: 3/5</h3>
- This PR is directionally safe but needs a correctness gate before merging.
- The core helper logic is small and covered by unit tests, but the sanitizer applies an OpenAI-specific transcript mutation to all model providers when `thinkingEnabled` is true, which can break non-OpenAI payload schemas and turn validation.
- src/agents/pi-embedded-runner/google.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#10786: fix: strip thinking signatures from sessions_list and add includeTh...
by 1kuna · 2026-02-07
82.6%
#6685: fix: suppress thinking leak for Synthetic reasoning models
by AkiLetschne · 2026-02-01
80.5%
#23462: fix: extract thinking blocks as fallback in extractTextFromChatContent
by nszhsl · 2026-02-22
79.3%
#10998: fix(agents): pass session thinking/reasoning levels to session_stat...
by wony2 · 2026-02-07
78.8%
#22797: Feat/auto thinking mode
by jrthib · 2026-02-21
78.6%
#13361: fix(google-antigravity): add Opus 4.6 support and fix thinking.sign...
by SovranAMR · 2026-02-10
78.6%
#19407: fix(agents): strip thinking blocks on cross-provider model switch (...
by lailoo · 2026-02-17
78.5%
#11526: fix(control-ui): hide tool-only assistant messages when thinking is...
by Annaxiebot · 2026-02-07
78.3%
#20050: fix: Telegram polling regression and thinking blocks corruption (AI...
by Vaibhavee89 · 2026-02-18
78.1%
#6678: fix(agents): support thinking tags with attributes
by GHesericsu · 2026-02-01
78.1%