fix(grok): stop rejecting hosted web search domain and location filters - #125
Open
AlexanderKugel wants to merge 1 commit into
Open
fix(grok): stop rejecting hosted web search domain and location filters#125AlexanderKugel wants to merge 1 commit into
AlexanderKugel wants to merge 1 commit into
Conversation
Claude Code can declare Anthropic hosted web search with allowed_domains,
blocked_domains, or user_location. Grok's hosted web_search has no equivalent
fields, so the proxy returned HTTP 400 without calling Grok.
Claude Code surfaces that 400 to the model as an error tool_result, and the
model retries the same search without the filter. The retry is accepted and
runs unrestricted, so the rejection costs an extra round and does not preserve
the caller's constraint.
CCP_SEARCH_CONSTRAINTS selects the behaviour:
soft (default) drop the fields and turn each one into an instruction in
the upstream request's instructions field
warning drop the fields, log a warning, send the search unrestricted
hard keep the HTTP 400
Measured over 10 live searches with three allowed domains, soft returned 161
in-domain sources and 0 off-domain. The same query with no domain list returned
147 in-domain and 210 off-domain. Grok applies the instruction by adding site:
filters to its own queries. soft is a bias, not enforcement.
max_uses stays dropped, as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #123.
Problem
Claude Code can declare Anthropic hosted web search with
allowed_domains,blocked_domains, oruser_location. Grok's hostedweb_searchhas no equivalent fields, so the proxy returns HTTP 400 without calling Grok.Claude Code surfaces that 400 to the model as an error
tool_result. The model then retries the same search without the filter, and the retry is accepted and runs unrestricted. The rejection therefore costs an extra round and the caller's constraint is lost anyway.Change
CCP_SEARCH_CONSTRAINTSselects the behaviour for providers that cannot enforce these fields:soft(default)instructionsfield.warninghardhardpreserves today's behaviour for anyone who wants it. The 400 message now names every unsupported field in the request instead of only the first one found.max_usesstays dropped, as before.Example of the appended instruction:
Values are copied verbatim from the caller. The proxy does not parse them.
Why
softis the defaultMeasured with 10 live searches per group, same query, three allowed domains:
softGrok applies the instruction by adding
site:filters to its own search queries.softis a bias, not enforcement; the model can ignore it.Notes
user_location.cargo fmt --checkandcargo clippy --lib -- -D warningsare clean. The library suite passes exceptproviders::codex::tests::cancellation_while_replacement_startup_is_blocked_aborts_request_state, which fails onmainwithout this change and is reported in Testcancellation_while_replacement_startup_is_blocked_aborts_request_statefails: replacement startup never reaches the blocked handshake #124.