fix(proxy): consume UsageBypass on OpenAI chat completions#776
fix(proxy): consume UsageBypass on OpenAI chat completions#776rohith500 wants to merge 3 commits into
Conversation
Lock in bypass weekly-limit fallthrough and subscription-only refuse on ProxyOpenAIChatCompletion before wiring the Messages consumer. Signed-off-by: N Rohith Reddy <rohithreddy2202@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Wire bypassAnthropicOpenAI after runTurnLoop so Anthropic usage-bypass turns get skip-billing pass-through and 429→routeFor fallthrough, matching ProxyMessages. Signed-off-by: N Rohith Reddy <rohithreddy2202@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
|
PR author is not in the allowed authors list. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7994e67. Configure here.
Subscription-only streaming marker must not commit SSE before upstream; Discard on retryable bypass so 402 refuse leaves no partial stream. Signed-off-by: N Rohith Reddy <rohithreddy2202@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
|
Addressed Bugbot: Added |
|
Thanks @rohith500 — this one follows the repo conventions nicely and needs no changes. 👍 The UsageBypass consumer sits on |

Summary
runTurnLoopalready setsUsageBypass=truefor both wire formats when the per-installation gate engages, but onlyProxyMessagesconsumed it viabypassToAnthropic(strict subscription pass-through, skip ledger, and on a retryable 429 fall through torouteFor).ProxyOpenAIChatCompletionignoredrouteRes.UsageBypassand continued normal dispatch.429to the client.Confirmed unintentional incomplete port in #775 (same class as #771). No overlap with #762 (preemptive exhaustion suppress) or #773 (post-dispatch baseline / subscription-credit retry).
Expected vs actual (pre-fix → post-fix)
Happy path (gate on, util 0.20, requested
claude-sonnet-4-6)bypassAnthropicOpenAIx-router-decisionusage_bypassusage_bypassusage_bypassbypassToAnthropicbypassAnthropicOpenAI(skip billing)chat.completionchat.completionWeekly-limit 429 on the bypass attempt
cluster:v0.2usage_bypasscluster:v0.2claude-haiku-4-5)Subscription-only + bypass 429
ErrCreditsExhaustedSubscriptionUnavailableErrCreditsExhaustedSubscriptionUnavailableFix
bypassAnthropicOpenAI(usage_bypass.go) — OpenAI-wire counterpart tobypassToAnthropic:PrepareAnthropic+NewSSETranslator→ OpenAI client responseerrBypassRetryableonproviders.IsRetryablepre-commitflushBufferedIfPresentrouter.usage_bypassspan (same attrs as Messages)ProxyOpenAIChatCompletionafterrunTurnLoop— mirror Messages (service.go~2168):turnLoopResult.UsageBypassgodoc — names both surfaces.Design: second helper (not a shared Messages/OpenAI abstraction) because emit/flush differ (
flushUpstreamErrorAsAnthropicvsflushBufferedIfPresent+ SSE translator). Eligibility / fallthrough control flow matches Messages exactly.ProxyMessagesuntouched (diff only in OpenAI entry + new helper).What changed
internal/proxy/usage_bypass.gobypassAnthropicOpenAIinternal/proxy/service.goProxyOpenAIChatCompletioninternal/proxy/turnloop.gointernal/proxy/openai_usage_bypass_test.goLive verification (committed tip
7994e67)Re-ran the same
bypassFixtureshapes used in #775 against the committed branch (throwaway probe; not committed):Pre-fix OpenAI 429 (from #775):
status=429,scorer=0,anthCalls=3, decision stuck onusage_bypass.Billing
Successful OpenAI bypass now skips the ledger (early return), matching Messages
bypassToAnthropic— not the prior coincidence path’semitBillingdelta=0 notional row.Not in scope / not overlapping
routeFor)Test plan
TestProxyOpenAI_UsageBypass_WeeklyLimit_FallsBackToRoutedDispatch+ subscription-only refuse fail on main, pass hereTestUsageBypass_*/TestBypass_*/ Messages weekly-limit suite greenmake checkgreengo test ./internal/proxy/... -raceclean except knownTestFireTelemetryRecoversFromPanicflakeProxyMessagesregion unchanged in diffFixes #775
Made with Cursor