From b140b3655b9e73fa5a3d2f9b2377d409cc42abe5 Mon Sep 17 00:00:00 2001 From: Gabi Simons Date: Sun, 12 Apr 2026 12:34:21 +0000 Subject: [PATCH] fix(agent-runner): reply to originating channel in single-destination shortcut When an agent has one configured destination (e.g. Discord) but receives a message from a different channel (e.g. Slack), the single-destination shortcut was routing replies to the destination instead of the originating channel. Now uses the inbound message's routing context (channel_type, platform_id) when available, falling back to the destination table only when routing context is absent. Co-Authored-By: Claude Opus 4.6 (1M context) --- container/agent-runner/src/poll-loop.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/container/agent-runner/src/poll-loop.ts b/container/agent-runner/src/poll-loop.ts index 208c89a..2e401af 100644 --- a/container/agent-runner/src/poll-loop.ts +++ b/container/agent-runner/src/poll-loop.ts @@ -365,9 +365,23 @@ function dispatchResultText(text: string, routing: RoutingContext): void { .replace(/[\s\S]*?<\/internal>/g, '') .trim(); - // Single-destination shortcut: the agent wrote plain text and has exactly - // one destination. Send the entire cleaned text to it. + // Single-destination shortcut: the agent wrote plain text — send to + // the session's originating channel (from session_routing) if available, + // otherwise fall back to the single destination. if (sent === 0 && scratchpad) { + if (routing.channelType && routing.platformId) { + // Reply to the channel/thread the message came from + writeMessageOut({ + id: generateId(), + in_reply_to: routing.inReplyTo, + kind: 'chat', + platform_id: routing.platformId, + channel_type: routing.channelType, + thread_id: routing.threadId, + content: JSON.stringify({ text: scratchpad }), + }); + return; + } const all = getAllDestinations(); if (all.length === 1) { sendToDestination(all[0], scratchpad, routing);