Skip to content

fix(drift): report provider quota exhaustion as infra, not drift - #598

Merged
jpr5 merged 9 commits into
mainfrom
fix/drift-quota-as-infra
Nov 2, 2026
Merged

jpr5 merged 9 commits into
mainfrom
fix/drift-quota-as-infra

Conversation

@jpr5

@jpr5 jpr5 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Bug

On the Oct 29 11:10 PM PDT scheduled Drift Tests run (41012506730) the OpenAI drift account ran out of credit. The run failed as real drift:

  • Responses HTTP/WS legs: error / response.failed right after response.created became critical SSE:error / SSE:response.failed ("real API emits event type error but mock does not") and broke the K5/K9 contracts. Exit 2 on all 3 retries.
  • Realtime: close 1013: insufficient_quota.credit_balance_exhausted landed in the "surface went silent" lane.
  • Live: "provider refusal" was quarantined (exit 5).

Change

Out of credit is now handled like the other infra conditions (the isInfraSkip 402 out-of-credit / 429 class), not as drift:

  • Legs: throwIfProviderQuotaExhausted (providers.ts) checks the real side before grading (Responses HTTP streaming + 429 body, K5/K9 live wire, Responses WS text/tool/K5, Live error event). It throws InfraError("INFRA_ERROR: <provider> — provider quota exhausted — top up credit (<code>)", 402).
  • Collector: parseProviderQuotaExhausted matches insufficient_quota / credit_balance_exhausted (not drift-like, no drift block) before every other lane. The leg goes to the existing exit-6 "nothing graded" lane with providerQuotaExhausted: { code }. It is never critical, never quarantined, and never a clean baseline. Real drift still wins (exit 2).
  • Slack summary: a "Provider quota exhausted — top up credit" line. With no other findings the headline is infra-transient.
  • Workflow: a ::error title=provider-quota-exhausted:: annotation, the quota_exhausted job output, and a 💳 notify branch ("top up credit … not API drift").

RED → GREEN (local, real run payloads, no provider calls)

Fixtures: verbatim failure messages and diffs from the run's drift-report.json. The Responses stream bodies were not retained by the run. They are rebuilt from the run's event order plus the Realtime error object OpenAI sent on the same key in the same run.

RED (origin/main, the real collector + leg comparison code):

HTTP leg critical diffs: [ 'SSE:error', 'SSE:response.failed' ]
entries: [ 'OpenAI Responses/streaming text events: SSE:error,SSE:response.failed' ]
quarantine: [ 'OpenAI Live … client lifecycle', 'OpenAI Live … managed lifecycle' ]
timeouts: [ 3× Realtime serverClose 1013 quota=undefined ]
collector exit: 2
Slack: *Classification:* real-drift

GREEN (this branch, same inputs):

HTTP leg threw: InfraError: INFRA_ERROR: OpenAI Responses — provider quota exhausted — top up credit (credit_balance_exhausted)
WARNING: 6 live drift leg(s) failed because the provider account is out of credit — provider quota exhausted — top up credit. This is infra, NOT API drift
entries: []   quarantine: []   timeouts: 6, all providerQuotaExhausted=credit_balance_exhausted
collector exit: 6

Genuine drift is unchanged. The run's own drift block (no body) is still exit 2. A drift block whose values contain insufficient_quota is still exit 2. A real critical next to quota legs still wins (exit 2).

The regression tests are in src/__tests__/drift-quota-exhausted.test.ts (11 tests). With the fix reverted, all 11 fail. If only the collector routing is disabled, 4 fail. If only leg detection is disabled, 5 fail.

Checks: format:check, typecheck, lint, build, actionlint are clean. The full suite has 19993 passing tests. 5 tests failed in response-a9-equivalence / validate-cli under full-suite load. These files are unrelated, and they pass when run alone.

Known limitation (not changed here): on days when the approved Anthropic/Gemini native diffs are present and the effective exit is not 0, the Slack detail still prints Classification: real-drift for those approved diffs. The quota line and the 💳 headline are shown above it.

Round 1 review fixes

Quota is now read only from structured provider evidence, and every OpenAI leg reports it. Each fix was reproduced on fa2484bb (RED) and re-run on this branch (GREEN) against the same inputs.

1. Real test failures were classified as quota. A scratch drift leg ran against the real aimock mock-side insufficient_quota fixture. Its real vitest failures went through collectDriftEntries:

RED   (fa2484bb)  toStrictEqual / toThrow / thrown Error echoing the body -> QUOTA/TIMEOUT {"code":"insufficient_quota"} (x3)
GREEN (branch)    the same three -> QUARANTINE (a test failure, exit 5)

3. Quota on every leg. The real openai-responses and openai-embeddings legs ran against a fake out-of-credit api.openai.com (fetch shim). The real ws-live leg ran against a loopback WS peer.

HTTP 429  RED: Embeddings x2, K5/K9 x2 -> QUARANTINE; namespaced/custom x4 -> SKIPPED
          GREEN: all 12 legs -> QUOTA
Live close 1013 (no error event)  RED: quarantine x2, 2 paid connects   GREEN: quota x2, 1 connect
Live quota error then other error RED: quarantine x2                    GREEN: quota x2
Live upgrade 429 quota body       RED: quarantine x2                    GREEN: quota x2 (status 429)

4. Reporting.

RED   conclusion=live-timeout, class infra-transient, refusal 4001 close stored in serverClose
GREEN conclusion=provider-quota-exhausted, class provider-quota, serverClose omitted for the refusal code

5. Workflow. The collector step, the notify step and the PR base/head blocks were extracted from test-drift.yml and run under bash against sample reports:

quota+silent exit 6    RED: Slack names only quota        GREEN: quota + "Also: 1 live drift leg(s) went silent"
quota+AG-UI exit 6     RED: AG-UI line dropped            GREEN: listed
quota on exit 2 / 5    RED: no quota_exhausted, no alert  GREEN: output, annotation and Slack quota line
PR base/head quota     RED: "no messages in nullms"       GREEN: provider-quota-exhausted annotation
malformed report       RED: silent zero                   GREEN: ::error title=drift-report-unreadable

Mutations. Each was applied alone and each is now killed: removing the second-pass quota guard, quotaCodeOf depth 2→1, removing the Live refusalQuotaCode latch, and dropping the response.error recursion. Reverting each fix in a scratch copy also fails the suite. This covers the free-text match, the Live close, first-cause-wins and upgrade-429 changes, the refusal serverClose guard, the conclusion, the headline class, the real status, and the non-JSON warn.

Fixtures: the README in fixtures/quota-exhausted-2026-10-30/ says which data is real and which was reconstructed. Slack testName escaping: the existing quarantine bullets do not escape, so neither does the quota list.

Checks: format:check, lint, typecheck, build and actionlint are clean. The full unit suite passes: 487 files, 20010 tests.

When the OpenAI drift account ran out of credit, the Responses legs saw an
error / response.failed event and reported "real API emits event type error
but mock does not" as critical drift, Live was quarantined, and Realtime
1013 closes were reported as a silent surface.

The legs now report an out-of-credit error event or 429 body as an
InfraError naming the quota code. The collector recognizes
insufficient_quota / credit_balance_exhausted before any other lane and
records the leg in the exit-6 "nothing graded" lane with
providerQuotaExhausted, so the run is never a clean baseline and is never
critical drift. The Slack summary and the drift workflow alert say
"provider quota exhausted — top up credit".
@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@598

commit: 6f00ab6

jpr5 added 8 commits November 2, 2026 13:16
The collector matched `insufficient_quota` anywhere in a failure message, so
a real assertion failure that only names the code (a toStrictEqual, a
toThrow, an Error echoing the mock-side quota fixture) was reported as
"top up credit" and never as a test failure.

Quota is now read only from structured provider evidence on the failure's
first line: the harness's quota marker, which a leg throws after reading the
code from the real provider, or a WS server-close whose reason names a quota
code. The code list and the marker live in one module, scripts/drift-quota.ts,
shared by the harness and the collector.
Legs that met an out-of-credit account still failed or skipped without
naming quota. Each now throws the quota marker from the provider's own
evidence:

- K5/K9 exhaustion probe reads a non-200 body before asserting status.
- Namespaced and custom tool legs check a 429 body before skipping and the
  200 stream / response before grading.
- assertOk reads the whole error body, so the 300-char cut cannot hide the
  code; withInfraErrorTag passes the marker through unchanged.
- Live records the close code and reason and recognizes a quota close,
  keeps the first failure so a later error cannot overwrite a quota cause,
  and names quota from a refused upgrade, so later modes do not open paid
  sessions. ws-upstream's refusal error carries the status and the JSON
  error code/type (never the body text).
- The quota InfraError carries the provider's real status (429 on a refused
  request, 0 in band) instead of a hardcoded 402.
- errorBodyEvents logs a non-JSON 402/429 body instead of dropping it.
Quota legs share the exit-6 lane but are not silence. The collector now
counts them apart ("Live timeouts (zero observations)" counts only silent
legs), words the exit-6 message from both, and a quota-only run concludes
"provider-quota-exhausted" instead of "live-timeout". The Slack headline
class is the new "provider-quota": out of credit persists until someone
tops up, so it is not "infra-transient". TimeoutEntry, DriftReport and
summarizeDriftReport docs describe the quota form.
- The drift step counts quota and silent legs on every exit that writes a
  report (2, 5, 6), so quota beside a critical drift or a quarantine still
  sets quota_exhausted and its annotation. A report jq cannot read raises an
  explicit drift-report-unreadable error instead of counting zero.
- notify lists every ungraded cause: quota, silent legs and AG-UI schema
  drift together on exit 6, and a quota line on exit 2 / 5 alerts.
- The PR base/head legs split quota from silence the same way and never
  print "nullms".
A README in the fixture directory says which parts are copied from run
41012506730 (the drift-report.json failure messages and diffs) and which
were reconstructed (the Responses HTTP/WS streams, whose bodies the run
did not keep). The reconstructed created_at is now an obviously synthetic
0, not a plausible wrong-year timestamp.
A Live session can close for quota while the leg is still sending tool
results. The pending send then rejects with "WebSocket closed", and the
leg reported that instead of the quota close it had already recorded, so
the collector graded it as a generic failure. Rethrow the recorded quota
failure instead.
fetchWithRetry retried every 429 with backoff, so each OpenAI leg on an
empty account sent three requests and waited about three seconds before
it reported quota. A 429 whose body names a quota code is permanent:
return it on the first attempt. A plain rate-limit 429 is still retried.
The collector also writes drift-report.json on exit 1 (AG-UI skipped),
but the workflow read quota and silent legs only on exits 2, 5 and 6. An
out-of-credit run with AG-UI skipped gave no quota output, no annotation
and no "top up credit" line. Read the report whenever it exists, in the
drift job and in the PR base and head legs.
@jpr5
jpr5 merged commit 91260a8 into main Nov 2, 2026
36 checks passed
@jpr5
jpr5 deleted the fix/drift-quota-as-infra branch November 2, 2026 22:32
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