Repository navigation
fix(auth): retry preferred profile after cooldown - #136784
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 3, 2026, 2:54 AM ET / 06:54 UTC. ClawSweeper reviewWhat this changesThe PR lets an automatically selected fallback auth profile yield to a recovered higher-priority explicitly ordered profile and retains rate-limit failure history until a successful request. Merge readiness⛔ Blocked before merge - 5 items remain Keep open for maintainer review: current main still lacks the recovery behavior, but the PR also adopts a 24-hour rate-limit backoff policy that changes fallback spending and retry behavior. Priority: P2 Review scores
Verification
How this fits togetherAuth-profile selection chooses credentials for agent, cron, and gateway inference runs from configured order and persisted health state. Its result constrains the provider route used for the next model request. flowchart LR
A[Configured auth profile order] --> C[Session auth selection]
B[Persisted profile health] --> C
C --> D[Provider route selection]
D --> E[Agent or gateway model request]
E --> F[Success or failure health update]
Decision needed
Why: This is an intentional operator cost-versus-recovery tradeoff beyond the narrow session-promotion repair; source review cannot choose its default policy safely. Before merge
Agent review detailsSecurityNone. PR surfaceSource +62, Tests +192. Total +254 across 10 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land only after the auth owners explicitly accept the bounded 24-hour half-open retry policy and validate the exact head across the shared reply, cron, and gateway selection paths. Do we have a high-confidence way to reproduce the issue? Yes, from source: the focused test constructs the cooldown, automatic fallback, expiry, and same-session retry path, though this read-only review did not execute it. Is this the best way to solve the issue? Unclear: the automatic recovery is a targeted repair, but retaining rate-limit history into a 24-hour backoff is a separate default-policy choice requiring owner confirmation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6d763ee148d4. LabelsLabel justifications:
EvidenceAcceptance criteria:
What 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
History |
|
@clawsweeper re-review — the latest head adds the agreed 24-hour capped exponential retry path for OpenAI OAuth when WHAM supplies no reset timestamp, plus the corresponding regressions and corrected PR evidence. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* fix(auth): retry preferred profile after cooldown * fix(auth): cap unknown rate-limit backoff at 24 hours * fix(auth): preserve backoff after incomplete quota probes * test(auth): align cooldown expiry contract * test(auth): deduplicate cooldown expiry coverage * fix(auth): preserve user-selected session profiles * fix(auth): scope recovery to explicit provider order * fix(auth): isolate rate-limit retry history * test(auth): assert isolated retry counters * fix(auth): recover only cooldown fallbacks * fix(auth): retain rate-limit history until success
Related: #25510
Related: #38335
Related: #117006
What Problem This Solves
When an operator explicitly orders OAuth before a metered API key, a session can correctly fail over to the API key while OAuth is unavailable and then remain on that paid fallback after OAuth becomes eligible to retry.
The recovery policy in this PR is:
auth.order.No background provider traffic or scheduler is added. The next real request is the half-open probe.
Scenario That Led To This Work
This investigation started from a personal gateway running OpenClaw
2026.7.1-2:auth.order; an API key was the emergency fallback.429 usage_limit_reached, so the session correctly failed over and persisted the API-key profile as an automatic override.compactionCountunder the wrong result metadata subtree. Session accounting therefore did not observe the compaction and could not use it as a rotation signal. fix(codex): persist automatic compaction history #110587 later fixed that historical counter defect.Current
mainhas a related but distinct gap. #123894 deliberately keeps ordinary compaction/cooldown rotation on the current physical auth route, so a correctly counted compaction still does not promote a session from an API-key route back to an earlier OAuth route. This PR adds a narrow, directional recovery rule for that case without undoing general route stickiness.Identifying account, organization, payment, profile, and credential details are intentionally omitted.
Why This Approach
The auth-profile subsystem already owns profile health, provider reset timestamps, persisted failure counters, and cooldown expiry. Session selection is therefore the right place to ask whether an automatically selected fallback should yield; the usage-state owner remains responsible for deciding when the preferred profile is eligible to probe.
Boundaries preserved:
Production LOC and ownership
Against
origin/main, production code is+94/-32(net+62) and tests are+239/-47(net+192). The production growth implements two missing state transitions in their existing owners: explicit-order session recovery (session-override.ts) and persisted half-open rate-limit retry (usage.ts/usage-state.ts).An absorbing refactor was attempted by reusing the existing auth-order resolver, usage-state fields, provider-reset path, and capped exponential helper. Removing same-route rotation or replacing the existing health owner would be shorter only by discarding #123894's billing-safety invariant or creating a parallel state machine. The change adds no scheduler, schema, config, or duplicate retry owner.
User Impact
Operators can keep OAuth first and a metered API key second without making the paid fallback the de facto session default. Recovery occurs on the first real request after the preferred profile's provider deadline or local backoff deadline. If that probe fails again without a provider deadline, retries back off
30s -> 1m -> 2m -> ... -> 24h; successful use resets the sequence.Evidence
Both regressions were written red before implementation:
Both now pass on the production selection and usage-state seams.
Focused auth-profile validation:
The focused cases prove:
Repository changed-file validation:
Dependency Contract Checked
OpenAI Codex's current
account/rateLimits/readimplementation reads authenticated backend quota snapshots and exposes backend-ownedordinaryUsageAllowed: request processor, protocol response, and rate-limit snapshot. The protocol explicitly distinguishes a reset estimate from proof of recovery, which is why this change treats the next real request as the probe.Research Trail
Exact auth-fallback reports:
auth.order.Prior implementations and constraints:
03cadc4b7aa428195807edef72f5849031152628— cooldown auto-expiry reused here.Related but separate boundaries considered:
Direct Codex Verification
The acting agent directly verified pinned Codex commit
0588fc941c3bd5abd0cb8cd38c51cd6e72e9eb16in the local sibling checkout withgit cat-fileandgit show. The cited response type contains backend-ownedordinary_usage_allowedand explicitly says clients must not infer recovery from percentages or reset times; the request processor exposes it only after matching the active account. This supports using a real provider request as the recovery proof rather than treating expiry alone as success.