Skip to content

Commit a491a21

Browse files
committed
perf(cli): keep gateway status off full config IO
1 parent 992ecc3 commit a491a21

9 files changed

Lines changed: 167 additions & 200 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { readBestEffortConfig, resolveGatewayPort } from "../../config/config.js";
2+
import { createConfigIO } from "../../config/io.js";
3+
import { mergeGatewayServiceEnv } from "../../daemon/service-env-merge.js";
4+
import { resolveGatewayService } from "../../daemon/service.js";
5+
import { parseTcpPortFromArgs } from "../../infra/tcp-port.js";
6+
7+
export async function resolveGatewayLifecycleContext(
8+
service = resolveGatewayService(),
9+
requireEffective = false,
10+
) {
11+
const command = requireEffective
12+
? await service.readCommand(process.env, { requireEffective: true })
13+
: await service.readCommand(process.env).catch(() => null);
14+
if (requireEffective && !command) {
15+
throw new Error(
16+
"Updated gateway service could not be inspected; run `openclaw gateway status --deep`.",
17+
);
18+
}
19+
const env = mergeGatewayServiceEnv(process.env, command);
20+
const config = await createConfigIO({
21+
env,
22+
observe: false,
23+
pluginValidation: "skip",
24+
suppressFutureVersionWarning: true,
25+
})
26+
.readBestEffortConfig()
27+
.catch(() => undefined);
28+
const port = parseTcpPortFromArgs(command?.programArguments) ?? resolveGatewayPort(config, env);
29+
return { port, env, command };
30+
}
31+
32+
export async function resolveGatewayConfigPorts() {
33+
const config = await readBestEffortConfig({ observe: false }).catch(() => undefined);
34+
return { explicit: config?.gateway?.port, fallback: resolveGatewayPort(config, process.env) };
35+
}

‎src/cli/daemon-cli/lifecycle.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
appendGatewayLifecycleAudit,
4949
createGatewayLifecycleMutationAudit,
5050
} from "./lifecycle-audit.js";
51+
import { resolveGatewayConfigPorts, resolveGatewayLifecycleContext } from "./lifecycle-context.js";
5152
import {
5253
runServiceRestart,
5354
runServiceStart,
@@ -69,11 +70,7 @@ import {
6970
waitForGatewayHealthyListener,
7071
waitForGatewayHealthyRestart,
7172
} from "./restart-health.js";
72-
import {
73-
resolveGatewayLifecycleContext,
74-
resolveGatewayConfigPorts,
75-
renderGatewayServiceStartHints,
76-
} from "./shared.js";
73+
import { renderGatewayServiceStartHints } from "./shared.js";
7774
import { repairLoadedGatewayServiceForStart } from "./start-repair.js";
7875
import type { DaemonLifecycleOptions } from "./types.js";
7976

‎src/cli/daemon-cli/shared.ts‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Shared Gateway service CLI helpers: status styles, env filtering, port parsing, and hints.
22
import { colorize, isRich, theme } from "../../../packages/terminal-core/src/theme.js";
3-
import { readBestEffortConfig, resolveGatewayPort } from "../../config/config.js";
4-
import { createConfigIO } from "../../config/io.js";
53
import { resolveIsNixMode } from "../../config/paths.js";
64
import {
75
resolveGatewayLaunchAgentLabel,
@@ -14,9 +12,6 @@ import {
1412
buildPlatformRuntimeLogHints,
1513
buildPlatformServiceStartHints,
1614
} from "../../daemon/runtime-hints.js";
17-
import { mergeGatewayServiceEnv } from "../../daemon/service-env-merge.js";
18-
import { resolveGatewayService } from "../../daemon/service.js";
19-
import { parseTcpPortFromArgs } from "../../infra/tcp-port.js";
2015
import { formatCliCommand } from "../command-format.js";
2116
import { parsePort } from "../shared/parse-port.js";
2217
import { createDaemonActionContext } from "./response.js";
@@ -225,33 +220,3 @@ export function filterContainerGenericHints(
225220
!hint.includes("systemd user services are unavailable; install/enable systemd"),
226221
);
227222
}
228-
229-
export async function resolveGatewayLifecycleContext(
230-
service = resolveGatewayService(),
231-
requireEffective = false,
232-
) {
233-
const command = requireEffective
234-
? await service.readCommand(process.env, { requireEffective: true })
235-
: await service.readCommand(process.env).catch(() => null);
236-
if (requireEffective && !command) {
237-
throw new Error(
238-
"Updated gateway service could not be inspected; run `openclaw gateway status --deep`.",
239-
);
240-
}
241-
const env = mergeGatewayServiceEnv(process.env, command);
242-
const config = await createConfigIO({
243-
env,
244-
observe: false,
245-
pluginValidation: "skip",
246-
suppressFutureVersionWarning: true,
247-
})
248-
.readBestEffortConfig()
249-
.catch(() => undefined);
250-
const port = parseTcpPortFromArgs(command?.programArguments) ?? resolveGatewayPort(config, env);
251-
return { port, env, command };
252-
}
253-
254-
export async function resolveGatewayConfigPorts() {
255-
const config = await readBestEffortConfig({ observe: false }).catch(() => undefined);
256-
return { explicit: config?.gateway?.port, fallback: resolveGatewayPort(config, process.env) };
257-
}

0 commit comments

Comments
 (0)