Skip to content

Stop a CLI session's processes on macOS too - #88

Merged
haizhongzheng merged 3 commits into
Infini-AI-Lab:mainfrom
ruiling-smartbear:fix/descendants-without-proc
Nov 9, 2026
Merged

haizhongzheng merged 3 commits into
Infini-AI-Lab:mainfrom
ruiling-smartbear:fix/descendants-without-proc

Conversation

@ruiling-smartbear

@ruiling-smartbear ruiling-smartbear commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Change

On macOS a CLI session stopped at its timeout or on cancel could leave processes running or fail (hermit/agent/base/cli.py, core):

  • _stop found the processes below a session through /proc, which macOS lacks. _parents() now uses ps there; Linux is unchanged.
  • os.killpg on a group of exited, unreaped processes raises PermissionError on macOS. It now means the group ended when proc.poll() shows the session exited; otherwise it is raised. The same in the AgentDyn and Lean swarm stops.

Left as before: evolver/agent.py and harbor/runner.py call killpg without this handling.

Validation

  • New tests/core/test_cli_agent.py::test_a_stopped_session_takes_a_descendant_in_a_session_of_its_own: fails without the change on macOS. The AgentDyn test now checks for survivors on macOS too.
  • python -m pytest --changed on macOS: 10 failed (vs 13 on main; the other 10 need bubblewrap or /proc).

Review

  • Tests and documentation cover the affected behavior, where applicable: the new test; CHANGELOG.
  • Commands, defaults, and public interfaces are consistent: unchanged.
  • Shared logs and examples contain no credentials or private data.
  • Documentation-only: not applicable.
  • Core changes. _stop and _descendants in hermit/agent/base/cli.py, as above.
  • Independent review (post-PR audit) at cfca793: no blocking findings; test cleanup and the AgentDyn check fixed in the next commit.

The processes below a session were found through /proc, which macOS lacks, so one in a session of its own was
never stopped; they are now found with ps there. On macOS, signalling a group left with only exited, unreaped
processes raises PermissionError; it now means the group has ended, in the Base Agent's stop and in the AgentDyn
runner's and the Lean swarm launcher's.
@ruiling-smartbear
ruiling-smartbear marked this pull request as draft November 8, 2026 05:17
@ruiling-smartbear
ruiling-smartbear marked this pull request as ready for review November 9, 2026 18:14
…back on Linux too

- an exited, unreaped grandchild (under a subreaper, or a container's PID 1 that does not reap) is stopped, not a
  survivor
- parametrized proc / ps: CI on Linux now runs the macOS ps fallback; the ps case fails without it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@haizhongzheng
haizhongzheng merged commit a5c0485 into Infini-AI-Lab:main Nov 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants