fix: preserve zsh-fork escalation fds in unified-exec PTYs

This commit is contained in:
Michael Bolin
2026-03-05 16:13:42 -08:00
parent 4e77ea0ec7
commit 92d239d53b
7 changed files with 451 additions and 22 deletions
@@ -48,12 +48,23 @@ mod imp {
use crate::unified_exec::SpawnLifecycle;
use codex_shell_escalation::EscalationSession;
const ESCALATE_SOCKET_ENV_VAR: &str = "CODEX_ESCALATE_SOCKET";
#[derive(Debug)]
struct ZshForkSpawnLifecycle {
escalation_session: EscalationSession,
}
impl SpawnLifecycle for ZshForkSpawnLifecycle {
fn inherited_fds(&self) -> Vec<std::os::fd::RawFd> {
self.escalation_session
.env()
.get(ESCALATE_SOCKET_ENV_VAR)
.and_then(|fd| fd.parse().ok())
.into_iter()
.collect()
}
fn after_spawn(&mut self) {
self.escalation_session.close_client_socket();
}
@@ -1,5 +1,6 @@
#![allow(clippy::module_inception)]
use std::os::fd::RawFd;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
@@ -25,6 +26,10 @@ use super::UnifiedExecError;
use super::head_tail_buffer::HeadTailBuffer;
pub(crate) trait SpawnLifecycle: std::fmt::Debug + Send + Sync {
fn inherited_fds(&self) -> Vec<RawFd> {
Vec::new()
}
fn after_spawn(&mut self) {}
}
@@ -535,14 +535,16 @@ impl UnifiedExecProcessManager {
.command
.split_first()
.ok_or(UnifiedExecError::MissingCommandLine)?;
let inherited_fds = spawn_lifecycle.inherited_fds();
let spawn_result = if tty {
codex_utils_pty::pty::spawn_process(
codex_utils_pty::pty::spawn_process_with_inherited_fds(
program,
args,
env.cwd.as_path(),
&env.env,
&env.arg0,
&inherited_fds,
)
.await
} else {