Skip to content

fix(bin): reclaim a status-presentation lock whose owner pid is dead or recycled - #3977

Open
eduardstan wants to merge 8 commits into
kunchenguid:mainfrom
eduardstan:fm/fm-upstream-3966-presentation-lock
Open

eduardstan wants to merge 8 commits into
kunchenguid:mainfrom
eduardstan:fm/fm-upstream-3966-presentation-lock

Conversation

@eduardstan

Copy link
Copy Markdown

Intent

Fix upstream firstmate issue #3966: "status-presentation lock: a dead owner is not reclaimed, so every wake drain blocks until its timeout". The captain's order (2026-09-08, while away): fix it upstream, through the no-mistakes pipeline as upstream requires, on Claude Opus 5.

The issue, condensed: every bin/fm-wake-drain.sh blocks for minutes and returns only the OPEN DECISIONS section plus a warning, no wake records and no WAKE_ACK_REQUIRED line, so queued wakes cannot be acknowledged and re-announce on every turn. Seen three times in four hours on one home (dead owner pids) and once on 2026-09-04. Manual fix each time: read state/.status-presentation-lock (a symlink), cat /pid, confirm with ps -p that the owner is gone, remove the symlink and the owner directory. The presentation lock is taken in bin/fm-wake-drain.sh (around lines 364 to 375) and bin/fm-classify-lib.sh (around line 774) through fm_lock_acquire_wait "$STATE/.status-presentation-lock"; fm_lock_acquire_wait (bin/fm-wake-lib.sh around 884 to 891) loops on fm_lock_try_acquire with a 0.1 second sleep, no bound, no stale-owner escape. The reclaim path exists (fm_pid_alive guarding a steal, around fm-wake-lib.sh 833) but the stranded owner directories contain only pid, no pid-identity, while the daemon lock's owner directory has both; fm_lock_points_to_owner reads pid-identity, so an owner written without it plausibly fails the identity comparison and the steal is abandoned. Second possibility to rule out: pid reuse making kill -0 succeed for an unrelated process, which is what pid-identity exists to prevent. Suggested direction from the reporter: (1) make the presentation-lock writer record pid-identity the way the auto-arm owner lock does (fm-wake-lib.sh around 1042 to 1063), so the existing steal path can prove the owner is gone; (2) give fm_lock_acquire_wait a bounded wait for this lock with a loud diagnostic naming the owner pid and the manual clear, instead of an unbounded spin. Reproduction is opportunistic (kill a drain mid-presentation); the stranded directories are the evidence.

What Changed

  • Every lock owner directory now records the owner process's start token beside its pid (fm_lock_record_start, split out of fm_pid_identity as fm_pid_start_token), and all steal paths in bin/fm-wake-lib.sh route their liveness check through a new fm_lock_owner_gone, which treats an owner as gone when the pid is dead or when the live pid's recomputed start token differs from the recorded one — only comparing tokens computed in the same format, and falling back to the previous pid-only proof when no token was recorded.
  • The presentation-lock timeout moved into a shared fm_status_presentation_lock_timeout helper, and the refused-wait message became a shared fm_lock_live_holder_advisory that names the holder pid, the ps -p confirmation, and a shell-quoted rm -rf clear covering both the lock symlink and its resolved owner directory.
  • bin/fm-classify-lib.sh's status-row retire swapped its unbounded fm_lock_acquire_wait for a new fm_lock_acquire_wait_retire, which waits a genuinely live holder out across 30 bounded windows (announcing the holder each window) before refusing with 124, and falls back to the unbounded wait if the bounding machinery itself fails.
  • Tests cover recycled-pid reclaim, same-format token comparison, handoff token transfer, the retire wait/refuse path, and the advisory text; docs/configuration.md documents FM_STATUS_PRESENTATION_LOCK_TIMEOUT and docs/watcher-continuity.md documents the ownership contract.

Risk Assessment

⚠️ Medium: The change correctly fixes the reported wedge at its root and is covered by behavior-driven regression tests, but it broadens lock-eviction semantics for every fm_lock_* consumer (watch, daemon, queue, presentation) and introduces a multi-minute blocking window plus a per-window owner-directory leak inside teardown, all of which are safe to merge and address as follow-ups.

Testing

Ran the four changed test scripts through bin/fm-test-run.sh; fm-teardown, fm-wake-drain-unread-status and fm-watcher-lock all pass (the latter serially, 37 ok), and fm-wake-queue passes everything except one pre-existing case that fails identically on the base commit and aborts the suite before the new cases, so I ran those in isolation and with only that case excluded to prove them. Two failures seen in the first concurrent run were host-load flakes and passed isolated. Beyond the suites I reproduced the reported field condition against the real drain and the real teardown retire path on the base checkout and on the branch head: base skips the presentation on every drain after burning its full bound and its retire never returns at all under a 45-second external timeout, while the head reclaims the stranded owner and presents status content, retires cleanly, still refuses to steal a genuinely live holder while naming it every wait window, and hands an operator a paste-ready manual clear for an unprovable legacy owner directory that unwedges the drain and strands nothing. The before/after CLI transcript and the three repro scripts are in the evidence directory.

Evidence: Before/after CLI transcript: #3966 drain wedge, retire spin, and operator remedy

Source: Before/after CLI transcript: #3966 drain wedge, retire spin, and operator remedy

SCENARIO 1 - the reported wedge (owner gone, pid recycled onto a live process) ### [BEFORE-891dc51] drain exit=0 wall=12s STATUS PRESENTATION SKIPPED: lock remains held by live pid 1856275 after 10s; retry on the next drain. ### [AFTER-bbd4dcd] drain exit=0 wall=5s wake annotation: latest wake-EVENT observed at drain, not current state: task.status: needs-decision [key=fixture]: recycled owner must not wedge the drain OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line): task [key=fixture] needs-decision: recycled owner must not wedge the drain SCENARIO 2 - the retire path (bin/fm-classify-lib.sh) ### [BEFORE-891dc51] retire NEVER RETURNED (killed by a 45s external timeout) - unbounded spin ### held.status still present after retire? YES-not-retired ### [AFTER-bbd4dcd] retire exit=0 wall=1s ### held.status still present after retire? no-retired SCENARIO 3 - owner directory from an OLDER build (pid only, unprovable) ### [BEFORE-891dc51] STATUS PRESENTATION SKIPPED: lock remains held by live pid 1882667 after 1s; retry on the next drain. ### advisory printed NO manual clear command ### [AFTER-bbd4dcd] STATUS PRESENTATION SKIPPED: lock remains held by live pid 1883938 after 1s. If ps -p 1883938 shows no firstmate process, clear it with rm -rf <state>/.status-presentation-lock.owner.legacy <state>/.status-presentation-lock. Retry on the next drain. $ rm -rf <state>/.status-presentation-lock.owner.legacy <state>/.status-presentation-lock ### exit=0 ### lock symlink left behind? no ### owner directory stranded in state/? none ### re-drain after the printed clear: OPEN DECISIONS ... needs-decision [key=fixture]: manual clear must strand nothing SCENARIO 4 - a GENUINELY live presentation holder ### retire exit=0 wall=13s (holder exits on its own after ~12s); held.status retired? yes STATUS PRESENTATION RETIRE WAITING: lock remains held by live pid 1897527 after 2s. If ps -p 1897527 shows no firstmate process, clear it with rm -rf ... (x5, one per wait window)

==============================================================================
upstream firstmate #3966 - status-presentation lock: a dead owner is not
reclaimed, so every wake drain blocks until its timeout
BEFORE = base 891dc51    AFTER = branch head bbd4dcd
host: Linux 7.0.0-31-generic   date: 2026-09-08T06:18:20Z
==============================================================================

########## SCENARIO 1 - the reported wedge #########################
# The presentation lock's recorded owner is gone, but the OS recycled its pid
# onto an unrelated live process, so kill -0 answers forever.

### [BEFORE-891dc51] checkout: /tmp/fm-3966-base
### staged owner dir: pid pid-start   (recorded pid 1856275 is a LIVE unrelated process)
### drain exit=0  wall=12s
--- stdout ---
1788848300	1	signal	task.status	signal: /tmp/fm-3966-run2/BEFORE-891dc51/state/task.status
STATUS PRESENTATION SKIPPED: lock remains held by live pid 1856275 after 10s; retry on the next drain.
--- stderr ---
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1856175.1788848301.nICRXQ

### [AFTER-bbd4dcd] checkout: <worktree>
### staged owner dir: pid pid-start   (recorded pid 1862134 is a LIVE unrelated process)
### drain exit=0  wall=5s
--- stdout ---
1788848313	1	signal	task.status	signal: /tmp/fm-3966-run2/AFTER-bbd4dcd/state/task.status
wake annotation: latest wake-EVENT observed at drain, not current state: task.status: needs-decision [key=fixture]: recycled owner must not wedge the drain
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
task [key=fixture] needs-decision: recycled owner must not wedge the drain
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'
--- stderr ---
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1862020.1788848314.O0Ej3i

########## SCENARIO 2 - the retire path (bin/fm-classify-lib.sh) ###########
# status_retire_presentation_task takes the same lock through the previously
# UNBOUNDED fm_lock_acquire_wait. Same stranded recycled-pid owner.

### [BEFORE-891dc51] retire against a stranded lock whose owner pid 1864715 was recycled
### retire NEVER RETURNED (killed by a 45s external timeout) - unbounded spin
### held.status still present after retire? YES-not-retired
--- stderr ---

### [AFTER-bbd4dcd] retire against a stranded lock whose owner pid 1881831 was recycled
### retire exit=0 wall=1s
### held.status still present after retire? no-retired
--- stderr ---

########## SCENARIO 3 - an owner directory from an OLDER build #############
# pid only, no start token: unprovable, so the operator gets a paste-ready
# manual clear instead of a silent forever-wedge.

### [BEFORE-891dc51] legacy stranded lock, owner pid 1882667 recycled onto a live process
--- drain stdout ---
1788848366	1	signal	task.status	signal: /tmp/fm-3966-run2/BEFORE-891dc51-manual-clear/state/task.status
STATUS PRESENTATION SKIPPED: lock remains held by live pid 1882667 after 1s; retry on the next drain.
### advisory printed NO manual clear command

### [AFTER-bbd4dcd] legacy stranded lock, owner pid 1883938 recycled onto a live process
--- drain stdout ---
1788848369	1	signal	task.status	signal: /tmp/fm-3966-run2/AFTER-bbd4dcd-manual-clear/state/task.status
STATUS PRESENTATION SKIPPED: lock remains held by live pid 1883938 after 1s. If ps -p 1883938 shows no firstmate process, clear it with rm -rf /tmp/fm-3966-run2/AFTER-bbd4dcd-manual-clear/state/.status-presentation-lock.owner.legacy /tmp/fm-3966-run2/AFTER-bbd4dcd-manual-clear/state/.status-presentation-lock. Retry on the next drain.
### operator pastes exactly what the advisory printed:
$ rm -rf /tmp/fm-3966-run2/AFTER-bbd4dcd-manual-clear/state/.status-presentation-lock.owner.legacy /tmp/fm-3966-run2/AFTER-bbd4dcd-manual-clear/state/.status-presentation-lock
### exit=0
### lock symlink left behind? no
### owner directory stranded in state/? none
### re-drain after the printed clear:
1788848369	1	signal	task.status	signal: /tmp/fm-3966-run2/AFTER-bbd4dcd-manual-clear/state/task.status
wake annotation: latest wake-EVENT observed at drain, not current state: task.status: needs-decision [key=fixture]: manual clear must strand nothing
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
task [key=fixture] needs-decision: manual clear must strand nothing
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'

########## SCENARIO 4 - a GENUINELY live presentation holder ###############
# The retire must not steal a live holder's lock, and must not go silent:
# it names the holder every window, then completes once the holder exits.
# holder pid 1897527 holds /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock -> .status-presentation-lock.owner.qVLCgK

### retire exit=0 wall=13s (holder exits on its own after ~12s)
### held.status retired? yes
--- stderr (every wait window names the holder) ---
STATUS PRESENTATION RETIRE WAITING: lock remains held by live pid 1897527 after 2s. If ps -p 1897527 shows no firstmate process, clear it with rm -rf /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.owner.qVLCgK /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.
STATUS PRESENTATION RETIRE WAITING: lock remains held by live pid 1897527 after 2s. If ps -p 1897527 shows no firstmate process, clear it with rm -rf /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.owner.qVLCgK /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.
STATUS PRESENTATION RETIRE WAITING: lock remains held by live pid 1897527 after 2s. If ps -p 1897527 shows no firstmate process, clear it with rm -rf /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.owner.qVLCgK /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.
STATUS PRESENTATION RETIRE WAITING: lock remains held by live pid 1897527 after 2s. If ps -p 1897527 shows no firstmate process, clear it with rm -rf /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.owner.qVLCgK /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.
STATUS PRESENTATION RETIRE WAITING: lock remains held by live pid 1897527 after 2s. If ps -p 1897527 shows no firstmate process, clear it with rm -rf /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.owner.qVLCgK /tmp/fm-3966-run2/live-holder/state/.status-presentation-lock.
Evidence: Repro harness: drain against a stranded recycled-pid presentation lock

Source: Repro harness: drain against a stranded recycled-pid presentation lock

#!/usr/bin/env bash
# Upstream firstmate #3966 reproduction / verification harness.
#   usage: fm-3966-repro.sh <checkout-root> <label> <outdir>
# Stages the exact field condition (a status-presentation lock whose recorded
# owner is gone but whose pid the OS recycled onto an unrelated live process)
# and runs that checkout's bin/fm-wake-drain.sh over a queued wake.
set -u
ROOT=$1; LABEL=$2; OUT=$3
TOOLS=${FM_3966_TOOLS:-$ROOT}   # checkout used only to MINT the fixture token
mkdir -p "$OUT/$LABEL"
work="$OUT/$LABEL"
state="$work/state"; mkdir -p "$state"
tangle="$work/tangle"; mkdir -p "$tangle"
status="$state/task.status"
lock="$state/.status-presentation-lock"
owner="$lock.owner.recycled"

printf 'needs-decision [key=fixture]: recycled owner must not wedge the drain\n' > "$status"
FM_STATE_OVERRIDE="$state" bash -c '. "$1"; fm_wake_append signal task.status "signal: $2"' \
  _ "$ROOT/bin/fm-wake-lib.sh" "$status" >/dev/null

sleep 300 & impostor=$!
mkdir "$owner"
printf '%s\n' "$impostor" > "$owner/pid"
if [ "${FM_3966_TOKEN:-yes}" = yes ]; then
  tok=$(bash -c '. "$1"; fm_pid_start_token "$2"' _ "$TOOLS/bin/fm-wake-lib.sh" "$impostor")
  case "$tok" in
    *-starttime=*) printf '%s=1\n' "${tok%%=*}" ;;
    *) printf 'Tue Sep  8 06:41:08 2020\n' ;;
  esac > "$owner/pid-start"
fi
ln -s "$owner" "$lock"

echo "### [$LABEL] checkout: $ROOT"
echo "### staged owner dir: $(ls "$owner" | tr '\n' ' ')  (recorded pid $impostor is a LIVE unrelated process)"
start=$(date +%s)
FM_STATE_OVERRIDE="$state" FM_ROOT_OVERRIDE="$tangle" FM_STATUS_PRESENTATION_LOCK_TIMEOUT=10 \
  "$ROOT/bin/fm-wake-drain.sh" > "$work/drain.out" 2> "$work/drain.err"
rc=$?
elapsed=$(( $(date +%s) - start ))
kill "$impostor" 2>/dev/null; wait "$impostor" 2>/dev/null
echo "### drain exit=$rc  wall=${elapsed}s"
echo "--- stdout ---"; cat "$work/drain.out"
echo "--- stderr ---"; cat "$work/drain.err"
echo
Evidence: Repro harness: status_retire_presentation_task against the same stranded lock

Source: Repro harness: status_retire_presentation_task against the same stranded lock

#!/usr/bin/env bash
# #3966, retire path: bin/fm-classify-lib.sh's status_retire_presentation_task
# takes the same status-presentation lock. Same stranded recycled-pid owner.
set -u
ROOT=$1; LABEL=$2; OUT=$3
TOOLS=${FM_3966_TOOLS:-$ROOT}
work="$OUT/$LABEL-retire"; state="$work/state"; mkdir -p "$state"
lock="$state/.status-presentation-lock"; owner="$lock.owner.recycled"
printf 'note: retire fixture\n' > "$state/held.status"
sleep 300 & impostor=$!
mkdir "$owner"; printf '%s\n' "$impostor" > "$owner/pid"
tok=$(bash -c '. "$1"; fm_pid_start_token "$2"' _ "$TOOLS/bin/fm-wake-lib.sh" "$impostor")
case "$tok" in *-starttime=*) printf '%s=1\n' "${tok%%=*}" ;; *) printf 'Tue Sep  8 06:41:08 2020\n' ;; esac > "$owner/pid-start"
ln -s "$owner" "$lock"
echo "### [$LABEL] retire against a stranded lock whose owner pid $impostor was recycled"
start=$(date +%s)
timeout 45 env "FM_STATE_OVERRIDE=$state" FM_STATUS_PRESENTATION_LOCK_TIMEOUT=5 bash -c '
  . "$1/bin/fm-wake-lib.sh"; . "$1/bin/fm-classify-lib.sh"
  status_retire_presentation_task "$STATE" held
' _ "$ROOT" > "$work/retire.out" 2> "$work/retire.err"
rc=$?
elapsed=$(( $(date +%s) - start ))
kill "$impostor" 2>/dev/null; wait "$impostor" 2>/dev/null
if [ "$rc" -eq 124 ]; then
  echo "### retire NEVER RETURNED (killed by a 45s external timeout) - unbounded spin"
else
  echo "### retire exit=$rc wall=${elapsed}s"
fi
echo "### held.status still present after retire? $([ -e "$state/held.status" ] && echo YES-not-retired || echo no-retired)"
echo "--- stderr ---"; cat "$work/retire.err"
echo
Evidence: Repro harness: legacy pid-only owner dir and the printed manual clear

Source: Repro harness: legacy pid-only owner dir and the printed manual clear

#!/usr/bin/env bash
# #3966, operator remedy: a lock owner directory written by an OLDER build (pid
# only, no start token) whose pid was recycled cannot be proven gone, so the
# drain must hand the operator a manual clear they can paste verbatim.
set -u
ROOT=$1; LABEL=$2; OUT=$3
work="$OUT/$LABEL-manual-clear"; state="$work/state"; tangle="$work/tangle"
mkdir -p "$state" "$tangle"
status="$state/task.status"; lock="$state/.status-presentation-lock"; owner="$lock.owner.legacy"
printf 'needs-decision [key=fixture]: manual clear must strand nothing\n' > "$status"
FM_STATE_OVERRIDE="$state" bash -c '. "$1"; fm_wake_append signal task.status "signal: $2"' \
  _ "$ROOT/bin/fm-wake-lib.sh" "$status" >/dev/null
sleep 300 & impostor=$!
mkdir "$owner"; printf '%s\n' "$impostor" > "$owner/pid"   # legacy shape: pid only
ln -s "$owner" "$lock"
echo "### [$LABEL] legacy stranded lock, owner pid $impostor recycled onto a live process"
FM_STATE_OVERRIDE="$state" FM_ROOT_OVERRIDE="$tangle" FM_STATUS_PRESENTATION_LOCK_TIMEOUT=1 \
  "$ROOT/bin/fm-wake-drain.sh" > "$work/1.out" 2> "$work/1.err"
echo "--- drain stdout ---"; cat "$work/1.out"
clear_cmd=$(sed -n 's/^.*clear it with //p' "$work/1.out" | head -1); clear_cmd=${clear_cmd%%. *}; clear_cmd=${clear_cmd%.}
kill "$impostor" 2>/dev/null; wait "$impostor" 2>/dev/null
if [ -z "$clear_cmd" ]; then echo "### advisory printed NO manual clear command"; exit 0; fi
echo "### operator pastes exactly what the advisory printed:"
echo "\$ $clear_cmd"
bash -c "$clear_cmd" && echo "### exit=0"
echo "### lock symlink left behind? $([ -e "$lock" ] || [ -L "$lock" ] && echo YES || echo no)"
echo "### owner directory stranded in state/? $(ls -d "$state"/.status-presentation-lock.owner.* 2>/dev/null || echo none)"
echo "### re-drain after the printed clear:"
FM_STATE_OVERRIDE="$state" FM_ROOT_OVERRIDE="$tangle" FM_STATUS_PRESENTATION_LOCK_TIMEOUT=2 \
  "$ROOT/bin/fm-wake-drain.sh" > "$work/2.out" 2> "$work/2.err"
cat "$work/2.out"
- Outcome: ⚠️ 1 warning across 1 run (23m36s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 infos
  • ℹ️ bin/fm-wake-drain.sh:589 - The new advisory tells the operator clear it with rm -f &lt;lock&gt;, but &lt;lock&gt; is the symlink only. The documented manual procedure (and fm_lock_remove_path's own symlink branch) removes the symlink AND the owner directory it points at. An operator who follows the printed command unwedges the drain but leaves an orphan state/.status-presentation-lock.owner.XXXXXX directory behind on every clear, which accumulates in state/. Consider naming both, e.g. rm -rf &#34;$(readlink &lt;lock&gt;)&#34; &lt;lock&gt;, or printing the resolved owner directory alongside it.
  • ℹ️ bin/fm-wake-drain.sh:634 - Only the presentation-lock advisory gained the manual-clear hint. The queue-lock advisory (WAKE DRAIN SKIPPED: queue lock remains held by live pid %s) is the path that exit 0s before any wake record or WAKE_ACK_REQUIRED line is emitted — i.e. the exact operator symptom the issue describes ("no wake records and no WAKE_ACK_REQUIRED line, so queued wakes cannot be acknowledged"). An operator hitting a wedged .wake-queue.lock still gets a pid and nothing to act on. Root cause is fixed for both locks; this is only about diagnostic parity.
  • ℹ️ bin/fm-wake-lib.sh:1097 - _fm_lock_acquire_wait_handoff runs rm -f &#34;$ownerdir/pid-start&#34; before the [ &#34;$back&#34; != &#34;$current&#34; ] ownership check two lines below. If the helper is not in fact the recorded owner at that instant, it has just stripped a third party's start token; that lock then permanently falls back to pid-only proof and silently re-becomes unreclaimable on pid reuse — the exact bug this commit fixes. The window is not reachable today (a live helper with a matching token cannot be stolen, so back always equals current), so this is defensive ordering only: verify back = current first, then delete the token, then write the caller pid.
  • ℹ️ tests/fm-wake-queue.test.sh:1882 - test_live_presentation_holder_advisory_names_the_manual_clear re-stages ~35 lines of live-presentation-holder setup (seed status, seed wake, background fm_lock_acquire_wait + exec sleep 30 holder, ready-file poll, bounded drain) that test_live_presentation_holder_is_deadlined_without_weakening_ack (same file, ~line 1752) already stages and already greps for STATUS PRESENTATION SKIPPED: lock remains held by live pid $presentation_holder. The only new assertion is one grep -F for the manual-clear sentence; adding that single grep to the existing case removes the duplicated scenario. The recycled-pid test at line 1841 is genuinely new and should stay.
  • ℹ️ docs/watcher-continuity.md:72 - Acknowledging the documented tradeoff, not asking for a change: owner directories already stranded in the field carry no pid-start, so fm_lock_owner_gone keeps the weaker pid-only proof for them and a home currently wedged on a recycled pid still needs one manual clear after upgrade. This is stated explicitly in the doc and the bin/fm-wake-lib.sh header, and the improved advisory is what covers it — correct and honest, worth noting only so the operator expectation on rollout is explicit.

🔧 Fix: check handoff ownership before dropping start token
3 infos still open:

  • ℹ️ bin/fm-wake-lib.sh:1102 - _fm_lock_acquire_wait_handoff drops pid-start and hands the pid to the caller, but nothing rewrites the token inside the helper; the invariant is only restored by the parent at fm_lock_acquire_wait_bounded line 1144. If the parent is killed between the helper's exit and that line, the lock is left with a live pid and no start token, i.e. back on the weaker pid-only proof - the exact state that wedges every later drain once the operating system recycles that pid (issue status-presentation lock: a dead owner is not reclaimed, so every wake drain blocks until its timeout #3966). The delete-first ordering is right (a caller pid beside the helper's token would read as reuse), but the helper can close the window itself: after the pid write succeeds, fm_pid_start_token &#34;$caller_pid&#34; &gt; &#34;$ownerdir/pid-start&#34;. The caller is already proven live above and the parent's later fm_lock_record_start writes the identical value, so this is idempotent and removes the dependency on a second process surviving.
  • ℹ️ bin/fm-wake-drain.sh:589 - The advisory tells the operator clear it with rm -f &lt;lock&gt;, naming only the symlink. fm_lock_remove_path's own symlink branch removes the symlink AND fm_lock_discard_owners the target, and the issue's documented manual procedure does the same. An operator who runs exactly the printed command unwedges the drain but leaves an orphan state/.status-presentation-lock.owner.XXXXXX directory behind; nothing in bin/ sweeps those, so they accumulate in state/ once per clear. This was raised in round 1 and is now additionally pinned by the new assertion in tests/fm-wake-queue.test.sh:1779, so the incomplete instruction is locked in. Print the resolved owner directory too, e.g. rm -rf &#34;$(readlink &lt;lock&gt;)&#34; &lt;lock&gt;.
  • ℹ️ bin/fm-classify-lib.sh:1189 - status_retire_presentation_task still takes the status-presentation lock with unbounded fm_lock_acquire_wait. The intent's suggested direction (2) - "give fm_lock_acquire_wait a bounded wait for this lock with a loud diagnostic naming the owner pid and the manual clear, instead of an unbounded spin" - names this lock, and the intent names bin/fm-classify-lib.sh as one of its two takers. Only bin/fm-wake-drain.sh got a bound (pre-existing). With the start-token reclaim in place this is now only reachable against an owner directory written by an older build (docs/watcher-continuity.md:74 acknowledges those keep pid-only proof and still need one manual clear), but in that case a teardown/retire hangs forever with no pid-naming diagnostic at all, unlike the drain. Flagging because it is a source-verifiable gap against a suggested direction rather than a hard requirement - the reported symptom (the drain) is fixed.

🔧 Fix: record caller start token inside the lock handoff
4 infos still open:

  • ℹ️ bin/fm-wake-lib.sh:124 - The extraction of _fm_proc_start_token silently changed fm_pid_identity's failure semantics. The old code entered the /proc branch on [ -r stat ] &amp;&amp; [ -r cmdline ] and hard-return 1ed on any parse failure inside it (short stat_fields, non-numeric starttime) - it never fell through to the ps fallback. Now if start=$(_fm_proc_start_token &#34;$pid&#34;); then ... fi treats a parse failure exactly like an absent /proc, so execution continues to ps -p -o lstart= -o command= and returns an identity in the OTHER format. A caller holding a recorded linux-starttime=... identity then sees a mismatch rather than a compute failure, and those are not equivalent: fm-watch-arm.sh:229 and fm_watcher_lock_stale_clear (bin/fm-wake-lib.sh:1660) evict on mismatch, while a compute failure is conservative. fm_pid_start_token inherits the same drift and feeds fm_lock_owner_gone, where a format flip means a live holder reads as gone and its lock is stolen. Reachability on real Linux is essentially nil (stat field 22 always parses), so this is defensive only. Restore the old shape: gate on [ -r &#34;$proc_root/$pid/stat&#34; ] &amp;&amp; [ -r &#34;$proc_root/$pid/cmdline&#34; ] and hard-fail when _fm_proc_start_token fails inside that gate, in both fm_pid_start_token and fm_pid_identity.
  • ℹ️ bin/fm-wake-lib.sh:490 - fm_lock_record_start memoizes by pid and caches the FAILURE too: FM_LOCK_SELF_START=$(fm_pid_start_token &#34;$pid&#34; 2&gt;/dev/null || true) stores an empty string, and every later call for that same pid hits [ &#34;$pid&#34; != &#34;$FM_LOCK_SELF_START_PID&#34; ] as false and returns at the [ -n &#34;$FM_LOCK_SELF_START&#34; ] || return 0 guard without retrying. One transient failure (a ps fork that hits EAGAIN under load on the non-/proc fallback path, a momentary /proc read error) therefore poisons that process for its whole lifetime: every lock it acquires from then on records pid with no pid-start, which is precisely the pid-only proof this change exists to remove, so issue status-presentation lock: a dead owner is not reclaimed, so every wake drain blocks until its timeout #3966's wedge silently returns for that long-lived process's locks. Cache only a successful computation - keep the memo when the token is non-empty and let an empty result fall through to a recompute on the next acquire.
  • ℹ️ bin/fm-wake-drain.sh:589 - The advisory tells the operator to clear it with rm -f &lt;lock&gt;, naming only the symlink. fm_lock_remove_path's own symlink branch (bin/fm-wake-lib.sh:614-620) removes the symlink AND fm_lock_discard_owners the target, and the issue's documented manual procedure removes both as well. An operator who runs exactly the printed command unwedges the drain but strands a state/.status-presentation-lock.owner.XXXXXX directory; grep confirms nothing under bin/ ever sweeps *.owner.* for wake locks, so one accumulates in state/ per clear. The new assertion at tests/fm-wake-queue.test.sh:1779 pins the incomplete sentence. Print the resolved owner directory too, e.g. rm -rf &#34;$(readlink &lt;lock&gt;)&#34; &lt;lock&gt;.
  • ℹ️ bin/fm-classify-lib.sh:1189 - status_retire_presentation_task still takes $state/.status-presentation-lock with unbounded fm_lock_acquire_wait. The intent's suggested direction (2) - "give fm_lock_acquire_wait a bounded wait for this lock with a loud diagnostic naming the owner pid and the manual clear, instead of an unbounded spin" - names this lock, and the intent names bin/fm-classify-lib.sh as one of its two takers; only bin/fm-wake-drain.sh has a bound, and that bound pre-dates this change. With the start-token reclaim in place the remaining reachable path is an owner directory written by an older build, which docs/watcher-continuity.md:74 acknowledges keeps pid-only proof; against such a directory a teardown/retire hangs forever with no pid-naming diagnostic at all, unlike the drain. Flagged as a gap against a suggested direction, not a hard requirement - the reported symptom (the drain) is fixed and this line is unchanged by the diff.

🔧 Fix: share the presentation-lock advisory and bound the retire path
3 issues (1 warning, 2 infos) still open:

  • ⚠️ bin/fm-wake-lib.sh:1147 - fm_lock_live_holder_advisory builds a copy-pasteable destructive command by bare string concatenation: clear=&#34;rm -rf $ownerdir $lockdir&#34; (line 1147, and rm -rf $lockdir at line 1144). The paths come from $STATE, which is unconstrained - nothing in bin/ rejects whitespace or glob characters in a firstmate home path. With a home at /home/u/My Projects/fm, the advisory prints clear it with rm -rf /home/u/My Projects/fm/state/.status-presentation-lock.owner.ab12 /home/u/My Projects/fm/state/.status-presentation-lock, and an operator who runs exactly what the advisory told them to run deletes /home/u/My and Projects relative to the cwd instead of the lock. This is newly introduced text (the base advisory at bin/fm-wake-drain.sh printed no command at all), and tests/fm-wake-queue.test.sh:1879 actually executes the extracted string with bash -c, so the suite would execute the mis-split command too. Fix: emit shell-quoted paths, e.g. printf -v clear &#34;rm -rf %q %q&#34; &#34;$ownerdir&#34; &#34;$lockdir&#34;, and update the two advisory assertions (tests/fm-wake-queue.test.sh:1781, tests/fm-wake-drain-unread-status.test.sh:73) to match.
  • ℹ️ bin/fm-wake-lib.sh:520 - fm_lock_owner_gone replaced a fork-free fm_pid_alive (builtin kill -0) inside the hot path of fm_lock_acquire_wait, which polls every 0.1s with no bound. Per poll against a live holder it now forks for $(cat &#34;$lockdir/pid-start&#34;) (line 520), for $(fm_pid_start_token ...) (line 522), and inside that for $(_fm_proc_start_token ...) plus $(cat &#34;$proc_root/$pid/stat&#34;) - roughly 4x the forks per poll on Linux, and on a host with no readable /proc an additional ps exec plus a printf | sed pipeline (two more processes) every 100ms. fm_lock_acquire_wait is still unbounded on the mutation-critical acknowledgement path, so a contended ack can sustain ~60 forks/sec for as long as it waits. The reads are all single-line and can be done with builtins: read -r recorded &lt; &#34;$lockdir/pid-start&#34; in fm_lock_owner_gone and read -r stat_line &lt; &#34;$proc_root/$pid/stat&#34; in _fm_proc_start_token (line 82) remove three of the four Linux forks with no behavior change.
  • ℹ️ bin/fm-wake-lib.sh:513 - The comment above fm_lock_owner_gone states the owner is gone "when the live pid started later than the recorded owner did (pid reuse)", but line 524 is [ &#34;$current&#34; != &#34;$recorded&#34; ] - any difference, in either direction, evicts. That distinction is load-bearing for the safety argument the change rests on, because this file's own comment at line 68 records that the ps -o lstart= fallback's rendered date is not stable ("the wall-clock steps that re-render the ps lstart fallback's date (observed as WSL2 btime drift) and would evict a live watcher"). On a host that takes that fallback, a re-rendered lstart for an unchanged live holder reads as a mismatch and its lock is stolen, whereas an ordering comparison would not. Reachability is narrow in practice (Linux hosts take the /proc branch, and macOS lstart derives from a stored absolute p_starttime rather than boot time), so this is a comment-accuracy issue rather than a demonstrated defect - but state what the code does ("differs from") so the next reader does not rely on an ordering guarantee that is not implemented.

🔧 Fix: shell-quote the advisory clear and drop hot-path forks
3 issues (1 warning, 2 infos) still open:

  • ⚠️ bin/fm-wake-lib.sh:527 - read -r recorded &lt; &#34;$lockdir/pid-start&#34; 2&gt;/dev/null || true does not suppress the failure it is guarding. Bash applies redirections left to right and reports a failed input open on the stderr in effect at that moment, which is still the caller's - the later 2&gt;/dev/null never covers it. Reproduced directly against this worktree: fm_lock_owner_gone on a lock whose owner has a live pid and no pid-start prints bin/fm-wake-lib.sh: line 527: &lt;state&gt;/.l/pid-start: No such file or directory and then returns PRESENT. That is exactly an owner directory written by an older build (docs/watcher-continuity.md:76 documents those as supported and pid-only), plus the handoff window at line 1126, and fm_lock_owner_gone runs on every 0.1s poll of the unbounded fm_lock_acquire_wait, so a contended legacy lock emits ~10 raw bash errors per second into the drain's stderr. tests/fm-wake-queue.test.sh's test_live_presentation_holder_is_deadlined_without_weakening_ack already asserts that channel carries nothing but WAKE_ACK_REQUIRED ("presentation deadline leaked helper-process diagnostics"); it passes only because its holder is a real acquirer that does record a token, and tests/fm-watcher-lock.test.sh:511 (which does stage a tokenless live owner) captures stdout only, so the noise is invisible to the suite. Fix with the brace-group idiom this file already uses at fm_lock_claim line 586: { read -r recorded &lt; &#34;$lockdir/pid-start&#34;; } 2&gt;/dev/null || true. Same defect at line 85 (read -r stat_line &lt; &#34;$proc_root/$pid/stat&#34;, narrower - only a TOCTOU race past the -r guard) and line 512 (printf ... &gt; &#34;$dir/pid-start&#34; 2&gt;/dev/null, when the owner directory is unwritable).
  • ℹ️ bin/fm-wake-lib.sh:528 - Round 4 removed the /proc-path forks but the non-/proc path is untouched, and that is where the cost is highest. On a host with no readable /proc (macOS, which this file supports explicitly via _FM_UNAME/fm_path_mtime), one fm_lock_owner_gone poll costs: the $(fm_pid_start_token ...) subshell at line 528, the $(LC_ALL=C ps ...) subshell plus ps exec at line 119, and the printf | sed pipeline at line 121 - roughly five processes where the base code used the kill -0 builtin and forked nothing. fm_lock_acquire_wait polls every 0.1s with no bound on the mutation-critical acknowledgement path, so a contended ack sustains ~50 processes/sec for the length of the wait. The cheap win with no behavior change is dropping the sed: out=${out#&#34;${out%%[![:space:]]*}&#34;} strips the same leading whitespace with no fork, in fm_pid_start_token (line 121) and identically in fm_pid_identity (line 145).
  • ℹ️ bin/fm-wake-lib.sh:530 - Noting a deferred consequence, not asking for a change now: the author explicitly scoped round 4 to "comment and documentation only; do not change the predicate's logic in this round", and the comment at lines 514-521 is now accurate. The residual is that [ &#34;$current&#34; != &#34;$recorded&#34; ] compares tokens across formats. A token recorded as linux-starttime=N while /proc was readable, recomputed later through the ps fallback (_fm_proc_start_token returns 1 whenever /proc/&lt;pid&gt;/stat or /proc/&lt;pid&gt;/cmdline stops being readable for that pid - hidepid, ProtectProc, a cross-user contender), yields an lstart date string, which differs, so a LIVE holder is evicted. Blast radius includes $STATE/.watch.lock, where fm_lock_try_acquire line 1064 also publishes a false downtime episode on the steal. The base code could never steal a live holder, so this is new asymmetry: a false "present" is harmless, a false "gone" is not. Narrow in practice on same-user Linux and macOS. When it is picked up, the minimal guard is to compare only when both tokens carry the same &lt;key&gt;= prefix and treat a format change as "present".

🔧 Fix: silence guarded reads and refuse cross-format token eviction
3 issues (1 warning, 2 infos) still open:

  • ⚠️ bin/fm-classify-lib.sh:1194 - status_retire_presentation_task traded an unbounded wait for a hard failure, and teardown has no retry to absorb it. Concrete sequence: a watcher drain holds $state/.status-presentation-lock across status_presentation_snapshot + fm_wake_print_annotations + print_status_sections for longer than the 10s default (large fleet, loaded host), a teardown runs concurrently, fm_lock_acquire_wait_bounded returns 124, and bin/fm-teardown.sh:3339 does status_retire_presentation_task &#34;$STATE&#34; &#34;$ID&#34; || exit 1. By that point remove_grok_turnend_auth, remove_kimi_turnend_auth, rm -rf $TASK_TMP, remove_pr_poll_artifacts and retire_busy_state have all already run, so the teardown aborts half-done with the status file and its presentation-cursor row still present. The same applies at fm-teardown.sh:863 and :2933 (|| return 1). The non-124 branch widens it further: any _fm_wake_require_timeout, fm_current_pid, or helper-exec failure returns rc=1 and prints status retire: status presentation lock could not be acquired safely, where the old unbounded fm_lock_acquire_wait would simply have kept trying. The drain's own bound is safe precisely because presentation is retriable on the next drain; a retire is not. Note the start-token reclaim already removes the wedge this bound was added for on every owner directory written by this build - what the bound now catches is a genuinely live holder. Worth confirming the intended semantics: a longer bound for the retire path, or a bounded retry loop, would keep the loud refusal for a truly wedged legacy owner without turning ordinary drain contention into a partial teardown.
  • ℹ️ tests/fm-wake-queue.test.sh:1880 - The "strands nothing" assertion scans every .status-presentation-lock.owner.* under $state, but the drain's own bounded acquire manufactures those names on the same path. With FM_STATUS_PRESENTATION_LOCK_TIMEOUT=1 the helper spun by fm_lock_acquire_wait_bounded polls fm_lock_try_acquire every 0.1s, and fm_lock_try_create (bin/fm-wake-lib.sh:622-626) runs mktemp -d &#34;${lock_abs}.owner.XXXXXX&#34; BEFORE it tests [ -e &#34;$lockdir&#34; ] and discards. fm_run_timed terminates the whole process group at the deadline, and fm_lock_discard_owner reaches the mktemp'd directory through two external commands (rm -f in fm_lock_clean_known_files, then rmdir), so a TERM landing in that window leaks one .status-presentation-lock.owner.XXXXXX that has nothing to do with the printed clear - and find reports it as a stranded owner directory. The window is small next to the 0.1s sleep the helper spends most of its life in, but it is hit on ~10 poll cycles per run and by both test_printed_manual_clear_unwedges_and_strands_nothing and test_printed_manual_clear_is_safe_on_a_home_path_with_a_space. Anchor the check to the directory the fixture actually staged ([ ! -e &#34;$owner&#34; ]), or snapshot the matching directories before bash -c &#34;$clear_cmd&#34; and assert the delta, so the assertion tests the advisory rather than helper cleanup timing.
  • ℹ️ bin/fm-wake-lib.sh:535 - Acknowledging a tradeoff, not asking for a change: round 5 removed the cat and sed forks, but fm_lock_owner_gone still pays two subshells per poll on Linux against a live holder that recorded a token - $(fm_pid_start_token ...) at line 535 and $(_fm_proc_start_token ...) inside it - where the base code used the kill -0 builtin and forked nothing. fm_lock_acquire_wait still polls every 0.1s with no bound on the mutation-critical acknowledgement path, so a contended ack sustains ~20 forks/sec; on a host with no readable /proc it is ~30/sec including the ps exec. That is the cost of the reclaim proof and it is bounded and modest, but it is a real regression from zero, so it is worth having stated rather than rediscovered under load.

🔧 Fix: wait out live presentation holders on the retire path
3 infos still open:

  • ℹ️ bin/fm-wake-lib.sh:622 - fm_lock_try_create runs ownerdir=$(fm_lock_owner_dir &#34;$lockdir&#34;) (mktemp -d) BEFORE it tests [ -e &#34;$lockdir&#34; ], then discards through two external commands (rm -f in fm_lock_clean_known_files, then rmdir). Every fm_lock_acquire_wait_bounded window ends with fm_run_timed TERMing the whole process group while the helper is inside fm_lock_acquire_wait's 0.1s poll, so a TERM landing in that ~3ms exec window strands a state/.status-presentation-lock.owner.XXXXXX directory; grep confirms nothing under bin/ sweeps *.owner.*. The new fm_lock_acquire_wait_retire loop (line 1246) runs up to _FM_LOCK_RETIRE_INTERVALS=30 such kill windows per contended teardown where the base code's unbounded fm_lock_acquire_wait spawned no helper at all, so the expected leak per contended retire goes from 0 to roughly one directory. That this window is real is already conceded by this same fix round: exercise_printed_manual_clear in tests/fm-wake-queue.test.sh:1880 had to stop scanning .owner.* and anchor to the staged directory precisely because the bounded acquire manufactures these orphans. Fix at the shared boundary: test [ -e &#34;$lockdir&#34; ] || [ -L &#34;$lockdir&#34; ] before fm_lock_owner_dir, keeping the existing post-mktemp check for the genuine race.
  • ℹ️ bin/fm-wake-lib.sh:1147 - FM_STATUS_PRESENTATION_LOCK_TIMEOUT is now the unit of two very different budgets: the drain's single bound, and the retire path's _FM_LOCK_RETIRE_INTERVALS x seconds total (300s at the default). Nothing that documents the knob says so - bin/fm-wake-drain.sh:11 still describes it only as "the positive whole-second wait for presentation-path locks (default 10)", and docs/watcher-continuity.md:74 says the retire waits "across many of those bounds" without naming the multiplier or the variable. An operator who sets FM_STATUS_PRESENTATION_LOCK_TIMEOUT=1 to make drains snappy silently cuts a teardown's tolerance for a genuinely live presentation holder from five minutes to thirty seconds, and a teardown that then refuses aborts after remove_grok_turnend_auth, the TASK_TMP removal and retire_busy_state have already run (bin/fm-teardown.sh:3339). State the multiplier where the knob is documented, in the one owner (fm_status_presentation_lock_timeout's comment plus the drain header line it duplicates).
  • ℹ️ bin/fm-wake-lib.sh:540 - Acknowledging the accepted residual, not asking for a change. Round 5 closed the cross-format hole (a format change now reads as PRESENT, covered by test_cross_format_start_token_does_not_evict_a_live_holder), but two tokens in the SAME ps-lstart format that differ only because the date re-rendered still fail [ &#34;$current&#34; != &#34;$recorded&#34; ] and evict a LIVE holder - on $STATE/.watch.lock that also publishes a false downtime episode via fm_lock_try_acquire line 1075. The base code could never steal a live holder, so this direction of asymmetry is new. Reachability is very narrow and the code says so honestly: the comment at line 68 records that the /proc branch exists precisely because lstart re-renders under wall-clock steps, and the hosts that actually take the ps fallback (macOS, whose lstart derives from a stored absolute p_starttime) do not re-render. Worth having stated rather than rediscovered.
⚠️ **Test** - 1 warning
  • ⚠️ tests/fm-wake-queue.test.sh:294 - tests/fm-wake-queue.test.sh:294 test_secondmate_foreign_queue_stall_tracks_progress_and_alerts_once fails on this host ("a foreign queue with no progress did not alert"). It fails IDENTICALLY on the base commit 891dc51 with the same fixture, so it is pre-existing and not a regression from this change - but because the suite exits on first failure, it prevents a plain bin/fm-test-run.sh tests/fm-wake-queue.test.sh from ever reaching the three new status-presentation lock: a dead owner is not reclaimed, so every wake drain blocks until its timeout #3966 cases. I proved those pass by running the suite with only that one case excluded (43 ok, exit 0) and by running the three new cases in isolation. No fix attempted: it is outside this change's scope and touches secondmate wake-stall detection, not the presentation lock.
  • bin/fm-test-run.sh tests/fm-watcher-lock.test.sh tests/fm-wake-queue.test.sh tests/fm-wake-drain-unread-status.test.sh tests/fm-teardown.test.sh (first pass, 4-way bounded concurrency)
  • bin/fm-test-run.sh --jobs 1 tests/fm-watcher-lock.test.sh — 37 ok, exit 0
  • bin/fm-test-run.sh --jobs 1 tests/fm-wake-queue.test.sh — aborts at the pre-existing test_secondmate_foreign_queue_stall_tracks_progress_and_alerts_once
  • tests/fm-wake-queue.test.sh with only that pre-existing case excluded — 43 ok, exit 0
  • New cases in isolation: test_recycled_pid_presentation_lock_does_not_wedge_the_drain, test_printed_manual_clear_unwedges_and_strands_nothing, test_printed_manual_clear_is_safe_on_a_home_path_with_a_space
  • New cases in isolation: test_lock_records_owner_start_and_refuses_that_holder, test_lock_steals_reused_pid_lock, test_handoff_records_the_receiving_caller_start, test_unparseable_proc_entry_fails_instead_of_answering_in_ps_format, test_transient_start_token_failure_does_not_poison_later_locks, test_cross_format_start_token_does_not_evict_a_live_holder, test_lock_does_not_steal_live_lock
  • test_arm_hup_cleans_child_and_temp_output in isolation on BOTH head and base — passes on both, confirming the concurrent-run failure was host load
  • test_secondmate_foreign_queue_stall_tracks_progress_and_alerts_once on base 891dc51 (git archive 891dc51 into a temp tree) — fails identically, confirming pre-existing
  • Manual A/B repro: FM_STATE_OVERRIDE=&lt;state&gt; FM_STATUS_PRESENTATION_LOCK_TIMEOUT=10 bin/fm-wake-drain.sh over a staged .status-presentation-lock symlink whose owner dir records a gone owner on a recycled live pid — base 891dc51 vs head bbd4dcd
  • Manual A/B repro: status_retire_presentation_task &#34;$STATE&#34; held under timeout 45 against the same stranded lock — base spins unbounded, head completes
  • Manual operator remedy: legacy pid-only owner dir, then executing verbatim the rm -rf ... command the drain advisory printed, then re-draining
  • Manual live-holder case: a real fm_lock_acquire_wait holder held for 12s while status_retire_presentation_task ran with FM_STATUS_PRESENTATION_LOCK_TIMEOUT=2
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A stranded status-presentation lock made every wake drain burn its whole
deadline and skip presentation, so queued wakes were re-announced on every
turn with no way to acknowledge them. The recorded owner really was gone -
the operating system had recycled its pid onto an unrelated live process, so
`kill -0` answered forever and the stale-owner steal never fired.

Lock owners now record the acquiring process's start token beside the pid,
and the steal treats an owner as gone when the pid is dead or when the live
pid started later than the recorded owner did. The recorded fact is the start
token rather than the full process identity because a holder may legally
replace its own image while holding - bash execs the last command of a
subshell, so an ordinary `( take the lock; run one thing ) &` holder does
exactly that - and only the start time proves reuse.

`fm_pid_identity`'s recorded string is unchanged, so a watcher lock or
auto-arm claim written by a running older build still verifies. An owner
directory with no recorded start token keeps the weaker pid-only proof, which
is the behavior it had before.

The drain's existing bounded-wait advisory now also names the manual clear
operators were left to work out themselves.
@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with no new actionable issue beyond the owner-directory leak already raised in an existing review thread.

Token comparison fails closed when identity evidence is absent or incomparable, teardown refusal retains the durable task record for retry, and the remaining concrete cleanup concern is already under review.

Reviews (1): Last reviewed commit: "no-mistakes(document): document shared p..." | Re-trigger Greptile

mremond added a commit to mremond/firstmate that referenced this pull request Sep 25, 2026
… work is spent

Refs kunchenguid#4018

Limits, stated as limits:
- It closes nothing. Every forge call is a read, including in the opt-in
  --sweep mode: no issue is closed, labelled, or commented on, and no backlog
  is read or written. It is the evidence half of the claim problem, not the
  loop closure the triage also leaves open.
- A fix that cites the issue number nowhere - no PR body, branch, or title,
  no commit message, and no --symbol the caller supplies - stays invisible to
  every check.

bin/fm-issue-claim.sh runs five read-only checks per issue and prints an
inspectable verdict (open, claimed, partially-covered, fixed-on-main, or
unknown): timeline cross-references, maintainer triage stamps (OWNER, MEMBER,
or COLLABORATOR only; the existing-pr target PR is read for its current
state), the complete open-PR corpus fetched by paginated REST and checked
against the search API total, the issue author's fork branches (resolved to
the PR each heads), and main history since the issue opened (commit messages
citing the issue, plus optional caller --symbol pickaxe searches). Issue
numbers match only as whole numbers, so 4018 never matches 40181, and a
foreign owner/repo#N is not a citation. A failed or rate-limited read, a
short or unverified corpus, or a history ref that cannot be searched yields
unknown or an explicit disclosure, never open. One corpus is shared across
every issue in a run and can be saved and reused across runs with its
completeness verdict and age.

--sweep is opt-in and report-only: one disposition line per issue
(close-candidate, leave-open, no-action, undetermined) with link candidates,
judged only from durable evidence and never from titles, branches, PR checks,
reviews, or mergeability. An issue with a live PR stamped existing-pr is
always leave-open, and merged evidence with incomplete coverage is
undetermined rather than a close candidate.

Live proof against kunchenguid/firstmate, 2026-09-23, history ref
origin/main@9296f9b9, open-PR corpus 1261/1261:
- kunchenguid#4927 claimed, reproduced: PR kunchenguid#4943 and PR kunchenguid#4955 (timeline, corpus, fork,
  and the maintainer existing-pr stamp on kunchenguid#4955), plus kunchenguid#4026 named by the
  earlier stamp and still open.
- kunchenguid#3370 fixed-on-main, reproduced: commit baede47 (kunchenguid#4656), found only by
  the history check with --symbol 3370:rerecord_device, issue still open.
- kunchenguid#4412 partially-covered, reproduced: PR kunchenguid#4775 merged (landed as 9bc051f)
  and PR kunchenguid#4832 open.
- kunchenguid#4466 open, reproduced, with every check complete.
- Reporter's cases in one --sweep: kunchenguid#3966 claimed by PR kunchenguid#3977 and kunchenguid#3942
  claimed by PR kunchenguid#3978 (leave-open); kunchenguid#3928 (PR kunchenguid#3946) and kunchenguid#3926 (PR kunchenguid#3944)
  show fixed-on-main and have since been closed on the forge (no-action).
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: a quick overlap note for you, @eduardstan. #7886 (for #7885) just merged as 417cec2f. It makes the generic lock in bin/fm-wake-lib.sh record the holder's start time in a pid-start file, and it treats a live pid with a mismatched start time as stale in fm_lock_try_acquire and fm_lock_recheck_stale_owner. That covers the recycled-pid part of what this PR does, using a different record shape from your start token.

The rest of this PR (the status-presentation and drain handling for #3966, and the teardown changes) isn't covered by #7886. If you pick this back up, building on current main and dropping the parts #7886 now handles would make it a smaller review. Any merge conflict is ours to deal with, so you don't need to rebase for that. I'm not closing or changing anything here. This note is only so the overlap is on record in both places.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants