#23462: fix: extract thinking blocks as fallback in extractTextFromChatContent
size: S
Cluster:
Model Reasoning Fixes
## Problem
`extractTextFromChatContent()` in `src/shared/chat-content.ts` only extracts `type: "text"` content blocks, completely ignoring `type: "thinking"` blocks. When models running in extended-thinking or high-thinking modes (e.g. `thinkingDefault: "xhigh"`) place their response in thinking blocks, the subagent auto-announce flow silently drops the output.
This causes subagent completion messages to be lost — the run shows `status: "ok"` but no text is delivered back to the requester session. The issue is most visible with agents using high-thinking models (e.g. GPT-5.3 Codex), but affects all subagents when the LLM returns content primarily in thinking blocks.
### Call chain
1. `runSubagentAnnounceFlow()` calls `readLatestSubagentOutput()`
2. → `readLatestAssistantReply()` → `extractAssistantText()`
3. → `extractTextFromChatContent()` — **skips thinking blocks, returns null**
4. → announce delivers `"(no output)"` or is silently dropped
## Fix
Collect thinking blocks alongside text blocks in `extractTextFromChatContent()`. Text blocks are still preferred when both types exist (preserving existing behavior). Thinking blocks are only used as a fallback when no text content is found.
## Changes
- `src/shared/chat-content.ts`: Collect `type: "thinking"` blocks and use as fallback
- `src/shared/shared-misc.test.ts`: Add 3 test cases for thinking block extraction
## Testing
- Thinking-only content → extracts thinking text ✅
- Mixed text + thinking → prefers text blocks ✅
- Empty thinking → returns null ✅
- All existing tests pass (no behavior change for text-only content)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds fallback extraction of `type: "thinking"` blocks in `extractTextFromChatContent()` to prevent subagent output from being silently dropped when models place responses in thinking blocks instead of text blocks.
The fix collects thinking blocks alongside text blocks and uses thinking content only when no text blocks are present, preserving existing behavior while preventing "(no output)" failures in subagent announce flows. The change includes test coverage for thinking-only content, mixed content priority, and empty thinking blocks.
One issue found: thinking blocks don't apply the `sanitizeText` option, creating an inconsistency with text block processing that could cause sanitized content to be incorrectly filtered.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with one logical issue requiring attention
- The core fix correctly implements thinking block fallback extraction and includes comprehensive test coverage. However, thinking blocks bypass the `sanitizeText` option applied to text blocks, creating inconsistent behavior that could cause issues when callers rely on sanitization (like `sanitizeTextContent` in subagent-announce.ts)
- src/shared/chat-content.ts requires attention for sanitization consistency
<sub>Last reviewed commit: c128c5a</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#10097: fix: add empty thinking blocks to tool call messages when thinking is…
by cyxer000 · 2026-02-06
79.3%
#20050: fix: Telegram polling regression and thinking blocks corruption (AI...
by Vaibhavee89 · 2026-02-18
78.1%
#10786: fix: strip thinking signatures from sessions_list and add includeTh...
by 1kuna · 2026-02-07
77.8%
#17304: feat(gemini): robust handling for non-XML reasoning headers (`Think...
by YoshiaKefasu · 2026-02-15
77.8%
#19555: feat(android): collapsible thinking/code blocks in chat
by gregmousseau · 2026-02-17
77.3%
#16733: fix(ui): avoid injected newlines when tool output is hidden
by jp117 · 2026-02-15
77.2%
#17455: fix: strip content before orphan closing think tags
by jwt625 · 2026-02-15
76.9%
#19407: fix(agents): strip thinking blocks on cross-provider model switch (...
by lailoo · 2026-02-17
76.9%
#13235: feat: stream reasoning_content via /v1/chat/completions SSE
by mode80 · 2026-02-10
76.7%
#6678: fix(agents): support thinking tags with attributes
by GHesericsu · 2026-02-01
76.5%