From 087abb4d5f671c1d53746c9caee30be8251f5e86 Mon Sep 17 00:00:00 2001 From: Galygious Date: Fri, 20 Feb 2026 15:52:15 -0600 Subject: [PATCH] fix: expose resolvedTo as currentChannelId for sub-agent message routing When a sub-agent is spawned via sessions_spawn, the gateway agent handler already forwards to and threadId from the requester session. However, resolvedTo was never mapped to runContext.currentChannelId, so the message tool zero-param target inference had nothing to fall back on -- resulting in 'Action send requires a target' errors. Sets currentChannelId: resolvedTo in the runContext, flowing through runEmbeddedPiAgent -> createOpenClawCodingTools -> createMessageTool. Sub-agents calling message with no explicit to/channel/threadId now inherit the parent session's originating thread/channel automatically. Verified end-to-end: sub-agents spawned with only a task prompt send Discord messages to the correct thread without explicit routing params. AI-submitted: identified and implemented by Cognis (OpenClaw agent). Manual end-to-end tested. No automated test suite run. A regression test for sub-agent message tool target inference would be a good add. --- src/gateway/server-methods/agent.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gateway/server-methods/agent.ts b/src/gateway/server-methods/agent.ts index 3f828103ab5..06a1bfccb79 100644 --- a/src/gateway/server-methods/agent.ts +++ b/src/gateway/server-methods/agent.ts @@ -389,6 +389,11 @@ export const agentHandlers: GatewayRequestHandlers = { groupChannel: resolvedGroupChannel, groupSpace: resolvedGroupSpace, currentThreadTs: resolvedThreadId != null ? String(resolvedThreadId) : undefined, + // Expose resolvedTo as currentChannelId so the message tool's target + // inference (no explicit `to`) routes to the correct thread/channel. + // This allows sub-agents to send messages to the originating thread + // without needing an explicit target parameter. + currentChannelId: resolvedTo || undefined, }, groupId: resolvedGroupId, groupChannel: resolvedGroupChannel,