Skip to content

fix: web fetch fixes - #4945

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
07-06-fix_web_fetch_fixes
Jul 6, 2026
Merged

fix: web fetch fixes#4945
Pratham-Mishra04 merged 1 commit into
devfrom
07-06-fix_web_fetch_fixes

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

The Anthropic web_fetch_tool_result block was previously discarded after conversion — only the request URL was preserved. This PR carries the full typed result payload (fetched document content, metadata, error codes) through the Bifrost neutral format so that Anthropic-compatible reverse conversion can faithfully reconstruct the server_tool_use + web_fetch_tool_result block pair on both the streaming and non-streaming paths.

Changes

  • Introduced ResponsesWebFetchCall, ResponsesWebFetchDocument, and ResponsesWebFetchSource schema types to represent the web_fetch_tool_result payload in the neutral format. Embedded *ResponsesWebFetchCall in ResponsesToolMessage alongside the existing advisor and code-interpreter payloads.
  • Added convertAnthropicWebFetchResultToBifrost to map an AnthropicContentBlock web fetch result into the new neutral types, and convertBifrostWebFetchCallToAnthropicBlocks to rebuild the server_tool_use + web_fetch_tool_result block pair from a neutral ResponsesMessage. Both the streaming and non-streaming reverse converters now call these helpers instead of duplicating inline logic.
  • On the forward (Anthropic → Bifrost) streaming path, ToBifrostResponsesStream now attaches the typed result payload to the emitted web_fetch_call item instead of dropping it.
  • On the reverse (Bifrost → Anthropic) streaming path, ToAnthropicResponsesStreamResponse now emits the web_fetch_tool_result content_block_start/content_block_stop pair at output_item.done when the payload is present, removing the previous passthrough-only index-bump workaround for web fetch.
  • convertAnthropicContentBlocksToResponsesMessages now calls attachAnthropicWebFetchResult on web_fetch_tool_result blocks instead of silently skipping them, attaching the result to the matching web_fetch_call message.
  • ConvertBifrostMessagesToAnthropicMessages now delegates web fetch block construction to convertBifrostWebFetchCallToAnthropicBlocks, removing the duplicated inline assembly.
  • Added AnthropicToolTypeWebFetch20260318 and its response_inclusion field on AnthropicToolWebFetch. convertBifrostToolToAnthropic selects this type when ResponseInclusion is set. UseCache and ResponseInclusion are now round-tripped through convertAnthropicToolToBifrost.
  • Deep-copy paths in core/schemas/utils.go and framework/streaming/responses.go updated to cover ResponsesWebFetchCall and its nested Document/Source/Citations fields, and to copy Caller on ResponsesToolMessage.
  • Updated TestAnthropicConverterOnly_IndicesContiguous comments to reflect that web_fetch no longer collapses a result block on the all-normalized path. Added TestAnthropicWebFetchResultRoundTrip to verify the full Anthropic → Bifrost → Anthropic round-trip for a web fetch result with a nested document.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go test ./core/providers/anthropic/... -run TestAnthropicWebFetchResultRoundTrip
go test ./core/providers/anthropic/... -run TestAnthropicConverterOnly_IndicesContiguous
go test ./core/providers/anthropic/... -run TestDoesWebSearchOrFetchAutoInjectCodeExecution
go test ./...

The new TestAnthropicWebFetchResultRoundTrip test exercises the full round-trip: an AnthropicContentBlock web fetch result is converted to the neutral ResponsesWebFetchCall, assembled into a ResponsesMessage, and then rebuilt back into server_tool_use + web_fetch_tool_result blocks with the document content intact.

Breaking changes

  • Yes
  • No

Related issues

Security considerations

No new auth, secrets, PII, or sandboxing surface introduced. Fetched document content that was previously discarded is now stored in memory within the request lifetime and forwarded to the caller — consistent with how other tool result payloads are handled.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@CLAassistant

CLAassistant commented Jul 6, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b6822394-2ea8-4e86-8439-c338af41d674

📥 Commits

Reviewing files that changed from the base of the PR and between 8a5ec7a and 30c1b9a.

📒 Files selected for processing (9)
  • core/providers/anthropic/passthroughstream_test.go
  • core/providers/anthropic/requestbuilder_test.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/schemas/responses.go
  • core/schemas/utils.go
  • framework/streaming/responses.go
  • framework/streaming/responses_test.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for a newer web-fetch tool variant, including additional request options.
    • Web-fetch results now round-trip more completely, preserving typed document and source details.
  • Bug Fixes

    • Improved streaming/message conversion so web-fetch output stays aligned and indexes remain consistent.
    • Fixed deep-copy behavior to prevent shared nested data from being mutated unexpectedly.
    • Expanded coverage for web-fetch and tool-caller handling.

