Skip to content

Auto-Started Daemon Returns Incorrect Session Directories After Its Startup Directory Is Deleted #48879

Closed

Description

@pspi

Environment: Codex 0.157.1, macOS 26.6.2, arm64.

Reproduction

Use the same disposable CODEX_HOME throughout and two empty directories, A and B.

  1. Start with no daemon running for that CODEX_HOME.
  2. Run codex from A, then exit with Ctrl+D. This automatically starts the background daemon with cwd A; it remains running after exit.
  3. Run codex from B. Send one message, wait for completion, then exit without stopping the daemon.
  4. Through an initialized connection to that same daemon, read the second conversation:
{"id":1,"method":"thread/read","params":{"threadId":"<second-conversation-id>","includeTurns":false}}
  1. Confirm result.thread.cwd is B.
  2. Remove the empty directory A using rmdir, leaving B and the daemon intact.
  3. Repeat the request.

Expected

The second conversation’s cwd remains B.

Actual

Its cwd becomes the deleted directory A.

Restarting the daemon from an existing directory restores B without modifying the conversation.

Activity

  1. added
    bug
    CLI
    app-server
    on Sep 28, 2026
  2. hfycium commented on Sep 28, 2026

    @hfycium

    I traced the incorrect thread.cwd fallback to the absolute-path conversion used when reading persisted threads.

    thread_from_stored_thread calls AbsolutePathBuf::relative_to_current_dir(thread.cwd) even when thread.cwd is already absolute.

    relative_to_current_dir unconditionally calls std::env::current_dir() before resolving the path. In this reproduction, the daemon process was started in directory A, then A was deleted. As a result, current_dir() fails even though the stored thread cwd is the still-existing absolute directory B.

    The error handler then falls back to fallback_cwd, which is the daemon configuration cwd (A), causing thread/read to report A instead of B.

    Suggested fix:

    • In AbsolutePathBuf::relative_to_current_dir, normalize and return already-absolute paths before calling std::env::current_dir().
    • Only resolve against the process current directory when the input path is relative.

    Suggested Unix regression test:

    1. Start a child test process in a temporary directory.
    2. Remove that directory so current_dir() fails.
    3. Assert that converting an already-absolute path still succeeds and preserves that path.

    This preserves current behavior for relative paths while preventing a deleted daemon startup directory from corrupting the displayed cwd.

    Note: this is source-level analysis with a proposed regression test. I could not complete local Rust test execution because the local Rust 1.95 toolchain repair failed during download.

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