← Back to PRs

#3622: fix(agents): drop orphan tool results

by mickobizzle open 2026-01-28 23:00 View on GitHub →
agents
## Summary Drops orphan toolResult messages that arrive without a matching pending tool call, preventing corrupted transcripts that can trigger repeated "No tool call found" loops. ## Details - Adds a guard option (default enabled) to ignore orphan toolResult messages. - Wires the option through the guard wrapper. - Adds a test to cover the orphan-drop behavior. ## Why A session can end up with a toolResult persisted without its toolCall (e.g., interrupted tool call). Replaying that session repeatedly hits the error and can burn tokens. This prevents new corruption at persistence time. ## Tests - `pnpm vitest src/agents/session-tool-result-guard.test.ts` ## Issue Closes #3621 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR extends the session tool-result guard to optionally drop “orphan” `toolResult` messages (default enabled) that don’t correspond to a currently-pending tool call, and threads the option through the guard wrapper. It also adds a vitest case asserting that an orphan `toolResult` is ignored. Overall this fits the existing guard’s responsibility (normalizing transcript/tool-call pairing and optionally synthesizing missing results) and should help prevent persistence-time corruption loops when replaying sessions. <h3>Confidence Score: 4/5</h3> - This PR looks safe to merge and is narrowly scoped to transcript persistence behavior. - Changes are small and localized (an additional guard branch plus wiring and a targeted test). Main functional concern is that malformed `toolResult` messages without an id are still persisted, which may still allow corruption in some edge cases, but the default orphan-drop should mitigate the reported loop for id-bearing orphans. - src/agents/session-tool-result-guard.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> **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