subagent, bash: run each subagent run and bash task in its own cgroup
hive-subagent-daemon and hive-bash-daemon are now delegated their cgroup (Delegate=memory pids, DelegateSubgroup=daemon). At start each daemon enables memory+pids below its unit and creates runs/ (subagent) or tasks/ (bash). Each subagent run gets runs/<name>-<n>/ and each bash task tasks/<id>/, both with memory.oom.group=1, and the daemon removes the directory when the run ends. An OOM kill now takes one whole run instead of one process out of the daemon's shared cgroup, and never the daemon itself. Subagent runs get oom_score_adj +1000; bash tasks and both daemons stay at 0; the harness stays at -500. The unit-level OOMScoreAdjust=500 on the subagent daemon goes: it was both the daemon's own score and a floor no run below it could be lowered past. Bash tasks enter their cgroup from the existing pre_exec hook, writing to a cgroup.procs fd opened by the parent. hive-claude builds its Command itself and exposes neither a pre_exec hook nor the child's pid, so a subagent's claude (and an ACP agent's process) is started as the daemon's own binary with the run's cgroup in its environment; main() enters the cgroup, raises oom_score_adj and execs the real program, the trampoline swarm-review-classifier already uses. Both enter before the program executes, so nothing it forks starts outside the run's cgroup. Without a delegated `daemon` leaf (tests, a dev shell) each daemon logs one warning and runs everything in its own cgroup, as before. The shared helper is hive-agent-sock's run_cgroup module, the crate both daemons already use for what in-container plugins share. Closes #5007
This commit is contained in:
parent
baf282131f
commit
b31db6c7d9
14 changed files with 600 additions and 56 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
What's common across the in-container "agent plugins" — the matrix / bash /
|
||||
subagent MCP daemons and `forge_notify` today, plus any user-configured MCP
|
||||
server declared in an agent's `agent.nix`. Two things live here:
|
||||
server declared in an agent's `agent.nix`. Three things live here:
|
||||
|
||||
## Wire types for the in-agent socket
|
||||
|
||||
|
|
@ -38,3 +38,12 @@ entry into the shape claude expects in a
|
|||
`availableToSubagents`) — both already depend on this crate for the socket
|
||||
types above, so a new plugin-facing shared type belongs here rather than in
|
||||
a crate of its own.
|
||||
|
||||
## `run_cgroup`: one cgroup per run
|
||||
|
||||
`hive-bash-mcp` puts each bash task in `<unit>/tasks/<id>/` and
|
||||
`hive-subagent-mcp` each subagent run in `<unit>/runs/<name>-<n>/`, both with
|
||||
`memory.oom.group=1`, so the OOM killer takes one whole run and leaves the
|
||||
daemon alone. Both daemons are delegated their cgroup with `Delegate=memory
|
||||
pids` and `DelegateSubgroup=daemon` (`nix/agent-modules/mcp.nix`); outside such
|
||||
a unit the module logs one warning and runs stay in the daemon's cgroup.
|
||||
|
|
|
|||
Loading…
Reference in a new issue