Repository navigation
fix(translator): drop orphan tool results on the Claude->OpenAI request path (#4385) - #4413
Merged
Merged
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
diegosouzapw
force-pushed
the
fix/4385-claude-orphan-tool
branch
from
June 20, 2026 19:50
fa34314 to
bf2f26d
Compare
tkgo11
pushed a commit
to tkgo11/OmniRoute
that referenced
this pull request
Sep 23, 2026
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.
Closes #4385
Problem
Routing a Claude-protocol conversation (
/v1/messages) to an OpenAI-compatible provider (command-code, customopenai-compatible) returned a 502 from the upstream:claudeToOpenAIRequestemits arole:"tool"message for every Claudetool_resultblock, but never drops an orphan one — atool_resultwhosetool_use_idhas no matchingassistant.tool_calls(e.g. when history truncation / compression removed the assistant turn that issued the call but kept the result). OpenAI-compatible upstreams reject those sequences. This is why downgrading to 3.8.25 "worked" — it depends on the exact history shape the agent sends.Fix
After
fixMissingToolResponses, filter outrole:"tool"messages whosetool_call_idmatches noassistant.tool_callsid. This mirrors the filter already applied on the Responses→Chat path (openai-responses.ts, #2893). Placeholders inserted byfixMissingToolResponses(which DO match a tool_call) are kept; only genuine orphans are removed.Validation (TDD)
New
tests/unit/translator-claude-to-openai-orphan-tool-4385.test.ts— fails on the unfixed code (orphan survives), passes after the fix (3/3): drops an orphan, preserves a paired tool_result, and keeps valid while dropping orphan in the same turn.One existing test (
...converts tool_result blocks into tool messages...) built an unpairedtool_result(technically an orphan that produces the 502); it now pairs it with the assistant tool_call so it still exercises the content-extraction mechanics on a valid sequence — assertions on"20C"/"Thanks"are unchanged. Full translator suites green;typecheck:core+ lint clean.