Walkthrough

This PR adds typed web-fetch result support across Anthropic and Bifrost, including new schemas, conversion helpers, streaming/message wiring, deep-copy updates, a new web_fetch_20260318 tool type, and expanded tests.

Changes

Web Fetch Typed Result Support

Layer / File(s) Summary
Schema and deep-copy support
core/schemas/responses.go, core/schemas/utils.go, framework/streaming/responses.go, framework/streaming/responses_test.go
Adds typed web-fetch result schema types, extends web-fetch tool config, and deep-copies the new caller/result structures; includes deep-copy test coverage.
Anthropic tool type and option wiring
core/providers/anthropic/types.go, core/providers/anthropic/utils.go, core/providers/anthropic/requestbuilder_test.go
Adds web_fetch_20260318, extends web-fetch request options, and updates code-execution auto-injection coverage.
Web-fetch conversion helpers
core/providers/anthropic/responses.go
Adds helpers for Anthropic↔Bifrost web-fetch result conversion and updates tool-spec version/option mapping.
Streaming and message conversion wiring
core/providers/anthropic/responses.go
Wires typed web-fetch conversion into streaming, grouped message conversion, and passthrough index handling.
Round-trip and passthrough tests
core/providers/anthropic/passthroughstream_test.go
Adds web-fetch round-trip and passthrough index tests, plus related comment updates.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • maximhq/bifrost#4890: Both PRs modify Anthropic passthrough streaming and web-fetch framing/index alignment in responses.go and related tests.
  • maximhq/bifrost#4932: Both PRs update SetResponsesStreamPassthrough behavior and tests around web-fetch/web-search content-block index handling.

Suggested reviewers: danpiths, akshaydeo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and does not clearly describe the main change beyond general web fetch fixes. Rename it to something specific like “fix: preserve Anthropic web fetch results through Bifrost conversions”.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description follows the template well and includes summary, changes, testing, breaking changes, security, and checklist sections.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 07-06-fix_web_fetch_fixes

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands.

TejasGhatte commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@TejasGhatte TejasGhatte mentioned this pull request Jul 6, 2026
17 tasks
@TejasGhatte
TejasGhatte marked this pull request as ready for review July 6, 2026 10:20
@coderabbitai
coderabbitai Bot requested review from akshaydeo and danpiths July 6, 2026 10:22

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (3)
core/providers/anthropic/passthroughstream_test.go (1)

429-493: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider adding an error-variant round-trip test.

TestAnthropicWebFetchResultRoundTrip only exercises the success path (web_fetch_result with a document). The error branch (ResultType: "web_fetch_tool_result_error", ErrorCode set, no Document) is a distinct code path in both convertAnthropicWebFetchResultToBifrost and convertBifrostWebFetchCallToAnthropicBlocks and isn't covered.

Want me to draft a second test case covering the web_fetch_tool_result_error round trip?

🤖 Prompt for 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.

In `@core/providers/anthropic/passthroughstream_test.go` around lines 429 - 493,
`TestAnthropicWebFetchResultRoundTrip` only covers the success path, so add a
second round-trip case for the error variant of the web fetch result. Update the
test to construct an `AnthropicContentBlock`/Bifrost payload with `ResultType`
set to `web_fetch_tool_result_error`, an `ErrorCode`, and no `Document`, then
verify both `convertAnthropicWebFetchResultToBifrost` and
`convertBifrostWebFetchCallToAnthropicBlocks` preserve that error state. Use the
existing helpers like `convertAnthropicWebFetchResultToBifrost`,
`convertBifrostWebFetchCallToAnthropicBlocks`, and `getAnthropicContentObject`
to assert the rebuilt block still represents the error variant.
core/providers/anthropic/responses.go (1)

5880-5896: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor: prefer schemas.Ptr() over &toolUseID.

Based on learnings, this repository prefers bifrost.Ptr()/schemas.Ptr() over the address operator even when & is syntactically valid.

✏️ Proposed tweak
-		msg.ResponsesToolMessage.CallID = &toolUseID
+		msg.ResponsesToolMessage.CallID = schemas.Ptr(toolUseID)
🤖 Prompt for 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.

In `@core/providers/anthropic/responses.go` around lines 5880 - 5896, Prefer the
repository’s pointer helper instead of taking the address directly in
attachAnthropicWebFetchResult. Update the CallID assignment on
ResponsesToolMessage to use schemas.Ptr() for toolUseID rather than &toolUseID,
keeping the existing conversion flow and symbol names unchanged.

Source: Learnings

core/schemas/responses.go (1)

1367-1369: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Avoid promoted-field ambiguity in ResponsesToolMessage The anonymous ResponsesAdvisorCall, ResponsesWebFetchCall, and ResponsesCodeExecutionCall embeddings all publish ResultType and ErrorCode, so ResponsesToolMessage.ResultType / .ErrorCode stays ambiguous. Keep those accesses fully qualified or switch these variants to named fields.

🤖 Prompt for 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.

In `@core/schemas/responses.go` around lines 1367 - 1369, The anonymous embeddings
in ResponsesToolMessage are causing promoted-field ambiguity for ResultType and
ErrorCode. Update ResponsesToolMessage so the ResponsesAdvisorCall,
ResponsesWebFetchCall, and ResponsesCodeExecutionCall variants are no longer
accessed through ambiguous promoted fields; either make those fields explicitly
qualified at each use site or replace the anonymous embeddings with named fields
and adjust all references accordingly.
🤖 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.

Nitpick comments:
In `@core/providers/anthropic/passthroughstream_test.go`:
- Around line 429-493: `TestAnthropicWebFetchResultRoundTrip` only covers the
success path, so add a second round-trip case for the error variant of the web
fetch result. Update the test to construct an `AnthropicContentBlock`/Bifrost
payload with `ResultType` set to `web_fetch_tool_result_error`, an `ErrorCode`,
and no `Document`, then verify both `convertAnthropicWebFetchResultToBifrost`
and `convertBifrostWebFetchCallToAnthropicBlocks` preserve that error state. Use
the existing helpers like `convertAnthropicWebFetchResultToBifrost`,
`convertBifrostWebFetchCallToAnthropicBlocks`, and `getAnthropicContentObject`
to assert the rebuilt block still represents the error variant.

In `@core/providers/anthropic/responses.go`:
- Around line 5880-5896: Prefer the repository’s pointer helper instead of
taking the address directly in attachAnthropicWebFetchResult. Update the CallID
assignment on ResponsesToolMessage to use schemas.Ptr() for toolUseID rather
than &toolUseID, keeping the existing conversion flow and symbol names
unchanged.

In `@core/schemas/responses.go`:
- Around line 1367-1369: The anonymous embeddings in ResponsesToolMessage are
causing promoted-field ambiguity for ResultType and ErrorCode. Update
ResponsesToolMessage so the ResponsesAdvisorCall, ResponsesWebFetchCall, and
ResponsesCodeExecutionCall variants are no longer accessed through ambiguous
promoted fields; either make those fields explicitly qualified at each use site
or replace the anonymous embeddings with named fields and adjust all references
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e3a48ce-8184-4503-bc59-c5304043d22e

📥 Commits

Reviewing files that changed from the base of the PR and between efc9fae and 70f1f9b.

📒 Files selected for processing (8)
  • core/providers/anthropic/passthroughstream_test.go
  • core/providers/anthropic/requestbuilder_test.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/schemas/responses.go
  • core/schemas/utils.go
  • framework/streaming/responses.go

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 6, 2026
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge; the web-fetch round-trip logic is well-tested and all previously flagged issues have been addressed

The three previously flagged issues (text-block drop, missing passthrough phantom-index fallback, and streaming Caller aliasing) are all resolved and covered by new tests. The remaining findings are narrow edge cases: the UseCache type-upgrade condition misses the 20260209 family for intermediate model versions, and a malformed item with a nil ResponsesToolMessage on the streaming path would produce a content_block_start with no block. Neither affects the primary web-fetch round-trip path.

core/providers/anthropic/responses.go — UseCache type-upgrade condition and the nil-ResponsesToolMessage guard on the streaming output_item.added path

Important Files Changed

Filename Overview
core/providers/anthropic/responses.go Core of the PR: adds convertAnthropicWebFetchResultToBifrost/convertBifrostWebFetchCallToAnthropicBlocks helpers; fixes streaming index alignment for web_fetch on passthrough path; fixes missing return/stop-event for ComputerCall output_item.done; UseCache type-upgrade condition leaves 20260209 (4.5 model family) unguarded
core/schemas/responses.go Introduces ResponsesWebFetchCall/Document/Source neutral schema types; adds UseCache and ResponseInclusion to ResponsesToolWebFetch — clean addition
core/schemas/utils.go Adds deep copy for ResponsesWebFetchCall (Document/Source/Citations) and ResponsesToolMessage.Caller in DeepCopyResponsesMessage — complete and correct
framework/streaming/responses.go Mirrors core deep-copy additions: Caller and ResponsesWebFetchCall (Document/Source/Citations) now fully copied in deepCopyResponsesMessage — addresses the previously flagged streaming aliasing issue
core/providers/anthropic/passthroughstream_test.go Adds TestAnthropicWebFetchResultRoundTrip, TestAnthropicWebFetchTextResultRoundTrip (exercises previously-missing text-block path), and TestAnthropicWebFetchPassthroughNoResultConsumesHiddenIndex — good coverage of the three new code paths
framework/streaming/responses_test.go Adds TestDeepCopyResponsesStreamResponseCopiesToolCaller verifying Caller pointer isolation — adequate coverage of the new deep-copy path
core/providers/anthropic/types.go Adds AnthropicToolTypeWebFetch20260318 constant and ResponseInclusion field on AnthropicToolWebFetch — straightforward type additions
core/providers/anthropic/utils.go Adds AnthropicToolTypeWebFetch20260318 to doesWebSearchOrFetchAutoInjectCodeExecution — consistent with the other 2026-era web_fetch variants

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant AC as Anthropic API
    participant FWD as ToBifrostResponsesStream
    participant NF as Neutral Format (ResponsesMessage)
    participant REV as ToAnthropicResponsesStreamResponse

    AC->>FWD: content_block_start (server_tool_use, web_fetch)
    FWD->>NF: output_item.added web_fetch_call (in_progress)
    AC->>FWD: content_block_start (web_fetch_tool_result)
    Note over FWD: accumulate result block
    AC->>FWD: content_block_stop (web_fetch_tool_result)
    FWD->>NF: output_item.done web_fetch_call + ResponsesWebFetchCall payload
    NF->>REV: web_fetch_call item with typed result
    REV->>AC: content_block_stop (server_tool_use)
    REV->>AC: content_block_start (web_fetch_tool_result)
    REV->>AC: content_block_stop (web_fetch_tool_result)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant AC as Anthropic API
    participant FWD as ToBifrostResponsesStream
    participant NF as Neutral Format (ResponsesMessage)
    participant REV as ToAnthropicResponsesStreamResponse

    AC->>FWD: content_block_start (server_tool_use, web_fetch)
    FWD->>NF: output_item.added web_fetch_call (in_progress)
    AC->>FWD: content_block_start (web_fetch_tool_result)
    Note over FWD: accumulate result block
    AC->>FWD: content_block_stop (web_fetch_tool_result)
    FWD->>NF: output_item.done web_fetch_call + ResponsesWebFetchCall payload
    NF->>REV: web_fetch_call item with typed result
    REV->>AC: content_block_stop (server_tool_use)
    REV->>AC: content_block_start (web_fetch_tool_result)
    REV->>AC: content_block_stop (web_fetch_tool_result)
Loading

Reviews (3): Last reviewed commit: "fix: web fetch fixes" | Re-trigger Greptile

@TejasGhatte
TejasGhatte force-pushed the 07-06-fix_web_fetch_fixes branch from 70f1f9b to 8a5ec7a Compare July 6, 2026 10:49
@coderabbitai
coderabbitai Bot requested a review from roroghost17 July 6, 2026 10:50

Pratham-Mishra04 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Merge activity

  • Jul 6, 11:29 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 6, 11:33 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 6, 11:34 AM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from 07-06-test_additions_to_harness_tests to graphite-base/4945 July 6, 2026 11:29
@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from graphite-base/4945 to dev July 6, 2026 11:32
@Pratham-Mishra04
Pratham-Mishra04 dismissed coderabbitai[bot]’s stale review July 6, 2026 11:32

The base branch was changed.

@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 07-06-fix_web_fetch_fixes branch from 8a5ec7a to 30c1b9a Compare July 6, 2026 11:32
@Pratham-Mishra04
Pratham-Mishra04 merged commit 149474f into dev Jul 6, 2026
14 of 16 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 07-06-fix_web_fetch_fixes branch July 6, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants