Repository navigation
test(perps-controller): cover userFills delivery over a shared SDK subscription - #11316
Open
javiergarciavera wants to merge 1 commit into
Open
javiergarciavera wants to merge 1 commit into
javiergarciavera wants to merge 1 commit into
Conversation
…bscription Model the SDK's shared per-payload subscription (all listeners receive every frame, server unsubscribe only when the last listener leaves) and cover: restore on the transport that still holds the original listener, restore onto a replacement transport, snapshot-shaped live frames after the initial snapshot, stale empty snapshots, and subscriber churn while an open or a teardown is still in flight. Co-authored-by: javiergarciavera <javiergarciavera@users.noreply.github.com>
javiergarciavera
temporarily deployed
to
default-branch
November 5, 2026 10:35 — with
GitHub Actions
Inactive
abretonc7s
approved these changes
Nov 10, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Since the extension moved to
@metamask/perps-controller@22.1.1(which includes #11160),perps-tpsl.spec.tsstill fails intermittently on Firefox. The symptom matches MetaMask/metamask-extension#47287: after a mockeduserFillspush, Perps Activity shows "No transactions yet". This PR checks whetherHyperLiquidSubscriptionServicecan still drop a liveuserFillsframe. It adds tests only and makes no runtime changes. In every scenario covered, core delivers the frame correctly.The existing userFills tests use a separate fake subscription per
userFills()call. That fake can't show what happens when several opens share one server subscription, which is how@nktkas/hyperliquidactually behaves. The newdescribeblock uses a fake that mirrors the SDK'sWebSocketSubscriptionManager:unsubscribeis sent only when the last listener leavesScenarios covered:
restoreSubscriptionsstops referencing the originalISubscriptionwithout unsubscribing it, so the first open's listener stays attached next to the replacement. Its generation is stale, so each frame reaches subscribers exactly once and nothing is lost. In production a reconnect replaces the transport, so the leftover listener dies with the old socket.isSnapshot: true) after the initial snapshot, which is the shape the E2E mock pushes. Each push reaches subscribers as(fills, true), and the cache holds the fill without duplicating it.To check that the tests can actually catch a failure, I removed the frame generation guard. Three of the new tests failed, then passed again once the guard was restored.
CI logs from the failing runs (MetaMask/metamask-extension runs 41977292884 and 41979580026) also point away from core. Passing and failing attempts have identical perps WebSocket traffic:
userFillssubscribe, sent on the second connectionunsubscribe, extra subscribe, or reconnect during the testWith stable wire traffic, core has nothing that would change the generation, so the frame callback stays live. The loss is therefore downstream, in the extension's
PerpsStreamBridgeorPerpsStreamManager.References
Checklist
Note
Low Risk
Test-only additions to the perps-controller suite; no runtime or consumer-facing behavior changes.
Reviewed by Cursor Bugbot for commit 9bf9231. Bugbot is set up for automated code reviews on this repo. Configure here.