← Back to PRs

#15143: fix(transcript-repair): validate tool call id and name to prevent Gemini 400 errors

by GreyC open 2026-02-13 03:10 View on GitHub →
agents stale size: S
This PR adds defensive validation to transcript repair to ensure tool calls have both an ID and a non-empty name. This prevents 400 REQUIRED_FIELD_MISSING errors from Gemini API caused by malformed tool calls in session history. Changes: 1. Added isValidToolCallBlock to check for id and name. 2. Updated repairToolCallInputs to drop invalid tool call blocks. 3. Hardened makeMissingToolResult to use "unknown" for empty names. 4. Updated extractToolCallsFromAssistant to skip tool calls with missing names. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR hardens transcript sanitization/repair for tool use by normalizing tool call IDs and names, filling missing `toolName` fields with `"unknown"`, and dropping assistant tool-call blocks that are missing required inputs/ids. It also updates tool call extraction so synthetic tool results always have a non-empty name, reducing Gemini “REQUIRED_FIELD_MISSING” 400s when session history contains malformed tool calls. These changes fit into the existing `sanitizeToolCallInputs` → `sanitizeToolUseResultPairing` pipeline in `src/agents/session-transcript-repair.ts`, whose goal is to produce provider-compatible message histories by ensuring tool calls have matching, adjacent tool results and by removing/repairing malformed entries. <h3>Confidence Score: 4/5</h3> - Mostly safe to merge, but there is one normalization mismatch that can still orphan and drop valid tool results in edge cases. - The changes are narrow and defensive, and they reduce malformed tool-call data reaching strict providers. The main remaining concern is inconsistent id normalization (toolCall ids are trimmed, toolResult ids are not), which can break pairing and cause silent toolResult drops when ids contain whitespace in persisted transcripts. - src/agents/session-transcript-repair.ts <sub>Last reviewed commit: 04f3747</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs