mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-25 08:02:04 +00:00
refactor: lazy load task cancellation control runtime
This commit is contained in:
committed by
Peter Steinberger
parent
192c02cd92
commit
08560c1f48
2
src/tasks/task-registry-control.runtime.ts
Normal file
2
src/tasks/task-registry-control.runtime.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { getAcpSessionManager } from "../acp/control-plane/manager.js";
|
||||
export { killSubagentRunAdmin } from "../agents/subagent-control.js";
|
||||
@@ -1,6 +1,4 @@
|
||||
import crypto from "node:crypto";
|
||||
import { getAcpSessionManager } from "../acp/control-plane/manager.js";
|
||||
import { killSubagentRunAdmin } from "../agents/subagent-control.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { onAgentEvent } from "../infra/agent-events.js";
|
||||
import { requestHeartbeatNow } from "../infra/heartbeat-wake.js";
|
||||
@@ -61,6 +59,8 @@ let listenerStop: (() => void) | null = null;
|
||||
let restoreAttempted = false;
|
||||
let deliveryRuntimePromise: Promise<typeof import("./task-registry-delivery-runtime.js")> | null =
|
||||
null;
|
||||
let controlRuntimePromise: Promise<typeof import("./task-registry-control.runtime.js")> | null =
|
||||
null;
|
||||
|
||||
type TaskDeliveryOwner = {
|
||||
sessionKey?: string;
|
||||
@@ -365,6 +365,13 @@ function loadTaskRegistryDeliveryRuntime() {
|
||||
return deliveryRuntimePromise;
|
||||
}
|
||||
|
||||
function loadTaskRegistryControlRuntime() {
|
||||
// Registry reads happen far more often than task cancellation, so keep the ACP/subagent
|
||||
// control graph off the default import path until a cancellation flow actually needs it.
|
||||
controlRuntimePromise ??= import("./task-registry-control.runtime.js");
|
||||
return controlRuntimePromise;
|
||||
}
|
||||
|
||||
function addRunIdIndex(taskId: string, runId?: string) {
|
||||
const trimmed = runId?.trim();
|
||||
if (!trimmed) {
|
||||
@@ -1708,12 +1715,14 @@ export async function cancelTaskById(params: {
|
||||
}
|
||||
try {
|
||||
if (task.runtime === "acp") {
|
||||
const { getAcpSessionManager } = await loadTaskRegistryControlRuntime();
|
||||
await getAcpSessionManager().cancelSession({
|
||||
cfg: params.cfg,
|
||||
sessionKey: childSessionKey,
|
||||
reason: "task-cancel",
|
||||
});
|
||||
} else if (task.runtime === "subagent") {
|
||||
const { killSubagentRunAdmin } = await loadTaskRegistryControlRuntime();
|
||||
const result = await killSubagentRunAdmin({
|
||||
cfg: params.cfg,
|
||||
sessionKey: childSessionKey,
|
||||
|
||||
Reference in New Issue
Block a user