Add --no-daemon to bypass the shared background server (#46088)

## What changed

- Run with `--no-daemon` without starting or probing the shared server, even when it is already running. Preserve the flag through `resume` and `fork`, and honor it for session archive commands.
- Reject combinations with `--remote`, `codex agents`, and `codex queue`, which require a server connection. Point users to `codex --no-daemon` when the agents overview cannot start its shared server.
- Centralize daemon eligibility checks and exclude launches using `--profile` or `CODEX_EXEC_SERVER_URL` from implicit daemon reuse.

## Testing

Add coverage for flag propagation, incompatible command combinations, and daemon eligibility. Add a PTY test verifying that `--no-daemon` starts the TUI without creating daemon state or connecting to an existing control socket.

GitOrigin-RevId: acc6a7cb339df6433bb8273c796194cdceda37c1
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-17 02:46:49 +00:00
1 parent 8452164c76
commit 787823cf95
10 files changed
+271 -67

No files matched your search

+39 -1
View File
@@ -14,7 +14,6 @@ use anyhow::Context;
use anyhow::Result;
use anyhow::bail;
use anyhow::ensure;
#[cfg(target_os = "macos")]
use pretty_assertions::assert_eq;
use tempfile::TempDir;
@@ -396,3 +395,42 @@ pub(super) fn write_test_config(codex_home: &Path, repo_root: &Path) -> Result<(
)
.context("write focus-test API-key authentication")
}
#[test]
fn no_daemon_skips_startup_and_discovery() -> Result<()> {
for running in [false, true] {
let workspace = tempfile::tempdir()?;
let home = tempfile::tempdir()?;
write_test_config(home.path(), workspace.path())?;
let socket_path = codex_app_server_client::app_server_control_socket_path(home.path())?;
std::fs::create_dir_all(socket_path.as_path().parent().unwrap())?;
let listener = if running {
let listener = std::os::unix::net::UnixListener::bind(socket_path.as_path())?;
listener.set_nonblocking(true)?;
Some(listener)
} else {
None
};
let mut terminal = PtyCodex::start(workspace.path(), home, &["--no-daemon"])?;
terminal.wait_for_startup()?;
terminal.write_input(b"/status")?;
terminal.wait_for_screen("show current session configuration")?;
terminal.read_output(Duration::from_millis(/*millis*/ 200))?;
terminal.write_input(b"\r")?;
terminal.wait_for_screen("Model:")?;
ensure!(
!terminal
._codex_home
.path()
.join("app-server-daemon")
.exists()
);
if let Some(listener) = listener {
assert_eq!(
listener.accept().unwrap_err().kind(),
std::io::ErrorKind::WouldBlock
);
}
}
Ok(())
}