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) <noreply@anthropic.com>
This commit is contained in:
Gabi Simons
2026-04-12 12:34:21 +00:00
parent 7e74bfd330
commit b140b3655b
+16 -2
View File
@@ -365,9 +365,23 @@ function dispatchResultText(text: string, routing: RoutingContext): void {
.replace(/<internal>[\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);