← Back to PRs

#6850: fix: support direct channel:account:peer format in session key extraction

by toboto open 2026-02-02 03:50 View on GitHub →
agents
## Problem The `sessions_send` tool hardcoded `channel: INTERNAL_MESSAGE_CHANNEL` when sending messages to other sessions, causing messages to be incorrectly routed to webchat instead of the intended channel. This particularly affected: - Isolated sessions with direct sessionKey format (`channel:account:peer`) - Cron tasks using `--deliver --channel <channel>` parameters - Any cross-agent messaging with non-agent-prefixed session keys ### Example of the issue: ```bash # This cron task would execute successfully but messages went to webchat openclaw cron add \ --session isolated \ --deliver \ --channel wecom \ --to user \ --message "Reminder" ``` ## Solution Added `extractChannelFromSessionKey()` helper function that: 1. Supports **two sessionKey formats**: - `agent:agentId:channel:account:peer` (existing) - `channel:account:peer` (new, direct format) 2. Dynamically extracts channel from sessionKey 3. Falls back to `INTERNAL_MESSAGE_CHANNEL` if extraction fails The function filters out special keywords (main, agent, subagent, etc.) to avoid false positives. ## Testing ✅ TypeScript compilation passes ✅ Backward compatible with existing agent-prefixed format ✅ Manually tested with WeCom channel + isolated sessions ### Test results: - Direct format (`wecom:default:user`) → correctly extracts `wecom` - Agent format (`agent:main:wecom:default:user`) → correctly extracts `wecom` - Invalid formats → correctly falls back to `INTERNAL_MESSAGE_CHANNEL` ## Impact - ✅ Fixes message routing for all channels (wecom, telegram, discord, slack, etc.) - ✅ Enables proper delivery mode in cron tasks - ✅ 100% backward compatible - ✅ No breaking changes <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes `sessions_send` message routing by deriving the target `channel` from the resolved session key instead of hardcoding `INTERNAL_MESSAGE_CHANNEL` (`webchat`). It introduces `extractChannelFromSessionKey()` to support both agent-prefixed session keys (`agent:agentId:channel:account:peer`) and direct keys (`channel:account:peer`), and uses the extracted channel when calling the gateway `agent` method. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge and addresses the routing bug, with a minor risk around channel normalization/aliases. - Change is localized and the new helper is straightforward, but the extracted channel bypasses existing message-channel normalization, which can matter for aliases and plugin-provided channel IDs. - src/agents/tools/sessions-send-tool.ts <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs