Describe the bug
I am experiencing a critical session handling bug with the latest version of Baileys (v6.7.19). The bug is 100% reproducible and causes the bot to fail to send replies after the first successful message exchange in a new session.
To Reproduce
Steps to reproduce the behavior:
- Start with a completely clean session (delete the entire auth_info_baileys folder).
- Start the bot and scan the new QR code to link a new device.
- Send the first message from a user phone (specifically an iPhone) to the bot.
- Result: The bot correctly receives and decrypts the message, processes it, and sends a reply. The reply is successfully received on the user's iPhone.
- Send a second message from the same iPhone.
Expected behavior
The bot should receive the second message and successfully send a reply.
Actual Behavior:
The bot receives and processes the second message correctly. However, when it tries to send the reply, it fails.
- The console logs Closing stale open session for new outgoing prekey bundle and dumps the session data. The reply is never sent.
- On the user's iPhone, when they send a third message, the "Waiting for message..." placeholder appears, as the session is now completely broken.
Environment (please complete the following information):
- Server Ubuntu
- What do your
connectOptions look like?
-
``` const { version, isLatest } = await fetchLatestBaileysVersion()
console.log(`using WA v${version.join('.')}, isLatest: ${isLatest} `)
const { state, saveCreds } = await useMultiFileAuthState(path.resolve(basicURI, "cache", "auth_info_baileys"));
this.sock = makeWASocket({
version,
auth: state,
printQRInTerminal: false,
getMessage: this.cacheService.getMensajeAConfirmar.bind(this.cacheService),
shouldSyncHistoryMessage: (_msg: any) => false,
syncFullHistory: false,
});```
- Do you have multiple clients on the same IP? NO
- Are you using a proxy? NO
Additional context
- This issue seems to be specific to client phones running iOS (iPhone). I have tested with Android clients and the conversation works correctly.
- The WhatsApp account being used for the bot is new (created last month). I have another bot with an older WhatsApp account that works correctly with the same iPhone client, which suggests the issue might be related to how new accounts handle sessions.
- The pattern is perfectly reproducible. Deleting the specific session-{jid}.json file for the iPhone contact allows the first message to work again, but the second reply always fails.
- This issue persists across multiple Baileys versions (I've tested about 3 up to v6.7.19)
Here is the log snippet that appears when the bot tries to send the reply to the second message:
Closing session: SessionEntry {
_chains: {
BZrbvffEH2X49pr2WDqZDIt94RQOfkLBMtWIMSj99Wx8: { chainKey: [Object], chainType: 1, messageKeys: {} }
},
registrationId: 388033131,
currentRatchet: {
ephemeralKeyPair: {
pubKey: <Buffer ...>,
privKey: <Buffer ...>
},
...
},
...
}```
Describe the bug
I am experiencing a critical session handling bug with the latest version of Baileys (v6.7.19). The bug is 100% reproducible and causes the bot to fail to send replies after the first successful message exchange in a new session.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The bot should receive the second message and successfully send a reply.
Actual Behavior:
The bot receives and processes the second message correctly. However, when it tries to send the reply, it fails.
Environment (please complete the following information):
connectOptionslook like?Additional context
Here is the log snippet that appears when the bot tries to send the reply to the second message: