Skip to content

fix(whatsapp): group composing indicator, echo prevention, and presence subscription - #17326

Closed
globalcaos wants to merge 3 commits into
openclaw:mainfrom
globalcaos:fix/whatsapp-reliability-bundle
Closed

globalcaos wants to merge 3 commits into
openclaw:mainfrom
globalcaos:fix/whatsapp-reliability-bundle

Conversation

@globalcaos

@globalcaos globalcaos commented Feb 15, 2026 •

Copy link
Copy Markdown

Problem

Three independent but related WhatsApp reliability issues discovered while running a 24/7 OpenClaw agent on WhatsApp:

1. Typing indicator silently fails in groups

sendPresenceUpdate("composing", groupJid) does nothing in groups because Baileys requires presenceSubscribe(jid) first for group JIDs. This is a known Baileys behavior — without subscribing, presence updates are silently dropped.

2. Bot re-ingests its own voice notes / media

WhatsApp sometimes delivers the bot's own sent messages back as inbound messages.upsert events (especially voice notes and media). Without tracking, these get processed as new user messages, causing echo loops.

Fix

Group composing (send-api.ts)

  • Add presenceSubscribe to the sock type interface
  • Call presenceSubscribe(jid) before sendPresenceUpdate("composing") when the target is a group JID (@g.us)
  • Non-fatal: if subscribe fails, composing is still attempted

Echo prevention (sent-ids.ts + send-api.ts + monitor.ts)

  • New sent-ids.ts module: simple in-memory Set<string> with FIFO cleanup (max 500 entries)
  • send-api.ts: track message IDs after successful sends via trackSentMessageId()
  • monitor.ts: skip inbound messages whose ID matches a recently sent message via isSentByUs()

Monitor passthrough (monitor.ts)

  • Expose presenceSubscribe from the Baileys socket to the send API

Files Changed

File Change
src/web/inbound/send-api.ts Add presenceSubscribe to sock type, track sent IDs, subscribe before composing in groups
src/web/inbound/monitor.ts Pass presenceSubscribe to send API, skip self-sent messages on inbound
src/web/inbound/sent-ids.ts New — sent message ID tracking with bounded FIFO cleanup

3 files, 47 insertions, 0 deletions.

Testing

  • Build passes (pnpm build)
  • Manual testing: 24/7 WhatsApp agent with voice notes in groups — no more echo loops, typing indicator now visible in groups

Greptile Summary

Adds group typing indicator support and echo prevention for WhatsApp messages. The implementation correctly subscribes to presence before sending composing indicators in groups, and tracks sent message IDs to filter out echo loops.

  • Fixed typing indicator in groups by calling presenceSubscribe before sendPresenceUpdate for group JIDs
  • Added in-memory tracking of sent message IDs with bounded FIFO cleanup (max 500 entries)
  • Filters out self-sent messages in the inbound handler to prevent echo loops
  • One issue found: sendPoll doesn't track its message ID, which could cause poll messages to echo back

Confidence Score: 4/5

  • Safe to merge after addressing the sendPoll message ID tracking gap
  • The implementation correctly solves the stated problems with sound architectural choices. The typing indicator fix is straightforward and properly handles failure. The echo prevention mechanism uses an appropriate bounded in-memory Set with FIFO cleanup. However, sendPoll has the same echo vulnerability as sendMessage had before this fix - it returns a messageId but doesn't track it, which could cause poll messages to be re-ingested. This is a logical gap in the implementation that should be addressed to fully prevent echo loops.
  • src/web/inbound/send-api.ts requires attention for the sendPoll message ID tracking issue

Last reviewed commit: 218de1b

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps

greptile-apps Bot commented Feb 15, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (3)

src/web/inbound/send-api.ts
sendPoll doesn't track message IDs but can also echo back

      if (messageId !== "unknown") {
        trackSentMessageId(messageId);
      }
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/web/inbound/send-api.ts
Line: 91:91

Comment:
`sendPoll` doesn't track message IDs but can also echo back

```suggestion
      if (messageId !== "unknown") {
        trackSentMessageId(messageId);
      }
```

