From a08fbfb1aea9d52b873fbbcfa1e83ccad61e61b9 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 13 Apr 2026 16:23:27 +0100 Subject: [PATCH] perf(cron): lazy-load isolated cli runner runtime --- .../run-execution-cli.runtime.ts | 1 + .../isolated-agent/run-execution.runtime.ts | 24 ++++++++++++++++++- src/cron/isolated-agent/run-executor.ts | 6 ++--- src/cron/isolated-agent/run.runtime.ts | 1 + src/cron/isolated-agent/run.test-harness.ts | 1 + src/cron/isolated-agent/run.ts | 2 +- 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/cron/isolated-agent/run-execution-cli.runtime.ts diff --git a/src/cron/isolated-agent/run-execution-cli.runtime.ts b/src/cron/isolated-agent/run-execution-cli.runtime.ts new file mode 100644 index 00000000000..0be325f01d7 --- /dev/null +++ b/src/cron/isolated-agent/run-execution-cli.runtime.ts @@ -0,0 +1 @@ +export { getCliSessionId, runCliAgent } from "../../agents/cli-runner.runtime.js"; diff --git a/src/cron/isolated-agent/run-execution.runtime.ts b/src/cron/isolated-agent/run-execution.runtime.ts index 9688bff4661..bb70d126dc1 100644 --- a/src/cron/isolated-agent/run-execution.runtime.ts +++ b/src/cron/isolated-agent/run-execution.runtime.ts @@ -1,6 +1,5 @@ export { resolveEffectiveModelFallbacks } from "../../agents/agent-scope.js"; export { resolveBootstrapWarningSignaturesSeen } from "../../agents/bootstrap-budget.js"; -export { getCliSessionId, runCliAgent } from "../../agents/cli-runner.runtime.js"; export { resolveFastModeState } from "../../agents/fast-mode.js"; export { resolveNestedAgentLane } from "../../agents/lanes.js"; export { LiveSessionModelSwitchError } from "../../agents/live-model-switch.js"; @@ -15,3 +14,26 @@ export { normalizeVerboseLevel } from "../../auto-reply/thinking.js"; export { resolveSessionTranscriptPath } from "../../config/sessions.js"; export { registerAgentRunContext } from "../../infra/agent-events.js"; export { logWarn } from "../../logger.js"; + +let cronExecutionCliRuntimePromise: + | Promise + | undefined; + +async function loadCronExecutionCliRuntime() { + cronExecutionCliRuntimePromise ??= import("./run-execution-cli.runtime.js"); + return await cronExecutionCliRuntimePromise; +} + +export async function getCliSessionId( + ...args: Parameters +): Promise> { + const runtime = await loadCronExecutionCliRuntime(); + return runtime.getCliSessionId(...args); +} + +export async function runCliAgent( + ...args: Parameters +): ReturnType { + const runtime = await loadCronExecutionCliRuntime(); + return runtime.runCliAgent(...args); +} diff --git a/src/cron/isolated-agent/run-executor.ts b/src/cron/isolated-agent/run-executor.ts index 172aa2f2d01..14ecf3f7eb1 100644 --- a/src/cron/isolated-agent/run-executor.ts +++ b/src/cron/isolated-agent/run-executor.ts @@ -6,10 +6,10 @@ import type { CronJob } from "../types.js"; import { resolveCronPayloadOutcome } from "./helpers.js"; import { countActiveDescendantRuns, - listDescendantRunsForRequester, - LiveSessionModelSwitchError, getCliSessionId, isCliProvider, + listDescendantRunsForRequester, + LiveSessionModelSwitchError, logWarn, normalizeVerboseLevel, registerAgentRunContext, @@ -104,7 +104,7 @@ export function createCronPromptExecutor(params: { if (isCliProvider(providerOverride, params.cfgWithAgentDefaults)) { const cliSessionId = params.cronSession.isNewSession ? undefined - : getCliSessionId(params.cronSession.sessionEntry, providerOverride); + : await getCliSessionId(params.cronSession.sessionEntry, providerOverride); const result = await runCliAgent({ sessionId: params.cronSession.sessionEntry.sessionId, sessionKey: params.agentSessionKey, diff --git a/src/cron/isolated-agent/run.runtime.ts b/src/cron/isolated-agent/run.runtime.ts index a2080565004..65d07692b2d 100644 --- a/src/cron/isolated-agent/run.runtime.ts +++ b/src/cron/isolated-agent/run.runtime.ts @@ -31,6 +31,7 @@ export { normalizeThinkLevel, supportsXHighThinking } from "../../auto-reply/thi export { createOutboundSendDeps } from "../../cli/outbound-send-deps.js"; export { resolveAgentMainSessionKey, + resolveSessionTranscriptPath, setSessionRuntimeModel, updateSessionStore, } from "../../config/sessions.js"; diff --git a/src/cron/isolated-agent/run.test-harness.ts b/src/cron/isolated-agent/run.test-harness.ts index 2019a88d4d7..826b9c22e37 100644 --- a/src/cron/isolated-agent/run.test-harness.ts +++ b/src/cron/isolated-agent/run.test-harness.ts @@ -121,6 +121,7 @@ vi.mock("./run.runtime.js", () => ({ ensureAgentWorkspace: ensureAgentWorkspaceMock, normalizeThinkLevel: normalizeThinkLevelMock, supportsXHighThinking: supportsXHighThinkingMock, + resolveSessionTranscriptPath: resolveSessionTranscriptPathMock, setSessionRuntimeModel: setSessionRuntimeModelMock, setCliSessionId: vi.fn(), logWarn: (...args: unknown[]) => logWarnMock(...args), diff --git a/src/cron/isolated-agent/run.ts b/src/cron/isolated-agent/run.ts index bba5adbd9d8..934b9848252 100644 --- a/src/cron/isolated-agent/run.ts +++ b/src/cron/isolated-agent/run.ts @@ -18,7 +18,6 @@ import { } from "./helpers.js"; import { resolveCronModelSelection } from "./model-selection.js"; import { buildCronAgentDefaultsConfig } from "./run-config.js"; -import { resolveSessionTranscriptPath } from "./run-execution.runtime.js"; import { executeCronRun, type CronExecutionResult } from "./run-executor.js"; import { createPersistCronSessionEntry, @@ -50,6 +49,7 @@ import { resolveCronStyleNow, resolveDefaultAgentId, resolveHookExternalContentSource, + resolveSessionTranscriptPath, resolveSessionAuthProfileOverride, resolveThinkingDefault, setSessionRuntimeModel,