fix(core): gate cgroup helpers on Linux

This commit is contained in:
James Peter
2026-01-07 11:35:26 +10:00
parent 0bd37b5f20
commit 7369620a60
3 changed files with 22 additions and 37 deletions
+1 -21
View File
@@ -1,3 +1,4 @@
#[cfg(target_os = "linux")]
use std::path::{Path, PathBuf};
#[cfg(target_os = "linux")]
@@ -172,24 +173,3 @@ pub(crate) fn best_effort_cleanup_exec_cgroup(pid: u32) {
// Only remove the per-pid directory. The parent container stays.
let _ = std::fs::remove_dir(&dir);
}
#[cfg(not(target_os = "linux"))]
pub(crate) fn default_exec_memory_max_bytes() -> Option<u64> {
None
}
#[cfg(not(target_os = "linux"))]
pub(crate) fn best_effort_attach_self_to_exec_cgroup(_pid: u32, _memory_max_bytes: u64) {}
#[cfg(not(target_os = "linux"))]
pub(crate) fn exec_cgroup_oom_killed(_pid: u32) -> Option<bool> {
None
}
#[cfg(not(target_os = "linux"))]
pub(crate) fn exec_cgroup_memory_max_bytes(_pid: u32) -> Option<u64> {
None
}
#[cfg(not(target_os = "linux"))]
pub(crate) fn best_effort_cleanup_exec_cgroup(_pid: u32) {}
+21 -14
View File
@@ -564,24 +564,31 @@ async fn consume_truncated_output(
combined_handle.await.map_err(CodexErr::from)?
};
let mut oom_killed = false;
let mut cgroup_memory_max_bytes: Option<u64> = None;
#[cfg(target_os = "linux")]
{
if !timed_out {
if let Some(pid) = pid {
if matches!(exit_status.signal(), Some(SIGKILL_CODE))
&& crate::cgroup::exec_cgroup_oom_killed(pid).unwrap_or(false)
{
oom_killed = true;
cgroup_memory_max_bytes = crate::cgroup::exec_cgroup_memory_max_bytes(pid);
let (oom_killed, cgroup_memory_max_bytes) = {
#[cfg(target_os = "linux")]
{
let mut oom_killed = false;
let mut cgroup_memory_max_bytes: Option<u64> = None;
if !timed_out {
if let Some(pid) = pid {
if matches!(exit_status.signal(), Some(SIGKILL_CODE))
&& crate::cgroup::exec_cgroup_oom_killed(pid).unwrap_or(false)
{
oom_killed = true;
cgroup_memory_max_bytes = crate::cgroup::exec_cgroup_memory_max_bytes(pid);
}
}
}
if let Some(pid) = pid {
crate::cgroup::best_effort_cleanup_exec_cgroup(pid);
}
(oom_killed, cgroup_memory_max_bytes)
}
if let Some(pid) = pid {
crate::cgroup::best_effort_cleanup_exec_cgroup(pid);
#[cfg(not(target_os = "linux"))]
{
(false, None)
}
}
};
Ok(RawExecToolCallOutput {
exit_status,
-2
View File
@@ -135,8 +135,6 @@ pub(crate) async fn spawn_child_async(
StdioPolicy::RedirectForShellTool => crate::cgroup::default_exec_memory_max_bytes(),
StdioPolicy::Inherit => None,
};
#[cfg(not(target_os = "linux"))]
let exec_memory_max_bytes: Option<u64> = None;
cmd.pre_exec(move || {
// Start a new process group
let _ = libc::setpgid(0, 0);