Repository navigation
improve(ui): render provider usage histories with less repeated work - #141194
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. |
|
Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 8:01 AM ET / 12:01 UTC. ClawSweeper reviewWhat this changesThe PR reduces repeated currency formatting and history aggregation in provider usage cards while preserving their displayed values and moving detailed coverage beside the shared renderer. Merge readiness✅ Ready for maintainer review Keep open: this is a useful, bounded optimization absent from inspected main and the latest release. No actionable correctness defect was found, and the maintainer-authored PR is protected from cleanup closure. Priority: P3 Review scores
Verification
How this fits togetherThe Control UI receives provider-reported usage snapshots from the Gateway. A shared renderer turns those snapshots into billing totals, daily charts, and attribution details on the Usage and Models pages. flowchart LR
A[Gateway usage snapshots] --> B[Usage and Models pages]
B --> C{Provider error?}
C -->|Yes| D[Error message]
C -->|No| E[Prepare formatter and totals]
E --> F[Billing and history cards]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +1, Tests +93. Total +94 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep formatting and aggregation local to each shared render so both pages benefit without stale values or locale state. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug report; repeated formatter construction and history scans are directly visible in main, and the supplied comparison measures their cost. Is this the best way to solve the issue? Yes. Reusing preparation within the existing renderer removes repeated work without adding persistent caching, competing APIs, or changed formatting semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 01e307c2c295. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
Provider usage cards do repeated formatting and history scans whenever the Usage dashboard or Models settings renders. A 30-day history constructs currency formatters for every displayed value, including the same chart label twice.
Why This Change Was Made
Prepare one amount formatter for each billing row or nonempty history, reuse each chart label, and collect history totals and maximum in one pass. Keep this preparation local to the render so refreshed values and locale settings remain current. There is no cross-render cache.
Preserve raw unknown-unit spacing, JPY rounding, first-three attribution order, NaN/signed-zero behavior, left-to-right token summation and the two independent UTC date reads. Detailed history tests now live beside the shared component; Usage retains caller-level billing and visibility coverage. Production grows by one line; tests grow by 93 lines. No configuration, dependency, style, persistence or API changes.
User Impact
The same provider usage details render with less repeated work on both pages. In the fixed local comparison, creating a new 30-day history DOM is 36–40% faster; updating an existing one is about 89–90% faster. These are Lit/jsdom composition measurements, not browser paint/FPS, network or Gateway latency claims.
Evidence
All 136 tests across four complete component/page/format suites and all 20 selected normal checks passed. Independent P0–P2 review found no actionable findings. A separate audit reconciled complete numeric and browser outcomes.
Numeric proof uses the actual shared renderer plus Lit commit in jsdom, including new containers, unchanged renders, same-object mutation, replacement data, same-container reattachment, supported/raw currencies, multiple providers, billing-only and error controls. Fixed B0/C0/C1/B1 order retains 1,356 whole render operations (1,444 provider-detail invocations): 960 steady measurements, 240 warmups, 100 seeds and 56 literal control executions. Every corresponding full DOM surface matches, including attributes and text; all independent currency/arithmetic/date controls pass.
All paired medians below show percentage reduction and candidate-minus-baseline microseconds. Negative reduction means slower.
Fifty-six of 60 medians improve. All 19 adverse metrics out of 240 are retained: four medians, six means, two minima and seven maxima. The four adverse medians are empty-history controls; the largest absolute increase is 2.50 µs. Eight steady calls per row/process and one fixed cohort do not establish stable tail behavior. Same-container reattachment retains Lit’s existing root; it is not a fresh component lifetime.
Whole-process wall time falls 19.08%/19.89%; all ten retained CPU/RSS/wall comparisons improve, but these include imports, setup and capture and do not establish a general memory benefit. The full raw outputs, complete clock traces, every timing sample and resource observation remain retained.
Real Chromium with the repository’s source-server/mock-Gateway harness passed all 16 states: both actual pages, before and after Refresh, on baseline and candidate, with en-US and de-DE number formatting. Eight Refresh actions each produced a new
usage.statusrequest; noconfig.patchoccurred. Full provider-card DOM matches across variants, and shared detail DOM matches between pages. All browser/process owners closed and candidate source was restored. This is browser integration proof with synthetic data, not an authenticated live provider test.Two failed proof setups remain preserved separately: the first numeric baseline warmup incorrectly counted jsdom’s inert-document Date read as a provider clock; the first browser baseline reached seven states before its English Refresh selector met a legitimately German UI. The corrected observer retains provider/framework clock calls separately inside the same full-render timer; the corrected browser fixture uses the existing explicit server UI-language preference while leaving Intl locale varied. No production change, relaxed assertion, increased timeout or favorable timing rerun was used to resolve either issue.
Synthetic before/after captures below show unchanged presentation for Usage and refreshed Models details. They contain no real account data or credentials.