How can I resolve this? If you propose a fix, please make it concise.

src/web/inbound/send-api.test.ts
mock presenceSubscribe to match updated type signature

  const presenceSubscribe = vi.fn(async () => {});
  const api = createWebSendApi({
    sock: { sendMessage, sendPresenceUpdate, presenceSubscribe },
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/web/inbound/send-api.test.ts
Line: 13:13

Comment:
mock `presenceSubscribe` to match updated type signature

```suggestion
  const presenceSubscribe = vi.fn(async () => {});
  const api = createWebSendApi({
    sock: { sendMessage, sendPresenceUpdate, presenceSubscribe },
```

How can I resolve this? If you propose a fix, please make it concise.

src/web/inbound/send-api.test.ts
add test case for group composing with presenceSubscribe call

  it("sends composing presence updates to the recipient JID", async () => {
    await api.sendComposingTo("+1555");
    expect(sendPresenceUpdate).toHaveBeenCalledWith("composing", "[email protected]");
    expect(presenceSubscribe).not.toHaveBeenCalled();
  });

  it("subscribes to presence before composing for group JIDs", async () => {
    await api.sendComposingTo("[email protected]");
    expect(presenceSubscribe).toHaveBeenCalledWith("[email protected]");
    expect(sendPresenceUpdate).toHaveBeenCalledWith("composing", "[email protected]");
  });
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/web/inbound/send-api.test.ts
Line: 154:157

Comment:
add test case for group composing with `presenceSubscribe` call

```suggestion
  it("sends composing presence updates to the recipient JID", async () => {
    await api.sendComposingTo("+1555");
    expect(sendPresenceUpdate).toHaveBeenCalledWith("composing", "[email protected]");
    expect(presenceSubscribe).not.toHaveBeenCalled();
  });

  it("subscribes to presence before composing for group JIDs", async () => {
    await api.sendComposingTo("[email protected]");
    expect(presenceSubscribe).toHaveBeenCalledWith("[email protected]");
    expect(sendPresenceUpdate).toHaveBeenCalledWith("composing", "[email protected]");
  });
```

How can I resolve this? If you propose a fix, please make it concise.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps

greptile-apps Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

src/web/inbound/send-api.ts
sendPoll also returns messageId but doesn't track it - poll messages could echo back

      const messageId =
        typeof result === "object" && result && "key" in result
          ? String((result as { key?: { id?: string } }).key?.id ?? "unknown")
          : "unknown";
      if (messageId !== "unknown") {
        trackSentMessageId(messageId);
      }
      return { messageId };
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/web/inbound/send-api.ts
Line: 87:91

Comment:
`sendPoll` also returns messageId but doesn't track it - poll messages could echo back

```suggestion
      const messageId =
        typeof result === "object" && result && "key" in result
          ? String((result as { key?: { id?: string } }).key?.id ?? "unknown")
          : "unknown";
      if (messageId !== "unknown") {
        trackSentMessageId(messageId);
      }
      return { messageId };
```

How can I resolve this? If you propose a fix, please make it concise.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels Feb 22, 2026
…ce subscription

Three reliability fixes for WhatsApp Web (Baileys) integration:

1. **Group composing indicator**: Call presenceSubscribe() before
   sendPresenceUpdate('composing') in groups. Without this, the typing
   indicator silently fails for group JIDs — a known Baileys requirement.

2. **Sent message ID tracking**: Track IDs of messages sent by the bot
   and skip them on inbound. Prevents echo loops where WhatsApp delivers
   our own voice notes/media back as new messages.

3. **sent-ids module**: Simple in-memory Set with FIFO cleanup (max 500
   entries) to support the echo prevention above.
@globalcaos

globalcaos commented Mar 17, 2026 •

Copy link
Copy Markdown
Author

This fix is maintained in our fork: globalcaos/tinkerclaw

The WhatsApp group composing indicator, echo prevention, and presence subscription fixes are all active and have been running in production for months. If you're hitting these issues, the fork has the working code.


Comment by Jarvis, AI assistant to @globalcaos — Human reviewed and approved

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

Labels

channel: whatsapp-web Channel integration: whatsapp-web size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants