#8117: Agents: sanitize tool call ids for OpenAI
docker
agents
stale
size: M
Cluster:
Tool Call ID Sanitization
Agents: sanitize tool call ids for OpenAI
## Summary
- Sanitize tool call IDs for OpenAI/OpenRouter to keep them within the 40-char limit.
- Apply tool-call ID sanitization even when using images-only transcript sanitization.
- Update sanitize-session-history tests for openai-responses behavior.
## Why
OpenAI/OpenRouter reject tool calls when `tool_calls[].id` exceeds 40 chars. We only sanitized for Google/Mistral before, so OpenAI/OpenRouter could fail with:
`Invalid 'messages[...].tool_calls[0].id': string too long`.
## Testing
- Not run (config-only fix; relies on existing unit coverage)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR extends transcript/tool-call sanitization so OpenAI-family APIs (including OpenAI-compatible routing via OpenRouter/OpenCode) get tool call IDs rewritten to meet OpenAI’s 40-char limit and character constraints. It updates the transcript policy to enable tool-call ID sanitization for `modelApi` in the OpenAI set, ensures sanitization can run even under `images-only` mode, and adds/updates unit tests to cover OpenAI `tool_calls[].id` and `tool_call_id` rewrites plus the OpenRouter routing case.
Main potential issues are around (1) mixed message schema compatibility (OpenAI `tool` vs internal `toolResult` field names) where sanitization may not keep both sides in sync, and (2) an unrelated Docker default `CMD` change that could break existing container usage.
<h3>Confidence Score: 3/5</h3>
- This PR is reasonably safe to merge, but has a couple of edge-case and deployment-behavior concerns worth addressing first.
- Core logic change is small and has targeted tests, but the tool-call id rewrite may fail to keep IDs consistent when transcripts mix OpenAI-style `tool_call_id` and internal `toolCallId` fields, and the Dockerfile CMD change appears unrelated and could break existing deployments.
- src/agents/tool-call-id.ts (mixed schema rewrite behavior), Dockerfile (entrypoint behavior change)
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12812: fix(transcript-policy): sanitize tool call IDs for all non-OpenAI p...
by justin-nevins · 2026-02-09
86.5%
#12608: fix: sanitize client tool call IDs per provider requirements
by piyushhhxyz · 2026-02-09
83.9%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
83.9%
#4057: fix: sanitize tool call IDs for Azure OpenAI
by wangchuan3533 · 2026-01-29
83.5%
#3647: fix: sanitize tool arguments in session history
by nhangen · 2026-01-29
81.9%
#19094: Fix empty tool_call_id and function names in provider transcript pa...
by yxshee · 2026-02-17
80.9%
#21166: fix(agents): sanitize tool names in session transcript repair (#8595)
by dinakars777 · 2026-02-19
80.1%
#9861: fix(agents): re-run tool_use/tool_result repair after limitHistoryT...
by CyberSinister · 2026-02-05
80.1%
#15649: fix: sanitize tool_use IDs on session write path
by aldoeliacim · 2026-02-13
79.7%
#12487: fix(agents): strip orphaned tool_result when tool_use is sanitized ...
by skylarkoo7 · 2026-02-09
79.7%