← Back to PRs

#7525: Agents: skip errored tool calls during pairing

by justinhuangcode open 2026-02-02 22:59 View on GitHub →
agents
## 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