Skip to content

fix(ai): preserve Vertex Anthropic tool continuations - #43498

Merged
rekram1-node merged 1 commit into
anomalyco:v2from
major:vertex-anthropic-fix
Aug 25, 2026
Merged

rekram1-node merged 1 commit into
anomalyco:v2from
major:vertex-anthropic-fix

Conversation

@major

@major major commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Fixes #43478

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Vertex returns HTTP 404 when a Claude tool continuation ends with a native system message after a local tool result.
This folds chronological updates following local tool results into the user tool-result turn for Vertex Anthropic requests across active continuations and multi-turn history.
Direct Anthropic requests and ordinary terminal Vertex system updates remain native.
This complements #43479, which fixes the Gemini continuation path.

How did you verify your code works?

  • bun test test/provider/anthropic-messages.test.ts from packages/ai (64 passed)
  • bun typecheck from packages/ai
  • Live standalone testing with google-vertex/claude-opus-4-8@default multi-step tool execution, verifying zero 404s

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

The search found PR #43479 which is related but distinct:

Related PR:

No duplicate PRs found for the Vertex Anthropic tool continuations fix. The related PR #43479 addresses a similar issue but for Gemini instead of Anthropic/Vertex, making them distinct fixes for different providers.

@major
major force-pushed the vertex-anthropic-fix branch from 42be68d to 4da0afa Compare August 19, 2026 22:24
@major

major commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Good method for testing:

opencode2 run --standalone --model 'google-vertex/claude-opus-4-8@default' --format json 'Use your available tools to fetch current NVDA daily closing-price data and calculate its 20-trading-day simple moving average. You must make at least one tool call before answering. Report the SMA, data source, and the latest included trading date.'

@major
major force-pushed the vertex-anthropic-fix branch 2 times, most recently from 9178e70 to 6a12f2f Compare August 20, 2026 12:27
@major
major marked this pull request as draft August 20, 2026 13:24
@major
major force-pushed the vertex-anthropic-fix branch from 6a12f2f to bdeec0a Compare August 20, 2026 13:31
@major
major marked this pull request as ready for review August 20, 2026 14:14
@major
major force-pushed the vertex-anthropic-fix branch 2 times, most recently from 9547fae to 4588b78 Compare August 21, 2026 12:16
@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  • packages/ai/src/protocols/anthropic-messages.ts:35 — the "google-vertex-messages" route-id string is now hard-coded in two modules (also cache-policy.ts:9). Consider a shared protocol-id constant so the two checks can't drift apart when routes are renamed.
  • cache-policy.ts — adding google-vertex-messages to RESPECTS_INLINE_HINTS flips cache_control emission on for all Vertex Anthropic requests; this is a behavior change beyond the 404 fix. Live testing reportedly shows 100% cache hits, but reviewers should confirm Vertex accepts ephemeral (incl. TTL variants) on every block type the policy pass annotates.
  • anthropic-messages.ts:35 — early return only fires when previous?.role === "tool", so system-after-user and terminal-system cases keep native handling as the tests pin. Correct scope.
  • Tests: good coverage — folded continuation, multi-turn history persistence, direct-Anthropic parity, ordinary terminal Vertex native, plus a new cache-policy case for Vertex breakpoints.
  • Nit: comment says Vertex "rejects/404s" — worth linking the upstream issue/doc in the PR body if available. No blocking issues found.

@major
major force-pushed the vertex-anthropic-fix branch from 36b6c49 to 6fe5f6e Compare August 25, 2026 13:17
- fold system updates after local tool results into Vertex tool-result turns

- preserve native system updates for direct Anthropic and ordinary Vertex requests

Refs anomalyco#43478

Signed-off-by: Major Hayden <[email protected]>
@major
major force-pushed the vertex-anthropic-fix branch from 6fe5f6e to 597a907 Compare August 25, 2026 13:31
@rekram1-node
rekram1-node merged commit 2e7f06a into anomalyco:v2 Aug 25, 2026
2 checks passed
@major
major deleted the vertex-anthropic-fix branch August 26, 2026 11:47
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants