fix(protocols): accept return_token_budget for web_search tool - #1490
Conversation
Cherry-picked from 1e69d22909e954b1d53871bdd5b6c0645d968154. Signed-off-by: Tobel Atnafu <tobel.atnafu@oracle.com>
📝 WalkthroughWalkthroughThis PR extends the ChangesWeb Search Token Budget Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/protocols/tests/responses.rs`:
- Around line 277-323: Add a unit test that covers the "unlimited" variant of
WebSearchReturnTokenBudget by creating a payload with "type": "web_search" and
"return_token_budget": "unlimited", deserializing it with serde_json::from_value
into ResponseTool, asserting it matches ResponseTool::WebSearch(_), and
asserting serde_json::to_value(&tool) equals the original payload (round-trip).
Place the new test (e.g. test_web_search_tool_return_token_budget_unlimited)
alongside test_web_search_response_tool_echo_accepts_return_token_budget and use
the same serde_json helpers to validate both deserialization and serialization
for the unlimited variant.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 20373078-59aa-41aa-8674-85e41656e6b0
📒 Files selected for processing (2)
crates/protocols/src/responses.rscrates/protocols/tests/responses.rs
There was a problem hiding this comment.
Code Review
This pull request adds the "return_token_budget" field to the "WebSearchTool" struct and introduces the "WebSearchReturnTokenBudget" enum to support the new configuration options. Additionally, tests were updated and a new test case was added to verify the round-trip serialization of the new field. Feedback suggests clarifying the documentation for "return_token_budget" to ensure alignment with the OpenAI specification and distinguish it from "search_context_size".
| pub struct WebSearchTool { | ||
| /// Optional domain allowlist applied to candidate sources. | ||
| pub filters: Option<WebSearchFilters>, | ||
| /// Search-result context token budget. Spec enum: `"default" | "unlimited"`. |
There was a problem hiding this comment.
The term "context" in the comment for return_token_budget might be confusing as it overlaps with search_context_size. According to the OpenAI specification, return_token_budget refers to the budget for tokens returned in the search results, whereas search_context_size refers to the context budget. A more accurate description would be "Search-result token budget".
| /// Search-result context token budget. Spec enum: `"default" | "unlimited"`. | |
| /// Search-result token budget. Spec enum: "default" | "unlimited". |
References
- For protocol data structures that mirror an external API (e.g., OpenAI), prioritize alignment with the external specification over internal consistency.
Description
Problem
web_search responses from upstream OpenAI include return_token_budget field, but SMG’s WebSearchTool schema rejects that unknown field, causing a 500 during ResponsesResponse deserialization. web_search_preview works fine because it does not include that field.
Solution
Added typed return_token_budget support to SMG’s non-preview web_search protocol model and regression tests for the upstream echo shape.
Changes
return_token_budgetsupport to the non-previewweb_searchResponses tool schema.ResponsesResponse.tools[]echo deserialization with a regression test.Test Plan
After running SMG locally, register openai worker and perform a web_search request.
Previous experience (internal error):
After Fix is added, successful response:

Checklist
cargo +nightly fmtpassescargo clippy --all-targets --all-features -- -D warningspassesSummary by CodeRabbit
Release Notes
New Features
return_token_budgetfield to control token allocation behavior (supportsdefaultandunlimitedsettings).Tests
return_token_budgetfield to ensure proper serialization and deserialization.