From 68fcd85bff3199113c9b04eaa212af5eddabecaf Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 11 Apr 2026 11:55:59 +0100 Subject: [PATCH] fix(tasks): narrow control runtime override type --- src/tasks/task-registry.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/tasks/task-registry.ts b/src/tasks/task-registry.ts index 25e82f97913..8fcd65bd3c5 100644 --- a/src/tasks/task-registry.ts +++ b/src/tasks/task-registry.ts @@ -63,24 +63,26 @@ type TaskRegistryDeliveryRuntime = Pick< typeof import("./task-registry-delivery-runtime.js"), "sendMessage" >; -type TaskRegistryControlRuntime = Pick< - typeof import("./task-registry-control.runtime.js"), - "getAcpSessionManager" | "killSubagentRunAdmin" ->; +type TaskRegistryControlRuntime = { + getAcpSessionManager: () => Pick< + ReturnType<(typeof import("./task-registry-control.runtime.js"))["getAcpSessionManager"]>, + "cancelSession" + >; + killSubagentRunAdmin: (typeof import("./task-registry-control.runtime.js"))["killSubagentRunAdmin"]; +}; const TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY = Symbol.for( "openclaw.taskRegistry.deliveryRuntimeOverride", ); const TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY = Symbol.for( "openclaw.taskRegistry.controlRuntimeOverride", ); -type TaskRegistryGlobalWithDeliveryOverride = typeof globalThis & { +type TaskRegistryGlobalWithRuntimeOverrides = typeof globalThis & { [TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY]?: TaskRegistryDeliveryRuntime | null; [TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY]?: TaskRegistryControlRuntime | null; }; let deliveryRuntimePromise: Promise | null = null; -let controlRuntimePromise: Promise | null = - null; +let controlRuntimePromise: Promise | null = null; type TaskDeliveryOwner = { sessionKey?: string; @@ -376,7 +378,7 @@ function appendTaskEvent(event: { } function loadTaskRegistryDeliveryRuntime() { - const deliveryRuntimeOverride = (globalThis as TaskRegistryGlobalWithDeliveryOverride)[ + const deliveryRuntimeOverride = (globalThis as TaskRegistryGlobalWithRuntimeOverrides)[ TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY ]; if (deliveryRuntimeOverride) { @@ -387,7 +389,7 @@ function loadTaskRegistryDeliveryRuntime() { } function loadTaskRegistryControlRuntime() { - const controlRuntimeOverride = (globalThis as TaskRegistryGlobalWithDeliveryOverride)[ + const controlRuntimeOverride = (globalThis as TaskRegistryGlobalWithRuntimeOverrides)[ TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY ]; if (controlRuntimeOverride) { @@ -1978,28 +1980,28 @@ export function resetTaskRegistryForTests(opts?: { persist?: boolean }) { } export function resetTaskRegistryDeliveryRuntimeForTests() { - (globalThis as TaskRegistryGlobalWithDeliveryOverride)[ + (globalThis as TaskRegistryGlobalWithRuntimeOverrides)[ TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY ] = null; deliveryRuntimePromise = null; } export function setTaskRegistryDeliveryRuntimeForTests(runtime: TaskRegistryDeliveryRuntime): void { - (globalThis as TaskRegistryGlobalWithDeliveryOverride)[ + (globalThis as TaskRegistryGlobalWithRuntimeOverrides)[ TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY ] = runtime; deliveryRuntimePromise = null; } export function resetTaskRegistryControlRuntimeForTests() { - (globalThis as TaskRegistryGlobalWithDeliveryOverride)[ + (globalThis as TaskRegistryGlobalWithRuntimeOverrides)[ TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY ] = null; controlRuntimePromise = null; } export function setTaskRegistryControlRuntimeForTests(runtime: TaskRegistryControlRuntime): void { - (globalThis as TaskRegistryGlobalWithDeliveryOverride)[ + (globalThis as TaskRegistryGlobalWithRuntimeOverrides)[ TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY ] = runtime; controlRuntimePromise = null;