Repository navigation
fix(anthropic): avoid usage polling with setup tokens - #155805
saariuslystoned wants to merge 15 commits into
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 maintainer review before merge. Reviewed September 23, 2026, 1:20 AM ET / 05:20 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR skips unsupported quota requests for stored Anthropic setup tokens, preserves configured Claude web-session fallback, and adds credential-type metadata, tests, and documentation. Merge readiness✅ Ready for maintainer review The fix remains necessary, with no blocking correctness finding. The maintainer-edited compatibility decision resolves the previous blocker, and the supplied production-path evidence supports the changed behavior. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s provider usage subsystem turns configured credentials into quota information for status and billing displays. The Anthropic plugin selects organization billing, OAuth usage, or configured Claude web-session usage. flowchart TD
A[Configured credentials] --> B[Anthropic usage selection]
B --> C[Admin billing]
B --> D[OAuth quota]
B --> E[Stored setup token]
E --> F[Web session or skip]
C --> G[Usage displays]
D --> G
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +62, Tests +247, Docs 0. Total +309 across 7 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep credential selection authoritative and apply the accepted setup-token policy within the existing Anthropic usage owner, preserving OAuth and configured web fallback. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the path: a stored Anthropic token profile reaches OAuth usage polling on current main. The original report shows a quota error; no live current-main provider reproduction was run here. Is this the best way to solve the issue? Yes. Stored credential metadata avoids unreliable prefix classification, preserves selection order, and reuses the existing web fetcher; the compatibility tradeoff now has recorded maintainer acceptance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b373c9a9bcd4. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review Proof is now in the PR body for head Compatibility decision: preserve stored Anthropic |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(anthropic): avoid usage polling with setup tokens This is item 2/3 in the current shard. Shard 87/89. This temporary status tracks the active review worker. The completed review will appear in the durable ClawSweeper review comment. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
|
Closing in favor of the ownership refactor tracked in #156296 (move Claude usage fetching into the Anthropic plugin). This patch conflicts with current main after the recent infra/provider refactors and the maintainer decision is to fix #143419 through that refactor rather than a core-side skip. Happy to help with the #156296 work if contributor PRs are welcome there. |
Follow-up to #146726
Closes #143419 and carries the compatibility repair from #146726 onto a branch writable by this account.
What Problem This Solves
Fixes: Anthropic setup-token profiles poll
/api/oauth/usage, which those tokens cannot authorize, and then surface a misleading quota error.User Impact
User impact: a stored Anthropic setup-token profile no longer makes the unsupported OAuth usage request. If a claude.ai web session is configured, quota loads from that fallback; if that fallback fails, status shows
Claude web usage unavailable. Existing OAuth and API-key profiles keep their previous usage paths.Why This Change Was Made
Classification uses the stored auth-profile type. Anthropic setup-token onboarding persists
type: "token"; OAuth login persiststype: "oauth"even when the access token uses thesk-ant-oat01-shape; API keys persisttype: "api_key". Token prefix alone must not suppress usage.Compatibility decision
Maintainer decision — 2026-09-23: Ayaan accepted this compatibility tradeoff: “go for it, claude's setup-token is inference only”. Stored Anthropic
type: "token"profiles skip OAuth usage polling, including manually pasted bearer credentials that might otherwise have usage scope.Evidence that this is the stored-profile contract, not an over-broad skip:
type: "token"are setup-token auth andmodels auth paste-token, both validated byvalidateAnthropicSetupToken.type: "oauth". API-key auth writestype: "api_key".typeScore0) over token (1) over API key (2).sk-ant-oat01-credential with no stored token profile still uses the OAuth usage path.No code change in this follow-up. If later evidence shows a supported Anthropic writer storing a working OAuth usage token as
type: "token", narrow then.Evidence
Exact head:
c119d0e89f4673d1750cdccd5000b5bd6b5bfba8Isolated disposable store only. Temporary
HOME/OPENCLAW_STATE_DIR/OPENCLAW_CONFIG_PATH, loopback HTTP fixtures, synthetic sentinels. No live user Gateway, no inference/chat, no real provider request.After-fix request counters and usage snapshots from the PR-head Anthropic usage owner plus official auth-profile upsert:
/api/oauth/usagetype: "token"){ handled: true }, provider omittedtype: "token"profileclaude.aiorgs=1, usage=15hwindow at 17%claude.aiorgs=1error: "Claude web usage unavailable"{ handled: true }(unchanged; not setup-token)5hwindow at 23%5hat 23%type: "token", then skippedCommands:
All passed.
The earlier contributor proof above used the registered plugin owner. The additional CLI verification below exercises the shipped status entry point.
The original PR head branch is owned by another fork and cannot be updated by this account; this follow-up preserves the repair without force-pushing or changing the original PR.
Maintainer CLI verification (2026-09-23)
Ran the supported
pnpm openclaw status --usage --json --timeout 2000entry point at the exact head with isolated synthetic auth stores, official auth-profile upsert, and a fetch-boundary response fixture (no real provider calls). All three commands exited 0:providers: [], no misleading quota error5husage at 23%HTTP 403: scope requirement user:profileThe authorization-error control verifies that the status path exposes a genuine denial rather than suppressing all usage errors; it is not a pre-fix binary run. The 39 focused tests across the three files listed above also passed again.