Skip to content

fix(provider): classify gateway quota exhaustion and 402 as non-retryable - #378

Merged
filipeforattini merged 3 commits into
mainfrom
gateway-quota-errors
Sep 23, 2026
Merged

filipeforattini merged 3 commits into
mainfrom
gateway-quota-errors

Conversation

@filipeforattini

@filipeforattini filipeforattini commented Sep 23, 2026 •

Copy link
Copy Markdown

Summary

Ports the ideas from upstream opencode 4a27842 and 6a30741 to both runtimes.

  • @reddb-io/redcode-llm: new isQuotaFailure / isContentPolicyFailure classifiers. Quota = HTTP 402, a quota code (insufficient_quota, usage_not_included, billing_error, usage_limit*, insufficient_credits, Zen FreeUsageLimitError / GoUsageLimitError / CreditLimitExceeded) wherever a provider or router puts it (including OpenRouter metadata.raw and Zen [code] labels), or quota/credits wording on a 429. Content policy = provider codes (content_filter, ResponsibleAIPolicyViolation, content_policy_violation, ...).
  • RequestExecutor (v2): 402 and gateway caps become QuotaExceeded (not retried) instead of UnknownProvider / RateLimit.
  • SessionRetry (core, both runtimes): quota and content-policy failures are never retried, even when the SDK marks a 429 retryable or the body says "try again". A 4xx other than 408/409/429 is only promoted to retryable by transport failures, so a gateway's substituted server_error on a 400 is no longer retried. Router-reported reasons (quota_exhausted with retry-at) keep router semantics.
  • Legacy ProviderError.parseAPICallError / parseStreamError: quota failures are non-retryable and the message says the account's quota, credits or free-tier limit is exhausted.

Tests

  • packages/llm/test/provider-error.test.ts, packages/llm/test/executor.test.ts
  • packages/core/test/session-retry.test.ts
  • packages/redcode/test/session/retry.test.ts (the FreeUsageLimitError/GoUsageLimitError case now expects no retry)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@filipeforattini
filipeforattini enabled auto-merge (squash) September 23, 2026 06:04
@filipeforattini
filipeforattini merged commit b778252 into main Sep 23, 2026
22 checks passed
@filipeforattini
filipeforattini deleted the gateway-quota-errors branch September 23, 2026 06:24
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.

1 participant