getMessage() returns { conversation: '' } on miss — Baileys relays an empty message and burns the retry, leaving "Waiting for this message" forever
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 76/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- postgresql, typescript
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- TypeScript
- Estrelas
- 9.7k
- Forks
- 7.3k
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de evolution-foundation/evolution-api
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
evolution-foundation/evolution-api#2723 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 88/100
evolution-foundation/evolution-api#2704 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
evolution-foundation/evolution-api#2702 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
evolution-foundation/evolution-api#2700 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
evolution-foundation/evolution-api#2675 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de evolution-foundation/evolution-api
Issues semelhantes
-
bug via-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
pingdotgg/t3code#14452 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
solana-foundation/program-examples#747 · 1 comentário ·
Mantenedores costumam responder em até 9 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
remotion-dev/remotion#11847 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
openwatersio/slackwater#355 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
melgarafael/DeskcommCRM#1998 · 3 comentários ·
Mantenedores costumam responder em até 1 dia