Repository navigation
Description
mcpx(pool): keyPIDAlive treats an EPERM pid as dead — pid-scoped instances for a live foreign-owned caller are reaped, never replaced, and skipped on restart
Summary
keyPIDAlive (pkgs/mcpx/internal/pool/pool.go:1238-1248) decides whether the
process named by a pid-scoped instance key still exists:
proc, err := os.FindProcess(pid)
if err != nil {
return false
}
return proc.Signal(syscall.Signal(0)) == nilSignal(0) returns EPERM when the process exists but belongs to another
user. This helper treats any error as "dead", so a live caller owned by a
different user reads as exited. The daemon already has the correct version of
this exact check — ProcessAlive (pkgs/mcpx/internal/daemon/paths.go:302-312):
if pid <= 0 {
return false
}
...
err = proc.Signal(syscall.Signal(0))
return err == nil || errors.Is(err, syscall.EPERM)The two helpers disagree on precisely the cross-user case, and the pool is the
one that acts destructively on the answer.
Where the wrong answer lands (all on current main, 5a34fa7)
- Reaper —
pool.go:1218:orphaned := in.holders == 0 && p.cfg.Scope.WatchesPID() && !keyPIDAlive(in.key)
→ the instance is stopped immediately (not after the idle timeout) even
though its caller is alive. - No replacement —
internal/pool/execwatch.go:253(replaceable):
a retired child for that caller gets no replacement. - Restart skip —
pool.go:1426-1429: restart skips the key with the error
textowning process has exited— a false statement in the EPERM case.
The caller pid itself is client-supplied and unvalidated for ownership:
internal/daemon/server.go:857-861 takes X-Mcpx-Pid verbatim into
cc.PID, and ScopePid.Key (internal/config/scope.go:103-107) keys the
instance pid:<n> for any n > 0. Cross-user is a real configuration for a
shared/system daemon serving per-user MCP clients — and even in the
single-user case, a client naming a system pid (e.g. 1) gets an instance that
can never survive the reaper.
Evidence (verified this run)
Laptop probe ~/git/fleet/probe-2026-10-29-laneB-pidalive/ (Go module with
PIDOf, keyPIDAlive, and ProcessAlive copied verbatim; source files at
main 5a34fa7, md5 pool.go 007347aeca38d00f12eeb6024a68263a, scope.go
5ba59164fb560a0b95e928eaccc9cb18, paths.go 1d922b391432f7e8275828d8b20da1b3),
run unprivileged (uid 1337; pid 1 is root-owned and alive):
pid 1 (root-owned, alive, EPERM for unpriv caller) keyPIDAlive=false ProcessAlive=true
own pid (alive, same owner) keyPIDAlive=true ProcessAlive=true
dead pid keyPIDAlive=false ProcessAlive=false
Signal(0) pid=1 err=operation not permitted (EPERM=true)
Checked and not part of this filing: pid 0 / pid -1 keys. The Rust id
analogue (#2142) is real because kill(0, 0) probes the caller's own process
group; in Go the os layer rejects both (process not initialized /
process already released), so keyPIDAlive("pid:0") and ("pid:-1") both
return false in the same probe. Adding ProcessAlive's pid <= 0 guard for
parity is harmless but is not the bug.
Why it matters
Pid scope exists to tie an instance's lifetime to its caller's. With the EPERM
blind spot, exactly the deployments where caller and daemon differ in uid —
the ones that most need the daemon to be conservative about killing instances —
get silent instance churn, unreplaced children, and restart output that
misreports a live process as exited, which sends diagnosis in the wrong
direction.
Acceptance criteria
-
keyPIDAlivetreats EPERM fromSignal(0)as alive, matching
daemon.ProcessAlivesemantics for the same pid (or the pool calls one
shared helper — triage pins which). - Regression test: a pid that exists but is not signalable by the test
process (or a seam/fake that injects EPERM) is reported alive; a dead
pid is still reported dead; same-owner live pid unchanged. - Restart no longer reports
owning process has exitedfor an
EPERM-only pid. - No change to
daemon.ProcessAlive/PruneStalebehaviour (mcpx daemons: dead records listed forever, custom-state daemons missed, paths.config file entry silently ignored #278,
closed) or to pid-scope key production.
Dedup
gh searches (open + closed) for keyPIDAlive, ProcessAlive, EPERM pid,
pool orphan pid alive, pid-scoped instance: no filing covers the pool
helper. #2142 is the Rust id serve lock (different codebase, and its pid-0
arm does not transfer to Go — see Evidence). #278 (closed) was daemon-record
pruning via ProcessAlive, which already handles EPERM correctly.
Activity
developing-today commentedon Oct 29, 2026
CODE-1182
dezren39 commentedon Oct 29, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 1, 2026
🤖 Agent note · picked up
26 remaining items
dezren39 commentedon Nov 2, 2026
🤖 Agent note · parked
dezren39 commentedon Nov 2, 2026
🤖 Agent note · picked up
keyPIDAlivefor mcpx(pool): keyPIDAlive treats an EPERM pid as dead — live foreign-owned callers' pid-scoped instances are reaped, never replaced, and skipped on restart #2336; resuming from awaiting CI on PR fix(mcpx): treat EPERM as alive in pool keyPIDAlive (#2336) #4149.dezren39 commentedon Nov 2, 2026
🤖 Agent note · parked
gh pr checksshowed build, docs-history, lint, plugin, and stress checks pending (other checks skipped).dezren39 commentedon Nov 2, 2026
🤖 Agent note · picked up
Merge pull request #4149 from developing-today/queue/5270-2336-keypid…
dezren39 commentedon Nov 2, 2026
🤖 Agent note · done