Skip to content

Comments

fix(connect-multichain): clean up MWP session on connection rejection#180

Merged
jiexi merged 3 commits intomainfrom
ad/fix-rejection-stale-session-stored
Feb 20, 2026
Merged

fix(connect-multichain): clean up MWP session on connection rejection#180
jiexi merged 3 commits intomainfrom
ad/fix-rejection-stale-session-stored

Conversation

@adonesky1
Copy link
Contributor

Summary

  • Fix stale MWP session persisting in KVStore after user rejects a QR code connection in the wallet, which prevented subsequent connection attempts

Problem

When connecting via QR code, the MWP handshake completes and stores a session:{id} entry in the KVStore before the wallet responds to wallet_createSession. If the user then rejects the connection in the wallet:

  1. rejectConnection() is called in initialConnectionMessageHandler, but dappClient.disconnect() is never called
  2. dappClient.disconnect() is the only method that calls sessionstore.delete(session.id) to remove the session from the KVStore
  3. The stale session remains in storage indefinitely
  4. On the next connection attempt, getActiveSession() finds this stale session and enters the resume branch — trying to resume a session the wallet already rejected
  5. The resume either hangs or times out, blocking the user from connecting

Fix

Call dappClient.disconnect() in MWPTransport.connect()'s catch handler so that any connection failure (rejection, timeout, etc.) properly cleans up the dappClient session from the KVStore. The .catch(() => {}) on disconnect ensures cleanup errors don't mask the original connection error.

Test plan

  • Initiate a QR code connection from the dapp
  • Scan the QR code with the MetaMask wallet
  • Reject the connection in the wallet
  • Verify the rejection error propagates to the dapp
  • Initiate a new QR code connection — it should show a fresh QR code and not hang/timeout
  • Accept the second connection and verify it completes successfully

@adonesky1 adonesky1 requested a review from a team as a code owner February 20, 2026 19:53
When a user rejects a QR code connection in the wallet, the MWP
handshake has already completed and stored a session in the KVStore.
Without calling dappClient.disconnect(), the stale session persists
and causes subsequent connection attempts to enter the resume path
with a rejected session, resulting in a timeout.
@adonesky1 adonesky1 force-pushed the ad/fix-rejection-stale-session-stored branch from cefe0f5 to b094194 Compare February 20, 2026 20:02
@jiexi jiexi merged commit a77dfd8 into main Feb 20, 2026
51 checks passed
@jiexi jiexi deleted the ad/fix-rejection-stale-session-stored branch February 20, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants