Skip to content

fix(perps): address bugbot findings from core PR #7941#26474

Merged
abretonc7s merged 9 commits intomainfrom
fix/perps/bugbot-core-7941
Feb 25, 2026
Merged

fix(perps): address bugbot findings from core PR #7941#26474
abretonc7s merged 9 commits intomainfrom
fix/perps/bugbot-core-7941

Conversation

@abretonc7s
Copy link
Contributor

@abretonc7s abretonc7s commented Feb 24, 2026

Description

Addresses 5 confirmed Bugbot findings from Core PR #7941.

What changed

  1. Missing 'canceled' spelling — deposit+order .catch() only checked 'cancelled', not 'canceled'
  2. Cancelled deposits stay pending — non-placeOrder cancellation cleared UI state but left the deposit request as 'pending'
  3. Stale activeProviderInstance after disconnect — standalone reads could route through a disconnected provider
  4. Disconnect skips preload teardown — preload timer and messenger subscriptions were not stopped, causing background work during teardown
  5. Analytics side effect inside immer producertrackPerpsEvent() and #debugLog() moved out of this.update()

Disconnect design note

Fix 4 inlines the preload cleanup logic from stopMarketDataPreload() rather than calling it directly, because stopMarketDataPreload() calls #cleanupStandaloneProvider() fire-and-forget, while disconnect() needs the awaited version to prevent races with reconnection.

Changelog

CHANGELOG entry: null

Related issues

Fixes: Bugbot findings on MetaMask/core#7941

Manual testing steps

Feature: Perps deposit cancellation and disconnect cleanup

  Scenario: user cancels a deposit transaction
    Given user is on the Perps deposit screen with a pending deposit

    When user rejects the transaction in the wallet prompt
    Then the deposit request status should be 'cancelled' (not stuck as 'pending')

  Scenario: user disconnects from Perps
    Given user is on Perps screens with active market data preload

    When user navigates away triggering disconnect
    Then preload timer is stopped, provider instance is nulled, and no stale subscriptions remain

Screenshots/Recordings

N/A — internal controller logic, no UI changes.

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 deposit/withdrawal status transitions and disconnect teardown ordering, which can affect transaction UX, metrics emission, and background polling behavior if regressions occur.

Overview
Fixes several PerpsController lifecycle edge cases around deposits, withdrawals, and teardown.

Deposit tracking now correctly treats both cancelled and canceled error strings as user cancellation, and ensures non-order deposit cancellations update the corresponding depositRequests entry to cancelled instead of leaving it pending.

updateWithdrawalStatus no longer performs analytics/logging side-effects inside the this.update() immer producer; it computes whether tracking/logging is needed during the state update and runs trackPerpsEvent/#debugLog afterward.

disconnect() now proactively stops market-data preload intervals and unsubscribes messenger listeners, resets cached preload config, clears activeProviderInstance to avoid stale routing, and awaits standalone-provider cleanup. A new unit test asserts preload work does not continue after disconnect.

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

- Add missing 'canceled' spelling in deposit+order cancellation check
- Mark cancelled deposits as 'cancelled' in persisted state
- Null activeProviderInstance on disconnect to prevent stale reads
- Tear down preload timer and subscriptions in disconnect()
- Move analytics/debug side effects out of immer producer
@abretonc7s abretonc7s requested a review from a team as a code owner February 24, 2026 13:02
@github-actions
Copy link
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.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
70.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Only log "Updated withdrawal status" when a matching withdrawal
was actually found and mutated.
aganglada
aganglada previously approved these changes Feb 24, 2026
Aligns with the invariant that status and success are always
set together on deposit request updates.
Copy link

@cursor cursor bot left a comment

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.

abretonc7s and others added 4 commits February 25, 2026 10:01
…ateWithdrawalStatus

The debugLog call was accidentally placed inside the shouldTrack guard
when side effects were moved out of the immer producer, causing it to
only log on status changes. Restore original behavior by logging
whenever a matching withdrawal is found.
Cover the new preload timer/subscription teardown branches
in disconnect() to reach 100% new code coverage.
@github-actions github-actions bot added size-M and removed size-S labels Feb 25, 2026
@abretonc7s abretonc7s enabled auto-merge February 25, 2026 12:26
@github-actions
Copy link
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:
The changes are isolated to the PerpsController, which is a Phase 6 (business logic) controller for perpetuals trading. The changes include:

  1. Deposit cancellation fix: Properly marks deposit requests as 'cancelled' when user cancels the transaction
  2. Spelling variant handling: Added "canceled" (American spelling) to cancellation detection
  3. Withdrawal tracking refactor: Moved analytics tracking outside of state update callback for better code quality
  4. Resource cleanup improvement: Added proper cleanup of preload subscriptions during disconnect to prevent memory leaks and stale references

These are bug fixes and code quality improvements that affect the Perps deposit/withdrawal flows. The PerpsController is not integrated into the core Engine but is a standalone feature controller. The changes don't affect initialization order, messenger configuration, or state schema.

Per the tag descriptions:

  • SmokePerps: Directly tests perpetuals trading including Add Funds flow (deposits) and balance verification
  • SmokeWalletPlatform: Perps is a section inside the Trending tab, so changes to Perps views affect Trending
  • SmokeConfirmations: Add Funds deposits are on-chain transactions requiring confirmations

Performance Test Selection:
The changes affect the PerpsController's disconnect and cleanup logic, including preload subscription cleanup and withdrawal status tracking. These changes could impact the performance of the perps feature, particularly around resource management and state updates. The @PerformancePreps tag covers perps market loading, position management, add funds flow, and order execution - all areas potentially affected by these changes.

View GitHub Actions results

@abretonc7s abretonc7s added this pull request to the merge queue Feb 25, 2026
Merged via the queue into main with commit c784084 Feb 25, 2026
100 of 101 checks passed
@abretonc7s abretonc7s deleted the fix/perps/bugbot-core-7941 branch February 25, 2026 13:28
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2026
@metamaskbot metamaskbot added the release-7.68.0 Issue or pull request that will be included in release 7.68.0 label Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.68.0 Issue or pull request that will be included in release 7.68.0 size-M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants