Repository navigation
fix(perps): force controller REST refresh when Activity refetches - #47643
Conversation
Activity's forced refresh only cleared the UI coalesce cache. The controller still served its 60s REST cache for perpsGetOrderFills, perpsGetOrders and perpsGetFunding, so a just-closed trade could be missing unless the live userFills stream delivered it. Pass forceRefresh on explicit refetches only, and drop the second userFills push from the close-fill E2E flow. Co-authored-by: Cursor <cursoragent@cursor.com>
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/perps (4 files, +307 -97)
🧪 @MetaMask/qa (1 files, +3 -4)
|
Builds ready [65964ed]
⚡ Performance Benchmarks (Total: 🟢 5 pass · 🟡 5 warn · 🔴 3 fail)
Bundle Size Diffs
|
|
Forced refetch can be silently downgraded to an in-flight passive request.
The window is the duration of the in-flight request, so it is narrow, but it is the exact failure mode the PR targets. Suggested fix: forced calls should bypass |
|
Test gap for the in-flight case above. Suggest adding a test that starts a passive fetch, then calls The current |
A forced Activity refetch invalidated the UI cache but still adopted an in-flight passive request, so forceRefresh never reached the controller. Forced reads now replace that in-flight slot, and tests cover the race for fills, orders, and funding. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Addressed both comments in b2641ab. A forced read now passes The new hook test starts the passive read, then mounts with |
Builds ready [b2641ab]
⚡ Performance Benchmarks (Total: 🟢 5 pass · 🟡 5 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
|



Description
Opening Perps Activity force-refreshes transaction history, but that refresh only cleared the UI-side coalesce cache.
perpsGetOrderFills,perpsGetOrdersandperpsGetFundingstill reachedPerpsControllerwithoutforceRefresh, so the controller's 60s REST coalesce cache could return a result from before a just-closed trade. The trade then only appeared if the liveuserFillsstream delivered it. That is why the TP/SL E2E specs fail intermittently on Firefox after the@metamask/perps-controller@22.1.1bump.refetch()(used byforceFreshOnMounton Activity and by pull-to-refresh) now passes{ forceRefresh: true }to the three REST reads. Passive fetches, such as the Recent activity preview on Perps home, keep the controller cache. The E2E flowassertPerpsActivityShowsCloseFillno longer pushesuserFillsa second time, because the forced REST read now returns the fill from the mock.Related: MetaMask/metamask-extension#47600, MetaMask/core#11160.
Changelog
CHANGELOG entry: Fixed a bug where a just-closed Perps trade could be missing from Perps Activity
(This helps the Release Engineer do their job more quickly and accurately)
Related issues
Fixes:
Manual testing steps
PERPS_ENABLED=trueand sign in with an account that has an open ETH long position.Screenshots/Recordings
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes Perps transaction history fetch semantics and HyperLiquid REST traffic on Activity open/refetch; behavior is covered by new unit tests and a simplified E2E flow.
Overview
Fixes missing just-closed trades on Perps Activity when the UI cleared its own coalesce cache but
PerpsControllerstill served 60s-cachedperpsGetOrderFills/ orders / funding reads (often after the home “Recent activity” preview had already fetched).usePerpsTransactionHistorynow treatsrefetch()(pull-to-refresh andforceFreshOnMount) as a true refresh: background calls include{ forceRefresh: true }, and the UI coalescer usesreplaceInFlightso a forced read does not join an in-flight passive request that would omitforceRefresh. Passive previews keep cache-friendly reads.coalesceBackgroundRequestgains an optionalreplaceInFlightflag (with tests). The E2E close-fill flow drops the extrapushUserFills()retry now that the forced REST path is expected to return the fill from the mock.Reviewed by Cursor Bugbot for commit b2641ab. Bugbot is set up for automated code reviews on this repo. Configure here.