Skip to content

bug: proactive messages (send_message) never persisted to channel session history — agent unaware of its own outbound messages #1600

Closed

Description

@vybe

Summary

When an agent sends a proactive message to a user via the MCP send_message tool (#321) — e.g. over Telegram — the delivered message is never persisted to the channel session history (public_chat_messages). The next inbound message from that user builds its conversation context from db.build_public_chat_context(session_id, ...), which contains only turns persisted by the channel message router — so the agent has no record of the proactive message it just sent. In the ensuing exchange the agent is unaware of its own outreach: it can repeat itself, contradict the earlier message, or fail to understand the user's reply ("yes, sounds good" — to what?).

Reported against Telegram, but the same gap applies to all proactive delivery channels: none of the _deliver_* helpers in src/backend/services/proactive_message_service.py write history.

Context

  • Inbound flow (src/backend/adapters/message_router.py): step 11 persists BOTH the user turn and the assistant reply via db.add_public_chat_message(...) with per-speaker attribution (Slack: scope chat session to thread, not channel #903), and the context prompt for each turn is built from that history via db.build_public_chat_context(session_id, ...).
  • Proactive flow (src/backend/services/proactive_message_service.py, feat: proactive agent messaging to channel users (Telegram / Slack / web) #321): _deliver_telegram / _deliver_slack / _deliver_whatsapp resolve the recipient and call the channel API directly — no add_public_chat_message call exists anywhere in the service (_deliver_web is unimplemented v1).
  • The persistence seam already exists for Telegram and WhatsApp: both delivery helpers look up the chat link, and telegram_chat_links.session_id / whatsapp_chat_links.session_id identify the recipient's channel session. The Slack path resolves the recipient by email across workspaces and has no chat-link/session mapping today.

Acceptance Criteria

  • A successful proactive Telegram delivery appends an assistant-role message to the recipient's channel session history (sender_label = agent name, mirroring router step 11 attribution semantics, Slack: scope chat session to thread, not channel #903)
  • The next inbound turn's build_public_chat_context includes the proactive message, so the agent responds aware of what it sent (regression test: proactive send → inbound reply → context contains the proactive message)
  • Same behavior for WhatsApp (chat link already carries session_id)
  • Slack: either persisted the same way (resolving/creating a session for the DM) or explicitly documented as a known limitation in the send_message tool description + user docs — no silent inconsistency
  • Persist only on confirmed successful delivery — a failed send must not write a phantom assistant turn into history
  • Recipient with no session yet (NULL session_id on the chat link) degrades gracefully: message still delivered, no crash; decide and document whether a session is created
  • MEM-001 interplay: the persisted assistant turn's sender_email follows the _assistant_sender_email semantics (Slack: scope chat session to thread, not channel #903) so sender-filtered summarization doesn't fold proactive messages into the wrong user's memory

Technical Notes

Activity

  1. added
    priority-p2
    type-bug
    theme-channels
    complexity-medium
    status-ready
    on Jul 13, 2026
  2. added
    status-in-progress
    and removed
    status-ready
    on Jul 16, 2026
  3. self-assigned this
    on Jul 16, 2026
  4. added
    status-in-dev
    and removed
    status-in-progress
    on Jul 16, 2026
  5. removed
    status-in-dev
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-mediumpriority-p2theme-channelstype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions