fix: route manual subagent spawn replies via OriginatingTo fallback

This commit is contained in:
Peter Steinberger
2026-02-18 03:48:02 +01:00
parent 4134875c31
commit 34851a78b2
2 changed files with 25 additions and 4 deletions

View File

@@ -1,7 +1,8 @@
import crypto from "node:crypto";
import type { SubagentRunRecord } from "../../agents/subagent-registry.js";
import type { CommandHandler } from "./commands-types.js";
import { AGENT_LANE_SUBAGENT } from "../../agents/lanes.js";
import { abortEmbeddedPiRun } from "../../agents/pi-embedded.js";
import type { SubagentRunRecord } from "../../agents/subagent-registry.js";
import {
clearSubagentRunSteerRestart,
listSubagentRunsForRequester,
@@ -35,7 +36,6 @@ import {
} from "../../shared/subagents-format.js";
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
import { stopSubagentsForRequester } from "./abort.js";
import type { CommandHandler } from "./commands-types.js";
import { clearSessionQueues } from "./queue.js";
import { formatRunLabel, formatRunStatus, sortSubagentRuns } from "./subagents-utils.js";
@@ -682,13 +682,19 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
};
}
const commandTo = typeof params.command.to === "string" ? params.command.to.trim() : "";
const originatingTo =
typeof params.ctx.OriginatingTo === "string" ? params.ctx.OriginatingTo.trim() : "";
const fallbackTo = typeof params.ctx.To === "string" ? params.ctx.To.trim() : "";
const normalizedTo = commandTo || originatingTo || fallbackTo || undefined;
const result = await spawnSubagentDirect(
{ task, agentId, model, thinking, cleanup: "keep", expectsCompletionMessage: true },
{
agentSessionKey: requesterKey,
agentChannel: params.ctx.OriginatingChannel ?? params.command.channel,
agentAccountId: params.ctx.AccountId,
agentTo: params.ctx.OriginatingTo ?? params.command.to,
agentTo: normalizedTo,
agentThreadId: params.ctx.MessageThreadId,
agentGroupId: params.sessionEntry?.groupId ?? null,
agentGroupChannel: params.sessionEntry?.groupChannel ?? null,