← Back to PRs

#15863: fix: route agent-to-agent Slack messages to bound sessions

by MisterGuy420 open 2026-02-14 00:17 View on GitHub →
channel: slack stale size: M
## Summary This PR fixes agent-to-agent communication via Slack channels. Previously, when an agent posted a message to a Slack channel via the `message` tool, other agents with bindings to that channel would not receive the message. The Slack routing logic was filtering out all messages from the bot user to prevent routing loops, which incorrectly filtered messages from OTHER agents too. ## Changes - Added `message-origin-cache.ts` to track the originating session when sending messages via Slack - Extended `ChannelOutboundContext` to include `originSessionKey` and `originAgentId` fields - Updated `sendMessageSlack` to record message origin after successful delivery - Modified `prepareSlackMessage` to check the origin cache when receiving bot messages and allow them through if they have a tracked origin - Updated `dispatchPreparedSlackMessage` to skip dispatching if the target session matches the originating session (prevents loops) ## Testing - Linting passed with 0 warnings and 0 errors - Code formatting applied successfully - The changes follow the existing code patterns and conventions Fixes openclaw/openclaw#15836 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This change introduces origin tracking for outbound Slack messages so that bot-authored messages sent via the `message` tool can be routed to other agent sessions bound to the same Slack channel, while preventing routing loops back into the originating session. It does this by: - Extending outbound channel context (`originSessionKey`/`originAgentId`) and plumbing it through outbound delivery into the Slack outbound adapter. - Recording a `(channelId, messageTs) -> {sessionKey, agentId}` mapping after successful Slack delivery. - On inbound Slack events, allowing “own bot” messages through only if they have a tracked origin, and skipping dispatch when the target session matches the origin. The overall approach matches the existing channel plugin/outbound delivery architecture, but there are a couple of correctness bugs in origin detection and origin recording that will prevent the feature from working reliably and may drop legitimate inbound bot messages. <h3>Confidence Score: 2/5</h3> - This PR has high functional risk and is not safe to merge as-is - Two logic bugs break the intended routing behavior: (1) inbound detection treats any bot message as ‘own bot’ when botUserId is set, which can incorrectly drop legitimate external bot messages; and (2) origin tracking for media uploads records a non-`ts` identifier, so inbound lookups won’t match and agent-to-agent routing won’t work for those messages. These issues directly affect correctness of Slack message handling. - src/slack/monitor/message-handler/prepare.ts, src/slack/send.ts <sub>Last reviewed commit: 069ab72</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs