Skip to content

fix(perps): fix stale data and missing price change after reconnection cp-7.70.1#27530

Merged
abretonc7s merged 6 commits into
mainfrom
fix/perps/connection-investigation
Mar 18, 2026
Merged

fix(perps): fix stale data and missing price change after reconnection cp-7.70.1#27530
abretonc7s merged 6 commits into
mainfrom
fix/perps/connection-investigation

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Description

Two fixes for perps foreground reconnection:

  1. Stale data after backgroundconnect() returned early when isConnected=true (grace period kept state alive) without checking if the WebSocket was dead. Fixed by adding ensureConnected() that always forces disconnect + reconnect on foreground return.

  2. Price change "–%" persists after reconnect — Prewarm called subscribeToPrices() without includeMarketData, so assetCtxs subscriptions (which provide prevDayPx for percentChange24h) were never re-established. Fixed by moving the assetCtxs subscription out of the includeMarketData guard in subscribeToPrices(). This is safe because assetCtxs is 1 subscription per DEX (2-3 total), not per-symbol. The expensive per-symbol activeAssetCtx subscriptions remain gated behind includeMarketData.

Changelog

CHANGELOG entry: Fixed stale perps data and missing 24h price change after returning from background

Related issues

Fixes:

Manual testing steps

Feature: Perps foreground reconnection

  Scenario: user returns after short background (grace period still active)
    Given user is on Perps screen with live data
    When user backgrounds app for 10s and returns
    Then data refreshes with live prices and positions
    And 24h price change % displays correctly (not "--%" )

  Scenario: user returns after long background (grace period already fired)
    Given user is on Perps screen with live data
    When user backgrounds app for 60s and returns
    Then data refreshes with live prices and positions
    And 24h price change % displays correctly (not "--%" )

  Scenario: initial mount unchanged
    Given user opens app fresh
    When user navigates to Perps
    Then connection establishes normally via connect()
    And 24h price change % displays correctly

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Touches perps WebSocket lifecycle and subscription behavior; regressions could cause extra reconnects or missed/duplicated subscriptions, though changes are scoped and covered by updated tests.

Overview
Fixes perps reconnection reliability by switching foreground handling from connect() to a new PerpsConnectionManager.ensureConnected() that cancels any grace period, force-disconnects, resets ref-count, and reconnects, deduplicating concurrent calls.

Restores 24h % change after reconnection/prewarm by ensuring HyperLiquidSubscriptionService.subscribeToPrices() always establishes lightweight per-DEX assetCtxs subscriptions even when includeMarketData is false; price prewarm explicitly passes includeMarketData: false and documents the N² connection risk.

Updates unit tests and architecture docs to reflect ensureConnected() usage and the new subscription expectations.

Written by Cursor Bugbot for commit 1549f85. This will update automatically on new commits. Configure here.

After backgrounding 30-60s, market data/positions/prices stayed frozen
because connect() returned early when isConnected was still true from
the grace period. Added ensureConnected() which always does disconnect +
connect regardless of cached state, and call it from
PerpsAlwaysOnProvider on foreground return.
@abretonc7s abretonc7s added type-bug Something isn't working team-perps Perps team labels Mar 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk size-M labels Mar 17, 2026
@abretonc7s abretonc7s marked this pull request as ready for review March 17, 2026 12:38
@abretonc7s abretonc7s requested a review from a team as a code owner March 17, 2026 12:38
Comment thread app/components/UI/Perps/services/PerpsConnectionManager.ts
…e24h

Move assetCtxs subscription out of the includeMarketData guard in
subscribeToPrices() so it always runs for all DEXes. This ensures
prevDayPx is available after WebSocket reconnection, fixing the
persistent "--%" display for 24h price change.

assetCtxs is 1 subscription per DEX (lightweight), unlike
activeAssetCtx which is per-symbol (expensive). Prewarm uses
incrementRefCount: false so lifecycle stays managed by component
subscriptions. Reverts includeMarketData: true from prewarm call
to avoid N² WebSocket connections.
@abretonc7s abretonc7s changed the title fix(perps): force fresh reconnect on foreground to fix stale data fix(perps): fix stale data and missing price change after reconnection Mar 17, 2026
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 17, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 17, 2026
…onnect

performActualDisconnection() silently skips when connectionRefCount > 0.
When ensureConnected() is called without a preceding disconnect(), the
refCount guard prevents teardown and connect() returns early on
isConnected=true — the stale WebSocket persists.

Add force option to performActualDisconnection() and use it from
ensureConnected() so the disconnect always happens regardless of
how many components hold references.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread app/components/UI/Perps/services/PerpsConnectionManager.test.ts
gambinish
gambinish previously approved these changes Mar 17, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 18, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.19%. Comparing base (3456a82) to head (fd957a5).
⚠️ Report is 129 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27530      +/-   ##
==========================================
+ Coverage   81.97%   82.19%   +0.21%     
==========================================
  Files        4754     4788      +34     
  Lines      123695   123510     -185     
  Branches    27353    27366      +13     
==========================================
+ Hits       101404   101517     +113     
+ Misses      15285    14962     -323     
- Partials     7006     7031      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@metamaskbot metamaskbot removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 18, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 18, 2026
Reset connectionRefCount to 0 before connect() in ensureConnected to
prevent drift across repeated background/foreground cycles. Add
concurrency guard to deduplicate rapid foreground transitions.
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 18, 2026
@abretonc7s abretonc7s enabled auto-merge March 18, 2026 10:42
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
All changes are scoped to the Perps feature: PerpsAlwaysOnProvider, PerpsStreamManager, PerpsConnectionManager, and HyperLiquidSubscriptionService (controller-level service). These components manage streaming connections, subscriptions, and lifecycle handling for perpetuals trading on Arbitrum. This directly impacts the Perps trading flows (market loading, streaming updates, Add Funds deposits).

According to the tag rules:

  • SmokePerps is required because the changes affect core Perps providers and controller services used in the Perps trading experience.
  • SmokePerps requires also selecting SmokeWalletPlatform (Perps is embedded in the Trending section and wallet platform integration).
  • SmokePerps requires also selecting SmokeConfirmations because Add Funds deposits are on-chain transactions that go through the confirmations UI.

No evidence of impact to accounts, SRP, identity sync, network abstraction layer, multi-chain API, snaps, ramps, card, swaps, or predictions. Therefore those tags are not selected to minimize scope while maintaining safety.

Risk is medium because changes affect connection management and subscription services that could disrupt Perps market data, balance updates, or deposit flows, but are feature-scoped rather than core Engine-wide changes.

Performance Test Selection:
Changes modify PerpsAlwaysOnProvider, stream manager, connection manager, and HyperLiquidSubscriptionService, which directly influence streaming updates, market data loading, and connection lifecycle. These can affect Perps market loading time, balance updates, and add-funds responsiveness. Running @PerformancePreps ensures no regression in perps market rendering and trading performance.

View GitHub Actions results

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
16 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@abretonc7s abretonc7s added this pull request to the merge queue Mar 18, 2026
Merged via the queue into main with commit 1bf5d78 Mar 18, 2026
100 checks passed
@abretonc7s abretonc7s deleted the fix/perps/connection-investigation branch March 18, 2026 13:16
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 18, 2026
@metamaskbot metamaskbot added the release-7.71.0 Issue or pull request that will be included in release 7.71.0 label Mar 18, 2026
@gambinish gambinish changed the title fix(perps): fix stale data and missing price change after reconnection fix(perps): fix stale data and missing price change after reconnection cp-7.70.1 Mar 23, 2026
@chloeYue chloeYue changed the title fix(perps): fix stale data and missing price change after reconnection cp-7.70.1 fix(perps): fix stale data and missing price change after reconnection cp-7.70.1 cp-7.71.0 Mar 23, 2026
@chloeYue chloeYue changed the title fix(perps): fix stale data and missing price change after reconnection cp-7.70.1 cp-7.71.0 fix(perps): fix stale data and missing price change after reconnection cp-7.70.1 Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.71.0 Issue or pull request that will be included in release 7.71.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-perps Perps team type-bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants