#15509: fix(session): drop tool_use blocks with empty or missing name
stale
Cluster:
Error Handling in Agent Tools
## Summary
`repairToolCallInputs()` already drops tool calls without `input`/`arguments`, but passes through blocks with an empty `name` field. The Anthropic API rejects these with:
```
tool_use.name: String should have at least 1 character
```
This corrupts the session permanently — every subsequent message fails until `/new`.
## Changes
- Add `hasToolCallName()` guard in `session-transcript-repair.ts`
- Drop tool call blocks where `name` is empty string or missing
- Add 2 test cases covering empty and missing name scenarios
## Testing
All 12 tests pass in `session-transcript-repair.e2e.test.ts`.
Closes #15485
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR tightens transcript sanitization in `src/agents/session-transcript-repair.ts` by additionally dropping assistant tool-call blocks whose `name` is empty or missing, preventing provider-side 400s (`tool_use.name` must be non-empty) that can permanently break a session. It adds two E2E tests in `src/agents/session-transcript-repair.e2e.test.ts` to cover empty-name and missing-name tool blocks and asserts the sanitizer removes those blocks (and drops the now-empty assistant message when applicable).
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Change is narrow and defensive (dropping invalid tool-call blocks already known to be rejected by providers) and is covered by new test cases; no behavioral changes outside transcript repair/sanitization logic were observed in the diff.
- No files require special attention
<sub>Last reviewed commit: 3296ced</sub>
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#6687: fix(session-repair): strip malformed tool_use blocks to prevent per...
by NSEvent · 2026-02-01
87.5%
#12487: fix(agents): strip orphaned tool_result when tool_use is sanitized ...
by skylarkoo7 · 2026-02-09
86.0%
#8345: fix: prevent synthetic error repair from creating tool_result for d...
by vishaltandale00 · 2026-02-03
85.9%
#16966: fix: strip tool_use blocks from aborted/errored assistant messages
by StressTestor · 2026-02-15
84.4%
#8312: fix: add logging and markers for tool result repair
by ekson73 · 2026-02-03
84.3%
#4844: fix(agents): skip error/aborted assistant messages in transcript re...
by lailoo · 2026-01-30
84.0%
#19094: Fix empty tool_call_id and function names in provider transcript pa...
by yxshee · 2026-02-17
84.0%
#15143: fix(transcript-repair): validate tool call id and name to prevent G...
by GreyC · 2026-02-13
83.6%
#21166: fix(agents): sanitize tool names in session transcript repair (#8595)
by dinakars777 · 2026-02-19
83.6%
#4700: fix: deduplicate tool_use IDs and enable sanitization for Anthropic
by marcelomar21 · 2026-01-30
83.4%