Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test: treat terminated process-group zombies as stopped

Steven Enamakela55563fc5d1c
diff --git a/crates/openhuman-core/src/tools/timeout/group_exit.rs b/crates/openhuman-core/src/tools/timeout/group_exit.rs
index fe1c4e57d4..665f4f3a4c 100644
--- a/crates/openhuman-core/src/tools/timeout/group_exit.rs
+++ b/crates/openhuman-core/src/tools/timeout/group_exit.rs
@@ -44,7 +44,7 @@ fn active_members(group: u32) -> std::io::Result<bool> {
/// Zombies and dead tasks cannot execute further side effects.
#[cfg(target_os = "linux")]
-fn is_active_member(stat: &str, group: u32) -> bool {
+pub(super) fn is_active_member(stat: &str, group: u32) -> bool {
let Some((_, fields)) = stat.rsplit_once(") ") else {
return false;
};
diff --git a/crates/openhuman-core/src/tools/timeout/mod_tests.rs b/crates/openhuman-core/src/tools/timeout/mod_tests.rs
index 0e5d02ca49..16e578a646 100644
--- a/crates/openhuman-core/src/tools/timeout/mod_tests.rs
+++ b/crates/openhuman-core/src/tools/timeout/mod_tests.rs
@@ -218,6 +218,16 @@ async fn a_timed_out_command_takes_its_whole_process_group_with_it() {
gone = true;
break;
}
+ // A container's PID 1 may leave a killed orphan unreaped. It cannot
+ // execute side effects; use the same kernel-state rule as cleanup.
+ #[cfg(target_os = "linux")]
+ if let Ok(stat) = std::fs::read_to_string(format!("/proc/{grandchild}/stat")) {
+ let group = unsafe { libc::getpgid(grandchild) };
+ if group > 0 && !super::group_exit::is_active_member(&stat, group as u32) {
+ gone = true;
+ break;
+ }
+ }
tokio::time::sleep(Duration::from_millis(20)).await;
}
let _ = std::fs::remove_dir_all(&dir);