From ed82c7e57be116ad49738448c0b2d39929ddbecb Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 15 Mar 2026 23:11:36 -0700 Subject: [PATCH] Status: lazy-load tailscale and memory scan deps --- src/commands/status.scan.deps.runtime.ts | 2 ++ src/commands/status.scan.test.ts | 7 ++---- src/commands/status.scan.ts | 31 ++++++++++++++++++------ 3 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 src/commands/status.scan.deps.runtime.ts diff --git a/src/commands/status.scan.deps.runtime.ts b/src/commands/status.scan.deps.runtime.ts new file mode 100644 index 00000000000..b9838d2176f --- /dev/null +++ b/src/commands/status.scan.deps.runtime.ts @@ -0,0 +1,2 @@ +export { getTailnetHostname } from "../infra/tailscale.js"; +export { getMemorySearchManager } from "../memory/index.js"; diff --git a/src/commands/status.scan.test.ts b/src/commands/status.scan.test.ts index 7dccbefb621..6e778070c09 100644 --- a/src/commands/status.scan.test.ts +++ b/src/commands/status.scan.test.ts @@ -51,8 +51,9 @@ vi.mock("../infra/os-summary.js", () => ({ resolveOsSummary: vi.fn(() => ({ label: "test-os" })), })); -vi.mock("../infra/tailscale.js", () => ({ +vi.mock("./status.scan.deps.runtime.js", () => ({ getTailnetHostname: vi.fn(), + getMemorySearchManager: vi.fn(), })); vi.mock("../gateway/call.js", () => ({ @@ -69,10 +70,6 @@ vi.mock("./status.gateway-probe.js", () => ({ resolveGatewayProbeAuthResolution: mocks.resolveGatewayProbeAuthResolution, })); -vi.mock("../memory/index.js", () => ({ - getMemorySearchManager: vi.fn(), -})); - vi.mock("../process/exec.js", () => ({ runExec: vi.fn(), })); diff --git a/src/commands/status.scan.ts b/src/commands/status.scan.ts index eaa9ad3066c..bbe10301624 100644 --- a/src/commands/status.scan.ts +++ b/src/commands/status.scan.ts @@ -8,8 +8,6 @@ import { buildGatewayConnectionDetails, callGateway } from "../gateway/call.js"; import { normalizeControlUiBasePath } from "../gateway/control-ui-shared.js"; import { probeGateway } from "../gateway/probe.js"; import { resolveOsSummary } from "../infra/os-summary.js"; -import { getTailnetHostname } from "../infra/tailscale.js"; -import { getMemorySearchManager } from "../memory/index.js"; import type { MemoryProviderStatus } from "../memory/types.js"; import { runExec } from "../process/exec.js"; import type { RuntimeEnv } from "../runtime.js"; @@ -51,6 +49,9 @@ type GatewayProbeSnapshot = { let pluginRegistryModulePromise: Promise | undefined; let statusScanRuntimeModulePromise: Promise | undefined; +let statusScanDepsRuntimeModulePromise: + | Promise + | undefined; function loadPluginRegistryModule() { pluginRegistryModulePromise ??= import("../cli/plugin-registry.js"); @@ -62,6 +63,11 @@ function loadStatusScanRuntimeModule() { return statusScanRuntimeModulePromise; } +function loadStatusScanDepsRuntimeModule() { + statusScanDepsRuntimeModulePromise ??= import("./status.scan.deps.runtime.js"); + return statusScanDepsRuntimeModulePromise; +} + function deferResult(promise: Promise): Promise> { return promise.then( (value) => ({ ok: true, value }), @@ -184,6 +190,7 @@ async function resolveMemoryStatusSnapshot(params: { return null; } const agentId = agentStatus.defaultId ?? "main"; + const { getMemorySearchManager } = await loadStatusScanDepsRuntimeModule(); const { manager } = await getMemorySearchManager({ cfg, agentId, purpose: "status" }); if (!manager) { return null; @@ -226,9 +233,13 @@ async function scanStatusJsonFast(opts: { const tailscaleDnsPromise = tailscaleMode === "off" ? Promise.resolve(null) - : getTailnetHostname((cmd, args) => - runExec(cmd, args, { timeoutMs: 1200, maxBuffer: 200_000 }), - ).catch(() => null); + : loadStatusScanDepsRuntimeModule() + .then(({ getTailnetHostname }) => + getTailnetHostname((cmd, args) => + runExec(cmd, args, { timeoutMs: 1200, maxBuffer: 200_000 }), + ), + ) + .catch(() => null); const gatewayProbePromise = resolveGatewayProbeSnapshot({ cfg, opts }); @@ -318,9 +329,13 @@ export async function scanStatus( const tailscaleDnsPromise = tailscaleMode === "off" ? Promise.resolve(null) - : getTailnetHostname((cmd, args) => - runExec(cmd, args, { timeoutMs: 1200, maxBuffer: 200_000 }), - ).catch(() => null); + : loadStatusScanDepsRuntimeModule() + .then(({ getTailnetHostname }) => + getTailnetHostname((cmd, args) => + runExec(cmd, args, { timeoutMs: 1200, maxBuffer: 200_000 }), + ), + ) + .catch(() => null); const updateTimeoutMs = opts.all ? 6500 : 2500; const updatePromise = deferResult( getUpdateCheckResult({