#7525: Agents: skip errored tool calls during pairing
agents
Cluster:
Error Handling in Agent Tools
## Summary
- Skip tool calls from errored/aborted assistant messages when pairing tool results or tracking pending calls.
- Drop orphaned tool results that belong to errored tool calls.
- Add regression tests and note the fix in the changelog.
## Changes
- Ignore tool calls on stopReason="error"/"aborted" in session tool-result guard + transcript repair.
- Add tests for errored tool-call pairing behavior.
## Testing
- pnpm vitest run --config vitest.unit.config.ts \
src/agents/session-transcript-repair.test.ts \
src/agents/session-tool-result-guard.test.ts
Fixes #7329
AI-assisted: Yes (Codex). Prompts/session logs available on request.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the agent session transcript tooling to treat tool calls from errored/aborted assistant messages as non-authoritative for pairing.
- `session-tool-result-guard` now skips tracking tool calls when the assistant message has `stopReason: "error" | "aborted"`, preventing synthetic toolResult insertion for those calls.
- `session-transcript-repair` similarly ignores tool calls from errored/aborted assistant messages, which causes any associated toolResults to be treated as orphans and dropped.
- Adds regression tests covering these scenarios and records the fix in `CHANGELOG.md`.
This fits into the broader transcript-sanitization pipeline meant to satisfy strict model/provider requirements that tool calls and tool results must be properly paired and ordered.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge, but there is a remaining edge case where orphan tool results can still be persisted.
- The core change is small and well-covered by new unit tests, but the session-level guard still appends toolResult messages even when they no longer correspond to tracked pending tool calls (especially after skipping errored tool calls), which can reintroduce strict-provider transcript rejection via free-floating toolResult entries.
- src/agents/session-tool-result-guard.ts
<!-- 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
#4844: fix(agents): skip error/aborted assistant messages in transcript re...
by lailoo · 2026-01-30
91.2%
#12487: fix(agents): strip orphaned tool_result when tool_use is sanitized ...
by skylarkoo7 · 2026-02-09
87.3%
#9416: fix: drop errored/aborted assistant tool pairs in transcript repair
by xandorklein · 2026-02-05
87.2%
#9085: fix: improve stability for terminated responses and telegram retries
by vladdick88 · 2026-02-04
85.9%
#3622: fix(agents): drop orphan tool results
by mickobizzle · 2026-01-28
85.0%
#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
by heliosarchitect · 2026-02-03
84.7%
#3362: fix: auto-repair and retry on orphan tool_result errors
by samhotchkiss · 2026-01-28
84.1%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
83.8%
#4852: fix(agents): sanitize tool pairing after compaction and history tru...
by lailoo · 2026-01-30
83.7%
#3647: fix: sanitize tool arguments in session history
by nhangen · 2026-01-29
83.4%