Skip to content

fix: keep Claude tool results adjacent - #6035

Merged
diegosouzapw merged 6 commits into
diegosouzapw:release/v3.8.44from
KooshaPari:fix/6026-agentbridge-tool-result
Jul 3, 2026
Merged

diegosouzapw merged 6 commits into
diegosouzapw:release/v3.8.44from
KooshaPari:fix/6026-agentbridge-tool-result

Conversation

@KooshaPari

Copy link
Copy Markdown
Contributor

Fixes #6026.

Problem:

  • Antigravity AgentBridge can send an OpenAI-compatible sequence where a role:"tool" result is separated from the assistant tool call by an intervening user turn.
  • The existing OpenAI -> Claude translator only checked that the tool_use id existed somewhere in the conversation. Anthropic requires each tool_result user turn to immediately follow the assistant turn containing the matching tool_use.

Change:

  • Reattach valid tool_result blocks immediately after the matching assistant tool_use message.
  • Preserve intervening user text after the repaired tool-result turn.
  • Drop true orphan tool_result blocks that cannot be matched safely.

Validation:

  • npm exec --yes tsx -- --test tests/unit/translator-openai-to-claude.test.ts
  • node scripts/check/check-file-size.mjs
  • git diff --check

Note: tests/unit/translator-antigravity-to-openai.test.ts hung with no output when run standalone in this worktree, so I interrupted it and did not count it as a pass.

@KooshaPari
KooshaPari requested a review from diegosouzapw as a code owner July 3, 2026 03:07
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @KooshaPari. Two things before this can land: (1) Scope/labeling — it says "Fixes #6026", but #6026 is an Antigravity-native (Anthropic-format) payload that flows through the executor (AntigravityExecutor), which does not import openai-to-claude — so this translator change doesn't actually intercept the reported #6026 case. That one is fixed at the executor layer by #6055. Please drop the "Fixes #6026" (so it doesn't close an issue it doesn't cover) and reposition this as a general openai→claude tool-result-adjacency improvement. (2) Possible new failure — enforceToolResultAdjacency() can emit two consecutive user turns (e.g. [user, assistant(tool_use), user{tool_result}, user "…"]), which Anthropic rejects with roles must alternate. The new test only checks index order, not role alternation, so it'd pass with an invalid output. Please add a role-alternation assertion (or merge adjacent user turns) and validate. Leaving open for you. 🙏

…gentbridge-tool-result

# Conflicts:
#	config/quality/file-size-baseline.json
@diegosouzapw

Copy link
Copy Markdown
Owner

Merged — thank you, @KooshaPari! 🙏 To be clear, this is not subsumed by the earlier #6026 fix (#6115): that one strips orphan tool_result on the Antigravity→OpenAI MITM path, whereas this PR fixes the opposite direction (OpenAI→Claude) by reattaching a tool_result immediately after its matching tool_use when an intervening user turn separated them (Anthropic requires strict adjacency). I synced your branch onto the current release tip (the file-size baseline conflict was a pre-existing release-side rebaseline, resolved in favor of the release). Your toolResultAdjacency extraction + the regression test (17/17 green here) land as-is. Ships in the next release.

@diegosouzapw
diegosouzapw merged commit c02f8d5 into diegosouzapw:release/v3.8.44 Jul 3, 2026
2 of 3 checks passed
@diegosouzapw diegosouzapw mentioned this pull request Jul 4, 2026
@KooshaPari
KooshaPari deleted the fix/6026-agentbridge-tool-result branch August 13, 2026 06:53
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
Reattach OpenAI tool_result adjacent to tool_use before Claude send (diegosouzapw#6026). Integrated into release/v3.8.44.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants