Skip to content

perf: reduce low-power Codex cost refresh work - #3257

Open
Carl723000 wants to merge 11 commits into
steipete:mainfrom
Carl723000:codex/spend-dashboard-low-energy
Open

perf: reduce low-power Codex cost refresh work#3257
Carl723000 wants to merge 11 commits into
steipete:mainfrom
Carl723000:codex/spend-dashboard-low-energy

Conversation

@Carl723000

@Carl723000 Carl723000 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve the opt-in contract that every completed menu opening starts a fresh provider and token refresh
  • reuse persisted day aggregates when Codex session sources are unchanged, while still running the exact incremental scanner after an append or other source change
  • avoid loading project/session rows for low-power startup, scheduled refreshes, and menu-open summaries
  • when global low-power mode and refresh-on-open are both enabled, keep both scheduled token-history scans and post-refresh incremental catch-up on a six-hour background cadence; provider quota refreshes keep their existing cadence, and menu-open/manual refreshes remain immediate
  • preserve wider cached history while an incremental catch-up is still incomplete, preventing partial discovery from undercounting older days
  • preserve exact aggregate token and authoritative-cost totals when low-power reads intentionally omit replay rows
  • keep reviewed Pi cache generations compatible when only the aggregate read view changes, avoiding an unnecessary full Pi rescan
  • keep the shared 365-day Spend Dashboard publisher and automatic catch-up dormant in low-power mode until the dashboard is explicitly visible
  • retain full-detail behavior for explicit manual refreshes and visible Spend Dashboard loads

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

  • Release builds passed for CodexBar and CodexBarCLI
  • SwiftFormat passed for Sources and Tests
  • SwiftLint passed across 2,037 Swift files with zero violations
  • GitHub CI passed both macOS test shards plus Linux x64, arm64, and musl builds on the final revision
  • app localization and CLI installer checks passed
  • focused scanner coverage verifies:
    • unchanged sources use summary-only store reads
    • an appended log is incorporated exactly
    • unchanged cached history remains available while incremental catch-up work is pending
    • every completed menu opening still starts a refresh, while in-flight requests coalesce
    • hidden low-power Spend Dashboard catch-up stays stopped, while an explicitly visible dashboard can still run
    • low-power refresh-on-open uses a six-hour background token TTL and preserves manual-only cadence
    • post-refresh automatic Codex catch-up also waits six hours in that mode, while explicit accelerated catch-up remains immediate
    • summary-only storage reads preserve standard/priority token ownership and exact aggregate costs without loading raw usage rows
    • compatible Pi caches are reused across the current aggregate-only parser revision
  • a real 30-day cache summary returned 30 daily entries in about 0.34 seconds without project/session details
  • real-cache catch-up completed 1,226/1,226 files with no pending scans; SQLite integrity passed, and the application summary reported 11,173,069,852 input-plus-output tokens across the displayed 30-day window
  • local packaged-app sampling reproduced 6-7 second background scans at the old 30-minute cadence, then held CPU time flat between scans; the new cadence limits those redundant background passes to once per six hours while retaining immediate menu-open refresh

The 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-types package; JavaScript formatting itself passed.

🤖 Generated with OpenAI Codex

Carl723000 and others added 2 commits August 28, 2026 19:37
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>
@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +28 to +32
if self.settings.backgroundWorkLowPowerModeEnabled,
preferredMode != .accelerated
{
self.cancelSpendDashboardCodexCostCatchUp()
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +40 to +44
if let retryNotBefore = self.spendDashboardCodexCostCatchUpRetryNotBefore {
if self.spendDashboardCodexCostCatchUpRetryScopeSignature == scopeSignature,
retryNotBefore > Date()
{
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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>
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed August 28, 2026, 5:49 PM ET / 21:49 UTC.

ClawSweeper review

What this changes

The PR reduces low-power Codex cache scanning and hidden Spend Dashboard work while retaining explicit menu-open and dashboard refreshes.

Regression provenance

Possible 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
Reviewed head: 95b0269300dc03e84d7a34c61ce7140a554ceae7

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The optimization has substantial focused tests, but two concrete scheduler regressions and missing inspectable real-behavior proof block merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The changed production owners are the local Codex cache scanner/read path and Spend Dashboard catch-up scheduler. The body reports real-cache and packaged-app outcomes, but supplies no inspectable after-fix artifact showing low-power suppression and subsequent successful visible-dashboard recovery; provide a redacted terminal trace, log, recording, or diagnostic screenshot. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The changed production owners are the local Codex cache scanner/read path and Spend Dashboard catch-up scheduler. The body reports real-cache and packaged-app outcomes, but supplies no inspectable after-fix artifact showing low-power suppression and subsequent successful visible-dashboard recovery; provide a redacted terminal trace, log, recording, or diagnostic screenshot. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Introduced low-power branch clears a durable user stop: The introduced low-power suppression branch calls full cancellation before the existing durable-stop guard. Full cancellation resets the stop flag, so a later normal synchronization can restart work the user explicitly stopped.
Visible dashboard remains blocked by retry backoff: The new retry gate returns before it considers preferred mode. The visible dashboard calls this method with accelerated mode, so reopening it during a same-scope no-progress backoff does not retry; the added test covers direct manual start instead.
Prior review concerns remain applicable: The existing review threads identify the same durable-stop and visible-retry paths; the current head retains both introduced control-flow triggers.
Findings 2 actionable findings [P2] Preserve user stops when suppressing low-power catch-up
[P2] Let visible dashboard synchronization bypass retry backoff
Security None None.

How this fits together

CodexBar 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]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The changed production owners are the local Codex cache scanner/read path and Spend Dashboard catch-up scheduler. The body reports real-cache and packaged-app outcomes, but supplies no inspectable after-fix artifact showing low-power suppression and subsequent successful visible-dashboard recovery; provide a redacted terminal trace, log, recording, or diagnostic screenshot. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve user stops when suppressing low-power catch-up (P2) - cancelSpendDashboardCodexCostCatchUp() clears spendDashboardCodexCostCatchUpStopRequested, but this new branch runs before the durable-stop guard. A user who stopped catch-up can therefore have it restarted after low power is disabled. Preserve the flag when suppressing hidden work or check it first.
  • Let visible dashboard synchronization bypass retry backoff (P2) - This backoff gate also returns for preferredMode: .accelerated. The visible pane uses that mode when it appears, so a user reopening Usage & Spend during the backoff cannot retry; the new test only exercises the direct manual-start path. Exempt accelerated synchronization from the background backoff.
  • Resolve merge risk (P1) - In low-power mode, automatic synchronization can erase a user's explicit stop and later restart the hidden dashboard worker.
  • Resolve merge risk (P1) - A visible Usage & Spend opening can remain paused for the full no-progress backoff despite being an explicit recovery action.
  • Resolve merge risk (P1) - No inspectable runtime artifact yet proves that low-power suppression preserves visible-dashboard recovery on a real cache.

Findings

  • [P2] Preserve user stops when suppressing low-power catch-up — Sources/CodexBar/UsageStore+SpendDashboardCodexCostCatchUp.swift:31
  • [P2] Let visible dashboard synchronization bypass retry backoff — Sources/CodexBar/UsageStore+SpendDashboardCodexCostCatchUp.swift:40-44
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta production +401/-60, tests +428/-92 The broad cache and scheduler change has substantial focused test coverage, but the two dashboard UI-to-scheduler sequences remain untested.

Merge-risk options

Maintainer options:

  1. Restore explicit dashboard control (recommended)
    Preserve the stop flag during low-power suppression and exempt accelerated visible synchronization from the no-progress backoff, with focused regression coverage.
  2. Pause the optimization
    Do not merge the low-power dashboard scheduling changes if the existing Stop and visible recovery behavior cannot be retained.

Technical review

Best 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:

  • [P2] Preserve user stops when suppressing low-power catch-up — Sources/CodexBar/UsageStore+SpendDashboardCodexCostCatchUp.swift:31
    cancelSpendDashboardCodexCostCatchUp() clears spendDashboardCodexCostCatchUpStopRequested, but this new branch runs before the durable-stop guard. A user who stopped catch-up can therefore have it restarted after low power is disabled. Preserve the flag when suppressing hidden work or check it first.
    Confidence: 0.99
  • [P2] Let visible dashboard synchronization bypass retry backoff — Sources/CodexBar/UsageStore+SpendDashboardCodexCostCatchUp.swift:40-44
    This backoff gate also returns for preferredMode: .accelerated. The visible pane uses that mode when it appears, so a user reopening Usage & Spend during the backoff cannot retry; the new test only exercises the direct manual-start path. Exempt accelerated synchronization from the background backoff.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9769d7394926.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The introduced low-power suppression can silently replace an existing explicit Stop choice with later automatic restart behavior.

Label justifications:

  • P2: The PR can make an existing dashboard recovery or stop-control workflow behave incorrectly, but the blast radius is limited to Codex cost catch-up.
  • merge-risk: 🚨 compatibility: The introduced low-power suppression can silently replace an existing explicit Stop choice with later automatic restart behavior.
  • merge-risk: 🚨 availability: The introduced retry gate can leave a visible dashboard catch-up paused despite an explicit user request to resume it.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The changed production owners are the local Codex cache scanner/read path and Spend Dashboard catch-up scheduler. The body reports real-cache and packaged-app outcomes, but supplies no inspectable after-fix artifact showing low-power suppression and subsequent successful visible-dashboard recovery; provide a redacted terminal trace, log, recording, or diagnostic screenshot. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Acceptance criteria:

  • [P1] swift test --filter UsageStoreSpendDashboardCodexCostCatchUpTests.
  • [P1] make test.
  • [P1] make check.

What I checked:

Likely related people:

  • Yuxin Qiao: Authored the recent merged visible Codex spend catch-up safety work in this exact dashboard scheduling path. (role: recent area contributor; confidence: high; commits: 75894c9fb983, 6538ac34597e; files: Sources/CodexBar/UsageStore+SpendDashboardCodexCostCatchUp.swift, Sources/CodexBar/PreferencesSpendDashboardPane.swift)
  • Peter Steinberger: Recent history attributes semantic catch-up progress and configured-history behavior to this area. (role: catch-up policy contributor; confidence: medium; commits: 2c55f0dcb901, 95ec2495df75; files: Sources/CodexBar/UsageStore+SpendDashboardCodexCostCatchUp.swift, Sources/CodexBar/CodexCostCatchUpPolicy.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Preserve explicit Stop state through hidden low-power suppression and bypass retry backoff for visible accelerated synchronization.
  • Add focused coverage for both UI-to-scheduler sequences.
  • Post redacted real-cache evidence of low-power idle behavior and visible-dashboard recovery, then update the PR body for re-review.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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-review comments, 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-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to 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 explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-28T18:58:41.406Z sha 635d245 :: needs real behavior proof before merge. :: [P2] Preserve explicit stops during low-power suppression | [P2] Let visible dashboard synchronization bypass retry backoff
  • reviewed 2026-08-28T19:03:48.283Z sha 635d245 :: needs real behavior proof before merge. :: [P2] Preserve explicit stops during low-power suppression | [P2] Let visible dashboard sync bypass the retry backoff
  • reviewed 2026-08-28T19:28:38.070Z sha 9885cd6 :: needs real behavior proof before merge. :: [P2] Preserve user stops during low-power suppression | [P2] Let visible dashboard sync bypass retry backoff
  • reviewed 2026-08-28T19:35:05.487Z sha 9885cd6 :: needs real behavior proof before merge. :: [P2] Preserve explicit stops during low-power suppression | [P2] Bypass background backoff for visible dashboard sync
  • reviewed 2026-08-28T19:53:31.928Z sha c287772 :: needs real behavior proof before merge. :: [P2] Preserve the explicit stop during low-power suppression | [P2] Let visible dashboard sync bypass the retry backoff
  • reviewed 2026-08-28T20:01:19.561Z sha c287772 :: needs real behavior proof before merge. :: [P2] Preserve explicit stops during low-power suppression | [P2] Let visible dashboard synchronization bypass retry backoff
  • reviewed 2026-08-28T20:42:20.892Z sha bf99c50 :: needs real behavior proof before merge. :: [P2] Preserve explicit stops during low-power suppression | [P2] Let visible dashboard sync bypass no-progress backoff
  • reviewed 2026-08-28T21:13:22.162Z sha 95b0269 :: needs real behavior proof before merge. :: [P2] Keep dashboard stops durable through low-power suppression | [P2] Bypass backoff for a visible dashboard retry

Carl723000 and others added 3 commits August 29, 2026 02:04
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>
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. and removed merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Aug 28, 2026
Carl723000 and others added 4 commits August 29, 2026 03:23
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>
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. label Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant