getMessage() returns { conversation: '' } on miss — Baileys relays an empty message and burns the retry, leaving "Waiting for this message" forever
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, typescript
Research direction
Start in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts and trace getMessage plus its seven call sites. Verify the missing-row path and how the Baileys getMessage option handles a falsy result, then check the retry lookup query and its suggested index. Done means missing messages are not relayed or treated as real messages, and the lookup is addressed as intended.
Written by the indexing model from the issue text.
Description
What happened
getMessage() returns { conversation: '' } when the message is not found. Baileys treats any
truthy return as "message found", so it relays an empty message and consumes one of the retry
attempts. On the recipient's phone the message becomes a permanent
"Waiting for this message. This may take a moment." placeholder — the retry that was supposed to
recover it delivered an empty envelope instead.
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts (still on main today):
private async getMessage(key: proto.IMessageKey, full = false) {
try {
const webMessageInfo = (await this.prismaRepository.$queryRaw`
SELECT * FROM "Message"
WHERE "instanceId" = ${this.instanceId} AND "key"->>'id' = ${key.id}
`) as proto.IWebMessageInfo[];
if (full) return webMessageInfo[0];
...
return webMessageInfo[0].message;
} catch {
return { conversation: '' }; // <-- row not found => webMessageInfo[0] is undefined
} // => `.message` throws => empty text is returned
}
Baileys, Socket/messages-recv.js:
if (msg && (await willSendMessageAgain(ids[i], participant))) {
updateSendMessageAgainCount(ids[i], participant); // burns 1 of maxMsgRetryCount (4)
await relayMessage(key.remoteJid, msg, msgRelayOpts);
} else {
logger.debug({ jid: key.remoteJid, id: ids[i] }, 'recv retry request, but message not available');
}
Returning undefined instead makes Baileys take the else branch: no attempt is consumed and
nothing is sent, so the peer can ask again and gets the real message once the row is committed.
Why the row can be missing
sendMessageWithTyping persists the row after the send, after the Chatwoot integration
round-trip and, for media, after writing the media file — while retryRequestDelayMs is 350 ms.
Baileys' in-memory recent-message cache (512 entries) usually covers this, but it is lost on every
socket restart, so after a reconnect or a re-pair the DB path is the only one left. That is exactly
when a burst of retries happens (a re-pair invalidates every peer's session), so the failure
concentrates precisely where it hurts most.
We saw this in production right after a QR re-pair: group media sent 4 minutes later reached every
participant as the "Waiting for this message" placeholder, permanently.
Suggested fix
} catch (error) {
this.logger.warn(`getMessage failed for ${key.id}: ${error}`);
return undefined;
}
All 7 call sites of this.getMessage( already handle a falsy return — and four of them get
strictly better, because today they silently receive a fake message and carry on:
| call site | current handling |
|---|---|
Baileys getMessage option |
if (msg && ...) — relays the empty message |
messages.edit |
f?.id |
| poll updates | h && (...) — aggregates votes against a fake message |
| quoted message | S && (c = S) — quotes an empty message |
getBase64FromMediaMessage |
if (!n) throw 'Message not found' — never reached today |
formatUpdateMessage |
t?.messageType |
updateMessage |
if (!i) throw new BadRequestException('Message not found') — never reached today |
Also worth noting: the retry lookup filters on "key"->>'id', and there is no index for it — it is
a sequential scan of Message on every retry. Adding
("instanceId", (("key"->>'id'))) took the query from 9.76 ms to 0.158 ms on a 15.8k-row table
here, and it only gets worse as the table grows.
Version
v2.3.6, self-hosted, Postgres, Chatwoot integration enabled.
- Dominant language
- TypeScript
- Stars
- 9.7k
- Forks
- 7.3k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from evolution-foundation/evolution-api
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
evolution-foundation/evolution-api#2723 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
evolution-foundation/evolution-api#2704 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
evolution-foundation/evolution-api#2702 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
evolution-foundation/evolution-api#2700 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
evolution-foundation/evolution-api#2675 ·
Maintainers usually reply within 1 day
All issues in evolution-foundation/evolution-api
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
supabase/agent-skills#611 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
polka-codes/test#345 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 92/100
GoogleChromeLabs/project-sesame#217 ·
Maintainers usually reply within 12 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
solana-foundation/solana-com#2202 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100