Repository navigation
fix(auth-profiles): keep per-model quota buckets usable under an account block - #125573
jesse-merhi wants to merge 1 commit into
Conversation
…unt block An OpenAI account can exhaust its account-wide window while individual models keep their own unexhausted allowance; the usage probe reports those in `additional_rate_limits`. That field was never parsed, so a quota block covered every model on the profile and the fallback chain skipped the one model that still had capacity — the chain went dark exactly when it was supposed to take over. Record the models the probe observed as still allowed and let a profile-wide block exclude them. Model ids come from the reported bucket names by lowercasing, so no per-model table is needed and an unrecognized name simply never matches (it cannot unblock anything by accident). A probe rejected with 401 also stopped claiming the caller's `rate_limit`: the probe, not the model request, is what failed there, and labelling a 12h profile-wide hold as a model-scopable quota block left state that no consumer could read correctly.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed October 5, 2026, 4:10 AM ET / 08:10 UTC (Revision 8). ClawSweeper reviewWhat this changesThe branch preserves access to OpenAI models with separate available quota buckets during an account-wide block and labels usage-probe authentication failures correctly. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 8 items remain The quota-exemption behavior remains missing on current main, so this maintainer-owned PR still has value. All three prior blockers remain, and successful exempt-model runs expose another lifecycle defect. Priority: P1 Review scores
Verification
How this fits togetherAuth-profile health state determines which saved provider credentials and models OpenClaw may try. Provider usage probes update that state, which then feeds credential rotation, model fallback, and unavailable-provider diagnostics. flowchart TD
A[Model request failure] --> B[Provider usage probe]
B --> C[Quota and credential classification]
C --> D[Persisted profile health]
D --> E[Model eligibility]
E --> F[Credential rotation and fallback]
D --> G[Operator diagnostics]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +75, Tests +59. Total +134 across 5 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Carry verified quota observations through main's shared reducers and persisted normalization, replacing exemptions on every probe while preserving unrelated active blocks after exempt-model success; the new per-model state justifies bounded growth. Do we have a high-confidence way to reproduce the issue? Yes, source inspection establishes deterministic reprobe, missing-bucket, auth-reporting, and successful-run failure paths. They were not executed during this read-only review. Is this the best way to solve the issue? No, the initial exemption path is incomplete across refresh and successful-run settlement; main's canonical reducers and auth classification provide the maintainable integration boundary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c1b9f4ec91e5. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
|
Thanks for the PR. We're closing older pull requests that have gone stale against current This draft has had no commits since August 18 and review left 8 blocking items; closing as stale. Please reopen or open a fresh PR if per-model quota buckets are still needed. |
What Problem This Solves
An OpenAI account can exhaust its account-wide window while individual models keep their own separate, unexhausted allowance. The usage probe already receives those per-model buckets in
additional_rate_limits, but nothing parsed the field, so a quota block covered every model on the profile.The result is that the model fallback chain goes dark exactly when it is supposed to take over. Observed on a live gateway: all four OpenAI profiles reported
primary_window.used_percent: 100, while every one of them also reported{"limit_name": "GPT-5.3-Codex-Spark", "metered_feature": "codex_bengalfox", "rate_limit": {"allowed": true, "limit_reached": false, "primary_window": {"used_percent": 0}}}The configured chain was
openai/gpt-5.6-sol->openai/gpt-5.3-codex-spark. Sol hit the account limit, spark was correctly selected next, and then skipped:Every agent run on that gateway failed for ~13 hours with capacity sitting unused.
A second, smaller fault sat next to it. A usage probe rejected with HTTP 401 produced a flat 12h profile-wide cooldown that inherited the caller's
rate_limitreason. That leftcooldownReason: "rate_limit"with nocooldownModel— a reason that claims model scope on a record that blocks everything.isProfileUnusablecan only narrow a model-scoped cooldown when a model is named, so it widened, and no consumer could tell a quota block from a dead token.Why This Change Was Made
A block should describe exactly what the provider limited. Anything broader discards capacity the provider still grants, and a fallback chain whose whole purpose is surviving a quota limit must not be disabled by that limit.
The state model already supported narrowing (
blockedModel,blockedScope,cooldownModel,isModelScopedCooldownReason); it had no way to express "the account window is spent, but these models are still served".blockExemptModelsrecords exactly what the probe observed, and only that probe's observation may grant it — a stale list can never unblock a model the provider did not clear.Model ids come from the reported bucket names by lowercasing, so there is no per-model table to maintain. An unrecognized name simply matches no model and changes nothing.
User Impact
When an account-wide quota is exhausted, models with their own unexhausted bucket stay usable and the fallback chain keeps working. Behavior is unchanged for providers that report no per-model buckets: absent
additional_rate_limitsmeans no exemptions and the block stays profile-wide, exactly as before.A 401 from the probe is now recorded as
auth. The 12h hold is unchanged and still profile-wide, which is correct for a credential the provider rejects — it is only labelled honestly now, soopenclaw doctor, logs, and the cooldown predicates agree on what happened.Persisted state gains one optional field. Older rows lack it and normalize to
undefined, which is today's behavior; no migration is needed.Evidence
Three regression tests, each failing on pre-fix code for its intended reason:
Local validation, all green after the fix:
node scripts/run-vitest.mjs src/agents/auth-profiles— 27 files, 381 testsnode scripts/run-vitest.mjs src/agents/auth-profiles.getsoonestcooldownexpiry.test.ts src/agents/model-fallback.test.ts src/agents/model-fallback.probe.test.ts src/commands/models/list.status.test.ts src/commands/models/list.auth-overview.test.ts src/commands/doctor-auth.profile-health.test.ts src/commands/doctor/repair-sequencing.test.ts src/commands/doctor/shared/codex-route-warnings.test.ts— every suite consuming these predicatespnpm tsgo:core,scripts/run-oxlint.mjson changed files,oxfmt --checkDependency contract proof: the
additional_rate_limitsshape above was read live fromchatgpt.com/backend-api/codex/usageacross four accounts, each returning an allowed spark bucket beside a 100%-used primary window.Production delta is +75 lines against +59 test lines. The growth is the capability itself — a provider contract field that was not read, plus the state to carry the observation to the consumer that needs it. No behavior was duplicated and no path was left behind.
Proof gap: this fixes the block that made spark unreachable, but the account this was diagnosed on has no OpenAI capacity left in any window until 20 Aug, so a live end-to-end run of the fallback actually landing on spark is not possible right now. The probe parse is proven against the real payload, and the predicate change is proven by unit tests.