Skip to content
Draft
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
22 changes: 1 addition & 21 deletions code-rs/core/src/cgroup.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(target_os = "linux")]
use std::path::{Path, PathBuf};

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -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) {}
35 changes: 21 additions & 14 deletions code-rs/core/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions code-rs/core/src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading