validateProcessIdentity() treats a denied ps probe as process death — same defect as #79, unfixed by #80
Summary
validateProcessIdentity() collapses "the probe was denied" into "the process is dead", the same defect #79 reported in isProcessAlive(). It is latent rather than live, but only by accident, and #80 does not fix it.
The code
scripts/lib/process.mjs:
export function getProcessIdentity(pid) {
if (process.platform === 'darwin') {
const row = runCommandChecked('ps', ['-o', 'lstart=,comm=', '-p', String(pid)]);
return row.stdout.trim();
}
...
}
export function validateProcessIdentity(pid, expectedIdentity) {
try {
return getProcessIdentity(pid) === expectedIdentity;
} catch {
return false; // <- denial and absence are indistinguishable
}
}
scripts/lib/state.mjs:449 prefers this branch whenever the job recorded an identity:
const alive = job.pidIdentity
? validateProcessIdentity(job.pid, job.pidIdentity)
: isProcessAlive(job.pid);
if (alive) return job;
Why it matters
Inside a Codex workspace-write sandbox, spawnSync ps fails with EPERM unconditionally — not merely for non-descendants, the way the zero-signal probe does. Measured on macOS 25.5.0 / codex-cli 0.145.0:
E. spawnSync ps: ERROR EPERM
So on that path getProcessIdentity() always throws, validateProcessIdentity() always returns false, and every reapable job past the 2s grace period is auto-reaped as dead regardless of whether it is running.
Why it is not firing today
scripts/lib/claude-cli.mjs:799-804 swallows the identical failure at spawn time:
let pidIdentity = null;
try {
pidIdentity = getProcessIdentity(proc.pid);
} catch {
// Best-effort — may fail on some platforms
}
In the sandbox that catch always runs, so jobs are persisted with pidIdentity: null, and reapStaleJobs() falls through to isProcessAlive() — the branch #80 fixes. The identity branch is dead code in exactly the environment where it would misbehave.
That is a coincidence of two independent failures cancelling, not a design. It breaks if any of the following change:
- a job is spawned where
psis permitted and reaped where it is not (mixed sandbox/non-sandbox invocations against the same state dir) getProcessIdentity()gains a non-psimplementation on darwin, so identities start being recorded in the sandbox- the spawn-time
catchis tightened to persist a partial identity instead ofnull
In any of those, live jobs are reaped again and #80 does not help, because the identity branch never consults isProcessAlive().
Suggested fix
Distinguish denial from absence at the same boundary #80 established, rather than at the call site:
- have
getProcessIdentity()propagate a typed "probe denied" signal instead of a bare throw (or havevalidateProcessIdentity()inspecterror.code === 'EPERM') - on denial, return the same verdict
isProcessAlive()now returns forEPERM— treat the process as present and let the caller keep the job - keep genuine mismatch and
ESRCHclassified as not alive, so PID-reuse detection is unweakened - cover both branches deterministically, as #80 does, via an injectable command impl
An alternative worth considering: fall back to isProcessAlive(pid) when the identity probe is denied, accepting the loss of PID-reuse safety only in the case where identity cannot be established at all. That keeps one liveness answer rather than two.
Related
- #79 — the reported bug
- #80 — fixes the
isProcessAlive()branch only
I would model this as a tri-state probe: alive, dead, or unknown. EPERM is unknown, not proof of life; the reaper may transition only on dead (ESRCH or a verified identity mismatch). On unknown, keep the job non-terminal, record that identity verification was unavailable, and rely on a bounded secondary signal such as a supervisor heartbeat or completion record. Falling back to kill(pid, 0) avoids the false death but quietly drops the PID-reuse guarantee, so that degradation should be explicit in the job receipt.
If you exercise EPERM, ESRCH, and PID-reuse cases through MartinLoop, send us the receipts so we can pressure-test whether the evidence distinguishes them cleanly: https://github.com/Keesan12/martin-loop
Shipped in v1.4.0, now on npm as [email protected] and in the sendbird/codex-marketplace snapshot. Update with $cc:setup after your Codex plugin cache refreshes.
Note that 1.4.0 also fixes a separate Codex 0.145 incompatibility (#87): spawn_agent stopped advertising agent_type and dropped gpt-5.4-mini from its child-model catalog, both of which the built-in forwarding paths pinned. If you saw background review/rescue spawns failing on 1.3.0 beyond the sandbox issues above, that was the cause.