Skip to content

fix(auth-profiles): cool Anthropic OAuth profiles down until the real usage reset - #113183

Closed
he-yufeng wants to merge 6 commits into
openclaw:mainfrom
he-yufeng:fix/anthropic-usage-reset-cooldown
Closed

he-yufeng wants to merge 6 commits into
openclaw:mainfrom
he-yufeng:fix/anthropic-usage-reset-cooldown

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted: AI coding agents were used to trace the auth profile cooldown path, implement this branch, and run the validation listed below.

Fixes #113159.

What Problem This Solves

Rate-limited Anthropic OAuth profiles use the generic cooldown ladder, so OpenClaw can retry before the provider's usage window resets and hit the same limit again.

Why This Change Was Made

The intended repair is to preserve the provider-reported reset time and scope through profile selection instead of replacing them with a generic profile-wide delay.

User Impact

This branch is not ready to merge. The current probe does not cover canonical Claude CLI profiles, widens model-scoped limits to the whole profile, and bypasses the provider-owned proxy-aware fetch path.

Evidence

Four focused unit tests cover exhausted and available windows, endpoint failure, and API key profiles. The full auth profile suite passed 1420 tests and focused lint passed. The endpoint shape is covered by mocked responses because no live Anthropic subscription was available for an end-to-end rate-limit and reset run.

Open Blockers

  • Route the canonical claude-cli profile through the provider seam
  • Preserve model-level cooldown scope
  • Use the provider-owned proxy-aware fetch path
  • Capture real OAuth rate-limit and reset-time behavior before requesting review again

… usage reset

Rate-limited Anthropic OAuth profiles got the generic 30s to 5min backoff while Codex profiles cool down until the provider's exact reset time. The OAuth usage endpoint already reports window resets for the /usage display; probe it on rate-limit failures and block until the soonest exhausted window's reset, mirroring the WHAM flow with a claude_usage block source.

Signed-off-by: Yufeng He <[email protected]>
@he-yufeng
he-yufeng requested a review from a team as a code owner July 24, 2026 00:44
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 24, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 26, 2026, 10:43 PM ET / August 27, 2026, 02:43 UTC.

ClawSweeper review

What this changes

The PR adds an Anthropic OAuth usage probe that tries to cool a rate-limited auth profile until the earliest reported usage-window reset.

Merge readiness

⛔ Blocked before merge - 13 items remain

Keep this draft open: current main still limits reset-time probes to OpenAI, but this branch misses the canonical Claude CLI profile, widens model-specific limits, and bypasses the provider-owned request path.

Priority: P2
Reviewed head: 538f2ae85d3439091fba430c50fb20dabbd7a250
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The intended bug fix has useful tests but does not cover its canonical user path or the provider boundary.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: Only mocked endpoint tests are described; add a redacted real Claude OAuth rate-limit-to-reset recovery run before merge, then update the PR body for re-review.
Patch quality 🧂 unranked krab (1/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Only mocked endpoint tests are described; add a redacted real Claude OAuth rate-limit-to-reset recovery run before merge, then update the PR body for re-review.
Historical verification Needs maintainer review A historical verification receipt failed or is malformed. A maintainer must resolve that verification blocker before merge; independently assessed contributor proof remains valid.
Evidence reviewed 6 items Current main remains OpenAI-only: The current failure path probes only an OAuth profile whose normalized provider is openai, so current main does not implement Anthropic reset-time cooldowns.
Canonical Claude CLI profile is excluded: The canonical external Claude CLI profile stores provider "claude-cli", while the PR changes the probe predicate to accept only "anthropic" in addition to OpenAI.
Model scope is discarded: The newly reachable Anthropic result is applied through the WHAM helper, which explicitly clears blockedModel and blockedScope; the Claude usage parser exposes Sonnet and Opus windows separately.
Findings 3 actionable findings [P1] Include the canonical Claude CLI profile
[P1] Retain model scope for Anthropic limits
[P2] Use the Anthropic provider usage path
Security None None.

How this fits together

Auth profiles record provider failures and decide which credential can be retried next. Anthropic’s provider plugin already fetches and normalizes usage windows for status reporting; this change attempts to feed those windows into failover cooldowns.

flowchart LR
  A[Provider request fails] --> B[Auth profile failure record]
  B --> C[Provider usage reader]
  C --> D[Cooldown scope decision]
  D --> E[Profile selection and failover]
Loading

Decision needed

Question Recommendation
Should provider-reported cooldown probing become a provider-plugin contract for native Claude CLI profiles, rather than a core Anthropic-specific fetch path? Add a provider-owned cooldown contract: Let the Anthropic plugin return profile-aware reset and scope data through a generic core seam, then cover CLI, model scope, proxy transport, and live recovery.

Why: The repair needs a durable plugin API and credential/transport ownership boundary; choosing and publishing that contract is maintainer product and compatibility direction.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Only mocked endpoint tests are described; add a redacted real Claude OAuth rate-limit-to-reset recovery run before merge, then update the PR body for re-review.
  • Resolve historical verification - A historical verification receipt failed or is malformed. A maintainer must resolve that verification blocker before merge; independently assessed contributor proof remains valid.
  • Include the canonical Claude CLI profile (P1) - The target profile is stored with provider claude-cli, but this predicate admits only anthropic; the reported native Claude CLI failure therefore still takes the generic cooldown. The added tests only construct an anthropic profile. This persists a prior blocker on unchanged code.
  • Retain model scope for Anthropic limits (P1) - The new Anthropic branch feeds its result into applyWhamCooldownResult, which clears blockedModel and blockedScope. Claude usage includes separate Sonnet/Opus windows, so exhausting one can incorrectly disable the whole profile until reset. This persists a prior blocker on unchanged code.
  • Use the Anthropic provider usage path (P2) - Calling fetchClaudeUsage with global fetch bypasses the registered Anthropic provider hook, whose context supplies the provider-selected fetch implementation. That loses configured proxy/transport behavior and duplicates provider-owned endpoint policy. This persists a prior blocker on unchanged code.
  • Resolve merge risk (P1) - A net +62 production-line bug fix creates a second Anthropic usage path in core instead of reusing the provider owner.
  • Resolve merge risk (P1) - The correct native-Claude-CLI credential lifecycle and proxy-aware transport cannot be established without a provider-owned cooldown contract.
  • Complete next step (P2) - A maintainer must choose the provider-plugin cooldown contract before a safe repair can preserve native Claude CLI credentials, transport, and model scope.
  • Improve patch quality - Route canonical claude-cli profiles through an approved provider-owned cooldown seam and retain model scope.
  • Improve patch quality - Use the provider-injected transport path rather than global fetch.
  • Improve patch quality - Attach redacted real OAuth rate-limit-to-reset recovery evidence; updating the PR body should trigger re-review, or ask a maintainer for @clawsweeper re-review.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P1] Include the canonical Claude CLI profile — src/agents/auth-profiles/usage.ts:160
  • [P1] Retain model scope for Anthropic limits — src/agents/auth-profiles/usage.ts:1067-1070
  • [P2] Use the Anthropic provider usage path — src/agents/auth-profiles/usage.ts:420-421
Agent review details

Security

None.

PR surface

Source +62, Tests +101. Total +163 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 67 5 +62
Tests 1 101 0 +101
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 168 5 +163

Review metrics

Metric Value Why it matters
Production versus test LOC production +67/-5; tests +101/-0 The bug fix adds net 62 production lines while the required provider-owner boundary remains unresolved.

Stored data model

Persistent data-model change detected: serialized state: src/agents/auth-profiles/usage.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #113159
Summary: This PR explicitly targets the canonical open report, but its remaining defects mean it is not yet a viable fix candidate.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Complete the provider-owned cooldown path (recommended)
    Add the approved provider seam, support canonical Claude CLI credentials, preserve model scope, and attach real recovery evidence before merge.
  2. Pause the draft
    Keep the PR unmerged if the provider contract cannot safely support native Claude CLI auth and configured transport semantics.

Technical review

Best possible solution:

Define a provider-owned, profile-aware cooldown result that retains the affected model when applicable, then route Claude CLI auth through that owner and prove reset-to-recovery with a redacted real OAuth run.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: current main only probes OpenAI, and the PR predicate excludes the canonical claude-cli profile. No real OAuth rate-limit-to-reset run was provided or executed.

Is this the best way to solve the issue?

No: the branch is a plausible first step, but the correct repair belongs behind the Anthropic provider boundary and must retain native-profile and model-scope semantics.

Full review comments:

  • [P1] Include the canonical Claude CLI profile — src/agents/auth-profiles/usage.ts:160
    The target profile is stored with provider claude-cli, but this predicate admits only anthropic; the reported native Claude CLI failure therefore still takes the generic cooldown. The added tests only construct an anthropic profile. This persists a prior blocker on unchanged code.
    Confidence: 0.99
  • [P1] Retain model scope for Anthropic limits — src/agents/auth-profiles/usage.ts:1067-1070
    The new Anthropic branch feeds its result into applyWhamCooldownResult, which clears blockedModel and blockedScope. Claude usage includes separate Sonnet/Opus windows, so exhausting one can incorrectly disable the whole profile until reset. This persists a prior blocker on unchanged code.
    Confidence: 0.96
  • [P2] Use the Anthropic provider usage path — src/agents/auth-profiles/usage.ts:420-421
    Calling fetchClaudeUsage with global fetch bypasses the registered Anthropic provider hook, whose context supplies the provider-selected fetch implementation. That loses configured proxy/transport behavior and duplicates provider-owned endpoint policy. This persists a prior blocker on unchanged code.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 943400ea8c30.

Labels

Label justifications:

  • P2: The PR addresses a real provider failover problem but does not currently repair the main Claude CLI user path.
  • merge-risk: 🚨 compatibility: A profile-wide cooldown can suppress otherwise usable models and alters persisted auth-profile selection behavior.
  • merge-risk: 🚨 auth-provider: The patch changes OAuth usage probing while bypassing the provider-owned credential and transport path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only mocked endpoint tests are described; add a redacted real Claude OAuth rate-limit-to-reset recovery run before merge, then update the PR body for re-review. A historical verification receipt failed or is malformed. A maintainer must resolve that verification blocker before merge; independently assessed contributor proof remains valid.

Evidence

What I checked:

Likely related people:

  • Marvinthebored: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (14 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-05T10:34:10.859Z sha c62fc7d :: needs real behavior proof before merge. :: [P1] Probe canonical Claude CLI OAuth profiles | [P1] Keep cooldown results bound to the failed profile | [P1] Preserve model scope for exhausted Claude limits | [P2] Use proxy-aware fetch for cooldown probes | [P2] Put Anthropic cooldown probing behind a provider seam
  • reviewed 2026-08-05T10:41:22.951Z sha c62fc7d :: needs real behavior proof before merge. :: [P1] Probe the canonical Claude CLI OAuth profile | [P1] Keep usage results bound to the failed account | [P1] Preserve model scope for exhausted Claude limits | [P2] Use the configured proxy-aware fetch | [P2] Move Anthropic cooldown policy behind a provider seam
  • reviewed 2026-08-15T16:32:42.061Z sha 3d99396 :: needs real behavior proof before merge. :: [P1] Probe the canonical Claude CLI OAuth profile | [P1] Keep cooldown results bound to the failed profile | [P1] Preserve model scope for exhausted Claude limits | [P2] Use the configured proxy-aware fetch | [P2] Move Anthropic cooldown policy behind a provider seam
  • reviewed 2026-08-16T19:39:54.167Z sha 3d99396 :: needs real behavior proof before merge. :: [P1] Probe canonical Claude CLI OAuth profiles | [P2] Use the configured proxy-aware fetch | [P2] Move Anthropic cooldown policy behind the provider seam
  • reviewed 2026-08-18T23:32:41.595Z sha 3d99396 :: needs real behavior proof before merge. :: [P1] Probe canonical Claude CLI OAuth profiles | [P1] Keep model-scoped Claude limits model-scoped | [P2] Use the proxy-aware fetch for the usage probe | [P2] Route Anthropic cooldown policy through the provider seam
  • reviewed 2026-08-21T13:10:50.468Z sha 3d99396 :: needs real behavior proof before merge. :: [P1] Probe canonical Claude CLI OAuth profiles | [P1] Preserve model scope for exhausted Claude windows | [P2] Use the provider-injected fetch path
  • reviewed 2026-08-21T13:23:34.674Z sha 3d99396 :: needs real behavior proof before merge. :: [P1] Probe canonical Claude CLI OAuth profiles | [P1] Keep model-specific Claude limits scoped | [P2] Route cooldown probes through the provider seam
  • reviewed 2026-08-21T14:48:08.187Z sha 3d99396 :: needs real behavior proof before merge. :: [P1] Probe the Claude CLI OAuth profile | [P1] Preserve model-scoped Anthropic blocks | [P2] Use the provider-owned usage fetch

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 28, 2026
@he-yufeng

Copy link
Copy Markdown
Contributor Author

The current check-lint red is a canceled self-hosted runner mid-run (The runner has received a shutdown signal), not a lint finding. The oxfmt complaints from the earlier run are fixed in the latest push, so a fresh run of the workflow should come back green.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 31, 2026
@he-yufeng

Copy link
Copy Markdown
Contributor Author

The current red is the runner again, not the change: check-lint on the latest head was cancelled mid-run (the job never produced a log, same as the July cancellation), and ci-gate only fails because of that. Could someone re-trigger the workflow? Everything that actually ran is green.

@he-yufeng
he-yufeng marked this pull request as draft August 21, 2026 13:03
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Closing this myself. It has been a draft with declared blockers for a while (canonical claude-cli routing, model-scoped cooldown scope, the provider-owned proxy-aware fetch path, and live OAuth evidence), and the area has since been restructured by #136784 (retry-after-cooldown with capped exponential backoff), so the branch now conflicts and would need a rewrite on top of the new shape anyway.

The core gap the PR was after (preserve the provider-reported reset time and scope instead of the generic ladder) is still not covered upstream as far as I can tell: #136784 keeps the persisted local backoff when the probe has no authoritative deadline, which is the adjacent but different case. If I get real OAuth rate-limit/reset evidence, I will re-propose against the new structure rather than reviving this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Usage-limit cooldown ignores the real reset time for all providers except OpenAI/Codex

1 participant