Conversation
📝 WalkthroughWalkthroughRouted-identity headers are now applied to Bifrost error responses and streaming or non-streaming passthrough responses. A shared error-header helper maps error metadata, with tests covering fallback, native, and empty metadata cases. ChangesRouted identity header propagation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
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. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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.
Inline comments:
In `@transports/bifrost-http/integrations/router.go`:
- Line 3384: Update the response-header handling around
ApplyBifrostResponseHeaders so the streaming response always retains
Cache-Control: no-cache after passthrough headers are applied. Reassert the
no-cache directive immediately after the call, or exclude Cache-Control from the
provider headers handled there, while preserving the existing passthrough
behavior for other headers.
In `@transports/bifrost-http/integrations/utils.go`:
- Around line 169-170: Update the error-response header flow around
ApplyBifrostErrorResponseHeaders to clear the complete managed x-bifrost-*
header set after forwarding provider headers, including stale routed identity
fields, then apply bifrostErr.ExtraFields so route-derived values overwrite
forwarded headers. Preserve the existing provider-header forwarding and
route-derived header behavior.
- Around line 169-170: Reserve the managed x-bifrost-* namespace after
provider-header forwarding and before applying routed identity fields. In
transports/bifrost-http/integrations/utils.go lines 169-170, clear every managed
Bifrost identity header before ApplyBifrostErrorResponseHeaders; apply the same
clearing in transports/bifrost-http/integrations/router.go lines 3287-3290 and
3381-3384 for non-stream and stream passthrough paths, respectively. Add a
regression test covering upstream Bifrost identity collisions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: cf881b5b-10e7-4200-a4a5-3a64b0853dda
📒 Files selected for processing (5)
transports/bifrost-http/handlers/utils.gotransports/bifrost-http/integrations/router.gotransports/bifrost-http/integrations/utils.gotransports/bifrost-http/lib/responseheaders.gotransports/bifrost-http/lib/responseheaders_test.go
1a21bc9 to
129aeff
Compare
Merge activity
|
The base branch was changed.
## Summary Error responses and passthrough responses (both streaming and non-streaming) were not emitting `x-bifrost-*` routing identity headers, making it impossible for callers to determine which provider ran or whether a fallback fired when a request failed or was proxied verbatim. ## Changes - Added `ApplyBifrostErrorResponseHeaders` in `lib/responseheaders.go` to bridge `BifrostErrorExtraFields` to the shared `ApplyBifrostResponseHeaders` writer, since error and success paths use different extra-fields types. - Called `ApplyBifrostErrorResponseHeaders` in `handlers/utils.go` (`SendBifrostError`) and `integrations/utils.go` (`sendStreamError`) so all error responses carry routed-identity headers. Applied after provider-header forwarding so a chained upstream's `x-bifrost-*` headers cannot overwrite bifrost's own identity. - Called `ApplyBifrostResponseHeaders` in `integrations/router.go` for both `handlePassthroughNonStream` and `handlePassthroughStream`, since passthrough responses forward provider bytes 1:1 and cannot carry `extra_fields` in the body. - When `bifrostCtx` is `nil` (native error path), context-only headers such as `x-bifrost-fallback-index` and `x-bifrost-upstream-latency` are intentionally omitted; `routing_info-*` headers still report which provider ran and whether a fallback fired. - Added `TestApplyBifrostErrorResponseHeaders` covering fallback-exhausted errors, the nil-context native error path, and empty extra fields. ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [x] Transports (HTTP) - [x] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./transports/bifrost-http/lib/... go test ./transports/bifrost-http/integrations/... go test ./transports/bifrost-http/handlers/... ``` Send a request that triggers a provider error or exhausts all fallbacks and inspect the response headers — `x-bifrost-provider`, `x-bifrost-routing-info-is-fallback`, `x-bifrost-routing-info-provider`, and related headers should be present. Repeat with a passthrough route (streaming and non-streaming) and confirm the same identity headers appear after provider-forwarded headers. ## Screenshots/Recordings N/A ## Breaking changes - [x] No ## Related issues N/A ## Security considerations No auth, secrets, or PII implications. Headers added are routing metadata already present on success responses. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
## Summary Error responses and passthrough responses (both streaming and non-streaming) were not emitting `x-bifrost-*` routing identity headers, making it impossible for callers to determine which provider ran or whether a fallback fired when a request failed or was proxied verbatim. ## Changes - Added `ApplyBifrostErrorResponseHeaders` in `lib/responseheaders.go` to bridge `BifrostErrorExtraFields` to the shared `ApplyBifrostResponseHeaders` writer, since error and success paths use different extra-fields types. - Called `ApplyBifrostErrorResponseHeaders` in `handlers/utils.go` (`SendBifrostError`) and `integrations/utils.go` (`sendStreamError`) so all error responses carry routed-identity headers. Applied after provider-header forwarding so a chained upstream's `x-bifrost-*` headers cannot overwrite bifrost's own identity. - Called `ApplyBifrostResponseHeaders` in `integrations/router.go` for both `handlePassthroughNonStream` and `handlePassthroughStream`, since passthrough responses forward provider bytes 1:1 and cannot carry `extra_fields` in the body. - When `bifrostCtx` is `nil` (native error path), context-only headers such as `x-bifrost-fallback-index` and `x-bifrost-upstream-latency` are intentionally omitted; `routing_info-*` headers still report which provider ran and whether a fallback fired. - Added `TestApplyBifrostErrorResponseHeaders` covering fallback-exhausted errors, the nil-context native error path, and empty extra fields. ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [x] Transports (HTTP) - [x] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./transports/bifrost-http/lib/... go test ./transports/bifrost-http/integrations/... go test ./transports/bifrost-http/handlers/... ``` Send a request that triggers a provider error or exhausts all fallbacks and inspect the response headers — `x-bifrost-provider`, `x-bifrost-routing-info-is-fallback`, `x-bifrost-routing-info-provider`, and related headers should be present. Repeat with a passthrough route (streaming and non-streaming) and confirm the same identity headers appear after provider-forwarded headers. ## Screenshots/Recordings N/A ## Breaking changes - [x] No ## Related issues N/A ## Security considerations No auth, secrets, or PII implications. Headers added are routing metadata already present on success responses. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
## Summary Error responses and passthrough responses (both streaming and non-streaming) were not emitting `x-bifrost-*` routing identity headers, making it impossible for callers to determine which provider ran or whether a fallback fired when a request failed or was proxied verbatim. ## Changes - Added `ApplyBifrostErrorResponseHeaders` in `lib/responseheaders.go` to bridge `BifrostErrorExtraFields` to the shared `ApplyBifrostResponseHeaders` writer, since error and success paths use different extra-fields types. - Called `ApplyBifrostErrorResponseHeaders` in `handlers/utils.go` (`SendBifrostError`) and `integrations/utils.go` (`sendStreamError`) so all error responses carry routed-identity headers. Applied after provider-header forwarding so a chained upstream's `x-bifrost-*` headers cannot overwrite bifrost's own identity. - Called `ApplyBifrostResponseHeaders` in `integrations/router.go` for both `handlePassthroughNonStream` and `handlePassthroughStream`, since passthrough responses forward provider bytes 1:1 and cannot carry `extra_fields` in the body. - When `bifrostCtx` is `nil` (native error path), context-only headers such as `x-bifrost-fallback-index` and `x-bifrost-upstream-latency` are intentionally omitted; `routing_info-*` headers still report which provider ran and whether a fallback fired. - Added `TestApplyBifrostErrorResponseHeaders` covering fallback-exhausted errors, the nil-context native error path, and empty extra fields. ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [x] Transports (HTTP) - [x] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./transports/bifrost-http/lib/... go test ./transports/bifrost-http/integrations/... go test ./transports/bifrost-http/handlers/... ``` Send a request that triggers a provider error or exhausts all fallbacks and inspect the response headers — `x-bifrost-provider`, `x-bifrost-routing-info-is-fallback`, `x-bifrost-routing-info-provider`, and related headers should be present. Repeat with a passthrough route (streaming and non-streaming) and confirm the same identity headers appear after provider-forwarded headers. ## Screenshots/Recordings N/A ## Breaking changes - [x] No ## Related issues N/A ## Security considerations No auth, secrets, or PII implications. Headers added are routing metadata already present on success responses. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable

Summary
Error responses and passthrough responses (both streaming and non-streaming) were not emitting
x-bifrost-*routing identity headers, making it impossible for callers to determine which provider ran or whether a fallback fired when a request failed or was proxied verbatim.Changes
ApplyBifrostErrorResponseHeadersinlib/responseheaders.goto bridgeBifrostErrorExtraFieldsto the sharedApplyBifrostResponseHeaderswriter, since error and success paths use different extra-fields types.ApplyBifrostErrorResponseHeadersinhandlers/utils.go(SendBifrostError) andintegrations/utils.go(sendStreamError) so all error responses carry routed-identity headers. Applied after provider-header forwarding so a chained upstream'sx-bifrost-*headers cannot overwrite bifrost's own identity.ApplyBifrostResponseHeadersinintegrations/router.gofor bothhandlePassthroughNonStreamandhandlePassthroughStream, since passthrough responses forward provider bytes 1:1 and cannot carryextra_fieldsin the body.bifrostCtxisnil(native error path), context-only headers such asx-bifrost-fallback-indexandx-bifrost-upstream-latencyare intentionally omitted;routing_info-*headers still report which provider ran and whether a fallback fired.TestApplyBifrostErrorResponseHeaderscovering fallback-exhausted errors, the nil-context native error path, and empty extra fields.Type of change
Affected areas
How to test
Send a request that triggers a provider error or exhausts all fallbacks and inspect the response headers —
x-bifrost-provider,x-bifrost-routing-info-is-fallback,x-bifrost-routing-info-provider, and related headers should be present. Repeat with a passthrough route (streaming and non-streaming) and confirm the same identity headers appear after provider-forwarded headers.Screenshots/Recordings
N/A
Breaking changes
Related issues
N/A
Security considerations
No auth, secrets, or PII implications. Headers added are routing metadata already present on success responses.
Checklist
docs/contributing/README.mdand followed the guidelines