First provider tab switch stalls 100–200 ms: quotaWeekSummaries runs on the main thread with no cache
On 0.63.0 the first switch to the Codex or Claude tab in the menu hitches visibly. Later switches to the same tab are smooth, so the prebuilt-tab work from #2547/#2570 still holds. The new cost is in building the card itself.
Setup: CodexBar 0.63.0 (151), macOS 26.7 (25G229), Apple Silicon. Codex and Claude enabled, local cost history on.
What I measured: I ran sample <pid> 60 1 while switching tabs about ten times. On the main thread, CostUsageTokenSnapshot.quotaWeekSummaries shows up in 17 separate calls: three at about 195 ms, six at about 80 ms, eight at about 115 ms. That adds up to roughly 1.9 s of main-thread time in one minute. A single 200 ms block is enough to see the menu freeze.
Most of each call goes to String(format:). The chain:
InlineUsageDashboardContent.costHistoryQuotaPresentationcallssnapshot.quotaWeekSummaries(...)whenevershowsQuotaWeekCostis true andhistoryDays >= 7. Right now that means Codex and Claude.quotaWeekSummaries→quotaProjectionDaysmakes oneCostUsageLocalDay.key(from:calendar:)call per hourly entry or quota slice.CostUsageLocalDay.key(CostUsageModels.swift:1556) builds each key withString(format: "%04d-%02d-%02d", ...), after callingdateComponentsandgregorianCalendar(matching:)again for every entry.
Nothing caches the result, so every card build walks the whole hourly history again. This path arrived with #3358 in 0.62.
Possible fixes, roughly from smallest to largest:
- Build the day key without
String(format:), using integer-to-digits padding, and resolve the Gregorian calendar once per call rather than once per entry. - Memoize
quotaWeekSummariesper snapshot, keyed onupdatedAt, the reset inputs and the calendar. The output only changes when the snapshot or the reset observations change. - Compute quota weeks off the main thread, when the snapshot lands, and give the menu a precomputed value.
Option 2 alone would probably make the switch feel instant again. Option 1 still helps the first build after each refresh.
I can attach the full sample output if that helps.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed September 21, 2026, 5:45 AM ET / 09:45 UTC.
Summary Current main retains the reported synchronous, uncached calculation. This is a concrete, bounded performance repair; the earlier tab-rendering fixes address a different mechanism.
Reproducibility: yes. for the source-level mechanism: constructing an eligible card traverses history synchronously and repeats per-entry calendar/key work. The reported 100–200 ms latency was not independently reproduced.
Regression provenance Possible regression — suspected (reviewed change). No predecessor PR is attributed.
Next step The source establishes a narrow hot path with existing semantic tests and no identified open fix PR; establish a regression fixture and baseline before optimizing.
Review details
Best possible solution:
Make quota projection inexpensive on first build and reusable where justified, while preserving reset chronology, calendar behavior, partial totals, and provider/account isolation.
Do we have a high-confidence way to reproduce the issue?
Yes for the source-level mechanism: constructing an eligible card traverses history synchronously and repeats per-entry calendar/key work. The reported 100–200 ms latency was not independently reproduced.
Is this the best way to solve the issue?
Yes to a focused hot-path optimization; benchmark it before adding cache complexity. Timestamp-only memoization is insufficient because reset observations, explicit now, calendar, and snapshot contents can change independently.
AGENTS.md: found and applied where relevant.
Codex review notes: model internal, reasoning medium; reviewed against d8d0f3394989.
Label changes
Label changes:
- add
P2: A bounded menu responsiveness problem affects existing local-history cards without blocking setup or normal usage. - add
impact:ux-friction: The reported first-switch hitch interrupts provider navigation, while subsequent switches remain usable. - add
issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label. - add
clawsweeper:source-repro: Current issue advisory state selects this label. - add
clawsweeper:queueable-fix: Current issue advisory state selects this label. - add
clawsweeper:fix-shape-clear: Current issue advisory state selects this label.
Label justifications:
P2: A bounded menu responsiveness problem affects existing local-history cards without blocking setup or normal usage.impact:ux-friction: The reported first-switch hitch interrupts provider navigation, while subsequent switches remain usable.
Evidence reviewed
Acceptance criteria:
- swift test --filter CostUsageQuota
- swift test --filter InlineCostHistoryDashboardLabelTests
- make test
- make check
What I checked:
- Current synchronous call: Card construction calls quotaWeekSummaries when quota costs are enabled and history spans at least seven days, passing reset observations, current time, and the bucket calendar without memoization. (
Sources/CodexBar/InlineUsageDashboardContent.swift:197, d8d0f3394989) - Per-entry work remains: quotaProjectionDays creates a local-day key for every exact entry, residual slice, or hourly entry; CostUsageLocalDay.key reconstructs a Gregorian calendar and uses String(format:). This establishes the repeated work, but does not independently establish the reported millisecond timings. (
Sources/CodexBarCore/CostUsageModels.swift:1563, d8d0f3394989) - Existing row cache does not eliminate first-build cost: Sibling warmup runs through RunLoop.main and MainActor.assumeIsolated, constructs missing content, then caches rendered rows. It does not precompute quota projections away from the main actor. (
Sources/CodexBar/StatusItemController+MenuSwitcherWarmup.swift:25, d8d0f3394989) - Established semantics and regression coverage: The UI contract preserves exact reset boundaries, partial subtotals, and calendar fallback. Existing quota tests cover missing reset metadata, DST, cancelled forecasts, and closely spaced redeemed resets; these semantics must survive optimization. (
TestsLinux/CostUsageQuotaWeekLinuxTests.swift:44, d8d0f3394989) - History and ownership: Path history records the merged quota-window feature at b1f14ba and subsequent Antigravity extension. Menu warmup history records several changes by Peter Steinberger. Local blame and deeper blob comparisons failed because historical blobs were unavailable; GitHub's commit endpoint supplied the quota-feature patch, so no blame-based introduction claim is made. (
Sources/CodexBar/InlineUsageDashboardContent.swift, b1f14ba2594e) - Released implementation still performs projection: The v0.63.0 source also calls quotaProjectionDays directly. Current main retains this behavior; the changelog identifies quota-window history as shipped in 0.62.0, not as a pending performance fix. (
Sources/CodexBarCore/CostUsageModels+QuotaWindows.swift:51, f3e718c897d5)
Likely related people:
- stabey: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
- steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
How this review workflow works
- ClawSweeper keeps one durable marker-backed review comment per issue or PR.
- Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
- A fresh review can be triggered by eligible
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch. - PR/issue authors and users with repository write access can comment
@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only. - Maintainers can also comment
@clawsweeper reviewto request a fresh review only. - Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
- Maintainer-only repair and merge flows require explicit commands such as
@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review. - Maintainers can comment
@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.
Reproduced the repeated projection work with 50,000 synthetic slices and implemented the fix in #3859. The projection now belongs to the immutable snapshot and bucket time zone, while reset evidence and current time remain live. The relative timing regression failed before and passes after; DST, time-zone changes, and distinct snapshots with identical timestamps are covered. All 841 focused tests and make check pass. Thanks @giuseppebisemi for the diagnosis and original implementation.