fix: route discord native subagent announce to channel target

This commit is contained in:
Peter Steinberger
2026-02-18 02:42:52 +00:00
parent c1928845ac
commit 4134875c31
3 changed files with 11 additions and 2 deletions

View File

@@ -155,6 +155,8 @@ describe("/subagents spawn command", () => {
const params = buildCommandTestParams("/subagents spawn beta do the thing", baseCfg, {
CommandSource: "native",
CommandTargetSessionKey: "agent:main:main",
OriginatingChannel: "discord",
OriginatingTo: "channel:12345",
});
params.sessionKey = "agent:main:slack:slash:u1";
@@ -164,6 +166,8 @@ describe("/subagents spawn command", () => {
expect(result?.reply?.text).toContain("Spawned subagent beta");
const [, spawnCtx] = spawnSubagentDirectMock.mock.calls[0];
expect(spawnCtx.agentSessionKey).toBe("agent:main:main");
expect(spawnCtx.agentChannel).toBe("discord");
expect(spawnCtx.agentTo).toBe("channel:12345");
});
it("returns forbidden for unauthorized cross-agent spawn", async () => {

View File

@@ -686,9 +686,9 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
{ task, agentId, model, thinking, cleanup: "keep", expectsCompletionMessage: true },
{
agentSessionKey: requesterKey,
agentChannel: params.command.channel,
agentChannel: params.ctx.OriginatingChannel ?? params.command.channel,
agentAccountId: params.ctx.AccountId,
agentTo: params.command.to,
agentTo: params.ctx.OriginatingTo ?? params.command.to,
agentThreadId: params.ctx.MessageThreadId,
agentGroupId: params.sessionEntry?.groupId ?? null,
agentGroupChannel: params.sessionEntry?.groupChannel ?? null,

View File

@@ -790,6 +790,11 @@ async function dispatchDiscordCommandInteraction(params: {
Timestamp: Date.now(),
CommandAuthorized: commandAuthorized,
CommandSource: "native" as const,
// Native slash contexts use To=slash:<user> for interaction routing.
// For follow-up delivery (for example subagent completion announces),
// preserve the real Discord target separately.
OriginatingChannel: "discord" as const,
OriginatingTo: isDirectMessage ? `user:${user.id}` : `channel:${channelId}`,
});
const { onModelSelected, ...prefixOptions } = createReplyPrefixOptions({