fix(agent): handle duplicate tool call IDs in OpenAI-compatible transcripts#283
Merged
viettranx merged 2 commits intoMar 19, 2026
Merged
Conversation
Replace complex occurrence-aware queue system with simpler approach: - uniquifyToolCallIDs: append runID+iteration+index to all IDs at response time, guaranteeing cross-turn uniqueness via UUID - sanitizeHistory: simple seen-set dedup for legacy sessions with pre-existing duplicate IDs, no queue/counter logic needed - Restore full problem description in sanitizeHistory docstring - Add unit tests for both dedup paths and edge cases
pull Bot
pushed a commit
to Stars1233/goclaw
that referenced
this pull request
Mar 19, 2026
…cripts Simplified approach to fix duplicate tool_call_ids that cause HTTP 400 on OpenAI-compatible APIs (OpenRouter, vLLM, DeepSeek). - uniquifyToolCallIDs: appends runID+iteration+index to all IDs at response time, guaranteeing cross-turn uniqueness via UUID - sanitizeHistory: simple seen-set dedup for legacy sessions with pre-existing duplicate IDs - Anthropic guard: skips ID rewriting when RawAssistantContent is present - Unit tests for both paths + edge cases Closes nextlevelbuilder#283
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Issue
Several "OpenAI-compatible" APIs (including OpenRouter, vLLM, and certain local models) strictly enforce unique tool_call_ids across the entire conversation history. If a transcript contains duplicate IDs, the provider returns an HTTP 400 Bad Request, effectively breaking the session. This happens in two ways:
The Fix
This PR implements an "occurrence-aware" ID sanitization strategy to ensure transcript-level uniqueness without losing data.
sanitizeHistoryininternal/agent/loop_history.goto track how many times a raw ID has been seen in the transcript. Duplicate IDs are elegantly rewritten (e.g., id , id_1, id_2) while maintaining the correct pairing between assistant calls and tool results via encounter-order queues.normalizeToolCallIDsininternal/agent/loop.go. This catches and fixes collisions immediately as they are returned by the LLM, ensuring that new messages join the history with unique IDs from the start.