Skip to content

fix(assets-controller): bypass balance cache on every poll tick - #9926

Merged
juanmigdr merged 3 commits into
mainfrom
fix/accounts-api-polling-cache-mismatch
Aug 20, 2026
Merged

fix(assets-controller): bypass balance cache on every poll tick#9926
juanmigdr merged 3 commits into
mainfrom
fix/accounts-api-polling-cache-mismatch

Conversation

@juanmigdr

@juanmigdrjuanmigdr commented Aug 20, 2026

Copy link
Copy Markdown
Member

Explanation

AccountsApiDataSource polls for balances every 30s, but the underlying ApiPlatformClient caches responses for 60s (STALE_TIMES.BALANCES). Since the poll didn't pass forceUpdate, every other tick was served the cached response instead of hitting the network — balances only actually refreshed every ~60s.

This passes forceUpdate: true on the poll's fetch call so it always bypasses the cache, same as other call sites (unlock, account switch, tx confirmation) already do.

Kept the fix scoped to just the poll instead of removing caching everywhere, since #9591 added forceUpdate specifically to avoid bursts of duplicate calls when multiple triggers fire close together, and the unmerged #9867 ran into that regression by disabling the cache globally.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Low Risk
Narrow cache-bypass on the 30s poll path only; does not change auth or other fetch sites. Slightly more Accounts API traffic on that interval, which is the intended behavior.

Overview
Fixes AccountsApiDataSource polling serving stale balances on roughly every other tick. The 30s poll used fetch() without forceUpdate, so the 60s TanStack balances cache (STALE_TIMES.BALANCES) won.

Recurring pollFn now passes forceUpdate: true so each tick hits the network (staleTime: 0, gcTime: 0), matching other authoritative refreshes. Bypass is scoped to the poll only so nearby unlock/switch/tx triggers still share the cache.

Reviewed by Cursor Bugbot for commit d162463. Bugbot is set up for automated code reviews on this repo. Configure here.

AccountsApiDataSource's recurring balance poll (default pollInterval
30s) fetches balances via ApiPlatformClient, which caches responses
with STALE_TIMES.BALANCES (60s, in @metamask/core-backend). Since the
poll's fetch() call didn't set forceUpdate, roughly half of its 30s
ticks were silently served a cached response instead of hitting the
network, so balances were effectively only refreshed every ~60s.
Pass forceUpdate: true on every poll tick so it always bypasses the
cache, matching the intended 30s cadence.
@juanmigdr
juanmigdr marked this pull request as ready for review August 20, 2026 15:50
@juanmigdr
juanmigdr requested review from a team as code ownersAugust 20, 2026 15:50
@juanmigdr
juanmigdrdeployed to default-branch August 20, 2026 15:50 — with GitHub Actions Active
@juanmigdr
juanmigdr enabled auto-merge August 20, 2026 15:56
@juanmigdr
juanmigdr added this pull request to the merge queueAug 20, 2026
Merged via the queue into main with commit b241fa4Aug 20, 2026
58 checks passed
@juanmigdr
juanmigdr deleted the fix/accounts-api-polling-cache-mismatch branch August 20, 2026 16:12
Sign up for freeto 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

@juanmigdr@Prithpal-Sooriya