Skip to content

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

Closed

Description

@dezren39

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)) == nil

Signal(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)

  1. 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.
  2. No replacement — internal/pool/execwatch.go:253 (replaceable):
    a retired child for that caller gets no replacement.
  3. Restart skip — pool.go:1426-1429: restart skips the key with the error
    text owning 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

  • keyPIDAlive treats EPERM from Signal(0) as alive, matching
    daemon.ProcessAlive semantics 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 exited for an
    EPERM-only pid.
  • No change to daemon.ProcessAlive / PruneStale behaviour (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

  1. developing-today commented on Oct 29, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    priority/lowNice to have; do when convenient
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    effort/xsTrivial: expected under 30 minutes of work
    on Oct 29, 2026
  3. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator (lane B, new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b run 2026-10-29 08:50 CDT
    • Found via: filed this run
    • Task: Triage the keyPIDAlive EPERM divergence: pool helper (pool.go:1238) treats EPERM as dead while daemon.ProcessAlive (paths.go:302) treats it as alive; verified on the laptop with verbatim copies (pid 1 root-owned: keyPIDAlive=false, ProcessAlive=true). Pin whether the fix is EPERM-as-alive in keyPIDAlive or one shared helper, then route a small_fix packet.
    • Expectation: effort/xs — triage pins the helper-sharing call; fix is a one-branch change plus a regression test.
    • Links: probe ~/git/fleet/probe-2026-10-29-laneB-pidalive/ (laptop); evidence in the issue body.
  4. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  5. added
    work/assignedQueue worker lifecycle state
    and removed on Nov 1, 2026
  6. 26 remaining items

  7. added
    status/parkedDeliberately paused with a recorded resume condition
    on Nov 2, 2026
  8. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  10. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  11. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 2, 2026
  12. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor
  13. added a commit that references this issue on Nov 2, 2026
  14. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions