Widget token/cost data should follow the global refresh frequency instead of a fixed hourly TTL
Summary
The usage/quota values and the token/cost rows shown by CodexBar do not currently share the same automatic refresh cadence.
When the global refresh frequency is configured to a shorter interval (for example, one minute), the main provider usage refresh follows that setting, but the token/cost data written into the widget snapshot remains governed by a separate fixed one-hour TTL. As a result, a widget can show recently refreshed quota bars together with token/cost values that are up to an hour old.
This is distinct from the WidgetKit presentation-staleness issue in #2091: the request here concerns when CodexBar refreshes the token/cost data that it puts into the snapshot, not whether WidgetKit renders a newly supplied timeline.
Environment
- CodexBar: 0.42.1 (103), official signed release
- Global refresh frequency: one minute
- Widget: CodexBar Usage
No account names, email addresses, usage amounts, credentials, device identifiers, usernames, or local paths are included.
Reproduction
- Enable token/cost usage.
- Set CodexBar's global refresh frequency to one minute.
- Add or view a CodexBar Usage widget that shows both quota and token/cost data.
- Continue using the provider so both values should change.
- Observe that quota data refreshes according to the configured cadence, while the token/cost timestamp and values can remain unchanged for roughly one hour.
Expected behavior
The widget's token/cost data should follow the same global refresh-frequency setting as the rest of CodexBar.
For a one-minute setting, CodexBar should make token/cost data eligible for refresh every minute and publish the resulting snapshot to the widget. Existing in-flight coalescing and provider sequencing can continue to prevent overlapping work.
Manual refresh should continue to force an immediate refresh.
Actual behavior
Token/cost refresh uses a separate fixed hourly TTL, so the widget can combine fresh quota data with stale token/cost data.
Current source behavior
On current main at commit 7465c6a11674:
UsageStore.tokenFetchTTLis fixed at60 * 60.startTokenTimer()sleeps fortokenFetchTTL.- Automatic app refresh calls
scheduleTokenRefresh(), but non-forced token fetches are skipped while the fixed TTL has not elapsed. - Settings copy explicitly says
Auto-refresh: hourly.
Relevant files:
Sources/CodexBar/UsageStore.swiftSources/CodexBar/UsageStore+TokenRefreshSequence.swiftSources/CodexBar/PreferencesMenuPane.swift
Requested behavior
Use the configured global refresh frequency as the token/cost refresh eligibility interval, including for widget snapshot updates, rather than maintaining an independent fixed one-hour cadence.
If the hourly interval is intentional to protect expensive local scans, a useful alternative would be an explicit separate token/cost refresh setting. The key requirement is that the UI should not imply one global cadence while silently applying a different fixed cadence to part of the widget data.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 12, 2026, 8:16 PM ET / July 13, 2026, 00:16 UTC.
Summary Keep open for maintainer direction: current main retains an independent hourly token/cost refresh policy, and the recent widget-freshness work intentionally addressed sequencing and stale-age disclosure without changing that cadence.
Reproducibility: yes. at source level: current main retains a separate throttled token-refresh path and hourly user-facing cadence, matching the reported mixed-freshness behavior. A live WidgetKit run would strengthen runtime proof but is not necessary to establish the policy mismatch.
Root-cause cluster
Relationship: canonical
Canonical: https://github.com/steipete/codexbar/issues/2103
Summary: This issue is the canonical report for the token-scan eligibility policy; nearby reports concern presentation staleness or freshness attribution rather than the configured interval.
Members:
adjacent_distinct: https://github.com/steipete/codexbar/issues/2091 - That issue concerns WidgetKit failing to visually present an already refreshed timeline, not when token/cost data becomes eligible for rescanning.partial_overlap: https://github.com/steipete/codexbar/issues/1964 - That issue covered stale token snapshots and misleading freshness attribution, but not whether automatic scans should follow the global interval.partial_overlap: https://github.com/steipete/codexbar/pull/1967 - The merged PR improved stale-age disclosure and retry policy while intentionally leaving the normal token-scan cadence separate.
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Next step A maintainer must select the automatic token-scan cadence policy before the otherwise narrow implementation and regression coverage can proceed.
Maintainer decision needed
- Question: Should automatic token/cost scans follow the global refresh frequency, or remain independently throttled because local history scans can be expensive?
- Rationale: Recent merged work deliberately preserved slower asynchronous scanning, so switching to the potentially one-minute global cadence requires an explicit performance and UX policy choice.
- Likely owner: steipete — The recent history ties this person most directly to refresh-loop and widget token policy decisions.
- Options:
- Global cadence with safeguards (recommended): Use the configured global interval for eligibility while preserving coalescing and adding a minimum interval or timeout backoff for expensive scans.
- Separate token cadence: Keep token scans independent but add a dedicated setting and matching widget/preferences copy so the slower cadence is explicit.
- Retain hourly policy: Keep hourly automatic scans and clearly document that global refresh frequency applies to provider quota refreshes rather than local token history.
Review details
Best possible solution:
Choose an explicit cadence contract, preferably using the global interval with in-flight coalescing plus a safe minimum or timeout backoff, or expose a separate token/cost interval if hourly isolation remains intentional.
Do we have a high-confidence way to reproduce the issue?
Yes, at source level: current main retains a separate throttled token-refresh path and hourly user-facing cadence, matching the reported mixed-freshness behavior. A live WidgetKit run would strengthen runtime proof but is not necessary to establish the policy mismatch.
Is this the best way to solve the issue?
Unclear until maintainers select the intended performance policy. Directly adopting a one-minute interval may be too aggressive for scans that can take minutes, so safeguards or a separate explicit cadence may be more maintainable.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
- Using a one-minute global cadence for local token scans could repeatedly traverse large histories, increase CPU and disk activity, or continually encounter scans whose runtime exceeds the configured interval.
- Retaining the fixed hourly cadence leaves one apparent global refresh control governing only part of the widget data unless the independent policy remains clearly disclosed.
Codex review notes: model internal, reasoning high; reviewed against c852c135e10c.
Label changes
Label changes:
- add
P2: The widget can display materially different data ages under one apparent refresh control, but setup and core runtime remain usable. - add
impact:ux-friction: Users selecting a short refresh interval can still see token/cost rows remain up to an hour behind freshly updated quota data. - 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:no-new-fix-pr: Current issue advisory state selects this label. - add
clawsweeper:fix-shape-clear: Current issue advisory state selects this label. - add
clawsweeper:needs-maintainer-review: Current issue advisory state selects this label. - add
clawsweeper:needs-product-decision: Current issue advisory state selects this label.
Label justifications:
P2: The widget can display materially different data ages under one apparent refresh control, but setup and core runtime remain usable.impact:ux-friction: Users selecting a short refresh interval can still see token/cost rows remain up to an hour behind freshly updated quota data.
Evidence reviewed
Acceptance criteria:
- swift test --filter UsageStoreManualTokenRefreshTests
- swift test --filter UsageStoreTokenRetryPolicyTests
- swift test --filter UsageStoreWidgetSnapshotTests
- make test
- make check
What I checked:
- Current implementation: Current main still defines token/cost fetching as a separately throttled UsageStore path rather than deriving its eligibility interval directly from the global provider refresh cadence. (
Sources/CodexBar/UsageStore.swift, c852c135e10c) - Separate sequencing path: Automatic token refresh is scheduled and coalesced through a dedicated sequence, while explicit refresh can wait for that work; this makes the requested cadence change focused but behaviorally significant. (
Sources/CodexBar/UsageStore+TokenRefreshSequence.swift, c852c135e10c) - User-facing cadence disclosure: The preferences surface describes token/cost automatic refresh as hourly, confirming that the separate cadence is currently intentional user-visible behavior rather than an undocumented timer alone. (
Sources/CodexBar/PreferencesMenuPane.swift, c852c135e10c) - Recent widget freshness work: Merged pull request https://github.com/steipete/CodexBar/pull/1967 improved token-row age disclosure and retry behavior while retaining asynchronous, throttled scans because large local histories can take minutes or time out. (
Sources/CodexBar/UsageStore+WidgetSnapshot.swift, fc86568d15ff) - Related reports are distinct: https://github.com/steipete/CodexBar/issues/2091 concerns WidgetKit presenting a newly supplied timeline, while https://github.com/steipete/CodexBar/issues/1964 concerned stale token snapshots and freshness attribution; neither owns the remaining cadence-policy question.
- Released reproduction context: The reporter reproduced the mismatch on the latest listed release, v0.42.1, and current main still contains the separate token refresh path, so the report is not obsolete or already implemented. (3e05988f5c5f)
Likely related people:
- steipete: Recent history connects this person to UsageStore refresh sequencing, widget snapshot behavior, and the policy decisions around slower asynchronous token scans. (role: feature-history owner and recent verifier; confidence: high; commits: bdba75f, 98fd481366c4, 8cbe84873c52; files:
Sources/CodexBar/UsageStore.swift,Sources/CodexBar/UsageStore+TokenRefreshSequence.swift,Sources/CodexBar/UsageStore+WidgetSnapshot.swift) - zhulijin1991: Previously contributed the merged manual token/cost refresh sequencing work and therefore has relevant implementation history beyond reporting this issue. (role: token-refresh sequence contributor; confidence: high; commits: 06aab87, bdba75f; files:
Sources/CodexBar/UsageStore.swift,Sources/CodexBar/UsageStore+TokenRefreshSequence.swift) - irresi: Authored recent merged work covering token age, widget snapshot freshness, and retry throttling in the same behavior area. (role: recent widget freshness contributor; confidence: high; commits: 054743ab969f, c5db35c, fc27b17; files:
Sources/CodexBar/UsageStore.swift,Sources/CodexBar/UsageStore+WidgetSnapshot.swift,Sources/CodexBarCore/WidgetSnapshot.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.
@steipete Friendly ping on this one. It's been a few days since the bot review, and the decision here is blocking any further work on widget token/cost refresh cadence.
To summarize where things stand:
- The bot confirmed the issue is reproducible at the source level (separate hourly TTL for token/cost vs. configurable global cadence for quota).
- Three options were proposed: (1) align with global cadence + safeguards, (2) separate explicit token cadence setting, (3) keep hourly but document clearly.
Would appreciate a direction so we can move forward. Happy to implement whichever option you prefer. Thanks!
Fixed by #2282, merged as 5d1d22630513c335619ffa8f2b4ed07a8c46c92a.
Widget token/cost snapshot freshness now follows the global refresh cadence. One-, two-, and five-minute settings use a documented five-minute WidgetKit safety floor; Adaptive uses its nominal heuristic interval; Manual disables automatic token refresh. Cache hydration, settings changes, documentation, and localized preference copy were updated too.
Proof: focused cadence, hydration, manual refresh, retry, and widget snapshot tests passed; full local suite passed all 714 selections; make check passed; exact-head CI passed all jobs on attempt 2 after one unrelated SwiftPM cache race was rerun.