Skip to content

Gateway crash loop in 2026.4.26: logging.file paths starting with ~ are no longer expanded #73587

Closed

Description

@gabrielexito-stack

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

  1. Have openclaw.json with:
    "logging": {
      "level": "info",
      "file": "~/.openclaw/logs/gateway.log",
      "consoleLevel": "warn",
      "redactSensitive": "tools"
    }
  2. Start the gateway with 2026.4.26.
  3. 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.

Activity

  1. clawsweeper commented on Apr 28, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

    Summary
    Keep open. Current main and the latest shipped v2026.5.2 still pass logging.file through the logger unchanged before fs.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"; current main copies cfg.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.file paths, 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"; current main copies cfg.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() before isRollingPath() is the narrowest maintainable repair; a broad audit should not block the startup crash fix.

    Acceptance criteria:

    • pnpm exec oxfmt --check --threads=1 src/logging/logger.ts src/logging/logger-settings.test.ts src/logging/logger-redaction-behavior.test.ts CHANGELOG.md
    • pnpm test src/logging/logger-settings.test.ts src/logging/logger-redaction-behavior.test.ts src/logging/log-file-size-cap.test.ts
    • pnpm check:changed in Testbox before handoff

    What I checked:

    • Raw logging file path reaches logger settings: resolveSettings() reads the logging config directly and assigns cfg?.file to the resolved file path without home-prefix expansion. (src/logging/logger.ts:474, 9a49d143c819)
    • Crash boundary still uses unexpanded dirname: buildLogger() calls resolveActiveLogFile(settings.file) and immediately creates path.dirname(activeFile); resolveActiveLogFile() returns non-rolling paths unchanged, so ~/.openclaw/logs/gateway.log remains literal. (src/logging/logger.ts:520, 9a49d143c819)
    • Normal config materialization expands tilde paths, but logger bypasses it: materializeRuntimeConfig() calls normalizeConfigPaths(), whose test covers logging.file and agents.defaults.workspace; readLoggingConfig() instead parses and returns the raw logging object directly for logger startup. (src/config/materialize.ts:74, 9a49d143c819)
    • Regression coverage gap: Existing logger coverage verifies that logging.file is 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)
    • Latest release still has the same flow: Tag v2026.5.2 points at 8b2a6e57fef6c582ec6d27b85150616f9e3a7ba4, and its src/logging/logger.ts still assigns cfg?.file, calls fs.mkdirSync(path.dirname(activeFile)), and returns non-rolling active log paths unchanged. (src/logging/logger.ts:520, 8b2a6e57fef6)
    • Linked implementation is not merged: The issue timeline links PR fix(logging): expand leading tilde in logging.file (#73587) #73614 as fix(logging): expand leading tilde in logging.file, and the provided GitHub context marks it closed, unmerged, with head SHA 48e5220ad8e2f77806eede7c09161f49b38a3b23.

    Likely related people:

    • steipete: Local history ties Peter to 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)
    • vincentkoc: Local history shows recent merged work on logging module structure and logger/console cycle cleanup, and the prior review context also connected Vincent to recent logging config and rolling-log work. (role: recent logging maintainer; confidence: medium; commits: 91ad1e5fc584, 74e7b8d47b18; files: src/logging/logger.ts, src/logging/console.ts, src/logging/config.ts)

    Remaining risk / open question:

    • The reporter’s broader ~/... 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.

  2. gabrielexito-stack commented on Apr 28, 2026

    @gabrielexito-stack
    Author

    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.workspace in real-world configs. My affected config had:

    "agents": {
      "defaults": {
        "workspace": "~/.openclaw/workspace",
        ...
      }
    }

    This did not cause an immediate gateway crash on the 2026.4.24 → 2026.4.26 update — only the logging.file mkdir path was being hit eagerly during boot. But any future code path that resolves agents.defaults.workspace and then does an fs.mkdirSync / fs.writeFileSync / fs.cpSync against it without going through resolveUserPath will produce the same ENOENT: 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.workspace
    • logging.file (the original instance)
    • Anything else under agents.defaults.* or top-level config that resolves to a host path consumed by node:fs — compaction.* paths, memory.* paths, plugin-derived config paths, etc.

    A focused integration test would be: write a fixture openclaw.json where every config-derived path uses a leading ~, boot the gateway in a clean home dir, and assert no ENOENT mkdir errors on any path. Catches today's bug + every future regression of the same shape.

  3. steipete commented on May 4, 2026

    @steipete
    Contributor

    Fixed on current main.

    Proof:

    • Current main is c979ed3a3a87 and the active changelog has Gateway/logging ... Fixes #73587.
    • src/logging/logger.ts now expands a leading home prefix in resolveActiveLogFile() before rolling-path detection and before the logger creates the containing directory.
    • Regression coverage in src/logging/logger-redaction-behavior.test.ts asserts that ~/custom-openclaw.log resolves under HOME.

    Focused gate on current main:

    pnpm test src/logging/logger-redaction-behavior.test.ts src/logging/log-file-size-cap.test.ts

    Result: 2 files passed, 12 tests passed.

    Closing as fixed on main; this will be in the next release.

  4. locked as resolved and limited conversation to collaborators on May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions