Repository navigation
fix(auth): resume quota recovery after token expiry - #155665
Conversation
|
🦞👀 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: needs real behavior proof before merge. Reviewed September 22, 2026, 6:37 AM ET / 10:37 UTC. ClawSweeper reviewWhat this changesReconnects subscription quota recovery to OAuth token renewal, preserves normal credential fallback, and reorganizes supporting error handling and tests. Merge readiness⛔ Blocked before merge - 1 item remains The fix remains necessary: current main excludes expired credentials from quota recovery. No blocking correctness or security defect was found in the introduced patch. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw checks stored account quota before attempting an agent turn. This change lets that check renew an expired credential, obtain fresh usage information, and return control to normal authentication selection. flowchart TD
A[Agent turn] --> B[Stored account quota]
B --> C{Access token expired?}
C -->|Yes| D[Existing OAuth refresh owner]
C -->|No| E[Usage probe]
D --> E
E --> F[Locked credential and quota checks]
F --> G[Normal auth selection]
D -->|Settled credential failure| G
Before merge
Agent review detailsSecurityNone. PR surfaceSource +116, Tests +680, Other -1. Total +795 across 15 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep quota recovery composed with the existing refresh owner and normal auth selection, clearing blocks only from current usage observations. Do we have a high-confidence way to reproduce the issue? Yes, from source: an active subscription block with a due probe and expired OAuth token is rejected by current main's freshness predicate before refresh can run. This read-only review did not execute the scenario. Is this the best way to solve the issue? Yes. Reusing the credential owner and returning settled outcomes to normal auth selection repairs the missing composition without duplicating refresh or fallback policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 80b9608a25e1. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
@clawsweeper re-review The main PR body now includes an after-change runtime verdict for 9dfd6f4, the exact source tree and native report digest, and the command that exercised a real built Gateway with isolated SQLite state, WebSocket chat.send and mocked OpenAI OAuth/WHAM/inference endpoints. The expired-bearer scenario passed, including one refresh, restored delivery, blocked early/exhausted retries and rejected revoked credentials. This is mock-provider runtime behavior proof, not a live OpenAI account test or a not-applicable exemption. The CI contention-diagnostic and typed-lint failures were also repaired. Final focused validation passed 428 owner/sibling cases, catalog-worker retirement and typed lint; independent P2 review is clean. The two broader baseline SQLite I/O failures remain explicitly documented rather than counted as passing evidence. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* fix(auth): resume quota recovery after token expiry * fix(auth): preserve settled refresh diagnostics Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Fixes quota recovery getting stuck when an OpenAI subscription's access token expires while its usage limit is active.
User Impact
After capacity returns, the next turn can renew the credential and recheck usage. If renewal leaves no usable credential, normal auth selection can still choose an allowed configured API key or fallback. Account pins and hard storage failures retain their existing behavior.
Why This Change Was Made
The quota check previously required an already-fresh bearer, so it never reached the existing refresh owner for an expired one. It now composes that owner with the existing locked credential and quota-generation checks. Only a fresh usage observation clears the quota block.
The refresh owner records settled failures separately from provider-owned errors, preserving immutable errors, contention diagnostics and redaction. Quota reconciliation joins peer operations and reloads authoritative snapshots before returning control to normal auth selection. Tracked refresh settlement and catalog-worker retirement remain intact.
Error presentation and pure usage policy move to their existing owners. Pure tests no longer allocate mutation/bootstrap fixtures, and tests use real cooldown/unavailable-reason policy instead of copied approximations. Assertions, process isolation, deadlines and shard counts are preserved.
Evidence
After-change real behavior proof: an actual built OpenClaw Gateway, isolated SQLite state and WebSocket
chat.send, with mocked OpenAI OAuth/WHAM/inference HTTP endpoints. This is a runtime integration harness, not a live OpenAI account test. The complete expired-bearer scenario passed on the exact source tree in the verdict below; the summary records assertions exercised by that passing native test.CI=1 OPENCLAW_BUILD_PRIVATE_QA=1 OPENCLAW_E2E_WORKERS=1 \ node scripts/run-vitest.mjs run test/e2e/qa-lab/runtime/quota-reset.e2e.test.ts \ --config test/vitest/vitest.e2e.config.ts --testNamePattern 'wham, expired=true'Executed with verbose/JSON reporters on Linux Node 24.19 / pnpm 12.4, four CPUs and 15.4 GiB RAM. Native worker lease: GitHub Actions run 35718054596; the lease was stopped after collection, independently of the successful test command.
{ "verification": "real ephemeral OpenClaw Gateway with mocked OpenAI HTTP provider", "sourceCommit": "9dfd6f45156b962e54dcb1df45d8d8133064458a", "sourceTree": "24d141fa131b005f700eabff28d1ecd1b899c750", "platform": "linux-x64", "node": "v24.19.0", "pnpm": "12.4.0", "scenario": "Gateway quota reset (wham, expired=true, scoped=false, available=false, stale-success=false) recovers the next chat after upstream capacity returns without admitting exhausted or revoked auth", "result": "PASS", "passed": 1, "failed": 0, "notSelected": 8, "commandSeconds": 47.456, "verifiedAssertions": { "exhaustedAndEarlyRetriesRejected": true, "refreshRequestCount": 1, "usageProbeAndInferenceObservedOnRecovery": true, "recoveredChatDeliveredMarker": true, "quotaBlockAbsentAfterRecovery": true, "revokedRetriesRejected": 2, "authorizationAndAccountBindingsChecked": true, "providerFixtureErrors": 0 }, "nativeReportSha256": "b2bde2707fdc9cad0e1d36ddb491b8cfb3493a676842e8c2d68739993efccdea" }Production delta: +123 lines; tests/test support: +685; assertion baseline shrinks by two grandfathered assertions (one net line). Counts include pure owner/test moves. Growth implements missing refresh composition, generation validation and owner-scoped failure provenance while reusing existing credential, quota and auth-selection owners; no new configuration, persistence schema or alternative auth-selection flow.