Repository navigation
Conversation
The module was Linux-only because it reads procfs. On macOS start() was a no-op, so children a reloaded server inherited were never reaped and stale MCP servers were never killed: a shared server up for 35 hours carried 10 zombies, timed to its reloads. macOS lists children with proc_listpids(PROC_PPID_ONLY), which walks the zombie list too, and reads the environment with sysctl(KERN_PROCARGS2). The reap loop is shared. The marker test spawned /bin/sleep, whose environment macOS hides from KERN_PROCARGS2 (SIP platform binary). It now re-runs the test binary on an ignored helper test that only sleeps. Closes 1jehuang#2233
[Medium impact] The change reaches macOS process-start and daemon-reload cleanup. Fix the marker check before merging so reload cannot kill an unmarked child based on its arguments. FindingsFix with agent prompt### Issue 1
crates/jcode-base/src/inherited_children.rs:132-135
**Arguments can trigger unwanted kills.** `KERN_PROCARGS2` includes command arguments as well as the environment, but this scans both. If a still-running custom hook receives a literal argument beginning with `JCODE_MCP_CHILD=`, reload treats it as an MCP server and kills it and its process group, even without the environment marker. Skip the executable path and the recorded number of arguments before checking environment entries.
### Issue 2
crates/jcode-base/src/inherited_children.rs:199
**Zombie discovery is not tested.** This calls `children_of` only after `reap` has removed the exited child. The other test checks only a live child. An implementation that lists live children but misses zombies would pass both tests while leaving the macOS bug unfixed. Assert that the exited, unreaped child appears in `children_of` before calling `reap`, then keep the absence check afterward.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds macOS support for cleaning up children left behind by a reload.
The marker check can mistake command arguments for environment entries. The tests also miss the key case of finding an exited child before reaping it. Reviews (1) · Last reviewed commit: "inherited_children: reap inherited child..." · Reviewed by Greptile |
| buf.truncate(len); | ||
| let needle = format!("{}=", super::MCP_CHILD_MARKER_ENV); | ||
| buf.split(|b| *b == 0) | ||
| .any(|entry| entry.starts_with(needle.as_bytes())) |
There was a problem hiding this comment.
Arguments can trigger unwanted kills.
KERN_PROCARGS2 includes command arguments as well as the environment, but this scans both. If a still-running custom hook receives a literal argument beginning with JCODE_MCP_CHILD=, reload treats it as an MCP server and kills it and its process group, even without the environment marker. Skip the executable path and the recorded number of arguments before checking environment entries.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/inherited_children.rs
Line: 132-135
Comment:
**Arguments can trigger unwanted kills.** `KERN_PROCARGS2` includes command arguments as well as the environment, but this scans both. If a still-running custom hook receives a literal argument beginning with `JCODE_MCP_CHILD=`, reload treats it as an MCP server and kills it and its process group, even without the environment marker. Skip the executable path and the recorded number of arguments before checking environment entries.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| super::reap(&mut set); | ||
| assert!(set.is_empty()); | ||
| assert!(!std::path::Path::new(&format!("/proc/{pid}")).exists()); | ||
| assert!(!super::children_of(std::process::id()).contains(&pid)); |
There was a problem hiding this comment.
Zombie discovery is not tested. This calls
children_of only after reap has removed the exited child. The other test checks only a live child. An implementation that lists live children but misses zombies would pass both tests while leaving the macOS bug unfixed. Assert that the exited, unreaped child appears in children_of before calling reap, then keep the absence check afterward.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/inherited_children.rs
Line: 199
Comment:
**Zombie discovery is not tested.** This calls `children_of` only after `reap` has removed the exited child. The other test checks only a live child. An implementation that lists live children but misses zombies would pass both tests while leaving the macOS bug unfixed. Assert that the exited, unreaped child appears in `children_of` before calling `reap`, then keep the absence check afterward.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Snapshot Darwin children, including zombies, before this process image spawns new work. Reuse the existing reaper and identify stale MCP children from their environment. Upstream: 1jehuang#2234 Co-authored-by: Attilio Cianci <[email protected]>
Upstream-PR: 1jehuang#1357 Upstream-PR-Commit: 1jehuang#1357 0da5e81 Upstream-PR: 1jehuang#1362 Upstream-PR-Commit: 1jehuang#1362 5962058 Upstream-PR: 1jehuang#1486 Upstream-PR-Commit: 1jehuang#1486 fadc624 Upstream-PR: 1jehuang#1733 Upstream-PR-Commit: 1jehuang#1733 01f3415 Upstream-PR: 1jehuang#1750 Upstream-PR-Commit: 1jehuang#1750 1ac0c82 Upstream-PR: 1jehuang#1822 Upstream-PR-Commit: 1jehuang#1822 73f85fc Upstream-PR: 1jehuang#1912 Upstream-PR-Commit: 1jehuang#1912 36d7682 Upstream-PR: 1jehuang#1978 Upstream-PR-Commit: 1jehuang#1978 0f55643 Upstream-PR: 1jehuang#2007 Upstream-PR-Commit: 1jehuang#2007 638f87c Upstream-PR: 1jehuang#2213 Upstream-PR-Commit: 1jehuang#2213 c5e1487 Upstream-PR: 1jehuang#2234 Upstream-PR-Commit: 1jehuang#2234 0d4d5d4 Upstream-PR: 1jehuang#2266 Upstream-PR-Commit: 1jehuang#2266 217ddc2 Upstream-PR: 1jehuang#2267 Upstream-PR-Commit: 1jehuang#2267 e98c40b
Closes #2233
Problem
inherited_childrenonly had a Linux implementation (it reads procfs), so on macOSstart()was a no-op. A reloaded shared server never reaped the children it inherited and never killed stale MCP servers. Ajcode servedaemon on macOS 26 up for 35 hours carried 10 zombies, timed to its reloads.Change
mod impandstart()are enabled on macOS as well as Linux.children_ofon macOS usesproc_listpids(PROC_PPID_ONLY, pid, …). It walks the zombie list too, and it returns bytes (unlikeproc_listchildpids, whose unit changed across releases). A little headroom covers children spawned between the size query and the read.has_mcp_markeron macOS reads the environment of a same-user process withsysctl(KERN_PROCARGS2).detects_mcp_markerused to spawn/bin/sleep. macOS hides the environment of SIP platform binaries fromKERN_PROCARGS2, so the test now re-runs its own binary on an ignored helper test that only sleeps. Real MCP servers (node, npx, python) are readable, checked by hand.Tests (macOS 26, Apple Silicon)
cargo test -p jcode-base inherited_children: 2 passed, 1 ignored (the helper).has_mcp_markeralwaysfalse→detects_mcp_markerfails.children_ofreturning nothing →detects_mcp_markerfails at thechildren_ofassertion.cargo fmt --checkis clean for this file.cargo clippy -p jcode-base --testsreports nothing in it; it does stop on two existing errors inmobile_runner_events_tests.rsandruntime_activity.rs, unrelated to this change.stdand is left to CI.