Skip to content

id(serve): is_process_alive treats EPERM as dead — a live foreign-owned serve's lock is deleted by get_serve_info #2384

Closed

Description

@dezren39

Problem

is_process_alive (pkgs/id/src/commands/serve.rs:200-206) treats any kill(pid, 0) result other than 0 as "dead":

unsafe { libc::kill(pid as i32, 0) == 0 }

kill(pid, 0) also fails with EPERM when the process exists but is owned by another user — existence is exactly what the probe is asking about. On a multi-uid machine (serve started by one uid, a CLI/REPL process run by another — e.g. a user service vs an interactive shell, or a root-started serve inspected by the daily user) the function therefore answers "dead" for a live serve.

The only consumer, get_serve_info (serve.rs:171-185), acts on that answer destructively:

if !is_process_alive(info.pid) {
    // Stale lock file - remove it
    let _ = afs::remove_file(SERVE_LOCK).await;
    return None;
}

So a live serve's .iroh-serve.lock is deleted by a process running as a different uid, and discovery reports "no serve running" — every command that consults the lock first falls back instead of connecting to the serve that is actually up.

The codebase already knows the correct rule in the sibling component: mcpx's ProcessAlive (pkgs/mcpx/internal/daemon/paths.go:299-313) documents and implements "EPERM means the process is there but owned by somebody else, which is still alive". The converse bug in mcpx's pool checker is tracked separately as #2336.

This is distinct from #2142 (same function): that issue covers sentinel pids (0 / u32::MAX) being passed to kill and answering "alive" for no process. This issue covers the errno of a legitimate pid never being inspected, answering "dead" for a real process. Either fix alone leaves the other defect in place.

Evidence (verified this run, main 5a34fa70)

  • serve.rs:200-206: the return value is compared to 0 only; errno is never read.
  • serve.rs:1873-1880: the existing test test_is_process_alive_pid_1 deliberately asserts nothing ("Just check that the function doesn't panic") — pid 1 is the canonical foreign-owned live pid, and the test cannot assert true because the function gets it wrong for non-root callers.
  • Probe on the laptop (~/git/fleet/probe-2026-10-29-laneB-serveeperm/, verbatim function logic via a direct kill extern, run as the laptop's non-root daily user):
    own pid 1582009 -> true
    pid 1 (alive, root-owned) -> false
    dead pid 1582067 -> false
    
  • OS-level cross-check on the same host: kill(1, 0) returns errno 1 (EPERM) for the non-root user, while a dead pid returns errno 3 (ESRCH) — the information needed to distinguish the cases is present and is being discarded.

Why it matters

Serve discovery is the front door for most CLI commands in a served directory. Deleting a live serve's lock is worse than misreporting it: the lock does not come back until the serve restarts, so one cross-uid invocation permanently (for that serve's lifetime) breaks discovery for everyone, with no error naming the cause.

Acceptance criteria

  • is_process_alive distinguishes EPERM (alive) from ESRCH (dead): a live foreign-owned pid returns true.
  • get_serve_info no longer removes the lock of a live foreign-owned serve; it returns that serve's info.
  • Ordinary behaviour is unchanged: own live pid → true, dead pid → false (lock removed as stale).
  • Regression test: test_is_process_alive_pid_1 (or a successor) asserts pid 1 is alive on Unix when it exists, instead of asserting nothing — or an equivalent EPERM-path test is added.
  • The fix composes with id(serve): is_process_alive answers 'alive' for pid 0 and u32::MAX — a lock file with either pid is never stale and wedges serve discovery #2142's sentinel-pid guard (whichever lands first, the second rebases onto it rather than re-deciding the other case).

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/idPackage/app: id (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

  4. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    🤖 Correction (new-issue-creator-code-b): the agent-note footer on the filing note above reads at=2026-10-29T17:42:00Z; the actual filing time was 2026-10-29T17:29:00Z. Timestamp typo only — substance unaffected.

  5. added a commit that references this issue on Nov 1, 2026
  6. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

  7. 21 remaining items

  8. added
    queue/needs-reviewQueue task finished and is awaiting review
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 1, 2026
  9. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/needs-reviewQueue task finished and is awaiting review
    on Nov 1, 2026
  10. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

    Parked because the targeted cargo test --lib test_is_process_alive compile on the laptop is still running after ~18 minutes (laptop load ~115 from fleet-wide builds; the dependency tree is most of the cost — the change itself is 12 lines). The PR is open with the full diff; do not re-implement. On resume: the compiled test binary lands in ~/git/fleet/target-5262/debug/deps/ (or rerun the cargo command in ~/git/fleet/5262/pkgs/id with CARGO_TARGET_DIR=$HOME/git/fleet/target-5262 — the target dir is warm).

  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 1, 2026
  12. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

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

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (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 jobstatus:donetask/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