From 7b27d08e568edf2b3793e9b598b77365943595eb Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 17 Apr 2026 16:39:07 +0100 Subject: [PATCH] perf: lazy load system run config --- src/node-host/invoke-system-run.test.ts | 7 ++++++- src/node-host/invoke-system-run.ts | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/node-host/invoke-system-run.test.ts b/src/node-host/invoke-system-run.test.ts index 2aa2936457f..7ee2c2633f4 100644 --- a/src/node-host/invoke-system-run.test.ts +++ b/src/node-host/invoke-system-run.test.ts @@ -13,7 +13,11 @@ import { type Mock, vi, } from "vitest"; -import { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } from "../config/config.js"; +import { + clearRuntimeConfigSnapshot, + getRuntimeConfigSnapshot, + setRuntimeConfigSnapshot, +} from "../config/runtime-snapshot.js"; import type { SystemRunApprovalPlan } from "../infra/exec-approvals.js"; import { loadExecApprovals, saveExecApprovals } from "../infra/exec-approvals.js"; import type { ExecHostResponse } from "../infra/exec-host.js"; @@ -474,6 +478,7 @@ describe("handleSystemRunInvoke mac app exec host routing", () => { sendInvokeResult, sendExecFinishedEvent, preferMacAppExecHost: params.preferMacAppExecHost, + loadConfig: () => getRuntimeConfigSnapshot() ?? {}, }); return { diff --git a/src/node-host/invoke-system-run.ts b/src/node-host/invoke-system-run.ts index 5147b5d92df..e4a00e78070 100644 --- a/src/node-host/invoke-system-run.ts +++ b/src/node-host/invoke-system-run.ts @@ -1,6 +1,6 @@ import crypto from "node:crypto"; import { resolveAgentConfig } from "../agents/agent-scope.js"; -import { loadConfig } from "../config/config.js"; +import type { OpenClawConfig } from "../config/types.openclaw.js"; import type { GatewayClient } from "../gateway/client.js"; import { addDurableCommandApproval, @@ -171,8 +171,17 @@ export type HandleSystemRunInvokeOptions = { sendInvokeResult: (result: SystemRunInvokeResult) => Promise; sendExecFinishedEvent: (params: ExecFinishedEventParams) => Promise; preferMacAppExecHost: boolean; + loadConfig?: () => OpenClawConfig; }; +async function loadSystemRunConfig(opts: HandleSystemRunInvokeOptions): Promise { + if (opts.loadConfig) { + return opts.loadConfig(); + } + const { loadConfig } = await import("../config/config.js"); + return loadConfig(); +} + async function sendSystemRunDenied( opts: Pick< HandleSystemRunInvokeOptions, @@ -343,7 +352,7 @@ async function evaluateSystemRunPolicyPhase( opts: HandleSystemRunInvokeOptions, parsed: SystemRunParsePhase, ): Promise { - const cfg = loadConfig(); + const cfg = await loadSystemRunConfig(opts); const agentExec = parsed.agentId ? resolveAgentConfig(cfg, parsed.agentId)?.tools?.exec : undefined;