1+ import type { GatewayContextResolver } from "../../../gateway/server-methods/types.js" ;
12/** Owns subagent registration and queued collector launch transitions. */
23import {
34 getAgentEventLifecycleGeneration ,
45 isAgentEventLifecycleGenerationCurrent ,
56} from "../../../infra/agent-events.js" ;
67import { createSubsystemLogger } from "../../../logging/subsystem.js" ;
8+ import { bindGatewayContextResolver } from "../../../plugins/runtime/gateway-request-scope.js" ;
79import {
810 createQueuedTaskRun ,
911 createRunningTaskRun ,
@@ -87,6 +89,7 @@ export type RegisterSubagentRunParams = {
8789 /** Required when direct dispatch suppresses Gateway tracking. Out-of-process launches keep
8890 Gateway's existing best-effort CLI policy; other callers create a best-effort row here. */
8991 taskRowOwnership ?: "required" | "gateway_best_effort" ;
92+ gatewayContextResolver ?: GatewayContextResolver ;
9093} ;
9194
9295export class SubagentLaunchManager extends SubagentRecoveryManager {
@@ -181,6 +184,7 @@ export class SubagentLaunchManager extends SubagentRecoveryManager {
181184 retainAttachmentsOnKeep : registerParams . retainAttachmentsOnKeep ,
182185 } ) ;
183186 this . options . runs . set ( runId , entry ) ;
187+ bindGatewayContextResolver ( entry , registerParams . gatewayContextResolver ) ;
184188 const killReconciliationSnapshots = this . markOlderKillReconciliationsSuperseded ( entry ) ;
185189 const registeredKillReconciliationSnapshots = new Map (
186190 [ ...killReconciliationSnapshots . keys ( ) ] . map ( ( candidate ) => [
@@ -274,6 +278,7 @@ export class SubagentLaunchManager extends SubagentRecoveryManager {
274278 runId : string ,
275279 gatewayRunId ?: string ,
276280 lifecycleGeneration ?: string ,
281+ gatewayContextResolver ?: GatewayContextResolver ,
277282 ) : boolean => {
278283 const key = runId . trim ( ) ;
279284 const entry = this . findRunByIdentity ( key ) ;
@@ -367,6 +372,7 @@ export class SubagentLaunchManager extends SubagentRecoveryManager {
367372 try {
368373 this . options . persistOrThrow ( previousRunId , nextRunId ) ;
369374 if ( terminalBeforeAcceptance ) {
375+ bindGatewayContextResolver ( entry , gatewayContextResolver ) ;
370376 return true ;
371377 }
372378 persistedRunning = true ;
@@ -392,6 +398,7 @@ export class SubagentLaunchManager extends SubagentRecoveryManager {
392398 }
393399 throw error ;
394400 }
401+ bindGatewayContextResolver ( entry , gatewayContextResolver ) ;
395402 const cfg = this . options . getRuntimeConfig ( ) ;
396403 void this . waitForSubagentCompletion (
397404 nextRunId ,
0 commit comments