Repository navigation
fix(drift): report provider quota exhaustion as infra, not drift - #598
Merged
Merged
Conversation
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".
commit: |
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:
error/response.failedright afterresponse.createdbecame criticalSSE: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.close 1013: insufficient_quota.credit_balance_exhaustedlanded in the "surface went silent" lane.Change
Out of credit is now handled like the other infra conditions (the
isInfraSkip402 out-of-credit / 429 class), not as drift: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 throwsInfraError("INFRA_ERROR: <provider> — provider quota exhausted — top up credit (<code>)", 402).parseProviderQuotaExhaustedmatchesinsufficient_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 withproviderQuotaExhausted: { code }. It is never critical, never quarantined, and never a clean baseline. Real drift still wins (exit 2).infra-transient.::error title=provider-quota-exhausted::annotation, thequota_exhaustedjob 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):
GREEN (this branch, same inputs):
Genuine drift is unchanged. The run's own drift block (no body) is still exit 2. A drift block whose values contain
insufficient_quotais 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,actionlintare clean. The full suite has 19993 passing tests. 5 tests failed inresponse-a9-equivalence/validate-cliunder 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-driftfor 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_quotafixture. Its real vitest failures went throughcollectDriftEntries:3. Quota on every leg. The real
openai-responsesandopenai-embeddingslegs ran against a fake out-of-credit api.openai.com (fetch shim). The realws-liveleg ran against a loopback WS peer.4. Reporting.
5. Workflow. The collector step, the notify step and the PR base/head blocks were extracted from
test-drift.ymland run under bash against sample reports:Mutations. Each was applied alone and each is now killed: removing the second-pass quota guard,
quotaCodeOfdepth 2→1, removing the LiverefusalQuotaCodelatch, and dropping theresponse.errorrecursion. 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,buildandactionlintare clean. The full unit suite passes: 487 files, 20010 tests.