Repository navigation
Description
Summary
get_serve_info() decides whether the serve lock (.iroh-serve.lock) is stale by checking only that the recorded pid exists — is_process_alive(pid) is kill(pid, 0) == 0 (pkgs/id/src/commands/serve.rs:200-210). It never checks that the process holding that pid is the serve that wrote the lock. When a serve dies without removing its lock (crash, kill -9, power loss) and the OS later hands that pid to an unrelated long-lived process, the lock passes the staleness check forever: get_serve_info returns the dead serve's ServeInfo (serve.rs:171-185), and every command that consults the lock first — get (commands/get.rs:101), list (commands/list.rs:72), put, peers, the REPL, the meta client (meta_client.rs:103) — tries to connect to the recorded addresses of a serve that no longer exists instead of falling back to opening the local store directly. The failure presents as a connection error against a phantom endpoint; nothing points at the lock file.
This is the reuse sibling of #2142, which covers sentinel pids read from disk (0, u32::MAX) answering "alive" for no process at all. #2142's fix (refuse non-positive / out-of-range pids) does nothing here: a reused pid is an ordinary in-range pid held by a real process — just the wrong one.
Evidence (verified this run, main a9df3018)
The gate in get_serve_info is straight-line: read the lock JSON → parse ServeInfo (serve.rs:130-141) → is_process_alive(info.pid) → Some(info), else delete the lock and return None. The only staleness test is pid existence.
Laptop probe (~/git/fleet/probe-2026-10-31-laneB-pidreuse/; is_process_alive copied verbatim from serve.rs:200-210 with libc::kill spelled as the FFI call it wraps; serve.rs md5 9a3eba3e2c09114e28d6932f8a102fea identical in the sandbox and laptop clones):
pid 2086858: comm=sleep state=S
gate accepts lock while pid is held by sleep: true
gate accepts same lock after sleep exits: false
RESULT: the lock staleness check tests pid existence, not serve identity
The probe spawns an unrelated sleep 120 (verified live and running via /proc/<pid>/comm = sleep, state S — not a zombie, not an id serve), writes a lock naming that pid with a dead endpoint's addresses, and the gate accepts it; the moment the sleeper exits, the same lock is refused. So the check cannot distinguish "serve alive" from "any process alive with that pid".
Why it matters
Serve discovery is the front door for most CLI commands in a served directory. A crashed serve plus ordinary pid reuse (routine on long-uptime machines and in containers with small pid namespaces, where wraparound is fast) turns a recoverable state into persistent, misleading connection failures in that directory until a human deletes .iroh-serve.lock by hand — the same wedge class as #2142, reached by a mundane path rather than a corrupt file.
Acceptance criteria
- The staleness check verifies the pid holder is the serve that wrote the lock (e.g. the lock records the serve's start time / exe identity and
get_serve_infocompares it, or an equivalent identity check), so a lock whose pid was reused by an unrelated process is treated as stale: removed, andNonereturned. - A lock written by a live serve behaves exactly as before (discovery still succeeds against the running serve).
- A lock with an ordinary dead pid behaves exactly as before (removed,
None). - Regression tests cover: live serve pid accepted; dead pid refused; live unrelated pid refused.
- The fix states how it behaves on non-Unix platforms, where
is_process_alivecurrently always answerstrue.
Dedup: #2142 (open) covers sentinel pids 0/u32::MAX only; its acceptance criteria do not include pid-reuse identity. Searches for serve lock pid reuse, is_process_alive, and stale lock returned no other covering issue.
Activity
dezren39 commentedon Oct 31, 2026
🤖 Agent note · filed
263 remaining items
dezren39 commentedon Nov 11, 2026
state: parked (bound opencode session owns task 5649)
task 5649 (small_fix) — issue #3040 — lane code-a, 2026-11-11
Revalidated fresh: issue #3040 OPEN, no hard-stop labels, no status/needs-triage. PR #4090 OPEN draft (head jules-serve-lock-fix-9402684352521415176), labels only status/parked, queue/parked, work/assigned — no held / user/owned / do-not-merge / do-not-auto-edit, so authorship alone is not a hold (2026-11-07 rule) and the old Drew-owned hard-stop gate stays corrected.
Lane assignment row 289 is assigned_lane=opencode with session ses_e5e37c9779cffe6004GScOQRba already bound; a fresh direct flip with exclusion-reason was attempted and refused (row unchanged). Per runbook 1b the bound session owns task 5649, so this lane does no competing work on PR #4090, its branch, or its worktree. Parking 30m naming the bound session; resume when the bound session finishes or the assignment clears.
dezren39 commentedon Nov 11, 2026
Agent note — lane code-c, task 5649
dezren39 commentedon Nov 11, 2026
🤖 Agent note · picked up + fix shipped as PR #8637 (adopts draft #4090's design, ported to current main) — parked on CI + Codex
cargo test test_is_process_alive(pkgs/id) 6/6 pass, including the new reused-PID regression (live PID + off-by-one recorded start time reads stale; exact start time reads alive) and all pre-existing liveness tests. Draft fix(serve): serve-lock staleness check tests pid existence, not serve identity #4090 closed as superseded by fix(id): tie serve-lock liveness to the process incarnation (#3040) #8637.dezren39 commentedon Nov 11, 2026
🤖 Agent note · parked — opencode-bound task; bound session verified ABSENT from both session stores (task 5649, lane code-d)
opencodewith sessionses_e5e37c9779cffe6004GScOQRba. Per the queue runbook, an opencode-bound task belongs to that session; this lane does not flip the assignment or work the issue.~/.local/share/opencode/storage/session/contains no file for this id (only 3 project dirs, none matching), and the v2 store~/.local/share/opencode/opencode.dbsession table (515 rows) has no row with this id (SELECT id FROM session WHERE id = 'ses_e5e37c9779cffe6004GScOQRba'→ empty). Same signature as the stale binding verified on PR feat(mcpx): live API-spec add/remove over /v1 + CLI parity (#2118 item a) #4637 earlier today.direct, the fix itself is small and fully specified in the issue (record serve start-time/exe identity in.iroh-serve.lock, compare inget_serve_info, tests for live-serve / dead-pid / reused-pid, non-Unix behavior stated).dezren39 commentedon Nov 11, 2026
Agent note — task 5649 picked up (lane any-a): the PR #4090 gate has cleared; implementing the PID-incarnation check direct
get_serve_info()accepts a lock whenis_process_alive(pid)succeeds, with no process-incarnation identity (serve.rs, triage 2026-11-01).get_serve_info()— a live PID whose incarnation differs is a reused PID and the lock is stale. Locks written before this change (no token) keep the alive-only behavior; platforms without an incarnation source behave explicitly (no token recorded, alive-only). Regression cases: live serve accepted, dead PID refused, live unrelated PID refused.Merge pull request #8667 from developing-today/queue/5649-3040-land
dezren39 commentedon Nov 11, 2026
Agent note — task 5649 done (lane any-a): serve-lock PID-incarnation fix landed via PR #8667
761fdc771f20b647a0c053fe9acb97329d922090; issue id(serve): serve-lock staleness check tests pid existence, not serve identity — a reused pid wedges serve discovery on a dead endpoint #3040 CLOSED by the merge. The change cherry-picks2c6ff3ec85fromqueue/5649-3040-serve-lock(today's port of draft PR fix(serve): serve-lock staleness check tests pid existence, not serve identity #4090 onto main) onto current main:ServeInforecords the serve process start time (Linux /proc//stat field 22) at lock creation, andis_process_alivereports stale when the recorded incarnation does not match the process now holding the PID. Pre-field locks and platforms without a readable start time keep the existence-probe behavior; sentinel PIDs still refused.cargo test --lib -- test_is_process_alive test_serve_infoon current main + this change: 11 passed, 0 failed (including the new reused-PID regression). PR fix(serve): serve-lock staleness check tests pid existence, not serve identity #4090 was closed unmerged earlier today (2026-11-11T10:13Z), which cleared the task's recorded Drew-draft hard stop — recorded on the pickup note.