Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codex-rs/background-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ codex-utils-pty = { workspace = true }
libc = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["fs", "io-util", "process", "time"] }

[dev-dependencies]
pretty_assertions = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
26 changes: 22 additions & 4 deletions codex-rs/background-agent/src/worker_admission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,39 @@ impl WorkerAdmissionCommandRunner for ProcessWorkerAdmissionCommandRunner {
&self,
command: WorkerAdmissionCommand,
) -> anyhow::Result<WorkerAdmissionCommandOutput> {
let output = Command::new(&command.program)
// `todos agent --json` may exceed the CLI's pipe-output cap. Spool
// stdout to a private file so the structured admission response stays
// complete while stderr remains separately captured for diagnostics.
let stdout_capture = tempfile::NamedTempFile::new()
.context("failed to create worker-admission stdout capture")?;
let stdout_file = stdout_capture
.reopen()
.context("failed to open worker-admission stdout capture")?;
let child = Command::new(&command.program)
.args(&command.args)
.envs(command.env)
.stdin(Stdio::null())
.output()
.await
.stdout(Stdio::from(stdout_file))
.stderr(Stdio::piped())
.spawn()
.with_context(|| {
format!(
"failed to execute worker-admission dependency {}",
command.program.display()
)
})?;
let output = child.wait_with_output().await.with_context(|| {
format!(
"failed to wait for worker-admission dependency {}",
command.program.display()
)
})?;
let stdout = tokio::fs::read(stdout_capture.path())
.await
.context("failed to read worker-admission stdout capture")?;
Ok(WorkerAdmissionCommandOutput {
exit_code: output.status.code().unwrap_or(1),
stdout: output.stdout,
stdout,
stderr: output.stderr,
})
}
Expand Down
26 changes: 26 additions & 0 deletions codex-rs/background-agent/tests/worker_admission.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use codex_background_agent::process_lifecycle::WorkerProcessCommand;
use codex_background_agent::worker_admission::CONVERSATIONS_AGENT_ID_ENV;
#[cfg(unix)]
use codex_background_agent::worker_admission::ProcessWorkerAdmissionCommandRunner;
use codex_background_agent::worker_admission::WorkerAdmission;
use codex_background_agent::worker_admission::WorkerAdmissionCommand;
use codex_background_agent::worker_admission::WorkerAdmissionCommandOutput;
Expand All @@ -17,6 +19,8 @@ use std::ffi::OsString;
use std::fmt::Debug;
use std::fmt::Display;
use std::future::Future;
#[cfg(unix)]
use std::path::PathBuf;
use std::sync::Mutex;

const WORKER: &str = "worker-one";
Expand Down Expand Up @@ -631,3 +635,25 @@ fn worker_process_command_sets_explicit_conversations_identity() {
)]
);
}

#[cfg(unix)]
#[tokio::test]
async fn process_runner_preserves_large_stdout_for_worker_admission() {
let output = must_ok(
ProcessWorkerAdmissionCommandRunner
.run(WorkerAdmissionCommand {
program: PathBuf::from("sh"),
args: vec![
OsString::from("-c"),
OsString::from("head -c 131073 /dev/zero"),
],
env: Vec::new(),
})
.await,
"large worker-admission stdout capture",
);

assert_eq!(output.exit_code, 0);
assert_eq!(output.stdout, vec![0; 131_073]);
assert_eq!(output.stderr, Vec::<u8>::new());
}
Loading