Skip to content

chore(runway): cherry-pick fix(perps): fix stale data and missing price change after reconnection cp-7.70.1#27826

Merged
joaoloureirop merged 1 commit into
release/7.70.1from
runway-cherry-pick-7.70.1-1774297014
Mar 23, 2026
Merged

chore(runway): cherry-pick fix(perps): fix stale data and missing price change after reconnection cp-7.70.1#27826
joaoloureirop merged 1 commit into
release/7.70.1from
runway-cherry-pick-7.70.1-1774297014

Conversation

@runway-github
Copy link
Copy Markdown
Contributor

@runway-github runway-github Bot commented Mar 23, 2026

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.

[1bf5d78](https://github.com/MetaMask/metamask-mobile/commit/1bf5d785381031f824a1abc652368a7ba7d6da15)

…ce change after reconnection (#27530)

## **Description**

Two fixes for perps foreground reconnection:

1. **Stale data after background** — `connect()` 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**

```gherkin
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**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

<!-- CURSOR_SUMMARY -->
---

> [!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.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
1549f85. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@runway-github runway-github Bot requested a review from a team as a code owner March 23, 2026 20:17
@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.

@metamaskbot metamaskbot added the team-bots Bot team (for MetaMask Bot, Runway Bot, etc.) label Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - base branch is not main (base: release/7.70.1)

All E2E tests pre-selected.

View GitHub Actions results

@joaoloureirop joaoloureirop enabled auto-merge (squash) March 23, 2026 20:24
@sonarqubecloud
Copy link
Copy Markdown

@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

@joaoloureirop joaoloureirop merged commit dff0679 into release/7.70.1 Mar 23, 2026
107 checks passed
@joaoloureirop joaoloureirop deleted the runway-cherry-pick-7.70.1-1774297014 branch March 23, 2026 21:11
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size-M team-bots Bot team (for MetaMask Bot, Runway Bot, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants