fix: skip key selection on anthropic provider - #6536
Conversation
|
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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 6 reviews per hour. 📝 WalkthroughSummary by CodeRabbit
WalkthroughThe change restricts key-selection skipping to Anthropic OAuth passthrough. It evaluates the resolved base provider for wrapped providers and adds regression coverage for Anthropic and Fireworks behavior. ChangesProvider key selection
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change restricts key-selection bypass behavior to Anthropic and adds regression coverage for non-Anthropic routing; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The PR does not address the directly linked issue [ Full details: Description checkExplanation The description clearly explains the bug, the implementation, the affected areas, test commands, security impact, and checklist status. Screenshots are not needed because this PR has no UI changes. The Related issues section is not included, but the description is otherwise complete.
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Merge activity
|
## Summary `SkipKeySelection` was previously allowed for any provider that wasn't Azure, Bedrock, BedrockMantle, or Vertex. This meant that if a governance routing rule rewrote the provider/model after the Claude Code OAuth transport set the flag, a non-Anthropic provider (e.g. Fireworks) would skip key selection entirely — leaving it without a configured key and causing request construction to fall back to the OpenAI schema, which breaks providers like Fireworks that require `max_tokens`. The fix tightens `isKeySkippingAllowed` to an allowlist of exactly one provider (`Anthropic`), since `SkipKeySelection` exists solely for Claude Code OAuth passthrough where the caller's token is the upstream credential and only the Anthropic provider forwards it. ## Changes - `isKeySkippingAllowed` now returns `true` only for `schemas.Anthropic`, replacing the previous denylist approach. This ensures non-Anthropic providers always receive a configured key from the pool. - The `selectKeyFromProviderForModelWithPool` call site now passes `baseProviderType` instead of `providerKey` to `isKeySkippingAllowed`, so the gate is evaluated against the resolved base provider. - `SkipKeySelection` is intentionally **not** cleared in `clearAnthropicPassthroughForNonNativeProvider` — it also drives `IsClaudeCodeMaxMode`, which suppresses `x-api-key` on the Anthropic provider. Clearing it during a non-native attempt would cause an Anthropic fallback to send the account key alongside the caller's OAuth token. The flag is gated at the read site instead. - A new test `TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider` verifies that Anthropic skips key selection while Fireworks (with `UseAnthropicEndpoints`) still selects its own key. - `TestClearAnthropicPassthroughForNonNativeProvider` is updated to assert that `SkipKeySelection` survives the clear operation and documents why. ## Type of change - [x] Bug fix ## Affected areas - [x] Core (Go) - [x] Providers/Integrations ## How to test ```sh go test ./core/... -run TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider go test ./core/... -run TestClearAnthropicPassthroughForNonNativeProvider go test ./... ``` The new test covers the regression directly: with `SkipKeySelection` set and a Fireworks provider, the selected key must be present and must have `UseAnthropicEndpoints = true`. Without this fix, the key pool would be empty and that assertion would fail. ## Breaking changes - [ ] Yes - [x] No ## Security considerations `SkipKeySelection` bypasses key injection entirely, relying on the caller's OAuth token as the upstream credential. Tightening the allowlist to Anthropic-only reduces the surface where a misconfigured or rewritten routing rule could cause a request to be sent without any credential, or with the wrong credential type for the target provider. ## Checklist - [x] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [x] I verified the CI pipeline passes locally if applicable
## Summary `SkipKeySelection` was previously allowed for any provider that wasn't Azure, Bedrock, BedrockMantle, or Vertex. This meant that if a governance routing rule rewrote the provider/model after the Claude Code OAuth transport set the flag, a non-Anthropic provider (e.g. Fireworks) would skip key selection entirely — leaving it without a configured key and causing request construction to fall back to the OpenAI schema, which breaks providers like Fireworks that require `max_tokens`. The fix tightens `isKeySkippingAllowed` to an allowlist of exactly one provider (`Anthropic`), since `SkipKeySelection` exists solely for Claude Code OAuth passthrough where the caller's token is the upstream credential and only the Anthropic provider forwards it. ## Changes - `isKeySkippingAllowed` now returns `true` only for `schemas.Anthropic`, replacing the previous denylist approach. This ensures non-Anthropic providers always receive a configured key from the pool. - The `selectKeyFromProviderForModelWithPool` call site now passes `baseProviderType` instead of `providerKey` to `isKeySkippingAllowed`, so the gate is evaluated against the resolved base provider. - `SkipKeySelection` is intentionally **not** cleared in `clearAnthropicPassthroughForNonNativeProvider` — it also drives `IsClaudeCodeMaxMode`, which suppresses `x-api-key` on the Anthropic provider. Clearing it during a non-native attempt would cause an Anthropic fallback to send the account key alongside the caller's OAuth token. The flag is gated at the read site instead. - A new test `TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider` verifies that Anthropic skips key selection while Fireworks (with `UseAnthropicEndpoints`) still selects its own key. - `TestClearAnthropicPassthroughForNonNativeProvider` is updated to assert that `SkipKeySelection` survives the clear operation and documents why. ## Type of change - [x] Bug fix ## Affected areas - [x] Core (Go) - [x] Providers/Integrations ## How to test ```sh go test ./core/... -run TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider go test ./core/... -run TestClearAnthropicPassthroughForNonNativeProvider go test ./... ``` The new test covers the regression directly: with `SkipKeySelection` set and a Fireworks provider, the selected key must be present and must have `UseAnthropicEndpoints = true`. Without this fix, the key pool would be empty and that assertion would fail. ## Breaking changes - [ ] Yes - [x] No ## Security considerations `SkipKeySelection` bypasses key injection entirely, relying on the caller's OAuth token as the upstream credential. Tightening the allowlist to Anthropic-only reduces the surface where a misconfigured or rewritten routing rule could cause a request to be sent without any credential, or with the wrong credential type for the target provider. ## Checklist - [x] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [x] I verified the CI pipeline passes locally if applicable

Summary
SkipKeySelectionwas previously allowed for any provider that wasn't Azure, Bedrock, BedrockMantle, or Vertex. This meant that if a governance routing rule rewrote the provider/model after the Claude Code OAuth transport set the flag, a non-Anthropic provider (e.g. Fireworks) would skip key selection entirely — leaving it without a configured key and causing request construction to fall back to the OpenAI schema, which breaks providers like Fireworks that requiremax_tokens.The fix tightens
isKeySkippingAllowedto an allowlist of exactly one provider (Anthropic), sinceSkipKeySelectionexists solely for Claude Code OAuth passthrough where the caller's token is the upstream credential and only the Anthropic provider forwards it.Changes
isKeySkippingAllowednow returnstrueonly forschemas.Anthropic, replacing the previous denylist approach. This ensures non-Anthropic providers always receive a configured key from the pool.selectKeyFromProviderForModelWithPoolcall site now passesbaseProviderTypeinstead ofproviderKeytoisKeySkippingAllowed, so the gate is evaluated against the resolved base provider.SkipKeySelectionis intentionally not cleared inclearAnthropicPassthroughForNonNativeProvider— it also drivesIsClaudeCodeMaxMode, which suppressesx-api-keyon the Anthropic provider. Clearing it during a non-native attempt would cause an Anthropic fallback to send the account key alongside the caller's OAuth token. The flag is gated at the read site instead.TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProviderverifies that Anthropic skips key selection while Fireworks (withUseAnthropicEndpoints) still selects its own key.TestClearAnthropicPassthroughForNonNativeProvideris updated to assert thatSkipKeySelectionsurvives the clear operation and documents why.Type of change
Affected areas
How to test
The new test covers the regression directly: with
SkipKeySelectionset and a Fireworks provider, the selected key must be present and must haveUseAnthropicEndpoints = true. Without this fix, the key pool would be empty and that assertion would fail.Breaking changes
Security considerations
SkipKeySelectionbypasses key injection entirely, relying on the caller's OAuth token as the upstream credential. Tightening the allowlist to Anthropic-only reduces the surface where a misconfigured or rewritten routing rule could cause a request to be sent without any credential, or with the wrong credential type for the target provider.Checklist
docs/contributing/README.mdand followed the guidelines