Skip to content

Commit ffffb1f

Browse files
fix: enforce metadata write deadlines
agent-session-id: dev3.dotfiles-cos-misc-issue-1329-upstream agent-tool: Codex agent-tool-version: 0.145.0 agent-model: gpt-5.6-sol agent-runtime-profile: /nix/store/qlk5xbdfmj5nn1q145j0fx73f2pmdjj7-coding-agent-runtime-profile/share/coding-agents/profile.json agent-skills-manifest: /nix/store/2km8dbiyv3wc484l1hd8n2lh65121qvq-agent-skills-corpus/share/agent-skills/manifest.json tooling-profile: dotfiles@unknown-dirty
1 parent cf8adbe commit ffffb1f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/run.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ fn write_all_before(
8787
return Err(std::io::Error::last_os_error()).context("make metadata stdin nonblocking");
8888
}
8989
while !input.is_empty() {
90+
if Instant::now() >= deadline {
91+
return Ok(false);
92+
}
9093
match stdin.write(input) {
9194
Ok(0) => {
9295
return Err(std::io::Error::from(std::io::ErrorKind::WriteZero))
@@ -2374,6 +2377,22 @@ mod tests {
23742377
);
23752378
}
23762379

2380+
#[cfg(target_os = "linux")]
2381+
#[test]
2382+
fn expired_write_deadline_prevents_further_progress() {
2383+
use std::os::fd::{FromRawFd as _, OwnedFd};
2384+
2385+
let mut pipe_fds = [0; 2];
2386+
assert_eq!(unsafe { libc::pipe2(pipe_fds.as_mut_ptr(), libc::O_CLOEXEC) }, 0);
2387+
let _reader = unsafe { OwnedFd::from_raw_fd(pipe_fds[0]) };
2388+
let writer = unsafe { OwnedFd::from_raw_fd(pipe_fds[1]) };
2389+
2390+
assert!(
2391+
!write_all_before(ChildStdin::from(writer), b"x", Instant::now()).unwrap(),
2392+
"an expired child deadline still allowed stdin progress"
2393+
);
2394+
}
2395+
23772396
#[test]
23782397
fn expired_cleanup_deadline_hands_reaping_off_without_blocking() {
23792398
let child = Command::new("sleep").arg("60").spawn().unwrap();

0 commit comments

Comments
 (0)