perf: reduce low-power Codex cost refresh work - #3257
Conversation
Prevent repeated no-progress dashboard scans from immediately restarting, honor the global low-power interval for automatic passes, and preserve manual retries. Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Keep refresh-on-open exact while avoiding full cost-detail reads when Codex sources are unchanged. Keep the shared year dashboard dormant in low-power mode and compact the cache to the configured token window. Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8dddf2580b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if self.settings.backgroundWorkLowPowerModeEnabled, | ||
| preferredMode != .accelerated | ||
| { | ||
| self.cancelSpendDashboardCodexCostCatchUp() | ||
| return |
There was a problem hiding this comment.
Preserve user stop requests during low-power sync
When a user has stopped an active dashboard catch-up, spendDashboardCodexCostCatchUpStopRequested is supposed to survive background synchronization. If Low Power Mode later triggers this new hidden/automatic sync branch, cancelSpendDashboardCodexCostCatchUp() clears that flag, so turning low power back off lets the shared dashboard observation restart the worker without an explicit resume. Return while the stop flag is set, or preserve it when suppressing low-power background work.
Useful? React with 👍 / 👎.
| if let retryNotBefore = self.spendDashboardCodexCostCatchUpRetryNotBefore { | ||
| if self.spendDashboardCodexCostCatchUpRetryScopeSignature == scopeSignature, | ||
| retryNotBefore > Date() | ||
| { | ||
| return |
There was a problem hiding this comment.
Let visible dashboard bypass no-progress backoff
When a no-progress pass sets spendDashboardCodexCostCatchUpRetryNotBefore, this gate also catches calls with preferredMode: .accelerated. The visible Usage & Spend pane sends .accelerated from synchronizeCodexCostCatchUp() on appear, so opening the pane with the same account scope during the 30-minute backoff returns here instead of starting the explicit catch-up; only the manual button path bypasses it. Exempt accelerated/visible sync from the background backoff.
Useful? React with 👍 / 👎.
Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
|
Codex review: needs real behavior proof before merge. Reviewed August 28, 2026, 5:49 PM ET / 21:49 UTC. ClawSweeper reviewWhat this changesThe PR reduces low-power Codex cache scanning and hidden Spend Dashboard work while retaining explicit menu-open and dashboard refreshes. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked until stronger real behavior proof is added - 6 items remain Keep open: the performance direction is useful, but two previously reported dashboard-control regressions remain in the current head and real after-fix behavior proof is still not inspectable. Priority: P2 Review scores
Verification
How this fits togetherCodexBar scans local Codex session logs into cached token and cost summaries used by the status menu and Usage & Spend dashboard. This PR changes when those cache scans run and whether detailed dashboard data is materialized. flowchart LR
A[Local Codex session logs] --> B[Cost cache scanner]
B --> C[Usage store]
C --> D{Low-power scheduling policy}
D --> E[Status-menu summary]
D --> F[Spend Dashboard catch-up]
E --> G[Menu display]
F --> H[Dashboard display]
Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Preserve durable user stops, let an explicit visible dashboard synchronization bypass background retry backoff, and attach redacted runtime evidence showing low-power idle behavior followed by successful dashboard recovery. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: stop an active dashboard catch-up, trigger automatic low-power synchronization, then leave low-power mode; the new cancellation path has cleared the stop state. A same-scope no-progress backoff followed by opening Usage & Spend also returns before its accelerated synchronization can restart work. Is this the best way to solve the issue? No. The low-power optimization is appropriate, but it must retain the established Stop state and treat a visible accelerated dashboard synchronization as an explicit retry. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9769d7394926. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What 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
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Document and assert the second full snapshot read used to protect newer cache state during persistence. Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Keep the exact provider ownership audit aligned with the low-energy source changes, including the narrowed Codex breakdown branch. Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Document the two new Codex-specific low-power summary branches in the provider architecture gatekeeper. Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Summary
Why
The refresh-on-menu-open option was correctly bypassing the normal refresh interval, but each open could also materialize the full Codex cost store. On a large local cache this meant reading hundreds of thousands of replay rows even when no source had changed. Separately, the shared Spend Dashboard publication could start a hidden 365-day catch-up at app launch.
Even after the unchanged-source shortcut, a large ledger with pending catch-up work could start a second multi-second materialization about 33 minutes after a menu-open scan on AC power. That incremental catch-up worker used its own duty-cycle policy and did not account for CodexBar's global low-power setting. Users who opt into refresh-on-open already request a fresh bounded token scan whenever they inspect the menu, so the follow-up background pass can share the six-hour cadence without weakening provider quota freshness or explicit refresh behavior.
An earlier revision attempted to compact wider cached history during these passes. Real-cache validation showed that partial discovery could then discard older aggregates before catch-up completed, so that behavior was removed; this version deliberately preserves the scanner's existing wider-window retention semantics.
Validation
CodexBarandCodexBarCLIThe local open-source Swift toolchain can build the release products but cannot compile the repository's XCTest-importing test files without full Xcode; the complete test suite passed in CI. The full JavaScript check also encountered an unrelated host-level missing
undici-typespackage; JavaScript formatting itself passed.🤖 Generated with OpenAI Codex