fix(perps): correct CUF trace lifecycle and tags - #33562
Conversation
|
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. |
🧪 Flaky unit test detectionRun history flaky detectionHistorical failure rate is a hint, not proof — review each suggestion in context. See the flaky-test-detection skill for the full pattern reference and manual audit workflow. Failures / runs sampled per window:
AI-detected flaky patterns
|
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
These changes are internal to Perps measurement/tracing infrastructure. While they don't change user-visible behavior directly, they touch SmokePerps is selected as the primary tag since all changes are Perps-specific. Performance Test Selection: |
|
⚡ Performance Test Results
❌ 1 test failed · 2 tests · 1 device 📱 Devices tested (1)Android: Google Pixel 8 Pro (v14.0) ❌ Failed Tests (1)@mm-perps-engineering-team
✅ Passed Tests (1)
Branch: |



Description
usePerpsMeasurementleft a manual Sentry trace active when its view unmounted before readiness. This adds a mount-lifetime cleanup that ends only that hook instance's active trace once assuccess: falsewith reasonunmounted.It also adds the shared
featureandlifecycle_contexttags to the live-proven first-price direct/prewarm and first-order-book WebSocket trace starts.Failed reconnect traces now preserve
background_resumeuntil a later successful foreground-settling span, so a replacement reconnect retains the correct lifecycle context.Changelog
CHANGELOG entry: null
Related issues
Fixes: No linked public issue; isolated H1/H2/H3 telemetry-integrity findings.
Manual testing steps
Validation performed:
success=false reason=unmountedend.feature=perpsandlifecycle_context=warm.background_resume→ failed/disconnected completion →warm→ second startwarm.background_resume→ failed/disconnected completion →background_resume→ second startbackground_resume.xreview-mobile-h1-cuf-claude.Screenshots/Recordings
Before
N/A — these are non-visual telemetry fixes. Real Hermes boundary proof reproduced the leaked H3 trace, empty-tag H1 requests, and premature H2 foreground settlement.
After
N/A — no visible UI change. Real Hermes after-runs proved the H3 abandonment classification, corrected H1 tags, and retained H2
background_resumecontext across failed reconnect replacement.Pre-merge author checklist
Performance checks (if applicable)
Pre-merge reviewer checklist
Note
Low Risk
Observability-only changes to Perps trace lifecycle and tags; no auth, payments, or user-facing UI behavior.
Overview
Fixes Perps CUF / Sentry telemetry so spans close correctly and start with consistent tags.
usePerpsMeasurementnow runs unmount cleanup: if a manual trace is still open when the hook’s view unmounts, it ends once withsuccess: falseandreason: 'unmounted'(no double-end after success or reset).activeTraceNameis stored when a trace starts so cleanup uses the right span name.PerpsStreamManagerattachesbuildPerpsCufStartTags()(feature,lifecycle_context) when starting first-price (subscribe + prewarm) and first-order-book WebSocket traces.endPerpsCufTraceonly callssettlePerpsForegroundOnSpanwhen the end payload is not explicitly failed (success !== false), so a failed reconnect keepsbackground_resumeuntil a later successful foreground-settling span.Tests cover unmount behavior, WebSocket trace tags, and reconnect success vs failure lifecycle.
Reviewed by Cursor Bugbot for commit 49517da. Bugbot is set up for automated code reviews on this repo. Configure here.