test(clawrouter): avoid mocked oversized usage fetch#99860
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 4, 2026, 3:05 AM ET / 07:05 UTC. Summary PR surface: Source +16, Tests +19. Total +35 across 2 files. Reproducibility: yes. from source and submitted terminal proof. Current main uses Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the owner-boundary bounded read after maintainer acceptance of the 1 MiB ClawRouter usage cap, or adjust the cap first if real usage payloads can exceed it. Do we have a high-confidence way to reproduce the issue? Yes, from source and submitted terminal proof. Current main uses Is this the best way to solve the issue? Yes, after maintainer acceptance of the cap. The ClawRouter plugin owns this usage boundary, and reading through the existing bounded response helper before JSON parsing is the narrow maintainable fix. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f48ff25b3be3. Label changesLabel justifications:
Evidence reviewedPR surface: Source +16, Tests +19. Total +35 across 2 files. 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
|
|
Thank you for the contribution. This fix landed with contributor co-authorship preserved in #100258 ( I consolidated the source fixes into a maintainer takeover because the contributor branches were based on rewritten pre- |
Summary
readResponseWithLimithelper before JSON parsing.What Problem This Solves
ClawRouter usage is an external provider usage boundary with a configurable
baseUrl. The non-OK path already avoids exposing upstream bodies, but the successful path used bareresponse.json(), allowing a misconfigured or hostile usage endpoint to make OpenClaw buffer an unbounded JSON body before extracting a tiny budget summary.User Impact
/v1/usageresponse. Before this patch, a provider usage refresh could spend memory on the full body even though the UI only needs budget and summary fields.Origin / follow-up
extensions/clawrouter/usage.tsstill used bareresponse.json()on the success path.readResponseWithLimitwrapper, matching the existing extension/provider bounded-response pattern rather than adding a ClawRouter-only reader.Competition / linked PR analysis
clawrouter usage response limit OR bounded read OR response.json; result was[]inopen-pr-conflict-search.json.Real behavior proof
/v1/usagebody is rejected instead of being fully parsed byresponse.json().127.0.0.1with productionfetchClawRouterUsage, realfetch, and configurablebaseUrl; no mock fetch and no external credentials.1048576bytes, and a normal managed monthly budget response still maps to the sameProviderUsageSnapshotfields.fetch.Review findings addressed
Regression Test Plan
extensions/clawrouter/usage.test.ts/v1/usageresponse larger than 1 MiB rejects before JSON parsing, while a normal managed monthly budget response still maps to the expectedProviderUsageSnapshot.fetchClawRouterUsagewith realfetchso the body-size guard is exercised at the HTTP response boundary.node scripts/run-vitest.mjs extensions/clawrouter/usage.test.tspnpm lint:extensionspnpm test:extensions:package-boundarypnpm exec oxfmt --check extensions/clawrouter/usage.ts extensions/clawrouter/usage.test.tsgit diff --checkRisk / Compatibility
/v1/usage, but expected usage payloads contain only budget and summary fields and are far smaller than the cap.baseUrlmakes the response untrusted; failing fast on an oversized usage body is safer than buffering unbounded JSON, and normal response mapping is covered by both the regression test and local HTTP proof.fetchFndependency; this is the function's public seam for exercising success and error response paths without changing production API shape.Merge risk
Low. The diff is limited to ClawRouter usage parsing and one focused regression test. The only behavior change is rejecting unexpectedly large successful usage JSON before parsing.
What was not changed
Architecture / source-of-truth check
fetchClawRouterUsageis the source-of-truth owner for ClawRouter usage snapshots. The fix is applied at that external HTTP response boundary before JSON parsing, not downstream in UI formatting or provider catalog code.Root Cause
response.json()to consume/v1/usage, so a configurable provider usage endpoint could return an unbounded successful JSON body.Maintainer-ready confidence