fix(gateway): fail closed on missing mode

This commit is contained in:
Peter Steinberger
2026-04-03 19:48:46 +09:00
parent a6649201b7
commit 2c7eea8f10
5 changed files with 10 additions and 11 deletions

View File

@@ -207,7 +207,7 @@ describe("gateway run option collisions", () => {
);
});
it("defaults to local when snapshot is valid but has no gateway.mode", async () => {
it("blocks startup when the observed snapshot loses gateway.mode even if loadConfig still says local", async () => {
configState.cfg = {
gateway: {
mode: "local",
@@ -224,10 +224,12 @@ describe("gateway run option collisions", () => {
},
};
// Should NOT block — gateway.mode defaults to "local" when unset (#54801)
await runGatewayCli(["gateway", "run"]);
await expect(runGatewayCli(["gateway", "run"])).rejects.toThrow("__exit__:1");
expect(startGatewayServer).toHaveBeenCalled();
expect(runtimeErrors).toContain(
"Gateway start blocked: set gateway.mode=local (current: unset) or pass --allow-unconfigured.",
);
expect(startGatewayServer).not.toHaveBeenCalled();
});
it.each(["none", "trusted-proxy"] as const)("accepts --auth %s override", async (mode) => {

View File

@@ -348,12 +348,7 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
const configExists = snapshot?.exists ?? fs.existsSync(CONFIG_PATH);
const configAuditPath = path.join(resolveStateDir(process.env), "logs", "config-audit.jsonl");
const effectiveCfg = snapshot?.valid ? snapshot.config : cfg;
// Default to "local" when gateway.mode is unset. Prior to v2026.3.24 the
// gateway started without an explicit mode; the guard added in 3.24
// regressed startup on Windows (and other platforms) when the config file
// exists but doesn't contain gateway.mode — e.g. after `openclaw onboard`
// writes a minimal config. (#54801)
const mode = effectiveCfg.gateway?.mode ?? "local";
const mode = effectiveCfg.gateway?.mode;
if (!opts.allowUnconfigured && mode !== "local") {
if (!configExists) {
defaultRuntime.error(