Replace /proc process-table scanning with owned process-group handles in kill_agent#573
Merged
brickfrog merged 3 commits intoJun 12, 2026
Conversation
kill_agent now reads the recorded pgid from .choir/pids/<sanitized-agent-id> (written at spawn by the setsid wrapper), SIGTERMs the group, pauses ~300ms, SIGKILLs it, then deletes the pidfile. Recovery liveness probes the same recorded pgid with kill(pgid, 0), keyed by agent id instead of workspace. Deleted outright: list_pids_with_cwd_prefix (+ C helper and hard cap), list_orphan_choir_mcp_stdio_pids, list_choir_mcp_stdio_pids_for_agent, read_proc_process_table_entries, process_table_ppid_from_proc_stat, ProcessTableEntry and friends, init_reap_orphan_mcp_stdio_bridges (PDEATHSIG makes orphan shims impossible), the kill_agent /proc scan gate, the RemoveWorktree cwd-scan reap, and agent_process_alive_for_workspace.
Owner
Author
|
Choir: CI checks failing — routed to |
The hermeticity lint bans @exec helpers in optional-parameter defaults in src/tools/. Move pidfile parsing to pure @workspace.parse_agent_pgid (next to agent_pid_file_path), default read_agent_pgid to the permitted read-only @sys.read_file at the dispatch seam, and remove_pid_file to @sys.delete_file_sync — matching the sanctioned @sys-default pattern. @exec.read_agent_pgid (recovery liveness) reuses the same parser.
This was referenced Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements .choir/context/owned-process-handles-spec.md (choir-upk0).
What
.choir/pids/<sanitized-agent-id>(written at spawn by the setsid wrapper), SIGTERM the process group, ~300ms pause, SIGKILL, then delete the pidfile. Ordering preserved: pane close → worktree remove → pgroup kill → pidfile delete → registry Failed → beads mirror. New injected capabilities:read_agent_pgid?,kill_pgid?,remove_pid_file?(defaults via@exec/@sys, no direct mutations from src/tools).kill_pgid_sequence_best_effort(C helperchoir_kill_pgid_sequence, mirrorschoir_init_kill_server_pid_sequencesignaling-pgid; rejects pgid <= 1).@exec.agent_recorded_process_alive(project_dir, agent_id)= pidfile pgid +kill(pgid, 0).Deleted (no /proc table iteration remains)
list_pids_with_cwd_prefix(+choir_list_pids_with_cwd_prefixC body, hard cap, stubs),list_orphan_choir_mcp_stdio_pids,list_choir_mcp_stdio_pids_for_agent,read_proc_process_table_entries,process_table_ppid_from_proc_stat,ProcessTableEntry+ helpers,proc_name_pid,init_reap_orphan_mcp_stdio_bridges(PDEATHSIG makes orphan shims impossible), the kill_agent /proc scan + mcp-stdio cmdline grep, the handler_disconnect RemoveWorktree cwd-scan reap (tracked-pgroup kill already covers it; pgroup-kill logic untouched), andagent_process_alive_for_workspace/process_liveness_scan_prefix. Net −863 lines.Tests (TDD: red gate 194e457, 9 failing → green f130e33)
<=1, garbage, missing) and recorded-liveness probe.moon test --target native: 2006/2006 green. All spec grep gates pass.Verification
Generated by Choir from commands executed in the leaf workspace.
moon test --target native! grep -rn "list_pids_with_cwd_prefix" src/! grep -rn "mcp_stdio_pids" src/! grep -rn "read_proc_process_table_entries\|process_table_ppid_from_proc_stat" src/! grep -rn "choir_list_pids_with_cwd_prefix" src/sys/stub.c