fix(combo): do not treat credits-exhausted 401 as auth skip - #12449
diegosouzapw merged 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new quota/credits detection can miss quota signals when structured errors include a non-quota code, and the embeddings 402 mapping lacks a direct regression test.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes combo exhaustion classification so quota/credits exhaustion that surfaces as HTTP 401/403 does not take the auth-skip path (#8133), and surfaces credits_exhausted as HTTP 402 (Payment Required) from chat + embeddings to align with quota semantics.
Changes:
- Map
credits_exhaustedterminal credential state to HTTP 402 (chat + embeddings) instead of 401. - Add
isQuotaOrCreditsError()and use it to prevent misclassified quota/credits bodies from triggering auth-level combo exhaustion. - Add unit tests for the #12441 combo skip regression and the chat helper HTTP status mapping.
Commands / Coverage (custom):
- Commands run (per PR description):
node --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test tests/unit/12441-quota-not-auth-skip.test.ts tests/unit/chat-helpers.test.ts - Changed test files:
tests/unit/12441-quota-not-auth-skip.test.ts,tests/unit/chat-helpers.test.ts - Coverage result (custom): Not provided/verified in this review (no
npm run test:coverageoutput included).
File summaries
| File | Description |
|---|---|
open-sse/services/combo/targetExhaustion.ts |
Adds quota/credits detection helper and blocks auth-skip for misclassified quota/credits error bodies. |
src/sse/handlers/chatHelpers.ts |
Maps credits_exhausted terminal state to HTTP 402 instead of 401 in handleNoCredentials. |
src/lib/embeddings/service.ts |
Maps embeddings credential exhaustion with credits_exhausted to HTTP 402. |
tests/unit/chat-helpers.test.ts |
Adds regression test asserting handleNoCredentials returns 402 for credits_exhausted. |
tests/unit/12441-quota-not-auth-skip.test.ts |
New unit tests covering quota/credits bodies not triggering auth-level combo skips. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
3388a6b to
363ded3
Compare
|
sweep-reds / babysit: reds on this PR are inherited from base-red #12581, not this quota-skip diff. Skipping a code change; did not merge
|
|
sweep-reds round 6 / babysit: re-verified — every remaining red is inherited from base-red #12581, not this quota-skip diff. Skipping a code change; did not merge
STOP. Resume after #12581 drains. |
…-quota Keep credits-exhausted 401/403 off the auth-skip path when the quota signal lives in the message or errorText. Add embeddings 402 coverage for allExpired + credits_exhausted. Co-authored-by: Ravi Tharuma <RaviTharuma@users.noreply.github.com>
76a9341 to
4763ffd
Compare
8c1dfc4
into
diegosouzapw:release/v3.8.51
…zapw#12449) Validado em lote numa worktree combinada com os 10 PRs desta leva sobre o tip de `release/v3.8.51`: `typecheck:core` limpo, `check-file-size` OK e **241/242** nos 29 arquivos de teste que os PRs tocam. A única "falha" não é falha: `tests/unit/autoCombo/strict-zero-cost-filter.test.ts` é um teste em estilo Vitest que eu incluí por engano na invocação do runner nativo do Node — ele quebra no import (`@vitest/runner`), não numa asserção. Ao investigar, descobri que esse arquivo não roda em nenhum dos dois runners hoje (o glob do `test:unit` não lista `autoCombo` e o `include` do Vitest só pega `.tsx` nessa pasta); é um problema pré-existente do repositório, sem relação com esta leva, e vou registrá-lo separadamente. O diegosouzapw#12636 conflitava apenas na lista de testes do `@omniroute/opencode-plugin/package.json`, de forma aditiva: o tip já tinha `models-fetcher.test.ts` (do diegosouzapw#12607, irmão desta mesma leva) e o diegosouzapw#12636 acrescenta `telemetry.test.ts`. Fiz a união dos dois lados (25 arquivos contra 24 de cada) em vez de escolher um, o que teria removido um arquivo da suíte do plugin em silêncio. Obrigado, @RaviTharuma.
Summary
credits_exhaustedis now surfaced as HTTP 402 (PAYMENT_REQUIRED) from chat and embeddings credential exhaustion, matching the quota class.applyComboTargetExhaustionignores quota/credits bodies on the auth-skip path. Real expired 401 still marks the connection.Related Issues
Validation
npm run lint(CI)Focused command:
Result: 32 pass, 0 fail.
Tests Added Or Updated
tests/unit/12441-quota-not-auth-skip.test.tstests/unit/chat-helpers.test.tsCoverage Notes
handleNoCredentials maps credits_exhausted to HTTP 402 not 401.Reviewer Notes