Problem
When the Baileys connection closes, index.js calls startBot() immediately. There is no reconnect guard or in-flight state, so repeated close events can start multiple sockets at the same time. Multiple sockets may compete for the same auth files, QR server, and message events.
Expected behavior
A disconnect should result in one controlled reconnect attempt for the bot.
Suggested direction
Track whether a reconnect is already running, or centralize socket creation behind a small reconnect loop. Preserve the logged-out behavior that asks whether the auth directory should be deleted.
Acceptance criteria
- Repeated close events do not create overlapping sockets.
- A normal transient disconnect still reconnects automatically.
- Logged-out sessions retain the existing prompt and cleanup behavior.
- The reconnect state is reset after a successful connection or a terminal logout.
Problem
When the Baileys connection closes,
index.jscallsstartBot()immediately. There is no reconnect guard or in-flight state, so repeated close events can start multiple sockets at the same time. Multiple sockets may compete for the same auth files, QR server, and message events.Expected behavior
A disconnect should result in one controlled reconnect attempt for the bot.
Suggested direction
Track whether a reconnect is already running, or centralize socket creation behind a small reconnect loop. Preserve the logged-out behavior that asks whether the auth directory should be deleted.
Acceptance criteria