fix(perps): fix stale data and missing price change after reconnection cp-7.70.1#27530
Conversation
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.
|
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. |
…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.
…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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Reset connectionRefCount to 0 before connect() in ensureConnected to prevent drift across repeated background/foreground cycles. Add concurrency guard to deduplicate rapid foreground transitions.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: According to the tag rules:
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: |
|
✅ E2E Fixture Validation — Schema is up to date |
|




Description
Two fixes for perps foreground reconnection:
Stale data after background —
connect()returned early whenisConnected=true(grace period kept state alive) without checking if the WebSocket was dead. Fixed by addingensureConnected()that always forces disconnect + reconnect on foreground return.Price change "–%" persists after reconnect — Prewarm called
subscribeToPrices()withoutincludeMarketData, soassetCtxssubscriptions (which provideprevDayPxforpercentChange24h) were never re-established. Fixed by moving theassetCtxssubscription out of theincludeMarketDataguard insubscribeToPrices(). This is safe becauseassetCtxsis 1 subscription per DEX (2-3 total), not per-symbol. The expensive per-symbolactiveAssetCtxsubscriptions remain gated behindincludeMarketData.Changelog
CHANGELOG entry: Fixed stale perps data and missing 24h price change after returning from background
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
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 newPerpsConnectionManager.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-DEXassetCtxssubscriptions even whenincludeMarketDatais false; price prewarm explicitly passesincludeMarketData: falseand 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.