Skip to content

Auto-started daemon with a deleted startup directory blocks every new TUI session with "Cannot use the background server" (experimentalFeature/list → "failed to reload config: No such file or directory") #50619

Closed

Description

@sunburst89757

What version of Codex CLI is running?

codex-cli 0.160.0 (npm, linux-x86_64)

What subscription do you have?

ChatGPT (sign-in with ChatGPT account)

Which model were you using?

n/a — the failure happens during TUI startup, before any turn starts.

What platform is your computer?

Linux x86_64, headless SSH server (TencentOS Server 4.4, kernel 5.4)

What terminal emulator and version are you using (if applicable)?

SSH session running inside herdr (a terminal workspace manager whose task panes run in per-task git worktrees). The terminal itself doesn't matter; herdr matters only because it removes a worktree when the task ends — which is exactly what deletes the daemon's startup directory below.

Codex doctor report

Excerpt (paths sanitized). Note that doctor reports the background server as healthy while it is broken — the control-socket probes it uses never reload config:

{
  "app_server.status": {
    "status": "ok",
    "summary": "background server is running",
    "details": {
      "app-server version": "0.160.0",
      "control socket": "/home/<user>/.codex/app-server-control/app-server-control.sock",
      "mode": "ephemeral",
      "status": "running"
    }
  },
  "config.load": {
    "status": "ok",
    "summary": "config loaded",
    "details": {
      "CODEX_HOME": "/home/<user>/.codex",
      "config.toml parse": "ok",
      "cwd": "/home/<user>",
      "feature flag overrides": "none"
    }
  }
}

What issue are you seeing?

Every interactive codex start is blocked by the dialog "Cannot use the background server" with reason "Experimental feature request failed". "Restart with these settings" is disabled ("Restart cannot resolve this compatibility check."), so the only ways forward are "Run without daemon this time" or Cancel — and the next start hits the same dialog. This affects every session from any directory until the daemon is manually restarted.

Root cause: the auto-started managed daemon inherits the CWD of whichever terminal first launched it. When that directory is later deleted, every daemon RPC that reloads config without a cwd override fails with ENOENT. The TUI runs a daemon-feature compatibility check on every startup (request id tui-daemon-features, tui/src/daemon_startup.rs:145), which calls experimentalFeature/list; its handler reloads config strictly and turns the ENOENT into an internal error:

app-server/src/request_processors/catalog_processor.rs
  experimental_feature_list_response (v0.160.0 :346)
    → self.load_latest_config(/*fallback_cwd*/ None)                            // :373
      → config load with no cwd override
        → AbsolutePathBuf::current_dir()?     // core/src/config/mod.rs:1513 (v0.160.0; :1526 on current main)
          → ENOENT because the daemon cwd was deleted
    → .map_err(|err| internal_error(format!("failed to reload config: {err}")))  // :277

so the daemon answers:

{"error":{"code":-32603,"message":"failed to reload config: No such file or directory (os error 2)"}}

tui/src/experimental_features.rs:46 maps that to "Experimental feature request failed", which daemon_recovery.rs renders as the blocking dialog (restart disabled because restart_features is None).

Evidence, all reproduced locally on 0.160.0:

  1. Daemon process (PPID 1, started the previous day):
    $ readlink /proc/<pid>/cwd
    /home/<user>/.herdr/worktrees/<repo>/<branch> (deleted)
    $ tr '\0' ' ' < /proc/<pid>/cmdline
    /home/<user>/.codex/packages/app-server-daemon/releases/0.160.0-x86_64-unknown-linux-musl/bin/codex app-server --listen unix:// --managed-daemon
    
  2. Direct JSON-RPC against the control socket ($CODEX_HOME/app-server-control/app-server-control.sock, WebSocket upgrade over the Unix socket): initialize → OK; experimentalFeature/list → the -32603 error above.
  3. Controlled experiment with the same daemon binary: started in a temp dir, experimentalFeature/list answers normally with the full feature list (~154 entries); after rm -rf of that dir the very same request immediately returns the -32603 error. Nothing else changed — deleting the daemon's CWD alone is sufficient.
  4. codex doctor reports the background server healthy (excerpt above) while all of this is happening, because its probes never reload config.

What steps can reproduce the bug?

codex app-server daemon stop        # start clean (or use a fresh CODEX_HOME)
mkdir /tmp/A && cd /tmp/A
codex                               # auto-starts the managed daemon with cwd=/tmp/A
# exit codex; the daemon persists (PPID 1)
cd ~ && rm -rf /tmp/A
codex                               # → "Cannot use the background server", every start

Real-world trigger: the first codex session of the day runs inside a git worktree that is later cleaned up (task-per-worktree workflows, terminal workspace managers). Since the daemon's CWD is inherited from that first session, it is effectively guaranteed to be a disposable directory.

What is the expected behavior?

Any of these would resolve it — and the in-tree patterns already exist:

  • The daemon should not depend on the lifetime of its startup directory (e.g. chdir to $CODEX_HOME or / at startup).
  • This RPC could pass a stable fallback cwd, or fall back to the startup config on reload failure. Both patterns are already in the 0.160.0 tree:
    • app-server/src/config_manager.rs load_default_config() builds with .fallback_cwd(Some(self.codex_home.clone()));
    • request_processors/account_processor.rs load_latest_config() logs "failed to reload config, using startup config" and continues with the startup config.
  • The tui-daemon-features compatibility check could treat a config-reload failure as "daemon unhealthy — offer restart" instead of a dead-end dialog.

Additional information

Activity

  1. added
    bug
    CLI
    app-server
    on Oct 3, 2026
  2. Welith commented on Oct 4, 2026

    @Welith

    Independent confirmation on macOS ARM with the same failure mode.

    Environment:

    • Codex CLI 0.160.0, installed through npm
    • Managed app-server 0.160.0
    • macOS 26.4.0, arm64
    • Apple Terminal 470

    The managed daemon had remained alive after its startup project directory was deleted. lsof -a -p <daemon-pid> -d cwd still showed that deleted project as the daemon's CWD, while a normal filesystem lookup for the path returned ENOENT.

    I connected directly to the daemon's Unix control socket, initialized with experimentalApi: true, and sent experimentalFeature/list with limit: 100. The literal response was:

    {
      "error": {
        "code": -32603,
        "message": "failed to reload config: No such file or directory (os error 2)"
      },
      "id": 2
    }

    As a control, I started a fresh app-server from an existing directory using the same installed CLI version and the same user configuration, then sent the same request. The diagnostic output was:

    {
      "id": 2,
      "featureCount": 100,
      "nextCursor": "100"
    }

    This confirms the failure is tied to the long-lived daemon's deleted inherited CWD, rather than a CLI/app-server version mismatch or malformed user configuration. It also reproduces the same dead-end TUI dialog: Restart with these settings is disabled even though replacing the daemon from a valid CWD is the appropriate recovery.

  3. sghhhh commented on Oct 5, 2026

    @sghhhh

    Independent confirmation on macOS 27.0.1 / arm64, with the CLI installed through Homebrew. Both the CLI and the managed app-server are 0.160.0.

    A normal codex launch reproduces the blocking dialog with Experimental feature request failed. The managed daemon is still running, and lsof -a -p <daemon-pid> -d cwd shows its startup project directory, while a filesystem check confirms that directory no longer exists. daemon_auto_start is enabled.

    A controlled JSON-RPC experiment using codex app-server --stdio, the same installed CLI binary, and the existing user configuration confirms that deleting the server's working directory alone is sufficient:

    1. Start the server in an existing, empty temporary directory and initialize with experimentalApi: true.
    2. Send experimentalFeature/list with params: {}: success, 154 features, nextCursor: null.
    3. Remove only that temporary directory while keeping the server process alive.
    4. Send the identical request again:
    {
      "error": {
        "code": -32603,
        "message": "failed to reload config: No such file or directory (os error 2)"
      },
      "id": 3
    }

    codex --no-daemon successfully opens the TUI on this machine.

    This also supports starting the shared daemon from a stable service directory under CODEX_HOME, with project working directories and project configuration supplied separately per session. Global configuration/feature discovery should remain usable after a startup project directory is removed.

  4. masmau commented on Oct 5, 2026

    @masmau

    I encountered the same problem on Linux x86_64 with codex-cli 0.160.0, installed via npm, running inside tmux 3.4.

    Before applying the workaround:

    • codex app-server daemon version reported status: running, backend: pid, and CLI, managed Codex, and app-server versions all at 0.160.0.
    • codex doctor --summary reported 21 ok · 1 notes · 0 warn · 0 fail, including app-server running (ephemeral mode). The only note concerned rollout storage.

    I identified the managed daemon with:

    pgrep -af 'codex.*app-server.*managed-daemon'

    Then checked its working directory:

    readlink /proc/<daemon-pid>/cwd

    The result ended in (deleted).

    Restarting the daemon from my home directory resolved the problem:

    cd ~
    codex app-server daemon restart

    This independently confirms the deleted daemon CWD symptom and that Doctor can report the background server as healthy while this problem is occurring.

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

    CLIapp-serverbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions