You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Aligns WithOrgMonthlySpendCap and WithAPIKeySpendCap with WithBalanceCheck so that subscription-covered requests (which debit $0) are exempt from spend limits without requiring UsageBypassEnabled.
Problem
In WithBalanceCheck, any request presenting a valid covering credential (e.g. X-Weave-Anthropic-Subscription or X-Weave-OpenAI-Subscription) passes through flagged subscription-only because subscription turns debit $0 on the caller's own plan.
However, WithOrgMonthlySpendCap and WithAPIKeySpendCap erroneously required installation.UsageBypassEnabled && .... This caused organizations or keys with valid subscription credentials (but without the usage-bypass toggle active) to be rejected with HTTP 402 once their monthly or key limit was reached, even though the turn is free and incurs no platform cost.
Changes
Updated WithOrgMonthlySpendCap and WithAPIKeySpendCap to check proxy.RequestPresentsCoveringSubscription(...) directly, mirroring WithBalanceCheck.
Updated unit tests in org_monthly_spend_cap_test.go and api_key_spend_cap_test.go to assert that covered requests pass through as subscription-only regardless of whether UsageBypassEnabled is enabled.
This conforms to our conventions — nothing to change, thanks!
Reviewed against root AGENTS.md and the surrounding middleware patterns. The change lands in the right place and, more importantly, it makes both spend caps agree with WithBalanceCheck, which already documents the rule you're applying: the exemption depends only on whether the request presents a covering subscription, not on UsageBypassEnabled (routing config, not billing config). Both call sites keep flagging the turn billing.WithSubscriptionOnly so the proxy can't fail over to a paid model, so paid spend stays bounded at the cap. The comment edits shrink rather than grow, and the renamed tests assert the new behavior end to end (402 → 200 plus the subscription-only flag), so they'd break if the gate came back — no tautologies. go build ./..., go test ./internal/server/middleware/... and gofmt are all clean locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns
WithOrgMonthlySpendCapandWithAPIKeySpendCapwithWithBalanceCheckso that subscription-covered requests (which debit $0) are exempt from spend limits without requiringUsageBypassEnabled.Problem
In
WithBalanceCheck, any request presenting a valid covering credential (e.g.X-Weave-Anthropic-SubscriptionorX-Weave-OpenAI-Subscription) passes through flaggedsubscription-onlybecause subscription turns debit $0 on the caller's own plan.However,
WithOrgMonthlySpendCapandWithAPIKeySpendCaperroneously requiredinstallation.UsageBypassEnabled && .... This caused organizations or keys with valid subscription credentials (but without the usage-bypass toggle active) to be rejected with HTTP 402 once their monthly or key limit was reached, even though the turn is free and incurs no platform cost.Changes
WithOrgMonthlySpendCapandWithAPIKeySpendCapto checkproxy.RequestPresentsCoveringSubscription(...)directly, mirroringWithBalanceCheck.org_monthly_spend_cap_test.goandapi_key_spend_cap_test.goto assert that covered requests pass through as subscription-only regardless of whetherUsageBypassEnabledis enabled.