From c9ceab2ae935b68da5b8b0988e4569a07bd0617a Mon Sep 17 00:00:00 2001 From: root Date: Sat, 2 May 2026 13:12:15 +0200 Subject: [PATCH 1/2] fix: evict activeSessions on provider disconnect Provider 'disconnected' event left the session entry in activeSessions, so consumer reconnect via createSession() threw "Session already exists" and the connection stayed dropped until process restart. Now remove the entry (and detach listeners) before re-emitting SESSION_DISCONNECTED, so callers can recreate cleanly on transient drops (Baileys reason -1, 515, 503). Co-Authored-By: Claude Opus 4.7 (1M context) --- src/wasp.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/wasp.ts b/src/wasp.ts index f0a8ad4..96dcaa0 100644 --- a/src/wasp.ts +++ b/src/wasp.ts @@ -574,6 +574,17 @@ export class WaSP extends EventEmitter { status: 'DISCONNECTED' as SessionStatus, }); + // Evict from activeSessions so consumer can call createSession() to reconnect. + // Without this, transient drops (Baileys reason -1, 515, 503) leave a zombie + // entry that blocks reconnect with "Session already exists". + const entry = this.activeSessions.get(sessionId); + if (entry) { + try { + entry.provider.events.removeAllListeners(); + } catch {} + this.activeSessions.delete(sessionId); + } + await this.emitEvent({ type: 'SESSION_DISCONNECTED' as EventType, sessionId, From 416490a7b3fba6eda6919031ca28d5d270f50258 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 2 May 2026 13:18:32 +0200 Subject: [PATCH 2/2] fix: appease no-empty lint on disconnect catch Co-Authored-By: Claude Opus 4.7 (1M context) --- src/wasp.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wasp.ts b/src/wasp.ts index 96dcaa0..83cf302 100644 --- a/src/wasp.ts +++ b/src/wasp.ts @@ -581,7 +581,9 @@ export class WaSP extends EventEmitter { if (entry) { try { entry.provider.events.removeAllListeners(); - } catch {} + } catch { + // listeners may already be detached; safe to ignore + } this.activeSessions.delete(sessionId); }