evolution-api icon indicating copy to clipboard operation
evolution-api copied to clipboard

[BUG] Inbound messages received by Baileys are not emitted as MESSAGES_UPSERT webhooks; instance gets stuck and cannot be deleted until restart

Open denetha478 opened this issue 4 months ago • 6 comments

Welcome!

  • [x] Yes, I have searched for similar issues on GitHub and found none.

What did you do?

We are running Evolution API in production using a Baileys WhatsApp instance with webhook integration to n8n.

The system works normally for most messages. However, after the instance runs for some time, some inbound customer messages become visible in the WhatsApp mobile app but do not trigger a MESSAGES_UPSERT webhook.

To debug this, we enabled trace logging:

LOG_LEVEL=TRACE
LOG_BAILEYS=trace
LOG_COLOR=false

Then we compared the same affected message time windows across:

  • WhatsApp mobile app message timestamps
  • Evolution/Baileys container logs
  • Reverse proxy logs
  • n8n execution logs

We found multiple cases where the inbound message reached the Evolution/Baileys layer, but no webhook POST was sent to n8n.

We also noticed that around the same time this starts happening, Evolution Manager sometimes fails to delete the affected instance and shows:

Error: [object Object]

After restarting only the evolution-api container, the delete action works again.

If we delete and reconnect a fresh instance, webhook delivery becomes stable again for a few days, then the issue returns.

What did you expect?

Every inbound WhatsApp text message received by the Baileys socket should emit a normal MESSAGES_UPSERT webhook to the configured webhook URL.

If Evolution cannot process or emit the message, it should log a clear error explaining why the webhook was not emitted.

The instance should also remain manageable from Evolution Manager. Actions like delete/logout should not fail while the instance is shown as connected.

What did you observe instead of what you expected?

Some inbound WhatsApp messages are visible in the WhatsApp mobile app, but Evolution does not emit a MESSAGES_UPSERT webhook for those messages.

For affected messages:

  • No HTTP POST reaches the reverse proxy
  • No n8n execution is created
  • No downstream chat history row is created
  • Sometimes the message appears in Evolution/Baileys logs as a raw packet
  • Sometimes the message is even parsed/readable in Evolution logs, but still no webhook is dispatched
  • Sometimes the message appears later through a delayed/raw/sync-like path, but still no webhook is emitted

We observed these patterns:

Pattern 1: Message readable in Evolution logs, but no webhook

A customer sent:

Please place the order

Evolution/Baileys logs showed a readable message object:

remoteJid: [email protected]
remoteJidAlt: [email protected]
conversation: "Please place the order"

But during the same time window:

No messages.upsert event
No webhook dispatch log
No HTTP POST in reverse proxy logs
No n8n execution

Pattern 2: Raw encrypted packet received, but no readable conversation and no webhook

Another affected message appeared as:

<message from="REDACTED_LID@lid" type="text" id="REDACTED_MESSAGE_ID" notify="REDACTED_NAME" sender_pn="[email protected]">
  <enc v="2" type="pkmsg">REDACTED_ENCRYPTED_PAYLOAD</enc>
</message>

Then Evolution logged PN/LID mapping and device/session activity, but no readable conversation: object and no webhook.

Pattern 3: Message appears later in logs but never emits webhook

One customer message was visible in WhatsApp at the original send time. Evolution did not emit a webhook at that time.

Around one hour later, Evolution logs showed the same message ID and sender number in a raw/sync-like path:

<message from="REDACTED_LID@lid"
         type="text"
         id="REDACTED_MESSAGE_ID"
         offline="0"
         notify="REDACTED_NAME"
         sender_pn="[email protected]"
         t="REDACTED_TIMESTAMP">
  <url_number />
  <unavailable />
</message>

The same message ID later appeared again with encrypted content:

<message from="REDACTED_LID@lid"
         type="text"
         id="REDACTED_MESSAGE_ID"
         sender_pn="[email protected]">
  <enc v="2" type="pkmsg">REDACTED_ENCRYPTED_PAYLOAD</enc>
</message>

But again there was:

No readable conversation
No messages.upsert webhook
No HTTP POST to n8n

Around the same period, Evolution Manager sometimes cannot delete the instance and shows:

Error: [object Object]

After restarting the evolution-api container, the delete action works again.

Screenshots/Videos

I can provide screenshots and additional logs if needed.

For privacy/security reasons, I am not attaching production screenshots in the initial report because they contain customer phone numbers, profile names, instance names, webhook URLs, and internal workflow details.

Available evidence if maintainers need it:

  • Evolution Manager delete error screenshot (Error: [object Object])
  • WhatsApp screenshot showing the inbound message visible in the app
  • n8n execution window showing no execution for the affected timestamp
  • Sanitized Evolution/Baileys logs
  • Sanitized reverse proxy logs showing no HTTP POST for the affected message window

Which version of the API are you using?

2.3.7

What is your environment?

Linux

Other environment specifications

Deployment:

  • Ubuntu Linux server
  • Docker Compose
  • Evolution API container
  • PostgreSQL enabled
  • Redis enabled
  • Reverse proxy in front of n8n
  • n8n webhook receiver
  • WhatsApp instance type: Baileys / WhatsApp Web

Relevant Evolution environment settings:

LOG_LEVEL=TRACE
LOG_BAILEYS=trace
LOG_COLOR=false

REDIS_ENABLED=true
REDIS_URI=redis://redis:6379/1
REDIS_PREFIX_KEY=evocore

CACHE_REDIS_ENABLED=true
CACHE_REDIS_URI=redis://redis:6379/2
CACHE_REDIS_PREFIX_KEY=evocache
CACHE_LOCAL_ENABLED=false

DATABASE_ENABLED=true
DATABASE_PROVIDER=postgresql

STORE_MESSAGES=false
STORE_MESSAGE_UP=false
STORE_CONTACTS=false
STORE_CHATS=false

NODE_OPTIONS=--max-old-space-size=1024

Main enabled event:

MESSAGES_UPSERT

Traffic source:

  • Normal WhatsApp customer messages
  • Click-to-WhatsApp ads from Facebook/Instagram

If applicable, paste the log output

Sanitized log samples:

Raw message packet received

<message from="REDACTED_LID@lid"
         type="text"
         id="REDACTED_MESSAGE_ID"
         offline="0"
         notify="REDACTED_NAME"
         sender_pn="[email protected]"
         t="REDACTED_TIMESTAMP">
  <url_number />
  <unavailable />
</message>

Same message ID later appears with encrypted content

<message from="REDACTED_LID@lid"
         type="text"
         id="REDACTED_MESSAGE_ID"
         sender_pn="[email protected]">
  <enc v="2" type="pkmsg">REDACTED_ENCRYPTED_PAYLOAD</enc>
</message>

PN/LID mapping and device migration logs

Cache miss for PN user 94XXXXXXXXX; checking database
Storing 1 pn mappings
bulk device migration - loading all user devices
sent ack
LID mapping already exists, skipping

Example of readable message with no webhook

remoteJid: [email protected]
remoteJidAlt: [email protected]
conversation: "Please place the order"

But for the same message window:

No messages.upsert event
No webhook dispatch log
No HTTP POST in reverse proxy logs
No n8n execution

Other related errors seen during affected periods

Failed to decrypt message with any known session
Session error: Error: Bad MAC
Decrypted message with closed session
Invalid patch mac
failed to sync state from version, removing and trying from scratch

Downstream verification

For the affected message windows:

No webhook POST in reverse proxy logs
No n8n execution
No downstream chat_history row

Additional Notes

This is production-impacting because customer messages are silently missed.

