From 8d954d39edf93ebc21f416fc32dfaa73929261d8 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Fri, 17 Apr 2026 00:41:51 -0400 Subject: [PATCH] Agents: reuse delivery context for subagent routing --- src/agents/subagent-spawn.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/agents/subagent-spawn.ts b/src/agents/subagent-spawn.ts index ebb2a23595a..812b1b5b28a 100644 --- a/src/agents/subagent-spawn.ts +++ b/src/agents/subagent-spawn.ts @@ -7,6 +7,7 @@ import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, } from "../shared/string-coerce.js"; +import type { DeliveryContext } from "../utils/delivery-context.types.js"; import type { BootstrapContextMode } from "./bootstrap-files.js"; import { mapToolContextToSpawnedRunMetadata, @@ -74,13 +75,6 @@ type SubagentSpawnDeps = { updateSessionStore: typeof updateSessionStore; }; -type SubagentDeliveryOrigin = { - channel?: string; - accountId?: string; - to?: string; - threadId?: string | number; -}; - const defaultSubagentSpawnDeps: SubagentSpawnDeps = { callGateway, getGlobalHookRunner, @@ -306,7 +300,7 @@ async function ensureThreadBindingForSubagentSpawn(params: { threadId?: string | number; }; }): Promise< - { status: "ok"; deliveryOrigin?: SubagentDeliveryOrigin } | { status: "error"; error: string } + { status: "ok"; deliveryOrigin?: DeliveryContext } | { status: "error"; error: string } > { const hookRunner = params.hookRunner; if (!hookRunner?.hasHooks("subagent_spawning")) { @@ -361,9 +355,7 @@ async function ensureThreadBindingForSubagentSpawn(params: { } } -function resolveThreadBindingDeliveryOrigin( - childSessionKey: string, -): SubagentDeliveryOrigin | undefined { +function resolveThreadBindingDeliveryOrigin(childSessionKey: string): DeliveryContext | undefined { const activeBindings = getSessionBindingService() .listBySession(childSessionKey) .filter((binding) => binding.status === "active"); @@ -384,7 +376,7 @@ function resolveThreadBindingDeliveryOrigin( accountId: binding.conversation.accountId, to: target.to, threadId: target.threadId, - }) as SubagentDeliveryOrigin | undefined; + }); } export async function spawnSubagentDirect( @@ -431,7 +423,7 @@ export async function spawnSubagentDirect( accountId: ctx.agentAccountId, to: ctx.agentTo, threadId: ctx.agentThreadId, - }) as SubagentDeliveryOrigin | undefined; + }); let childSessionOrigin = requesterOrigin; const hookRunner = subagentSpawnDeps.getGlobalHookRunner(); const cfg = loadSubagentConfig();