← Back to PRs

#21166: fix(agents): sanitize tool names in session transcript repair (#8595)

by dinakars777 open 2026-02-19 18:51 View on GitHub →
agents size: S
Fixes #8595. Supersedes #8654. ## Description This PR addresses the issue where hallucinated whitespace in tool names breaks strict providers like OpenAI Codex. It now uses the standardized `normalizeToolName` helper for consistency and includes a new unit test. ## Changes - Trims and lowercases tool names in `extractToolCallsFromAssistant` using `normalizeToolName`. - Ensures `session-transcript-repair` logic persists sanitized names. - Adds `src/agents/tool-call-id.test.ts` to verify sanitization logic. - Type safety improvements (removed `as any` casts). ## Verification - Added new unit test `src/agents/tool-call-id.test.ts` covering valid, whitespace-padded, and missing-name scenarios. - Verified with `pnpm test src/agents/tool-call-id.test.ts`. <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR fixes tool name sanitization in session transcript repair by applying `normalizeToolName` to trim and lowercase tool names, preventing hallucinated whitespace from breaking strict providers like OpenAI Codex. The fix is applied in `extractToolCallsFromAssistant`, which is used by `repairToolUseResultPairing` to ensure consistent tool names throughout the transcript repair pipeline. Includes comprehensive test coverage and a separate logging improvement in compaction.ts. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The changes are focused, well-tested, and follow existing patterns. The fix correctly uses the standardized `normalizeToolName` helper which is already used throughout the codebase. The new tests provide good coverage of edge cases. The compaction.ts logging change aligns with the repo's logging standards. - No files require special attention <sub>Last reviewed commit: 4ce3310</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs