-
-
Notifications
You must be signed in to change notification settings - Fork 69.6k
iMessage: duplicate message delivery when processing batched/queued messages #25192
Description
Summary
When multiple iMessage messages arrive while the agent is busy and are processed as a queued batch ("Queued messages while agent was busy"), the iMessage channel delivers the single response multiple times — once per queued message in the batch.
Observed Behavior
Gateway log shows 6 delivered reply events firing within 362ms for a single agent run:
07:33:30.530Z — imessage: delivered reply to imessage:+15039278787
07:33:30.619Z — imessage: delivered reply to imessage:+15039278787
07:33:30.689Z — imessage: delivered reply to imessage:+15039278787
07:33:30.758Z — imessage: delivered reply to imessage:+15039278787
07:33:30.828Z — imessage: delivered reply to imessage:+15039278787
07:33:30.892Z — imessage: delivered reply to imessage:+15039278787
Run context:
runId=c9f3d15d-6622-46ed-a530-baa7f4d1dd81sessionId=8e887b0c-f15c-4add-aead-7a4e81c4f6b2provider=anthropic model=claude-sonnet-4-6 thinking=low messageChannel=imessage- The inbound event contained 2 queued messages ("Queued fix: add @lid format support and allowFrom wildcard handling #1" and "Queued Login fails with 'WebSocket Error (socket hang up)' ECONNRESET #2" in the batch)
- Result: 6 identical iMessages delivered to the recipient
Also seen with 2 deliveries within ~75ms for smaller batches (2 queued messages → 2 sends).
Steps to Reproduce
- Have an active iMessage conversation
- Send 2+ messages in quick succession while agent is processing a previous task
- Agent receives them as a "Queued messages while agent was busy" batch
- Agent produces one response
- iMessage channel delivers it N times (where N appears to correlate with queue depth or internal listeners)
Expected Behavior
One response delivered once per agent run, regardless of how many messages were in the inbound queue.
Environment
- OpenClaw version: 2026.2.22-2
- Channel: imessage
- OS: macOS (Darwin 25.3.0 arm64)
- Node: v22.22.0
- Model: anthropic/claude-sonnet-4-6, thinking=low
Likely Cause
Race condition in the queued-message batch delivery path. Hypothesis: when N messages are queued and coalesced into a single agent run, the completion handler may be registered N times (once per queued message), each firing independently on run completion.
Suggest adding a deduplication guard in the iMessage delivery path keyed on runId — first delivery wins, subsequent duplicate deliveries within a short window (e.g., 500ms) for the same runId are dropped.