A stop rule should check what a process is, not what its command line says
Our guard decides what an AI coding agent leaves behind on a Mac and what it can safely stop. To do that it labels every running process: MCP server, Codex session, Claude session, and so on. The label comes from a patte
Our guard decides what an AI coding agent leaves behind on a Mac and what it can safely stop. To do that it labels every running process: MCP server, Codex session, Claude session, and so on. The label comes from a pattern match over the whole command line. That is the right tool for protection, because we would rather spare a process by mistake than kill a live agent. It turned out to be the wrong tool for stopping one.
What broke
One of the rules looks for orphaned MCP servers. A process qualifies if its parent is PID 1, it is at least ten minutes old, and several copies of the same command line are running. The newest copy is kept and the older ones are the extras the guard can stop.
The label for "MCP server" is a text match. So this line gets it too:
python3 -m pytest tests/test_mcp_client.py
That is a test run. Nothing in it is a server. But it contains "mcp", the label says mcp-server, and a test run that was started three times and left behind by a dead terminal looks exactly like an orphaned server with duplicates.
I reproduced it against the guard as it was before the fix. I fed it three copies of that line, all with parent PID 1, aged 10, 5 and 1 hours. The old guard picked the two oldest as extras to stop. The fixed guard picks none.
The same label fed three other stop decisions: which processes count as a Codex session root, which count as a Claude CLI session root, and whether a session is idle. I ran that one against the old guard too: a Codex session whose only child was the pytest line above was judged long-idle and eligible to end, because the child counted as idle plumbing. The fixed guard treats the test run as work and spares the session.
The fix
We left the label alone, because protection has to stay as broad as it was. Instead, every rule that can signal a process because of its label now also asks one more question: is the process's own program that kind of thing?
function ownsKind(kind, command) {
const exe = agentExecutable(command);
if (kind === 'mcp-server') return ownsMcpServer(command);
if (kind === 'claude-cli') return exe === 'claude' || exe === 'claude.exe';
if (kind === 'codex') return exe === 'codex';
return true;
}
"Own program" means the first word of the command, or, when the first word is a launcher like node, python, uv or npx, the script, module or package it runs. python3 -m pytest ... runs pytest, so it is not an MCP server however many times "mcp" appears after it. python3 -m dayglass mcp and npx -y @scope/foo-mcp still qualify, because the thing being run is the server. If the shape is one the code cannot read, the answer is false and the process is spared. Failing toward "leave it alone" is the whole point.
How we checked we did not make the guard blind
A fix like this can quietly narrow protection or stop recognising real servers, so the PR checked both directions:
- A new test feeds eleven lines that only mention an agent (pytest, grep, vim, tail, a watcher script) to every stop rule and expects none to be picked. On the old guard it fails with
orphan rule must not pick: python3 -m pytest tests/test_mcp_client.py. - The same test feeds eleven real server shapes, including a Python framework binary,
claude mcp serveand a uv-managedpython -mserver, and expects the older duplicates to still be found. - The functions that protect processes were not edited. The pull request reports that 31 fixture lines and a full process snapshot gave identical protection answers before and after, with no differences.
- On a snapshot of that Mac with 1,356 processes, 69 carried an agent label before the change. After it, 68 passed the stricter check. The one that dropped was a
zsh -c source ...shell wrapper, which is not a server.
What to check on your own machine
If you run a cleanup script, a watchdog or a "kill the stale agents" alias, look at how it picks its targets. A grep mcp or pkill -f codex matches the whole command line, so it also matches your editor with a file called notes-about-codex.md, your test runner, and your tail -f on a log. Compare what the pattern matches against the program each process is actually running:
ps -axo pid,ppid,etime,command | grep -i mcp
Anything whose own program is not the thing you meant to stop should not be on the kill list. Text matching is fine for deciding what to protect. Before you stop anything, check what the program is.
Mac YOLO Safeguards is the Mac app this guard ships in. Downloads and the issue forms are here: https://github.com/IgorGanapolsky/mac-yolo-safeguards-releases
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.