Skip to content

fix: WASM tool schema advertisement for exported typed schemas - #1348

Closed
hanakannzashi wants to merge 2 commits into
stagingfrom
fix/brave-search
Closed

hanakannzashi wants to merge 2 commits into
stagingfrom
fix/brave-search

Conversation

@hanakannzashi

@hanakannzashi hanakannzashi commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fix WASM tool schema advertisement so small typed schemas exported by the component are exposed directly to the LLM instead of always falling back to a permissive {} schema.
  • Keep the existing compact-schema behavior for large exported schemas by retaining the permissive fallback plus tool_info hint when the exported schema is too large.
  • Update WASM loader warnings so they correctly state that exported WASM metadata/schema will be used when description or parameters are missing from the capabilities sidecar.
  • This fixes Brave web-search behavior where the agent previously saw only {} and repeatedly called the tool without the required query field.

Change Type

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • CI/Infrastructure
  • Security
  • Dependencies

Linked Issue

#1303

Validation

  • cargo fmt
  • cargo clippy --all --benches --tests --examples --all-features
  • Relevant tests pass: cargo check -q, cargo test -q test_advertised_schema_stays_permissive_until_sidecar_override --lib, cargo test -q test_large_exported_schema_stays_permissive_for_advertising --lib
  • Manual testing: verified local Brave web-search regression end-to-end; after the fix the agent successfully called the Brave WASM tool with real search parameters and completed a search, instead of repeatedly calling it with {} and failing on missing query

Security Impact

None.

Database Impact

None.

Blast Radius

Touches WASM tool schema advertisement and loader warning behavior. Regressions could affect how WASM tools are exposed to the LLM, especially tools with large exported schemas that should still stay compact.

Rollback Plan

Revert the WASM schema advertisement change in src/tools/wasm/wrapper.rs and the warning text updates in src/tools/wasm/loader.rs to restore the previous behavior.


Review track: B

@github-actions github-actions Bot added size: M 50-199 changed lines scope: tool/wasm WASM tool sandbox risk: medium Business logic, config, or moderate-risk modules and removed size: M 50-199 changed lines labels Mar 18, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the interaction between the agent and WASM tools by refining how tool schemas are advertised to the Language Model. It ensures that tools with small, well-defined schemas are presented accurately, allowing the agent to make precise calls, while larger schemas still provide necessary hints for discovery. This change directly addresses and fixes a critical regression in the Brave web-search functionality, making the agent's tool usage more robust and effective.

Highlights

  • WASM Tool Schema Advertisement: Fixed WASM tool schema advertisement to expose small typed schemas directly to the LLM, preventing a fallback to a permissive {} schema.
  • Large Schema Handling: Maintained the existing compact-schema behavior for large exported schemas by retaining the permissive fallback plus a tool_info hint.
  • WASM Loader Warnings: Updated WASM loader warnings to correctly state that exported WASM metadata/schema will be used when description or parameters are missing from the capabilities sidecar.
  • Brave Web Search Fix: Resolved an issue with Brave web-search where the agent previously saw only {} and repeatedly called the tool without the required query field.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions github-actions Bot added the contributor: new First-time contributor label Mar 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an issue where WASM tool schemas were not being advertised properly to the LLM, leading to incorrect tool calls. The approach of advertising small schemas directly while falling back to a permissive schema for large ones is sound. The new test cases provide good coverage for this new logic. I have one suggestion to improve the clarity of a test name.

Comment thread src/tools/wasm/wrapper.rs
@hanakannzashi hanakannzashi changed the title fix: brave web search fix: WASM tool schema advertisement for exported typed schemas Mar 18, 2026
@github-actions github-actions Bot added the size: M 50-199 changed lines label Mar 18, 2026
@hanakannzashi

Copy link
Copy Markdown
Contributor Author

Same PR #1352

@henrypark133 henrypark133 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: WASM tool schema advertisement — overlaps with #1352

Thanks for the contribution! Unfortunately this PR overlaps almost entirely with #1352 (G7CNF), which implements the same behavior (advertise typed WASM schemas directly to the LLM when small enough) and has already been approved.

Both PRs modify the same lines in src/tools/wasm/wrapper.rs and src/tools/wasm/loader.rs. If #1352 lands first, this will create merge conflicts.

One thing your PR gets right that #1352 doesn't: the 8KB size limit (MAX_ADVERTISED_SCHEMA_BYTES = 8 * 1024) is more appropriate than #1352's 64KB. These schemas get serialized into every LLM call alongside all other tools, so a tighter budget is better for context management. We've asked #1352 to adopt the 8KB limit.

I'd recommend closing this PR in favor of #1352 to avoid the conflict. Thank you for the work — it clearly identified the right fix.

Minor note: the branch name fix/brave-search doesn't match the PR content, and there's an unrelated channels-src/whatsapp/Cargo.lock version bump included.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes WASM tool schema advertisement so the LLM sees exported typed schemas for small/reasonable-size components (instead of always {}), while retaining the permissive advertisement + tool_info discovery path for large schemas. Also updates WASM loader warnings to reflect that WASM-exported metadata/schema can be used when sidecar fields are missing.

Changes:

  • Advertise small typed WASM-exported schemas directly; keep permissive fallback for large schemas.
  • Update/extend unit tests to cover small-vs-large exported schema advertisement behavior.
  • Adjust WASM loader warning messages about missing description / parameters in capabilities sidecars.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/tools/wasm/wrapper.rs Adds size/typed checks to decide whether to advertise exported schemas; updates tests for small vs large exported schemas.
src/tools/wasm/loader.rs Updates warning text for missing capabilities fields to indicate WASM-exported metadata/schema usage.
channels-src/whatsapp/Cargo.lock Bumps the whatsapp-channel package version in the lockfile (aligned with Cargo.toml).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tools/wasm/wrapper.rs
Comment on lines +528 to +538
fn should_advertise_discovery(schema: &serde_json::Value) -> bool {
Self::typed_property_count(schema) > 0
&& schema.to_string().len() <= Self::MAX_ADVERTISED_SCHEMA_BYTES
}

fn new(discovery: serde_json::Value) -> Self {
let advertised = if Self::should_advertise_discovery(&discovery) {
discovery.clone()
} else {
Self::permissive_schema()
};
Comment thread src/tools/wasm/wrapper.rs
Comment on lines +529 to +530
Self::typed_property_count(schema) > 0
&& schema.to_string().len() <= Self::MAX_ADVERTISED_SCHEMA_BYTES
Comment thread src/tools/wasm/loader.rs
path = %cap_path.display(),
"Capabilities file missing \"parameters\" field; \
tool will accept any JSON object (permissive fallback)"
using exported WASM schema when available"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: new First-time contributor risk: medium Business logic, config, or moderate-risk modules scope: tool/wasm WASM tool sandbox size: M 50-199 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants