Widget token usage can stay stale while usage snapshot shows as recently updated
Summary
The desktop widget can show a fresh update time and current quota bars, while the token/cost rows (Today, 30d) remain stale. Restarting CodexBar / the widget extension / chronod makes the token rows catch up, so this looks like a runtime cache invalidation issue rather than missing local usage data.
Environment
- CodexBar: 0.40.0 (99)
- Distribution: official signed app (
TeamIdentifier=Y5PE65HELJ) - Providers observed: Codex and Claude
- Token cost usage enabled
Observed behavior
- The widget refreshes and shows a recent timestamp, for example
a few seconds ago. - Quota bars update normally.
- Token/cost rows can remain stale.
- Running the bundled CLI shows newer token usage for the same provider:
/Applications/CodexBar.app/Contents/Helpers/CodexBarCLI cost --provider codex --format json
/Applications/CodexBar.app/Contents/Helpers/CodexBarCLI cost --provider claude --format json
- The widget snapshot file may have a fresh
generatedAt, but the provider entry'stokenUsagecan still contain the older in-memory token snapshot. - Restarting the runtime makes the widget snapshot catch up:
pkill -x CodexBarWidget
killall chronod
pkill -x CodexBar
open -a /Applications/CodexBar.app
Expected behavior
When CodexBar writes a fresh widget snapshot / reloads widget timelines, token usage should either:
- refresh with the same provider snapshot, or
- clearly keep a separate token-specific updated time so the widget does not appear fully fresh while token rows are stale.
Actual behavior
The widget can appear fresh because quota data updates, but token usage remains behind until the app/widget runtime is restarted.
Notes
This report intentionally omits screenshots, account IDs, emails, local usernames, and exact usage values. I can provide sanitized logs or a minimal redacted snapshot shape if useful.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 7, 2026, 12:19 AM ET / 04:19 UTC.
Summary Keep open. Current main still allows a regular refresh to write a fresh widget snapshot before the asynchronous token-cost refresh has completed, which matches the reported stale token rows with fresh quota/timestamp behavior.
Reproducibility: yes. from source inspection, though not by live WidgetKit execution: regular refreshes schedule token-cost refresh asynchronously and immediately persist a widget snapshot that reads whatever tokenSnapshots currently holds.
Next step This is a narrow source-reproducible widget freshness bug with clear files and stable unit-test seams.
Review details
Best possible solution:
Make widget snapshots either wait for or coalesce with a current token-cost refresh when token rows are displayed, or persist a tokenUsage-specific updatedAt so stale token rows cannot inherit the whole-snapshot freshness signal.
Do we have a high-confidence way to reproduce the issue?
Yes from source inspection, though not by live WidgetKit execution: regular refreshes schedule token-cost refresh asynchronously and immediately persist a widget snapshot that reads whatever tokenSnapshots currently holds.
Is this the best way to solve the issue?
Yes, a narrow fix in snapshot/refresh coordination is the maintainable path; avoid changing provider scanners or adding a setting unless maintainers prefer a token-specific updatedAt display contract.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
- I did not run a live macOS WidgetKit reproduction because the review is read-only and AGENTS.md cautions against live provider/keychain validation without explicit request.
Codex review notes: model internal, reasoning high; reviewed against 46edb383c0ac.
Label changes
Label changes:
- add
P2: This is a normal-priority user-visible correctness bug in widget freshness with limited blast radius and no setup blocker. - add
impact:session-state: The issue is about stale cached token state being associated with a newer widget snapshot state. - add
impact:ux-friction: The widget can mislead users by showing fresh quota and timestamp while token/cost rows lag behind. - 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: This is a normal-priority user-visible correctness bug in widget freshness with limited blast radius and no setup blocker.impact:session-state: The issue is about stale cached token state being associated with a newer widget snapshot state.impact:ux-friction: The widget can mislead users by showing fresh quota and timestamp while token/cost rows lag behind.
Evidence reviewed
Acceptance criteria:
- swift test --filter UsageStoreWidgetSnapshotTests
- swift test --filter WidgetSnapshotTests
- make check
- make test
What I checked:
- Issue report: The reporter observed CodexBar 0.40.0 widgets showing fresh quota/timestamp while Today and 30d token rows stayed stale until app/widget/chronod restart; the bundled CLI reported newer token data.
- Regular refresh schedules token-cost work asynchronously: On current main, non-forced refreshes call scheduleTokenRefresh(force: false) and then continue without waiting for token usage before snapshot persistence. (
Sources/CodexBar/UsageStore.swift:668, 46edb383c0ac) - Fresh widget snapshot can reuse old token state: makeWidgetSnapshot stamps generatedAt with now, while makeWidgetEntry reads tokenUsage from tokenSnapshots when no provider-derived token snapshot exists, so stale token state can be packaged into a fresh snapshot. (
Sources/CodexBar/UsageStore+WidgetSnapshot.swift:28, 46edb383c0ac) - Token refresh persists a second widget snapshot only after it finishes: refreshTokenUsage updates tokenSnapshots and calls persistWidgetSnapshot(reason: "token-usage") after a successful scan, leaving a window where the earlier refresh snapshot can advertise freshness with old token rows. (
Sources/CodexBar/UsageStore.swift:1622, 46edb383c0ac) - No canonical replacement found: GitHub searches for the central problem only found this issue; the provided related local-cost and iOS-widget items are adjacent but do not own this stale widget snapshot behavior.
- Latest release has the same snapshot ordering: v0.41.0 points at a83a83fa and shows the same regular-refresh scheduling and widget snapshot shaping; current main 46edb383 is not contained in a release tag and has no evidence of a fix. (
Sources/CodexBar/UsageStore.swift:668, a83a83fa4131)
Likely related people:
- Peter Steinberger: Authored the original widget snapshot persistence and token-cost refresh scheduling commits, and the current import/release commit in the available checkout owns the affected lines. (role: feature-history owner; confidence: high; commits: 98fd481366c4, 0b5293991d98, a83a83fa4131; files:
Sources/CodexBar/UsageStore.swift,Sources/CodexBar/UsageStore+WidgetSnapshot.swift,Sources/CodexBarCore/WidgetSnapshot.swift) - Alekstodo: Recently touched UsageStore.swift, UsageStore+WidgetSnapshot.swift, and widget snapshot tests in a quota-warning/widget-related change near the same surface. (role: recent adjacent contributor; confidence: medium; commits: 71a768b58e47; files:
Sources/CodexBar/UsageStore.swift,Sources/CodexBar/UsageStore+WidgetSnapshot.swift,Tests/CodexBarTests/UsageStoreWidgetSnapshotTests.swift)
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.