#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
app: web-ui
gateway
commands
agents
stale
Cluster:
Error Handling in Agent Tools
Fixes #8264
## Problem
The session transcript repair mechanism checks for tool call blocks with type `toolUse` (camelCase) but Anthropic uses `tool_use` (snake_case). This caused the repair to miss valid tool_use blocks when extracting tool calls from assistant messages.
When a tool result was missing and the repair mechanism inserted a synthetic error, it would reference a tool_use_id that appeared missing to Anthropic (because we didn't extract it properly), leading to permanent session corruption.
## Solution
Now checks for both format variants:
- `toolUse` (camelCase, used by some providers)
- `tool_use` (snake_case, Anthropic's format) ← **NEW**
- `toolCall` (alternative format)
- `functionCall` (OpenAI format)
This ensures the repair mechanism correctly identifies all tool call blocks regardless of which provider format is used, preventing the "unexpected tool_use_id" errors that permanently broke sessions.
## Testing
- Verified code change matches Anthropic's documented format
- Checked that both camelCase and snake_case variants are now supported
- Minimal change with no risk of breaking existing functionality
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR fixes transcript repair compatibility with Anthropic by treating assistant tool call blocks with `type: "tool_use"` the same as existing `toolUse`/`toolCall`/`functionCall` variants during tool call extraction, preventing spurious synthetic “missing tool result” insertions.
In addition, it includes a set of extensions (cortex, conversation-summarizer, self-reflection) and several related core changes:
- `message` tool and outbound send path now propagate the requester `sessionKey` and add a guard to avoid corrupting the original session’s delivery context when outbound routing resolves back to the requester session.
- Agent invocation paths accept a per-run `model` override to avoid session patch race conditions.
- Image tool resolves `maxTokens` from configured extra params instead of a hardcoded 512.
Overall, the key functional fix is small and targeted (support snake_case `tool_use`), while the rest of the PR introduces new plugins and some session/model-routing safeguards.
<h3>Confidence Score: 3/5</h3>
- This PR is likely safe to merge, but it includes broad additional changes beyond the stated transcript-repair fix that deserve extra scrutiny.
- The transcript repair change itself is straightforward and low risk. However, the PR also adds multiple new extensions and modifies outbound session handling and agent model override behavior; these are higher surface-area changes where small edge cases (e.g., assumptions about required fields) could cause runtime issues.
- src/agents/session-transcript-repair.ts, src/infra/outbound/outbound-session.ts, src/commands/agent.ts, and the new extensions under extensions/
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
87.3%
#4700: fix: deduplicate tool_use IDs and enable sanitization for Anthropic
by marcelomar21 · 2026-01-30
87.1%
#8345: fix: prevent synthetic error repair from creating tool_result for d...
by vishaltandale00 · 2026-02-03
86.8%
#4844: fix(agents): skip error/aborted assistant messages in transcript re...
by lailoo · 2026-01-30
86.7%
#12487: fix(agents): strip orphaned tool_result when tool_use is sanitized ...
by skylarkoo7 · 2026-02-09
86.3%
#14328: fix: strip incomplete tool_use blocks from errored/aborted messages...
by Kropiunig · 2026-02-12
86.1%
#3362: fix: auto-repair and retry on orphan tool_result errors
by samhotchkiss · 2026-01-28
84.9%
#7525: Agents: skip errored tool calls during pairing
by justinhuangcode · 2026-02-02
84.7%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
84.7%
#6687: fix(session-repair): strip malformed tool_use blocks to prevent per...
by NSEvent · 2026-02-01
84.4%