fix(provider-usage): bound Anthropic usage error response reads to prevent OOM#97614
Conversation
…event OOM Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB.
|
Codex review: needs maintainer review before merge. Reviewed June 28, 2026, 9:55 PM ET / 01:55 UTC. Summary PR surface: Source +1. Total +1 across 1 file. Reproducibility: yes. Source inspection shows current main calls Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Merge this narrow Claude OAuth error-path hardening after normal maintainer checks, while keeping shared success-reader and MiniMax follow-ups in their own focused PRs. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows current main calls Is this the best way to solve the issue? Yes. Reusing AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4a4657a1828f. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +1. Total +1 across 1 file. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB.
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB.
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB.
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB.
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB. (cherry picked from commit 615558f)
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB. (cherry picked from commit 615558f)
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB. (cherry picked from commit 615558f)
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB. (cherry picked from commit 615558f)
…event OOM (openclaw#97614) Replace unbounded res.json() with readProviderJsonResponse in the fetchClaudeUsage error path to cap error body reads at 16 MiB. (cherry picked from commit 615558f)
Summary
Replace unbounded
res.json()withreadProviderJsonResponsein thefetchClaudeUsageerror handler. This caps Anthropic usage API error response bodies at 16 MiB, preventing unbounded buffering when the API returns a large error body (CDN error pages, WAF blocks, misconfigured proxies, etc.).Real behavior proof (required for external PRs)
Behavior addressed: Unbounded
res.json()replaced withreadProviderJsonResponse(16 MiB cap) in the error handler path.Real environment tested: Linux, Node 22, OpenClaw main @ 87db23e
Exact steps or command run after fix:
Evidence after fix:
The harness creates a streaming 64 MiB error body with 1 MiB chunks. The bounded reader pulls only 17 chunks (stopping at the 16 MiB cap), cancels the stream, and throws. The existing catch block catches this and returns the error snapshot. Before the fix,
res.json()would have buffered the entire 64 MiB before parsing.Observed result after fix:
readProviderJsonResponsecaps Anthropic usage error bodies at 16 MiB. Streaming error bodies are cancelled at the cap. The existing catch block ("ignore parse errors") now also handles overflow errors, preserving the existing fallback behavior (scope-check → web fallback → HTTP error snapshot).All existing tests pass: 14 tests in
provider-usage.fetch.claude.test.ts.What was not tested: A live Anthropic usage API call returning a large error body was not tested.
Risk
Low. The 16 MiB cap matches the convention in
provider-http-errors.ts. The existing catch block gracefully handles both parse errors (existing) and overflow errors (new), preserving the same fallback behavior.