You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cancel never signals a foreground companion on Linux/macOS: process-group kill fails with ESRCH and there is no fallback to the pid #786
Plugin codex@openai-codex 1.0.6; main @ db52e28 has the same code
Linux, Node 24 (the code path is the same on every non-Windows platform)
Summary
On non-Windows platforms, terminateProcessTree() (plugins/codex/scripts/lib/process.mjs) signals the job's process group with process.kill(-pid, "SIGTERM"). That only works when the recorded pid leads its own process group. Detached background workers do (spawn(..., { detached: true })), but a companion started in the foreground from a shell (for example from Claude Code's Bash tool) does not: the shell does not give it its own group, so kill(-pid) fails with ESRCH.
The catch block falls back to process.kill(pid) only for errors other thanESRCH:
So for a foreground companion nothing is signalled. cancel (codex-companion.mjs, terminateProcessTree(job.pid ?? Number.NaN)) ignores the result and records the job as cancelled anyway. When the turn interrupt also fails (the situation in #540, Codex turn interrupt failed: ...), the companion keeps running while its job reports cancelled. We ran into this while cleaning up stuck foreground jobs.
Fall back to the pid whenever the group kill fails, including ESRCH, and report delivered: false only when that also fails with ESRCH:
try{killImpl(-pid,"SIGTERM");return{attempted: true,delivered: true,method: "process-group"};}catch{// Not a process-group leader (ESRCH) or not permitted: signal the process itself.}try{killImpl(pid,"SIGTERM");return{attempted: true,delivered: true,method: "process"};}catch(error){if(error?.code==="ESRCH")return{attempted: true,delivered: false,method: "process"};throwerror;}
Have cancel check delivered before recording the job as cancelled, or record that the process could not be signalled.
Signalling only the pid does not reach a foreground companion's own children (for example a direct-mode app-server). Starting those children in a process group the companion owns, or tracking their pids in the job record, would let cancel stop the whole tree.
Related: #540 (how jobs get stuck mid-turn), #222 and #517 (no pid liveness check for running jobs).
Activity