Repository navigation
refactor: normalize Claude usage responses at one boundary - #144707
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. |
|
/clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed September 11, 2026, 8:43 AM ET / 12:43 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR normalizes Claude quota windows, model labels, and billing through one typed schema while preserving existing usage summaries. Merge readiness✅ Ready for maintainer review Keep open as a useful, behavior-preserving cleanup with no actionable findings. Current main retains the older parsing structure, and the previous draft-status follow-up is resolved. Priority: P3 Review scores
Verification
How this fits togetherClaude usage collection converts OAuth or web API responses into provider-neutral quota and billing snapshots. These snapshots feed OpenClaw’s status commands and usage displays. flowchart LR
A[OAuth usage response] --> C[Normalize consumed fields]
B[Web usage response] --> C
C --> D[Order and deduplicate quota windows]
C --> E[Project extra usage billing]
D --> F[Provider usage snapshot]
E --> F
F --> G[Status and usage displays]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +13, Tests +22. Total +35 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep one normalization boundary for both Claude usage paths while preserving tolerant field handling and the existing public snapshot contract. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a behavior-preserving refactor, and source comparison found no concrete introduced failure. Is this the best way to solve the issue? Yes: the schema reuses existing coercion helpers, replaces the raw-record projection path, and serves both callers without adding a parallel implementation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4407ed19ac63. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
/clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
/clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* commit 'f2ce199238e974b1d4caff8f11112aa51eb00d9e': (310 commits) refactor(copilot): deduplicate transcript user text (#144888) refactor(sessions): await discovery and config readiness (#144854) refactor(e2e): deduplicate release file assertions (#144904) ci: keep growing hosted test plans within the job cap (#144965) fix(macos): avoid stale dashboard command assertions (#144710) refactor(memory): await standing intent operations (#144832) refactor(ui): derive native device settings types from schemas (#144705) refactor(memory): await journal operations and allocate sequences atomically (#144824) refactor(tests): share command field assertions (#144955) refactor(matrix): share bounded context cache insertion (#144939) refactor(i18n): share Apple catalog reader (#144848) fix(doctor): preserve legacy registry files when quarantine fails (#144787) refactor(tests): reuse PixVerse auth fixtures (#144926) fix(bonjour): silence transient ENODEV socket warnings (#144870) fix(matrix): preserve unrelated files when migration fails (#144883) feat(sqlite): run Team Reports storage in owned workers (#144871) fix(update): install explicit same-version artifacts (#144894) refactor(ui): share cached message extraction (#144244) refactor: normalize Claude usage responses at one boundary (#144707) refactor: simplify CLI child listener registration (#144929) ...
…144707) * refactor: normalize Claude usage responses at one boundary * refactor: remove Claude usage normalization wrapper
What Problem This Solves
Claude usage parsing currently normalizes billing but leaves windows and model scopes as raw records for projections to interpret. This maintainer-requested cleanup gives those consumed fields one typed boundary, reducing the places that must stay aligned when the provider response changes.
Why This Change Was Made
Use the existing Zod dependency with the existing finite-number, string and reset-time helpers. Infer the normalized type from the schema and remove downstream raw-record parsing. Normalize malformed fields independently so valid siblings survive.
User Impact
No intended behavior change. OAuth and web usage retain window ordering, Sonnet precedence, model-label deduplication, reset handling and their distinct billing projections. No dependency, configuration or authentication changes.
Evidence
Source-flow comparison:
Representative response through
fetchClaudeUsage:{"seven_day_sonnet":{"utilization":40},"limits":[{"percent":80,"scope":{"model":{"display_name":" sonnet "}}},{"percent":27,"scope":{"model":{"display_name":" ","id":" Fable "}}},{"percent":90,"scope":{"model":{"display_name":"FABLE"}}},{"percent":12,"is_active":"false","scope":{"model":{"id":"Other"}}}]}The preserved snapshot contains Sonnet 40%, Fable 27%, and Other 12%, in that order. Labels trim and deduplicate case-insensitively. Only literal
is_active: falsedisables a limit. This boundary fixture passed with the existing OAuth/web and billing cases.Head
4a151324d172a24be66d33f0578bcb6d2c5bd85fpassed all 27 Claude fetch tests on Blacksmith Testbox. Both callers invoke the schema directly; its preprocess step preserves the top-level nonobject fallback. Focused test run. Current-head CI and repository checks.Two native passes and a fresh independent review, including separate test and TypeScript assessments, found no actionable issues on this head. No review repairs were needed. Authenticated live Claude usage was not exercised.
The focused run's later broad check stopped at an assertion-baseline comparison in three untouched files against its remote main. Those paths and the baseline are unchanged by this PR; the linked PR-scoped CI runs the base-aware ratchet and remaining checks.
AI-assisted implementation.
Change Breakdown
The 13-line production increase gives windows and nested model scopes typed ownership while removing the raw-record projection path and handwritten normalized types.