#6850: fix: support direct channel:account:peer format in session key extraction
agents
Cluster:
Session Management Enhancements
## 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
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
81.3%
#9051: fix(sessions): respect dmScope config in CLI agent commands
by benleavett · 2026-02-04
81.1%
#17527: fix(gateway): allow WebChat to attach to main session regardless of...
by Glucksberg · 2026-02-15
80.7%
#20336: fix(sessions): resolve transcriptPath using agentId when storePath ...
by Limitless2023 · 2026-02-18
80.3%
#15792: fix: pass agentId to resolveSessionFilePath in additional call sites
by MisterGuy420 · 2026-02-13
80.2%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
80.0%
#3182: fix(gateway): use canonical session key in chat.send
by chrisherold · 2026-01-28
79.3%
#20078: feat(session): Add channelGroups config(optional config) for shared...
by demarlik01 · 2026-02-18
79.3%
#15744: fix: allow cross-agent session path validation
by scottgl9 · 2026-02-13
79.3%
#13881: fix: Address Greptile feedback - test isolation and channel resolution
by trevorgordon981 · 2026-02-11
79.1%