Skip to content

Fix misleading keepalive log messages and cache DateFormatters#434

Open
guglielmofonda wants to merge 3 commits intosteipete:mainfrom
guglielmofonda:main
Open

Fix misleading keepalive log messages and cache DateFormatters#434
guglielmofonda wants to merge 3 commits intosteipete:mainfrom
guglielmofonda:main

Conversation

@guglielmofonda
Copy link

Summary

  • Fix misleading log messages in AugmentSessionKeepalive: startup logs claimed "every 5 minutes" and "2 minutes" but the actual intervals were both 60s (1 min). The parenthetical labels were stale copy-paste. Now computed dynamically from the real values so they can never drift.

  • Cache DateFormatter as static singletons: DateFormatter is expensive to initialize (loads locale, calendar, and timezone data on each call). Five methods across four files were allocating a fresh instance on every invocation:

    • CursorStatusProbe.formatResetDate
    • ClaudeUsageFetcher.formatResetDate
    • FactoryStatusProbe.formatResetDate (inside FactoryStatusSnapshot)
    • UsageFormatter.creditEventSummary and creditEventCompact

    All replaced with nonisolated(unsafe) private static let singletons — initialized once, reused on every subsequent call. nonisolated(unsafe) is the Swift 6 idiom for opting out of the concurrency check when safety can be reasoned about manually (formatter is configured at init and never mutated after).

Test plan

  • swift build passes with no errors or warnings

- AugmentSessionKeepalive: log messages claimed "every 5 minutes" and
  "2 minutes" but the actual intervals were 60s (1 min) each; now
  computed dynamically from the real values so they can never drift
- CursorStatusProbe, ClaudeUsageFetcher, FactoryStatusProbe,
  UsageFormatter: DateFormatter was re-allocated on every call inside
  formatResetDate / creditEvent helpers; replaced with nonisolated(unsafe)
  static let singletons initialized once at first use
Copy link

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

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

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +320 to +324
nonisolated(unsafe) private static let resetDateFormatter: DateFormatter = {
let f = DateFormatter()
f.dateFormat = "MMM d 'at' h:mma"
f.locale = Locale(identifier: "en_US_POSIX")
return f

Choose a reason for hiding this comment

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

P2 Badge Preserve timezone updates when caching reset date formatter

This singleton DateFormatter now captures the process default timezone once and reuses it forever, so long-lived app sessions can show stale reset times after a system timezone change (travel, DST, manual timezone change) until restart. Before this commit, constructing a formatter per call picked up the current timezone each time. The same caching pattern was added in ClaudeUsageFetcher and FactoryStatusProbe, so all reset labels can drift; use .autoupdatingCurrent timezone (and locale where needed) or keep formatter creation thread/timezone-scoped.

Useful? React with 👍 / 👎.

When "Show time until reset" is enabled in Settings → Display, a compact
countdown (e.g. "72% · 28m" or "72% · 2h 5m") appears next to the
percentage in the menu bar. It picks the nearest upcoming reset across
the primary and secondary quota windows.

- MenuBarDisplayText: add timeUntilResetText() formatter
- StatusItemController+Animation: append countdown to menuBarDisplayText
- StatusItemController: start/stop a 60-second Timer so the label ticks
  down every minute without waiting for a data refresh
- SettingsStoreState / SettingsStore / SettingsStore+Defaults: persist
  the new `menuBarShowsTimeUntilReset` boolean via UserDefaults
- PreferencesDisplayPane: add toggle under "Menu bar shows percent"
  (disabled + faded when text mode is off, since the countdown is
  invisible in icon-only mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants