Skip to content

Commit 7b172d6

Browse files
committed
Revert "fix: respect OPENCLAW_HOME for isolated gateway instances"
This reverts commit 34b18ea.
1 parent 014a46d commit 7b172d6

2 files changed

Lines changed: 7 additions & 36 deletions

File tree

‎src/cli/gateway-cli/run.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "node:path";
33
import type { Command } from "commander";
44
import type { GatewayAuthMode } from "../../config/config.js";
55
import {
6-
getConfigPath,
6+
CONFIG_PATH,
77
loadConfig,
88
readConfigFileSnapshot,
99
resolveStateDir,
@@ -161,7 +161,7 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
161161
const tokenRaw = toOptionString(opts.token);
162162

163163
const snapshot = await readConfigFileSnapshot().catch(() => null);
164-
const configExists = snapshot?.exists ?? fs.existsSync(getConfigPath());
164+
const configExists = snapshot?.exists ?? fs.existsSync(CONFIG_PATH);
165165
const configAuditPath = path.join(resolveStateDir(process.env), "logs", "config-audit.jsonl");
166166
const mode = cfg.gateway?.mode;
167167
if (!opts.allowUnconfigured && mode !== "local") {

‎src/config/paths.ts‎

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,8 @@ export function resolveConfigPath(
182182
return path.join(stateDir, CONFIG_FILENAME);
183183
}
184184

185-
/**
186-
* @deprecated Use resolveConfigPathCandidate() instead. This constant is evaluated
187-
* at module load time and does not respect OPENCLAW_HOME set after import.
188-
* Kept for backwards compatibility but should be avoided in new code.
189-
*/
190185
export const CONFIG_PATH = resolveConfigPathCandidate();
191186

192-
/**
193-
* Runtime-evaluated config path that respects OPENCLAW_HOME.
194-
* Use this instead of CONFIG_PATH when OPENCLAW_HOME may be set dynamically.
195-
*/
196-
export function getConfigPath(env: NodeJS.ProcessEnv = process.env): string {
197-
return resolveConfigPathCandidate(env, envHomedir(env));
198-
}
199-
200187
/**
201188
* Resolve default config path candidates across default locations.
202189
* Order: explicit config path → state-dir-derived paths → new default.
@@ -271,34 +258,18 @@ export function resolveGatewayPort(
271258
cfg?: OpenClawConfig,
272259
env: NodeJS.ProcessEnv = process.env,
273260
): number {
274-
// When OPENCLAW_HOME is set (isolated instance), prefer config over inherited env vars.
275-
// This prevents a parent gateway's OPENCLAW_GATEWAY_PORT from bleeding through.
276-
const isIsolatedInstance = Boolean(env.OPENCLAW_HOME?.trim());
277-
278-
// Config port takes precedence for isolated instances
279-
const configPort = cfg?.gateway?.port;
280-
if (
281-
isIsolatedInstance &&
282-
typeof configPort === "number" &&
283-
Number.isFinite(configPort) &&
284-
configPort > 0
285-
) {
286-
return configPort;
287-
}
288-
289-
// Check env vars (for non-isolated or when config doesn't specify port)
290261
const envRaw = env.OPENCLAW_GATEWAY_PORT?.trim() || env.CLAWDBOT_GATEWAY_PORT?.trim();
291262
if (envRaw) {
292263
const parsed = Number.parseInt(envRaw, 10);
293264
if (Number.isFinite(parsed) && parsed > 0) {
294265
return parsed;
295266
}
296267
}
297-
298-
// Fall back to config for non-isolated instances
299-
if (typeof configPort === "number" && Number.isFinite(configPort) && configPort > 0) {
300-
return configPort;
268+
const configPort = cfg?.gateway?.port;
269+
if (typeof configPort === "number" && Number.isFinite(configPort)) {
270+
if (configPort > 0) {
271+
return configPort;
272+
}
301273
}
302-
303274
return DEFAULT_GATEWAY_PORT;
304275
}

0 commit comments

Comments
 (0)