Repository navigation
Conversation
Greptile SummaryFixes a bug where the websearch short-circuit path returned text-only responses, causing Claude Code to report "Did 0 searches". The root cause was that the pre-request hook had already renamed
Confidence Score: 4/5Safe to merge; the fix correctly addresses the tool-renaming ordering issue and existing tests are strengthened rather than weakened. The logic change is well-reasoned and the new tests validate the corrected contract end-to-end. One gap: the server_tool_use.web_search_requests usage field added to the synthetic non-streaming response is silently dropped by the streaming serializer's message_delta builder, leaving an inconsistency between the two paths that could affect usage-aware clients. fake_stream_iterator.py — the delta_usage construction does not propagate the server_tool_use usage entry.
|
| Filename | Overview |
|---|---|
| litellm/integrations/websearch_interception/handler.py | Unconditionally emits server_tool_use + web_search_tool_result + text on the short-circuit path; correctly addresses the root cause (pre-request hook had already renamed the tool before detection ran). |
| litellm/llms/anthropic/experimental_pass_through/messages/fake_stream_iterator.py | Adds serialization for server_tool_use and web_search_tool_result block types; server_tool_use usage is not forwarded in message_delta/message_start events. |
| tests/test_litellm/integrations/websearch_interception/test_websearch_native_blocks.py | Updated the standard-tool short-circuit test to assert native blocks (valid fix); the old text-only assertion was testing the buggy behavior, not a feature, so the change is correct. |
| tests/test_litellm/integrations/websearch_interception/test_websearch_short_circuit.py | Adds regression tests for post-conversion tool shape, structured source passthrough, and streaming SSE serialization; all tests use mocks and are free of real network calls. |
Comments Outside Diff (1)
-
litellm/llms/anthropic/experimental_pass_through/messages/fake_stream_iterator.py, line 190-208 (link)server_tool_useusage not forwarded inmessage_deltaThe PR adds
usage.server_tool_use.web_search_requests = 1to the synthetic response to advertise the search count, but_create_streaming_chunksonly copiesinput_tokens,output_tokens,cache_creation_input_tokens, andcache_read_input_tokensintodelta_usage. Any client that reads themessage_deltaSSE event's usage (the standard streaming consumption path) will see noserver_tool_useentry. The streaming test also uses a response dict withoutserver_tool_useinusage, so this gap is not covered. Addingif usage.get("server_tool_use"): delta_usage["server_tool_use"] = usage["server_tool_use"]here would make the streaming and non-streaming paths consistent.
Reviews (1): Last reviewed commit: "fix(websearch_interception): emit native..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ircuit path
The short-circuit path (`try_short_circuit_search`) returned a text-only
synthetic response for every real request, because it gated native-block
emission on `is_anthropic_native_web_search_tool(tool)`. That check can never
be true at this point: the pre-request hook rewrites every native
`web_search_*` tool to `litellm_web_search` (type=None) *before* the
short-circuit runs, so the native branch was dead code.
Consequences for clients that consume the standalone /v1/messages search
sub-request (Claude Code, Claude Desktop, Cowork):
- No `server_tool_use` block → Claude Code reports "Did 0 searches" and
discards the results, falling back to WebFetch.
- No `web_search_tool_result` block → citation panels stay empty.
Fix:
- handler.py: emit `server_tool_use` + `web_search_tool_result` + `text`
unconditionally on the short-circuit path. Reaching this code means every
tool is a web-search tool for a provider that can't run search natively,
which is exactly the short-circuit contract. Also advertise
`usage.server_tool_use.web_search_requests = 1`.
- fake_stream_iterator.py: teach the streaming serializer the
`server_tool_use` and `web_search_tool_result` block types. Claude Code
issues the sub-request with stream=True; previously these blocks were
dropped (bare content_block_stop with no matching start → malformed SSE).
Tests:
- Update `test_litellm_standard_tool_short_circuit_*` to assert the
post-conversion (`litellm_web_search`) shape emits native blocks — this is
the only shape production ever takes, not a "non-native" case.
- Add regression tests for the post-conversion tool shape, structured-source
passthrough, and streaming serialization of both block types.
Fixes BerriAI#31902
59d46d9 to
14693c0
Compare
|
#40967 fixes the same gap but only for native web_search tools, so other callers keep text-only replies. We plan to merge that one |
Relevant issues
Fixes #31902
Linear ticket
Pre-Submission checklist
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
End-to-end against a local
litellmproxy → GitHub Copilot backend → Tavily search (real API calls, no mocks). Same streamingweb_searchsub-request Claude Code issues, before vs. after:Before (unpatched
main/1.91.0rc1) — response stream is text-only:After (this PR) — native blocks present, sources carried:
Type
🐛 Bug Fix
Changes
litellm/integrations/websearch_interception/handler.py— emitserver_tool_use+web_search_tool_result+textunconditionally on the short-circuit path; advertiseusage.server_tool_use.web_search_requests = 1.litellm/llms/anthropic/experimental_pass_through/messages/fake_stream_iterator.py— serialize theserver_tool_useandweb_search_tool_resultblock types (previously dropped → malformed SSE understream=true).test_litellm_standard_tool_short_circuit_*to the correct post-conversion contract; added regression tests for the post-conversion shape, structured-source passthrough, and streaming serialization.