Skip to content

fix(whatsapp): carry forward message_id from latest event in text merge paths - #60409

Closed
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:fix/59582-whatsapp-message-id-merge
Closed

fix(whatsapp): carry forward message_id from latest event in text merge paths#60409
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:fix/59582-whatsapp-message-id-merge

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

Summary

When rapid-fire text messages arrive while the agent is busy (or within the Baileys bridge text-batch window), the merged pending event retains the FIRST message's message_id and reply_to_message_id. The agent's reply quotes the wrong (older) message because _reply_anchor_for_event() returns the stale first message's ID.

Root Cause

Two code paths have the same gap:

  1. merge_pending_message_event in gateway/platforms/base.py (line ~2114): when merge_text=True and two TEXT events are merged, text is appended but message_id/reply_to_message_id are never updated from the latest event.

  2. _enqueue_text_event in plugins/platforms/whatsapp/adapter.py (line ~1295): the Baileys bridge adapter's own text batching mechanism has the identical gap — it appends text and media but never carries forward the latest event's identity fields.

Compare _queue_text_debounce (base.py ~line 4272) which DOES correctly update message_id from the latest event — that was the reference implementation for this fix.

Fix

After appending text from the incoming event in both merge paths, also update message_id and reply_to_message_id on the existing merged event to reflect the latest inbound message. This ensures _reply_anchor_for_event() returns the correct (latest) message ID when the agent processes the merged event.

Testing

  • Verified the fix matches the same pattern used by _queue_text_debounce
  • Both merge paths (base adapter + Baileys bridge) are fixed

Fixes #59582

…ge paths

Root cause: when rapid-fire text messages are merged (via
merge_pending_message_event in base.py or _enqueue_text_event in
the Baileys bridge adapter), the merged event retains the FIRST
message's message_id and reply_to_message_id. The agent's reply
quotes the wrong (older) message because _reply_anchor_for_event
returns the stale first message's ID.

Fix: after appending text from the incoming event, also update
message_id and reply_to_message_id on the existing merged event
to reflect the latest inbound message. This matches the pattern
already used by _queue_text_debounce.

Fixes NousResearch#59582
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/whatsapp WhatsApp Business adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Fix PR for #59582 (open). Same reply-anchor-to-latest mechanism as Telegram's #43787, applied to WhatsApp's two text-merge paths (base gateway + Baileys bridge). Related, not duplicate.

@kyssta-exe

Copy link
Copy Markdown
Contributor Author

Stale — 6-7 days without merge activity. Can resubmit if still needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/whatsapp WhatsApp Business adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WhatsApp draft reply not updating from latest inbound message

2 participants