Repository navigation
Description
Summary
After updating from 2026.4.24 to 2026.4.26, the gateway enters a tight crash-loop on startup if openclaw.json has logging.file set to a path beginning with ~. Under launchd this produces a respawn-loop every ~1.85s that takes the entire stack down (gateway, channels, sidecars, crons all unreachable).
Environment
- macOS 26.3 (arm64), Node 25.8.1
- Install path:
/Users/agent/.local/lib/node_modules/openclaw/ - Service: LaunchAgent
ai.openclaw.gateway - Pre-update version:
2026.4.24(working with this exact config) - Post-update version:
2026.4.26(crashes immediately)
Reproduction
- Have
openclaw.jsonwith:"logging": { "level": "info", "file": "~/.openclaw/logs/gateway.log", "consoleLevel": "warn", "redactSensitive": "tools" }
- Start the gateway with
2026.4.26. - Observe the gateway exit immediately with the error below, and (under launchd) be respawned in a tight loop.
Error
[openclaw] CLI failed: Error: ENOENT: no such file or directory, mkdir '~/.openclaw/logs'
at Object.mkdirSync (node:fs:1334:26)
at buildLogger (file:///.../node_modules/openclaw/dist/logger-BYIbL3gn.js:433:5)
at getLogger (file:///.../node_modules/openclaw/dist/logger-BYIbL3gn.js:496:31)
at getChildLogger (file:///.../node_modules/openclaw/dist/logger-BYIbL3gn.js:502:15)
at emitLog (file:///.../node_modules/openclaw/dist/subsystem-rHhUC6qs.js:163:30)
at Object.info (file:///.../node_modules/openclaw/dist/subsystem-rHhUC6qs.js:196:4)
at runGatewayCommand$1 (file:///.../node_modules/openclaw/dist/gateway-cli-l4SoRD2p.js:848:13)
mkdir fails because ~ is a shell construct, not a filesystem one. fs.mkdirSync does not expand it.
Root cause
In dist/logger-BYIbL3gn.js, resolveActiveLogFile returns the configured path verbatim — no tilde or $HOME expansion — and buildLogger then calls fs.mkdirSync(path.dirname(activeFile)) on the literal string:
function resolveActiveLogFile(file) {
if (!isRollingPath(file)) return file; // ← returns "~/.openclaw/logs/gateway.log" as-is
return rollingPathForDate(path.dirname(file), new Date());
}
function buildLogger(settings) {
...
let activeFile = resolveActiveLogFile(settings.file);
fs.mkdirSync(path.dirname(activeFile), { recursive: true }); // ← line 433: ENOENT on '~/...'
...
}The same config worked under 2026.4.24, so this is a regression — either a previously-existing tilde-expansion call was removed, or some earlier call site that expanded the path was bypassed.
Suggested fix
Expand a leading ~ (or ~/) to os.homedir() inside resolveActiveLogFile (or in a new expandHome helper used wherever a configured path crosses into fs.*):
import os from "node:os";
function expandHome(p) {
if (typeof p !== "string") return p;
if (p === "~") return os.homedir();
if (p.startsWith("~/")) return path.join(os.homedir(), p.slice(2));
return p;
}
function resolveActiveLogFile(file) {
const expanded = expandHome(file);
if (!isRollingPath(expanded)) return expanded;
return rollingPathForDate(path.dirname(expanded), new Date());
}Worth applying this to any other config-derived path that hits fs — e.g. agents.workspace, plugin paths — since users with ~/-prefixed paths in those fields will hit the same regression the moment a code path tries to mkdir them.
Workaround
Replace ~ with the absolute path in openclaw.json:
- "file": "~/.openclaw/logs/gateway.log",
+ "file": "/Users/<user>/.openclaw/logs/gateway.log",Severity
High. Anyone whose openclaw.json was written with a ~/-prefixed logging.file (which is intuitive and common) will have their entire gateway taken down on update. Under launchd / systemd the respawn-loop also produces a lot of error-log churn (~30 crash loops per minute) until manually intervened.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Apr 28, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.
Summary
Keep open. Current
mainand the latest shippedv2026.5.2still passlogging.filethrough the logger unchanged beforefs.mkdirSync, while the runtime config normalizer that expands~/...is bypassed by the logger’s direct config read; the linked fix PR #73614 is closed and unmerged.Reproducibility: yes. A high-confidence source-level reproduction exists: enable non-silent file logging with
logging.file: "~/.openclaw/logs/gateway.log"; currentmaincopiescfg.file, returns that non-rolling path unchanged, then creates the literal dirname.Next step
This is a valid, narrow startup crash with clear files, a closed unmerged reference PR, and a focused regression-test path.
Review details
Best possible solution:
Expand a leading home prefix at the logger filesystem boundary before rolling-path detection and directory creation, add focused regression coverage for non-rolling and rolling
logging.filepaths, and track any wider config path audit separately.Do we have a high-confidence way to reproduce the issue?
Yes. A high-confidence source-level reproduction exists: enable non-silent file logging with
logging.file: "~/.openclaw/logs/gateway.log"; currentmaincopiescfg.file, returns that non-rolling path unchanged, then creates the literal dirname.Is this the best way to solve the issue?
Yes. Reusing the existing home-prefix/path helper in
resolveActiveLogFile()beforeisRollingPath()is the narrowest maintainable repair; a broad audit should not block the startup crash fix.Acceptance criteria:
What I checked:
resolveSettings()reads the logging config directly and assignscfg?.fileto the resolved file path without home-prefix expansion. (src/logging/logger.ts:474, 9a49d143c819)buildLogger()callsresolveActiveLogFile(settings.file)and immediately createspath.dirname(activeFile);resolveActiveLogFile()returns non-rolling paths unchanged, so~/.openclaw/logs/gateway.logremains literal. (src/logging/logger.ts:520, 9a49d143c819)materializeRuntimeConfig()callsnormalizeConfigPaths(), whose test coverslogging.fileandagents.defaults.workspace;readLoggingConfig()instead parses and returns the rawloggingobject directly for logger startup. (src/config/materialize.ts:74, 9a49d143c819)logging.fileis read from the active config path, but it only uses an already-expanded temp path and does not cover leading-tilde file paths. (src/logging/logger-redaction-behavior.test.ts:66, 9a49d143c819)v2026.5.2points at8b2a6e57fef6c582ec6d27b85150616f9e3a7ba4, and itssrc/logging/logger.tsstill assignscfg?.file, callsfs.mkdirSync(path.dirname(activeFile)), and returns non-rolling active log paths unchanged. (src/logging/logger.ts:520, 8b2a6e57fef6)fix(logging): expand leading tilde in logging.file, and the provided GitHub context marks it closed, unmerged, with head SHA48e5220ad8e2f77806eede7c09161f49b38a3b23.Likely related people:
fix: normalize ~ in path config,fix: audit clobbered config reads, logging startup performance work, and rolling-log behavior, all adjacent to the broken boundary. (role: adjacent config/path and logging maintainer; confidence: high; commits: 328d47f1df45, f52752889b2b, 842087319b30; files:src/config/normalize-paths.ts,src/infra/home-dir.ts,src/logging/config.ts)src/logging/logger.ts,src/logging/console.ts,src/logging/config.ts)Remaining risk / open question:
~/...config-path audit is not fully scoped here; the immediate gateway crash is narrower and should be fixed first.Codex review notes: model gpt-5.5, reasoning high; reviewed against 9a49d143c819.
gabrielexito-stack commentedon Apr 28, 2026
Thanks @clawsweeper — confirms my read of the source. Calling out the second instance to give the suggested audit some concrete scope:
The same bug is latent on
agents.defaults.workspacein real-world configs. My affected config had:This did not cause an immediate gateway crash on the 2026.4.24 → 2026.4.26 update — only the
logging.filemkdir path was being hit eagerly during boot. But any future code path that resolvesagents.defaults.workspaceand then does anfs.mkdirSync/fs.writeFileSync/fs.cpSyncagainst it without going throughresolveUserPathwill produce the sameENOENT: no such file or directory, mkdir '~/.openclaw/workspace'failure mode. I patched it to an absolute path locally to remove the landmine, but most users with~/-prefixed workspace values won't know to.So if/when the audit happens, suggested coverage at minimum:
agents.defaults.workspacelogging.file(the original instance)agents.defaults.*or top-level config that resolves to a host path consumed bynode:fs—compaction.*paths,memory.*paths, plugin-derived config paths, etc.A focused integration test would be: write a fixture
openclaw.jsonwhere every config-derived path uses a leading~, boot the gateway in a clean home dir, and assert noENOENTmkdir errors on any path. Catches today's bug + every future regression of the same shape.steipete commentedon May 4, 2026
Fixed on current main.
Proof:
mainisc979ed3a3a87and the active changelog hasGateway/logging ... Fixes #73587.src/logging/logger.tsnow expands a leading home prefix inresolveActiveLogFile()before rolling-path detection and before the logger creates the containing directory.src/logging/logger-redaction-behavior.test.tsasserts that~/custom-openclaw.logresolves underHOME.Focused gate on current main:
pnpm test src/logging/logger-redaction-behavior.test.ts src/logging/log-file-size-cap.test.tsResult: 2 files passed, 12 tests passed.
Closing as fixed on main; this will be in the next release.