Skip to content

WhatsApp DM interrupt silently fails due to session key mismatch in _quick_key #349

@Farukest

Description

@Farukest

When a WhatsApp DM user sends a new message while the agent is still processing a previous one, the interrupt mechanism silently fails. The message is swallowed and never processed.

Root cause: _quick_key in gateway/run.py (line 640) builds the key without chat_id for all DMs:

_quick_key = (
    f"agent:main:{source.platform.value}:{source.chat_type}:{source.chat_id}"
    if source.chat_type != "dm"
    else f"agent:main:{source.platform.value}:dm"
)

But _generate_session_key() in gateway/session.py includes chat_id for WhatsApp DMs:

if platform == "whatsapp" and source.chat_id:
    return f"agent:main:{platform}:dm:{source.chat_id}"

The running agent is stored under the full session key (with chat_id) at line 2096, but looked up with the shorter _quick_key (without chat_id) at line 645. The lookup always misses.

Impact:

  • WhatsApp DM users cannot interrupt a running agent
  • The interrupt message is stored in _pending_messages under the wrong key, so it is never picked up
  • The same mismatch affects the approval flow session_key_preview for non WhatsApp DMs (those also omit chat_id but the approval code at line 720 already has a WhatsApp specific branch, confirming the intent)

Reproduction:

  1. Send a message to the bot via WhatsApp DM
  2. While the agent is processing, send another message (e.g. "stop")
  3. Expected: agent is interrupted
  4. Actual: second message is silently lost, agent continues uninterrupted

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions