Skip to content

perf: background credits and dashboard fetch for regular refreshes#1078

Open
ptstory wants to merge 2 commits into
steipete:mainfrom
ptstory:perf/background-codex-refresh
Open

perf: background credits and dashboard fetch for regular refreshes#1078
ptstory wants to merge 2 commits into
steipete:mainfrom
ptstory:perf/background-codex-refresh

Conversation

@ptstory
Copy link
Copy Markdown
Contributor

@ptstory ptstory commented May 21, 2026

Summary

Background regular Codex web refreshes so the UI never blocks on slow network operations during the polling cycle. Add credits-refresh coalescing so repeated poll cycles cannot stack concurrent credits fetches.

Split from #1073 per review feedback. Related: #678.

What changed

For non-forced refreshes, refreshCreditsIfNeeded() and refreshOpenAIDashboardIfNeeded() now run in background tasks instead of blocking the regular refresh path. Credits refresh now uses a Task<Void, Never>? guard so a second poll skips starting another credits fetch while one is already in flight.

Why

The regular refresh cycle was awaiting Codex credits and OpenAI dashboard web work inline, which could block the main thread for seconds during slow network scrapes. It also allowed repeated poll cycles to stack concurrent credits fetches without any coalescing.

How to verify

swift test --filter CodexManagedOpenAIWebRefreshTests
./Scripts/lint.sh format
./Scripts/lint.sh lint
make check

Notable decisions

  • Forced refreshes still await inline so manual refresh behavior stays synchronous.
  • Credits coalescing uses a Task? reference instead of a boolean so the in-flight state is derived from the task itself.
  • Tradeoff: these non-forced refresh background tasks are unstructured and are not cancelled if the parent refresh is cancelled. Acceptable for a menu bar app on a 2-minute poll cycle.

Not included

Move refreshCreditsIfNeeded() and refreshOpenAIDashboardIfNeeded() into background tasks for non-forced refreshes. Add Task?-based coalescing guard for credits refresh to prevent unbounded stacking.

Forced refreshes (manual) still await inline.

Split from steipete#1073.
Copy link
Copy Markdown

@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: 55945600c8

ℹ️ 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 thread Sources/CodexBar/UsageStore.swift
Comment thread Sources/CodexBar/UsageStore.swift
Persist widget snapshots when background Codex credits and OpenAI dashboard refresh tasks complete so widget state does not lag behind successful async refreshes.

Add regression coverage proving widget snapshots update after backgrounded credits and dashboard fetch completion.
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.

1 participant