Skip to content

Fix token account switcher not refreshing menu with new account data#799

Closed
Zeko369 wants to merge 1 commit intosteipete:mainfrom
Zeko369:fix/token-account-switch-refresh
Closed

Fix token account switcher not refreshing menu with new account data#799
Zeko369 wants to merge 1 commit intosteipete:mainfrom
Zeko369:fix/token-account-switch-refresh

Conversation

@Zeko369
Copy link
Copy Markdown
Contributor

@Zeko369 Zeko369 commented Apr 27, 2026

Summary

  • Replace store.refresh() with targeted store.refreshProvider(display.provider) in the token account switcher's onSelect handler — avoids being silently dropped by the global isRefreshing guard when a menu-open refresh is already in-flight
  • Add refreshOpenMenuIfStillVisible after the async fetch completes so the open menu updates in-place (matching the Codex account switcher pattern)

Fixes #798

Test plan

  • Enable a provider with 2+ token accounts (e.g. Claude with multiple session keys)
  • Open the menu and switch between accounts — the usage card should update each time without needing to manually refresh or close/reopen the menu
  • Verify switching while a background refresh is in-flight still picks up the new account

🤖 Generated with Claude Code

When switching token accounts via the menu, the usage card did not update
because (1) `store.refresh()` was silently dropped by the global
`isRefreshing` guard when an existing refresh was in-flight, and (2) the
open menu was never repopulated after the async fetch completed.

Replace `store.refresh()` with `store.refreshProvider(display.provider)`
which targets only the relevant provider and is not blocked by the global
refresh gate. Add `refreshOpenMenuIfStillVisible` after the fetch
completes so the menu updates in-place, matching the pattern used by the
Codex account switcher.

Fixes steipete#798

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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: 3a24f18f0e

ℹ️ 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".

Task { @MainActor in
await ProviderInteractionContext.$current.withValue(.userInitiated) {
await self.store.refresh()
await self.store.refreshProvider(display.provider)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid concurrent provider refreshes on account switch

Calling refreshProvider(display.provider) here can race with the menu-open refresh that is already running (menuWillOpen -> scheduleOpenMenuRefresh -> refreshStore), because UsageStore.refreshProvider has no per-provider in-flight guard and applies results unconditionally (refreshingProviders.insert is bookkeeping only, then snapshot writes happen on completion). In that overlap, the earlier refresh (started with the previous token account) can finish after the new selection and overwrite the newer snapshot, so the menu may revert to stale account data even though the switcher shows the new account.

Useful? React with 👍 / 👎.

@steipete
Copy link
Copy Markdown
Owner

steipete commented May 4, 2026

Thanks @Zeko369 — I landed this on main in 1164cb8 with changelog credit and a regression test.

The final patch keeps your provider-scoped refresh idea, adapted to current main: token account selections now call refreshProvider(display.provider) so a menu-open global refresh cannot drop the account switch, then the open menu is refreshed again after fresh data arrives.

Verified:

  • swift test --filter StatusMenuTokenAccountSwitcherTests
  • swift test --quiet
  • pnpm check
  • swiftlint --strict
  • ./Scripts/compile_and_run.sh

@steipete steipete closed this May 4, 2026
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.

Token account switcher does not refresh menu with new account data

2 participants