Skip to content

fix: move anthropic raw request body check to core - #4430

Merged
akshaydeo merged 1 commit into
devfrom
06-16-fix_move_anthropic_raw_request_body_check_to_core
Jun 16, 2026
Merged

fix: move anthropic raw request body check to core#4430
akshaydeo merged 1 commit into
devfrom
06-16-fix_move_anthropic_raw_request_body_check_to_core

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

When an Anthropic-integration request is routed to a non-native Anthropic provider (e.g. Bedrock via a key alias), the raw-body passthrough flags must be cleared so the provider performs its own format conversion. Previously, this guard only fired during catalog resolution, meaning it was silently skipped when the provider was selected through a key alias, prefix, or governance rule — causing tool calls to break when Claude was routed to Bedrock outside of catalog resolution.

Changes

  • Introduced clearAnthropicPassthroughForNonNativeProvider in core/bifrost.go, which clears BifrostContextKeyUseRawRequestBody, BifrostContextKeySendBackRawResponse, and BifrostContextKeyPassthroughOverridesPresent whenever an Anthropic-integration request resolves to a provider that isn't Anthropic, Vertex, or Azure.
  • This function is now called per attempt inside requestWorker, after the final provider is resolved, ensuring it fires regardless of how the provider was selected and re-runs correctly on fallback attempts.
  • Removed the equivalent inline guard from modelcatalogresolver/main.go since the new per-attempt call in requestWorker covers all routing paths, making the catalog-level check redundant.
  • Added TestClearAnthropicPassthroughForNonNativeProvider covering Bedrock, Anthropic, Vertex, Azure, and non-Anthropic integration types to verify the flags are cleared only in the correct case.

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/... ./plugins/modelcatalogresolver/...

To validate end-to-end: configure a model with a key alias that routes to Bedrock, send a Claude tool-call request through the Anthropic integration, and confirm the request is correctly converted by Bedrock rather than passed through as a raw Anthropic body.

Screenshots/Recordings

N/A

Breaking changes

  • No

Related issues

Security considerations

No security implications. This change only affects internal context flag management for request routing.

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

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c38015e-4d72-45af-a24c-91592df4c2fc

📥 Commits

Reviewing files that changed from the base of the PR and between ad39b19 and 418762c.

📒 Files selected for processing (3)
  • core/bifrost.go
  • core/bifrost_test.go
  • plugins/modelcatalogresolver/main.go
💤 Files with no reviewable changes (1)
  • plugins/modelcatalogresolver/main.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Refined Anthropic integration request/response handling for non-native providers. Request/response passthrough now correctly manages behavior when using providers like AWS Bedrock, including during fallback attempts.
  • Tests

    • Added comprehensive test coverage for Anthropic integration with non-native providers.

Walkthrough

Moves Anthropic raw-body passthrough flag clearing from the model catalog resolver plugin into a new unexported core helper clearAnthropicPassthroughForNonNativeProvider. The helper is called inside requestWorker after each baseProvider resolution, including fallback attempts. The corresponding clearing code is removed from the plugin.

Changes

Anthropic passthrough flag clearing refactor

Layer / File(s) Summary
New clearAnthropicPassthroughForNonNativeProvider helper and call site
core/bifrost.go
Adds the helper function that clears UseRawRequestBody, SendBackRawResponse, and PassthroughOverridesPresent context flags when integrationType is anthropic but baseProvider is not Anthropic/Vertex/Azure. Wires the call into requestWorker immediately after baseProvider is resolved on each attempt.
Remove passthrough clearing from model catalog resolver
plugins/modelcatalogresolver/main.go
Deletes the 13-line post-selection conditional in ResolveProviderFromCatalog that previously cleared the same three context flags when the selected provider was non-native for Anthropic.
Unit tests for the helper
core/bifrost_test.go
Table-driven test pre-sets all passthrough flags to true, calls the helper across integrationType/baseProvider combinations, and asserts each flag is cleared or preserved as expected.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • maximhq/bifrost#4058: Adjusts the same three Anthropic raw-body passthrough context flags (UseRawRequestBody, SendBackRawResponse, PassthroughOverridesPresent) in the same providers to clear them when the resolved/fallback provider is not Anthropic/Vertex/Azure.

Suggested reviewers

  • akshaydeo

Poem

🐇 Hop, hop, the flags now clear,
Not in the plugin — moved to core, my dear!
Each fallback attempt, the helper runs neat,
Anthropic passthrough stays off when providers don't meet.
Refactored with care, the rabbit approves! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR description does not establish a clear connection between the refactoring changes and the Files API Support objective in #123. The PR moves validation logic but does not address file upload functionality. Clarify whether this refactoring is a prerequisite for the Files API work or if it addresses a separate issue. If unrelated, consider removing or clarifying the issue link.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: moving the Anthropic raw request body check logic from the plugin layer to the core module for broader coverage.
Description check ✅ Passed The description comprehensively covers the summary, changes, type of change, affected areas, testing approach, and relevant context with good detail.
Out of Scope Changes check ✅ Passed The changes are tightly scoped to moving and restructuring the Anthropic passthrough flag clearing logic, with no apparent out-of-scope modifications beyond the intended refactoring.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 06-16-fix_move_anthropic_raw_request_body_check_to_core

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 and usage tips.

@TejasGhatte
TejasGhatte marked this pull request as ready for review June 16, 2026 07:23

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
coderabbitai Bot requested a review from akshaydeo June 16, 2026 07:24

akshaydeo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Jun 16, 7:59 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 16, 7:59 AM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo merged commit e132d37 into dev Jun 16, 2026
15 checks passed
@akshaydeo
akshaydeo deleted the 06-16-fix_move_anthropic_raw_request_body_check_to_core branch June 16, 2026 07:59
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 3/5

The routing change addresses the intended alias/governance path but still needs fixes around fallback state and the moved lifecycle expectations before it is safe to merge.

The code paths are localized and covered by targeted tests, but the shared context mutation can affect fallback attempts and an existing integration expectation no longer matches the new timing.

core/bifrost.go and plugins/modelcatalogresolver/main.go

T-Rex T-Rex Logs

What T-Rex did

  • A new function clearAnthropicPassthroughForNonNativeProvider was added to core/bifrost.go to standardize clearing of passthrough flags for non-native providers.
  • The function is invoked in requestWorker before payload capture, and the catalog plugin guard was removed so all resolution paths clear the passthrough flags.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix: move anthropic raw request body che..." | Re-trigger Greptile

Comment thread core/bifrost.go
Comment on lines +5951 to +5956
if baseProvider == schemas.Anthropic || baseProvider == schemas.Vertex || baseProvider == schemas.Azure {
return
}
ctx.SetValue(schemas.BifrostContextKeyUseRawRequestBody, false)
ctx.SetValue(schemas.BifrostContextKeySendBackRawResponse, false)
ctx.SetValue(schemas.BifrostContextKeyPassthroughOverridesPresent, false)

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.

P1 Restore passthrough per attempt

This helper permanently clears the Anthropic passthrough flags on the shared request context when a Bedrock or other non-native provider is tried. Fallback attempts reuse the same context, and the native-provider branch returns without restoring the original values for Anthropic, Vertex, or Azure. When an Anthropic-integration request first tries Bedrock and then falls back to a native Anthropic-compatible provider, the fallback still sees UseRawRequestBody, SendBackRawResponse, and PassthroughOverridesPresent as false, so native Claude Code/raw passthrough is disabled incorrectly. Preserve the original passthrough intent separately or compute these as per-attempt effective values instead of destructively clearing the shared context.

@@ -224,19 +224,6 @@ func ResolveProviderFromCatalog(ctx *schemas.BifrostContext, catalog *modelcatal
if slices.Contains(providers, preferred) {

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.

P1 Update moved lifecycle test

Removing the catalog-time clear changes when these flags are visible. The existing Anthropic route test captures UseRawRequestBody, SendBackRawResponse, and PassthroughOverridesPresent inside RequestConverter, before the new requestWorker helper can run, but it still expects all three to already be false when catalog selection picks Bedrock. That test path will now observe the passthrough values set by checkAnthropicPassthrough instead of the worker-cleared values. Update the integration test to assert the new worker-level behavior, or keep a pre-conversion clear if converters still require these flags to be cleared before dispatch.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@CLAassistant

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.


tejas ghatte seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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