Repository navigation
Conversation
… stream
Claude CLI stream-json emits a rate_limit_event after every response (Agent SDK SDKRateLimitInfo). OpenClaw discarded it, so a subscription 400 ("Third-party apps now draw from your extra usage") was classified billing with no record of the plan state at that moment.
- Parse the record into CliOutput.diagnostics.rateLimit (closed type, zod-validated, retained on the error path).
- Append a compact digest to the "cli turn:" log line.
- Append "Subscription rate limit: <digest>." to billing/rate_limit FailoverError messages.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
A finite reset value above Date range would throw in the digest formatter and fail an otherwise successful turn; reject the record in the schema instead.
…imit digest The pinned Agent SDK adds canUserPurchaseCredits and hasChargeableSavedPaymentMethod to rate_limit_event for credits_required rejections. Keep both so a billing failure tells the operator whether buying credits or a saved card can recover the turn.
|
Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 1:33 PM ET / 17:33 UTC. ClawSweeper reviewWhat this changesThis PR captures Claude CLI Merge readinessThe patch cleanly records a previously discarded Claude stream fact through the parser, log, and billing-error paths. It remains open for maintainer review because the pinned Agent SDK event contract could not be directly inspected in this checkout, and the PR carries the protected Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherClaude CLI stream-json records enter OpenClaw’s shared CLI parser, which returns normalized agent output to the CLI runner. The runner then emits operator diagnostics or turns terminal failures into failover errors. flowchart LR
A[Claude CLI stream-json] --> B[CLI stream parser]
B --> C[Rate-limit diagnostic]
C --> D[Normalized CLI output]
D --> E[Turn log]
D --> F[Billing or rate-limit error]
Decision needed
Why: The dependency contract is material to this parser, but cannot be independently checked from the local dependency cache or network in this review environment. Before merge
Agent review detailsSecurityNone. PR surfaceSource +126, Tests +229. Total +355 across 9 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one Claude stream-json parser boundary that validates, retains, and renders the diagnostic fact after the pinned SDK contract is directly verified. Do we have a high-confidence way to reproduce the issue? No live current-main reproduction of the billing 400 is available; source inspection shows that current main discards the event, and the PR body supplies a real after-fix success-path record. Is this the best way to solve the issue? Yes, subject to direct SDK-contract verification: preserving the fact at the stream parser before logs and error classification is the narrowest owner-boundary repair. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a2ef21e43369. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Closing: not planned. Decision: the reported Why (proof, one operator host, live gateway untouched):
Supported path: keep using the What would reopen this: a reproducible case where the same turn fails repeatedly on retry while a plain |
What Problem This Solves
A Claude CLI turn on a production gateway (Agent SDK 0.3.232, native
claudelogin) failed withAPI Error: 400 Third-party apps now draw from your extra usage, not your plan limits…. OpenClaw classified itbillingand recorded nothing else. The Claude stream-json output of every turn carries arate_limit_event(SDKSDKRateLimitInfo: status, binding window, utilization, reset time, overage status/reason, error code) emitted right before theresult, and OpenClaw discarded it — so there was no record of the subscription state at the moment of the failure, and no way to tell plan exhaustion from an Anthropic-side billing classification without re-running the turn.Why This Change Was Made
Record the fact where it happens (Product Doctrine: recorded fact at the owning boundary, not multi-signal inference later).
src/agents/cli-output-contracts.ts:CliOutput.diagnostics.rateLimit(CliSubscriptionRateLimit): status, binding window id, awindowsmap of utilization/reset per wire window id, overage status/reason,isUsingOverage,errorCode.src/agents/cli-output-records.ts:parseClaudeCliRateLimit, a zod schema over the wholerate_limit_eventrecord, gated on the Claude stream-json dialect. The wireunifiedWindowsmap becomeswindowsverbatim; the SDK-typed shape (top-levelrateLimitType/utilization/resetsAt, nounifiedWindows) folds into a one-entry map. A malformed optional field drops the whole diagnostic record rather than partially recording it (accepted tradeoff, commented).src/agents/cli-output-stream.ts: the streaming parser keeps the last record and attaches it once ingetOutput, so it survives both success andis_errorresults.src/agents/cli-runner/log.ts:formatCliSubscriptionRateLimitDigestrenders one compact line, e.g.rateLimit=allowed five_hour=36%→2026-08-25T17:50Z seven_day=28% overage=rejected(org_level_disabled); the reset time is shown only on the binding window.src/agents/cli-runner/execute-process.ts: thecli turn:info line appends the digest.src/agents/cli-runner/output-error.ts:billing/rate_limitFailoverErrormessages appendSubscription rate limit: <digest>.;rawErrorstays the original CLI text.No config, env, storage, or plugin-SDK surface. Not touched:
extensions/, docs, CHANGELOG.User Impact
cli turn:line (agent/cli-backendsubsystem, info level).Evidence
OPENCLAW_STATE_DIRand dist built from this head, oneopenclaw agent --localturn through the Agent SDK path (anthropic/claude-fable-5):cli turn: … outBytes=2 outHash=2689367b205cwith no rate-limit facts. Note the third wire window (seven_day_overage_included) that the SDK type does not declare — the window map is keyed by wire id for that reason.error=credits_required, message enrichment) is covered by unit test only: 160 live probe turns on the same account (80 with the stock Claude Code prompt, 80 with OpenClaw's appended system prompt) all returnedstatus=allowed, so the 400 could not be reproduced on demand.node scripts/run-vitest.mjs src/agents/cli-output-stream.test.ts src/agents/cli-output-records.test.ts src/agents/cli-runner/output-error.test.ts— green (new: retain on success/error result, malformed record dropped, SDK-typed shape folds to one window, observed-record digest, minimal digest, billing failover enrichment, unrelated failure untouched). The new tests fail on pre-change code for the intended reasons (missingdiagnostics.rateLimit, missing digest export, unenriched billing message).oxfmt,scripts/run-oxlint.mjson changed files,git diff --check— clean.pnpm build— clean (the twoINEFFECTIVE_DYNAMIC_IMPORTwarnings are pre-existing UI-side).gpt-5.6-terra, high) on3ced009raised one P2: a finiteresetsAtaboveDaterange would throw in the digest formatter and fail a successful turn. Fixed inb28d410by bounding the reset at the schema (record dropped), with a regression test.cli-output-stream.ts54/41 is a re-indent of the unchangedgetOutputbody intobuildOutput(pure move), so net new production ≈ +95. Justified by a new recorded fact at its owning boundary. Tests +187.