Skip to main content

Module registry

Module registry 

Source
Expand description

AgentProcessRegistry — app-wide map from block_id → tracker handle.

Created once at host startup, passed into each SubprocessController / PersistentSubprocessController instance so it can wrap spawns in its per-block job. Polled periodically from a background task that emits agent:process-added / agent:process-exited events to the frontend’s swarm activity panel.

Centralizing this here (rather than one tracker per controller) means the lifetime of the tracker matches the lifetime of the pane — multiple turns on the same block share the same job, so descendants from turn N are still visible on turn N+1.

Structs§

AgentProcessRegistry
BlockMembers
One block’s tracked tree, as AgentProcessRegistry::members_by_block reports it.

Enums§

Join
How a spawn joins its block’s tracker (see spawn_tracked).

Constants§

AGENT_NICE_LEVEL
The nice level an agent’s process tree runs at on Unix while agent:belownormalpriority is on. Measured on Linux (2026-10-24): with agent builds at normal priority the page’s long tasks were 4x idle and an AgentInput took 2 s at the median; at nice 10 both were back within a third of idle, and 19 did no better.
SETTING_AGENT_BELOW_NORMAL_PRIORITY
Settings key: run agents’ process trees at below-normal CPU priority so their builds and tests yield to AgentMux (and the user’s foreground apps) under contention, while still using every idle core. Default on. Windows: a Job Object priority class. Linux and macOS: nice AGENT_NICE_LEVEL set at spawn (place_spawn, place_pty_spawn).

Functions§

global
own_process_group
An agent CLI srv runs outside any block’s tracker (the Drone runner, the ambient side call): it too leads its own process group on Unix, like place_spawn’s, so its kill takes its helpers and a signal to its group can’t reach srv. Call record_untracked_cli once it is spawned.
place_pty_spawn
place_spawn for an agent’s PTY spawn, which has no pre-exec hook: the command is wrapped to join first (cgroup_linux::join_before_exec_pty).
place_spawn
Make a child about to be spawned for block_id join its tracker before it execs, so nothing it forks escapes between spawn and track_spawned (Linux: the agent’s cgroup). create: start the block’s tracker if it has none (an agent’s own CLI); otherwise join only an existing one (Shell(), !cmd, like track_adopted). Still call track_spawned* / track_adopted after the spawn: that records the PID and covers platforms with no pre-exec placement.
record_untracked_cli
Record a CLI spawned with own_process_group for the launcher (roots_file), which ends it if srv dies first.
set_global
spawn_poller
Spawn the polling task. It holds the registry weakly and ends once the registry’s last Arc is dropped (host shutdown). ~2s cadence balances latency (new processes show up fast) with CPU overhead (job queries are cheap but not free).
spawn_tracked
Spawn cmd for block_id already inside the block’s tracker, so nothing it starts can escape between spawn and assignment: on Linux it joins the cgroup before exec (place_spawn); on Windows it starts suspended, is assigned to the job, then resumed. The one way an agent-side tokio spawn should start (the Codex App Server, which spawns internally, uses place_spawn and track_spawned_agent).
track_adopted
Put a process srv spawned on an agent’s behalf (Shell(), !cmd) into that agent’s tracker, so it dies with the agent like anything the agent started itself (SPEC_AGENT_TEARDOWN_SINGLE_PATH_2026_10_01.md §6.5). Unlike track_spawned it never creates a tracker (a block with no agent process has nothing to join) and doesn’t mark the PID as a root, so the process still counts as something the agent started. Best-effort, like track_spawned.
track_spawned
Assign a freshly-spawned child PID to block_id’s tracker, creating the tracker if needed. The single call site every Controller impl should use immediately after its own spawn — no-ops silently if the registry global isn’t initialized (tests), and with a warn log if the platform tracker rejects the PID, since this is opportunistic enrichment, not a liveness signal on its own (see broker::process::ProcessStatus’s own doc comment).
track_spawned_agent
track_spawned for an agent process: also applies the agent CPU priority policy to the block’s whole tree. Terminal panes a human types in keep calling track_spawned and are never deprioritized.