Skip to content

fix(providers/anthropic): keep metadata on web searches with no results - #65

Merged
ibetitsmike merged 4 commits into
coder_2_33from
mike/anthropic-empty-web-search-results
Oct 9, 2026
Merged

ibetitsmike merged 4 commits into
coder_2_33from
mike/anthropic-empty-web-search-results

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 9, 2026 •

Copy link
Copy Markdown

Problem

When an Anthropic web search finds nothing, its web_search_tool_result content is an empty list, and Generate and Stream attached no WebSearchResultMetadata to it. Consumers could not tell a search that found nothing from a result that cannot be replayed. coder/coder's chat sanitizer drops provider tool results without that metadata, so these searches vanished from saved chat history after clients had seen them stream.

Fix

Attach empty WebSearchResultMetadata when the result list is empty, in both Generate and Stream. It replays as an empty result list, which is what the encoder's missing-metadata fallback already sent, without the fallback's warning.

Validation

  • TestGenerate_WebSearchNoResultsKeepsMetadata and TestStream_WebSearchNoResultsKeepsMetadata fail with the coder_2_33 anthropic.go overlaid via go test -overlay and pass with the fix. TestToPrompt_WebSearchNoResultsRoundTrip checks that the empty result replays as an empty list.
  • go build ./..., go test ./..., and golangci-lint run ./providers/anthropic/... pass.
  • Downstream, fix: fold web searches, answer reasoning, and OpenAI narration into working blocks coder#30529 adds a chatd test that saves a search with no results; it fails on the previous pin and passes with this commit. Dogfood UAT confirmed the searches stay in saved history and follow-up turns replay them without provider errors.
  • govulncheck reports the same findings as on coder_2_33; none are introduced here.

The branch merges coder_2_33 in after #64, so a squash merge leaves the single fix.

Xum acted on Mike's (@ibetitsmike) behalf to create this PR.

Defer synthetic user media until all contiguous tool-result messages have
been emitted. OpenAI rejects media inserted between replies to parallel
tool calls. Preserve accompanying text and the order of media payloads.

Cover both Chat Completions serializers with separate and grouped tool
results, two media results, and following conversation messages.

> Xum acted on Mike's behalf.
A web_search_tool_result whose content is an empty list carried no
WebSearchResultMetadata in Generate or Stream, so consumers could not tell
a search that found nothing from a result that cannot be replayed. Coder's
chat sanitizer drops provider tool results without that metadata, so these
searches vanished from saved history after clients had seen them stream.

Attach empty metadata instead. It replays as an empty result list, as the
encoder's missing-metadata fallback already did, without the warning.

> Xum acted on Mike's behalf.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T09:19:00.255601Z 61440b2 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant