Skip to content

fix(antigravity): strip orphan tool_use/tool_result pairs before upstream send (#6026) - #6055

Closed
diegosouzapw wants to merge 1 commit into
release/v3.8.44from
fix/6026-antigravity-toolpairs
Closed

diegosouzapw wants to merge 1 commit into
release/v3.8.44from
fix/6026-antigravity-toolpairs

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Closes #6026.

Bug

Antigravity (Claude-opus-4.6 on Vertex) via AgentBridge/MITM returned 400:

messages.0.content.1: unexpected tool_use_id found in tool_result blocks: toolu_vrtx_... Each tool_result block must have a corresponding tool_use block in the previous message.

The client shipped a history whose first message already carried a tool_result with no preceding tool_use (an orphan).

Root cause

open-sse/services/contextManager.ts::fixToolPairs() already strips exactly this orphan — but AntigravityExecutor overrides BaseExecutor.execute(), and the base executor's tool-pair guard (base.ts ~L1099, fixToolPairs/fixToolAdjacency/stripTrailingAssistantOrphanToolUse) lives in the base execute(). So the Antigravity path never ran it — the orphan reached Vertex/Anthropic unmodified.

Fix

Add sanitizeAntigravityToolMessages() that mirrors the exact sequence the base executor uses for Claude-bound providers (fixToolPairs → fixToolAdjacency → re-fixToolPairs → stripTrailingAssistantOrphanToolUse), and call it in AntigravityExecutor.execute() on the upstream body before tool cloaking (which only remaps names). Idempotent on clean histories.

Validation (Hard Rule #18 — TDD)

  • New: tests/unit/antigravity-orphan-toolresult-6026.test.ts (3) — reproduces the orphan-tool_result-at-messages[0] payload and asserts it's stripped; asserts a valid tool_use→tool_result pair is preserved; asserts a no-op on bodies without a messages array. Fails on the pre-fix path (no sanitization ran).
  • typecheck:core ✓ · lint ✓ (0 errors) · check:cycles ✓ · check:docs-sync ✓ · existing antigravity suites (43) ✓

Note

Reproduced from the issue's error + confirmed root cause in code (executor override bypasses the base guard). Applied the proven base-executor sequence rather than a bespoke fix to avoid over/under-stripping.

Not merged — opened for review, pointed at release/v3.8.44.

@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!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@diegosouzapw

Copy link
Copy Markdown
Owner Author

Closing as superseded — the underlying issue #6026 (orphan Antigravity tool_result) was fixed and merged into the release via #6115 (strip orphan tool_result on Antigravity MITM path, commit 29e04b7), which lands the canonical translator-side fix plus a dedicated regression test. This PR's executor-side approach is no longer needed. 🙏

@diegosouzapw
diegosouzapw deleted the fix/6026-antigravity-toolpairs branch July 4, 2026 07:38
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.

1 participant