Skip to content

πŸ› fix(model-runtime): resolve Vertex AI $ref schema error and toolConfig incompatibility#13524

Merged
arvinxx merged 2 commits intocanaryfrom
fix/vertexai-ref-and-tool-config-clean
Apr 3, 2026
Merged

πŸ› fix(model-runtime): resolve Vertex AI $ref schema error and toolConfig incompatibility#13524
arvinxx merged 2 commits intocanaryfrom
fix/vertexai-ref-and-tool-config-clean

Conversation

@arvinxx
Copy link
Copy Markdown
Member

@arvinxx arvinxx commented Apr 3, 2026

πŸ’» Change Type

  • πŸ› fix

πŸ”— Related Issue

πŸ”€ Description of Change

Problem 1 β€” $ref schema error (160+ errors):
User tool schemas (specifically the memory tool manifest from recent refactor by neko in 6a2ca59592) contain $ref references (#/definitions/...). Vertex AI does not support $ref in function declaration schemas, causing requests to fail with: Unknown name "$ref" at tools[0].function_declarations[X].parameters.properties[Y].value.all_of[0].

Fix: Added resolveRefs() in google.ts context builder that inlines $ref definitions before sending to Google/Vertex AI. Also unwraps single-element allOf wrappers (common pattern: allOf: [{ $ref: '...' }]) and strips the definitions key from output.

Problem 2 β€” includeServerSideToolInvocations incompatibility (292 failures/24h):
Google AI supports toolConfig.includeServerSideToolInvocations for Gemini 3+ combined tools, but Vertex AI does not.

Fix: Added !this.isVertexAi guard before setting toolConfig, so only Google AI instances send this parameter.

πŸ§ͺ How to Test

  • Added/updated tests

5 new unit tests added:

  • $ref resolution from definitions
  • Nested $ref in oneOf
  • definitions stripped from output
  • Unknown $ref handled gracefully
  • Vertex AI instance does NOT set includeServerSideToolInvocations
cd packages/model-runtime && bunx vitest run src/core/contextBuilders/google.test.ts src/providers/google/index.test.ts

πŸ“ Additional Information

Both issues stem from recent changes:

  • Commit 6a2ca59592 (neko's memory search refactor) introduced $ref in tool schemas
  • Commit 7fd6d67fe3 added needsServerSideToolInvocations() without Vertex AI exclusion

…fig incompatibility

1. Dereference $ref in JSON Schema before sending to Google/Vertex AI β€” the memory
   tool manifest (from neko's recent refactor) uses $ref which Vertex AI rejects.
2. Skip includeServerSideToolInvocations for Vertex AI β€” only Google AI supports it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 3, 2026 3:03am

Request Review

@lobehubbot
Copy link
Copy Markdown
Member

@sxjeru @nekomeowww - This fixes Vertex AI $ref schema errors and toolConfig incompatibility in the Google provider. Please take a look.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c04a5f786c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 95.65217% with 2 lines in your changes missing coverage. Please review.
βœ… Project coverage is 66.44%. Comparing base (251e12c) to head (1f6a8da).
⚠️ Report is 6 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff            @@
##           canary   #13524     +/-   ##
=========================================
  Coverage   66.43%   66.44%             
=========================================
  Files        1977     1977             
  Lines      163655   163695     +40     
  Branches    18716    15769   -2947     
=========================================
+ Hits       108724   108766     +42     
+ Misses      54809    54807      -2     
  Partials      122      122             
Flag Coverage Ξ”
app 58.09% <ΓΈ> (+<0.01%) ⬆️
database 92.57% <ΓΈ> (ΓΈ)
packages/agent-runtime 88.98% <ΓΈ> (ΓΈ)
packages/context-engine 86.51% <ΓΈ> (ΓΈ)
packages/conversation-flow 92.36% <ΓΈ> (ΓΈ)
packages/file-loaders 87.02% <ΓΈ> (ΓΈ)
packages/memory-user-memory 66.68% <ΓΈ> (ΓΈ)
packages/model-bank 99.85% <ΓΈ> (ΓΈ)
packages/model-runtime 84.73% <95.65%> (+0.04%) ⬆️
packages/prompts 65.80% <ΓΈ> (ΓΈ)
packages/python-interpreter 92.90% <ΓΈ> (ΓΈ)
packages/ssrf-safe-fetch 0.00% <ΓΈ> (ΓΈ)
packages/utils 90.41% <ΓΈ> (ΓΈ)
packages/web-crawler 88.82% <ΓΈ> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Ξ”
Store 66.55% <ΓΈ> (ΓΈ)
Services 49.05% <ΓΈ> (ΓΈ)
Server 65.96% <100.00%> (+<0.01%) ⬆️
Libs 51.03% <ΓΈ> (ΓΈ)
Utils 91.01% <ΓΈ> (ΓΈ)
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

When a schema node has $ref plus sibling keys (e.g. description from
allOf unwrapping), the resolved definition now merges with those siblings
instead of dropping them. This preserves argument-level descriptions for
fields like timeIntent, improving tool-call quality.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@arvinxx arvinxx merged commit f9f7283 into canary Apr 3, 2026
34 checks passed
@arvinxx arvinxx deleted the fix/vertexai-ref-and-tool-config-clean branch April 3, 2026 04:06
arvinxx added a commit that referenced this pull request Apr 7, 2026
… Google tool schemas

Google Gemini / Vertex AI rejects `additionalProperties` and `$ref` in
function declaration schemas. The previous fix (PR #13524) resolved most
`$ref` via `resolveRefs()` but missed two cases:

1. `additionalProperties` was never stripped
2. `$ref` survived when `resolveRefs` hit its depth limit (>10) on
   recursive schemas

Add both keys to UNSUPPORTED_SCHEMA_KEYS so `sanitizeSchemaForGoogle()`
strips them after ref resolution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
arvinxx added a commit that referenced this pull request Apr 7, 2026
… Google tool schemas (#13613)

Google Gemini / Vertex AI rejects `additionalProperties` and `$ref` in
function declaration schemas. The previous fix (PR #13524) resolved most
`$ref` via `resolveRefs()` but missed two cases:

1. `additionalProperties` was never stripped
2. `$ref` survived when `resolveRefs` hit its depth limit (>10) on
   recursive schemas

Add both keys to UNSUPPORTED_SCHEMA_KEYS so `sanitizeSchemaForGoogle()`
strips them after ref resolution.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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