diff --git a/src/wasp.ts b/src/wasp.ts index f0a8ad4..83cf302 100644 --- a/src/wasp.ts +++ b/src/wasp.ts @@ -574,6 +574,19 @@ 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 { + // listeners may already be detached; safe to ignore + } + this.activeSessions.delete(sessionId); + } + await this.emitEvent({ type: 'SESSION_DISCONNECTED' as EventType, sessionId,