Repository navigation
fix(anthropic): avoid stale client version rejections on OAuth - #154098
Conversation
Keep the OAuth Claude Code identity at the maintained 2.1.278 floor and prefer a newer installed CLI through the Anthropic plugin's shared bounded version probe. Use one request snapshot for User-Agent and billing metadata in both transports, preserving case-insensitive header replacement. Cover the wire boundary and probe lifecycle, and repair the cold metadata fixture and OS-watch race encountered in the provider tests. Fixes #94716. Related: #154016. Supersedes the approach in #150790 with credit. Co-authored-by: Krasimir Kralev <[email protected]>
|
🦞👀 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 20, 2026, 9:05 PM ET / September 21, 2026, 01:05 UTC (Revision 3). ClawSweeper reviewWhat this changesUpdates Anthropic OAuth client identification using a maintained version floor or newer installed Claude CLI, with matching request headers and billing metadata. Merge readiness✅ Ready for maintainer review Still necessary: current main and the latest release retain the stale identity. No actionable correctness or security findings remain, and the maintainer explicitly disposed of the earlier live-proof request. Priority: P1 Review scores
Verification
How this fits togetherThe Anthropic plugin prepares model requests and discovers local Claude CLI capabilities. The shared AI package converts those requests into SDK or native HTTP calls to Anthropic. flowchart LR
A[Model request and credentials] --> B{Anthropic OAuth?}
B -->|Yes| C[Shared bounded CLI probe]
C --> D[Version floor and identity snapshot]
D --> E[SDK or native transport]
B -->|No| E
E --> F[Anthropic Messages API]
F --> G[Completion or provider error]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +121, Tests +326, Docs +7. Total +454 across 19 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 one transport-owned identity floor and plugin-owned discovery shared across request paths, preserving existing credentials and non-OAuth routing. Do we have a high-confidence way to reproduce the issue? Yes at the source boundary: main and v2026.9.5 emit the stale identity identified by the reported controlled comparison. This review did not execute a live OAuth request. Is this the best way to solve the issue? Yes. Reusing plugin-owned discovery and one shared transport identity avoids a competing startup manager or configuration surface while keeping the fallback usable without an installed CLI. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 03b6338390f1. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
…law#154098) Direct Anthropic OAuth requests could fail with claude_code_version_too_old because they advertised Claude Code 2.1.75. Maintain a 2.1.278 client-version floor and prefer a newer installed stable CLI through the Anthropic plugin's shared, bounded probe. Both transports use one selected version for request headers and billing metadata; failed or slow probes fall back to the floor. Preserve API-key and other provider routes without configuration, credential, dependency, or state migrations. Cover request identity and probe lifecycle, and repair the cold metadata fixture and OS-watch race encountered during validation. Focused tests and exact-head CI passed; candidate live OAuth acceptance remains unverified. Thanks to @Cyb3rb1ade, @raghidtawil-lab, and @davidcittadini for the reports and controlled comparisons. The single-snapshot and header/billing boundary-test approach builds on @KrasimirKralev's prior work. Fixes openclaw#94716. Related: openclaw#154016. Supersedes the approach in openclaw#150790 with credit; that PR remains open for maintainer follow-up. The separate model-allowlist issue openclaw#144903 is outside this repair. Co-authored-by: Krasimir Kralev <[email protected]>
Closes #94716. Related: #154016. Supersedes #150790 with credit to @KrasimirKralev; that PR remains open for maintainer follow-up.
What Problem This Solves
Direct Anthropic subscription/OAuth requests advertise Claude Code 2.1.75, which Anthropic rejects for newer models with HTTP 400
claude_code_version_too_old. The reporters' controlled comparison requires at least 2.1.251.User Impact
OAuth requests use a maintained client-version floor of 2.1.278 (the published
@anthropic-ai/claude-codeversion checked on 2026-09-20), or a newer installed stable Claude CLI version. Missing, older, malformed, failed, over-output, or slow probes fall back to the floor. Requests wait at most 1.5 seconds for the shared probe; a late result cannot change the cached identity. No configuration, credential, dependency, or state migration is required.API-key, Copilot, Foundry, and Cloudflare routes retain their existing behavior. This changes the direct Messages API client identity, not Claude CLI billing or model entitlement.
Why This Change Was Made
The Anthropic plugin reuses its existing lazy CLI capability probe and executable discovery, using direct PATH lookup to avoid a synchronous login-shell probe. Normal and simple-completion provider hooks pass installed-version evidence through existing request headers.
@openclaw/aispawns nothing: one shared owner enforces the floor and gives both transports a single header/billing snapshot. The command runner retains bounded output and process cleanup; request waiting has its own deadline.The single-snapshot and header/billing boundary-test approach builds on @KrasimirKralev's prior work. Thanks to @Cyb3rb1ade, @raghidtawil-lab, and @davidcittadini for the reports and controlled comparisons. #144903 is a distinct local model-allowlist rejection before provider I/O and is not repaired here.
Evidence
Injected-fetch boundary tests exercise both the SDK and native transport with
claude-fable-5-1. Before the fix, the regression failed on the stale default and mismatched newer-header/old-billing identities. After:Live OAuth acceptance is not verified: no subscription token was available, and no operator OpenClaw state was read. @Cyb3rb1ade and the canonical issue's reporters: please verify this branch build using your existing OAuth profile and the previously rejected model, and report the OpenClaw commit/version and whether
claude_code_version_too_olddisappears. Do not post tokens.--maxWorkers=1through the repository test runner.node scripts/check-changed.mjsand its remaining planned commands were completed by continuation after fixing two type errors: the new table needed an explicit header-record type, and an existing state-migration fixture imported a serializer from its retired location (the identical fix independently landed on main in fix(ui): avoid repeated waits in the people picker #153988). Core/extension production and test typechecks, formatting, line caps, dead exports, import cycles, and all other selected guards pass.node_modules/.bin/oxlint --tsconfig test/tsconfig/tsconfig.extensions.test.json <changed extension files>passes. Canary output before reverting its temporary line:cli-version.ts:47:7: error eslint(no-unused-vars): Variable 'l1084UnusedCanary' is declared but never used.Real-file result afterward: exit 0, no diagnostics. CI's extension lint remains authoritative.pnpm buildpasses on the final implementation (14m 21.7s); noINEFFECTIVE_DYNAMIC_IMPORTwarning.Bounded test repairs encountered during verification: the existing compaction-wrapper test cold-loaded plugin metadata and took 32,852 ms; the existing manifest-backed fixture reduced it to 5 ms without replacing endpoint classification. The catalog metadata-cache test depended on OS watch delivery inside real-time polling and failed after 2,923 ms; the existing event driver and direct reads preserve its assertions. Its final regression passes 20 executions (
--repeats=19), reported at 209 ms, with 83.59 s total cold runner wall. The three-file catalog/stream/CLI shard passed three times (92.93 / 149.07 / 106.21 s wall; two runs retained the original file order). The initial worker-termination warning did not recur. One subsequent preparation attempt raced a build replacing generated plugin output and ran no tests; serializing the final test after the build resolved that known preparation failure. The identical state-fixture import correction is already on main and is omitted from this PR; it passes all nine tests (87.07 s wall, largely transform/setup).Production: +195/−74 (net +121); tests: +343/−17 (net +326); docs: +8/−1 (net +7). No changelog edit: release-note context is recorded here. CI timings are pending at PR creation.
The branch was rebased onto the main-owned state-test repair after validation; all 19 Anthropic/doc file blobs remain identical to the reviewed and tested candidate.
Maintainer review disposition
The ClawSweeper review completed at 2026-09-21 00:32 UTC on
2312ae07d8452fede6df1272aa160e2516dbf36breports no actionable code or security findings. Its single Rank-up move requests a redacted live OAuth completion trace from this candidate. Skipped for this landing: no subscription token is available to this lane, and operator state access is outside its authorized scope. Candidate live acceptance remains unverified; the recorded injected-fetch boundary proof and green exact-head CI are the available evidence. This disposition does not claim live provider acceptance.