Important observations:

  1. Restarting the evolution-api container temporarily restores Manager actions such as delete.
  2. Deleting the old instance and creating/reconnecting a fresh instance temporarily fixes message delivery for a few days.
  3. After several days of production usage, the issue returns.
  4. This suggests the Baileys/Evolution instance state may degrade or become desynced over time.
  5. The issue seems related to LID/PN mapping, session/pre-key state, app-state sync, event buffering, or webhook emission.

Questions:

  1. Is this a known issue in v2.3.7?
  2. Could this be related to LID/PN mapping, app-state sync, pre-key/session state, or event buffer flushing?
  3. Is there a safe way to repair/reset an instance state without deleting and reconnecting it?
  4. Should we enable STORE_MESSAGES, STORE_MESSAGE_UP, STORE_CHATS, or other storage options to improve recovery?
  5. Is it recommended to enable additional events such as MESSAGES_SET, MESSAGES_UPDATE, or CHATS_UPDATE to recover messages that do not emit as MESSAGES_UPSERT?
  6. Should we avoid using latest and pin a specific stable version?
  7. Is there a recommended stable version for production use with Redis + PostgreSQL + Baileys?

denetha478 avatar Jul 17 '26 09:07 denetha478

We have similar issue with MESSAGE_UPSERT.

smad-bro avatar Jul 18 '26 20:07 smad-bro

We're hitting this too (v2.4.0-rc2, Baileys, Postgres storage, two instances). One of our two instances goes silent — connectionState stays open, but zero real MESSAGES_UPSERT events fire — while the other instance on the same container keeps working normally the whole time.

We built a watchdog that tracks the timestamp of the last row actually inserted into our own DB from a webhook delivery, and flags the instance as stuck once that goes stale for longer than 3 hours while connectionState still reports open. Over one day of production traffic it fired twice:

  • Stale window ~3h05m, recovered by a full docker restart of the evolution-api container
  • Stale window ~3h03m, ~3h21m after the first, same fix

So in our case it's recurring roughly every 3–3.5 hours, not a one-off. A full container restart clears it every time (we deliberately avoid /instance/restart for this — see #765, calling that endpoint on an already-connected instance is a separate trigger for a connecting/open/close loop for us).

One side effect worth flagging for anyone building the same kind of watchdog: the container restart itself wipes our webhook url/events/custom header back to empty for both instances every time (filed separately as #2694) — so a stale-pipeline watchdog needs a webhook-config watchdog right behind it, or the "fix" silently breaks webhook delivery on its own.

BenkiNew avatar Aug 16 '26 17:08 BenkiNew

Follow-up on our earlier comment — found a more severe variant of the same instability class that's worth flagging here too, since it might share a root cause with the "silently stale but still open" case above.

On a separate instance (same 2.4.0-rc2 setup) we saw the connection itself degrade beyond "silently stale" into an actual persistent reconnect loop — connecting → close (statusCode 428/500) → connecting — for roughly 6.5 hours straight. Unlike the stale-pipeline case above, a plain docker restart of the container did not fix this one; the instance kept cycling within minutes of every restart. What did fix it was a full DELETE /instance/logout → DELETE /instance/delete/{instance} → docker restart → POST /instance/create → POST /webhook/set/{instance} → /instance/connect, which recovered cleanly within ~15 minutes of the QR scan.

We've now automated this as an explicit 3rd escalation tier in our self-heal watchdog (plain restart → logout+reconnect → full recreate), since relying on "just restart the container" alone clearly stops being sufficient once the underlying session has degraded far enough — same lesson as your webhook-config-wipe finding in #2694: the restart-based fix needs something further downstream watching for the cases where it silently doesn't hold.

BenkiNew avatar Aug 27 '26 06:08 BenkiNew

This looks like the same fault as WhiskeySockets/Baileys#2491, which is open against baileys 7.0.0-rc.9. Evolution v2.3.7 pins exactly that version, and so do 2.4.0-rc1 and 2.4.0-rc2, so every released version is exposed. develop has moved to rc13.

Signature to compare against: connectionState keeps reporting open, no connection.update close event ever fires, so the reconnect path at whatsapp.baileys.service.ts is never entered, and only recreating the container clears it. Five occurrences here in 38 days, measurements posted upstream in #2491.

If that is the same thing, this is a pinned-dependency issue rather than an Evolution one, and the fix downstream is a release that pins rc13 or later. Is there a target release for pulling the baileys pin forward?

PalWorks avatar Sep 10 '26 07:09 PalWorks

Thanks for the pointer to Baileys#2491. Our first variant above (connectionState stays open, no real MESSAGES_UPSERT, cleared by a container restart, recurring roughly every 3 hours on 2.4.0-rc2) matches that symptom. We did not record whether a connection.update close event fired during those windows, so we can't confirm the exact signature you describe. The second variant (the 428/500 reconnect loop that survived a restart) does emit close events, so it is probably a different fault. The question about pulling the Baileys pin forward is for the maintainers.

BenkiNew avatar Sep 26 '26 07:09 BenkiNew

Same issue on v2.3.7 (Baileys 7.0.0-rc.9), production, with measurements: it is a growing delivery backlog, not only lost messages

Environment

Evolution API v2.3.7 (evoapicloud/evolution-api:latest resolving to 2.3.7), Baileys 7.0.0-rc.9, Node v24.11.1 Docker (Coolify), Postgres 16 + Redis, 4 Baileys instances on the same container, groupsIgnore=true, syncFullHistory=false Webhook per instance (MESSAGES_UPSERT), not global What we observed (Nov 5–7, 2026)

2 of 3 customer instances: connectionState = open, POST /chat/fetchBusinessProfile/{instance} = 200 (session looks alive), sending works. But inbound messages.upsert arrive only in bursts of ~10–20 messages right after each reconnection (every instance reconnects by itself about every 50 min — Baileys version … / CONNECTED TO WHATSAPP in the logs), then nothing until the next reconnection. The burst carries messages that were already read on the phone (status: 'READ'), oldest first. The backlog grows faster than it drains, so the delivery delay (webhook time − messageTimestamp) grows linearly: median 4 h on Nov 5 → 15 h on Nov 6 → 26 h on Nov 7. The third instance on the same container, same version and config, delivers with zero delay the whole time. The Evolution database confirms it is upstream of the webhook: the newest row in Message for the affected instances was ~27 h old, while the healthy instance had messages from minutes before. So nothing is stuck in the webhook queue; Baileys simply does not receive (or does not process) newer messages. Webhook retries are not the cause: only 3 retry sequences (retryWebhookRequest, HTTP 503) in 72 h. What did not help

docker restart of the Evolution container (Nov 7, 22:46 UTC): all 4 instances reconnected without 401 and webhook settings were preserved, but the 2 affected instances delivered one burst of 11 messages ~25 h old and stopped again. The automatic hourly reconnections (same effect as a restart). What we see in the logs around it

Frequent {"level":50,…,"fullErrorNode":{"tag":"stream:error",…"content":[{"tag":"ack","attrs":{"class":"status","type":"media"…}}]}} (≈180 in 72 h across instances, also on the healthy one), plus stream errored out code 503. PrismaClientValidationError … messageUpdate.create() … Argument remoteJid is missing on addressingMode: 'lid' receipts (19 in 72 h, affected instance and healthy one). Many Closing session: SessionEntry {…} (libsignal) — note: this log line prints session private keys at the default log level, which is a security concern on its own. Questions

Is the Baileys pin going to move past 7.0.0-rc.9? (WhiskeySockets/Baileys#2491 was mentioned above as fixed in rc.13+.) Is a "drain offline queue" / re-pair without QR possible, or is re-pairing the device the only recovery? We can provide more anonymized measurements if useful.

jeffersonrios17 avatar Nov 08 '26 01:11 jeffersonrios17