Repository navigation
fix(watcher): bound parked-crew stale wakes, harden watcher identity, and clean up review-diff refs - #9
fix(watcher): bound parked-crew stale wakes, harden watcher identity, and clean up review-diff refs#9SchokoShake wants to merge 5 commits into
Conversation
* fix(watcher): bound stale wakes for exited paused crew * no-mistakes(review): Gate pause suppression on confirmed agent death * no-mistakes(test): Fixed stale pause cadence * no-mistakes(document): Document dead-agent hold cadence
…anges (kunchenguid#752) * fix(watcher): stabilize Linux process identity * no-mistakes(document): document FM_PROC_ROOT_OVERRIDE and Linux starttime identity rationale
* fix: always fetch PR head for review diffs Prefer a freshly fetched refs/pull/<n>/head over a reachable recorded pr_head= so reviewers never hold a merge over a "missing" fix that already landed on the remote PR. Recorded SHA is offline fallback only; local branch is last resort with a warning. Store the tip under refs/fm-review/ so a later base-branch fetch cannot clobber the compare tip via FETCH_HEAD. * no-mistakes(test): Isolate session-start nudge tests from gate state * no-mistakes(document): Correct review-diff documentation
… on this fork The cherry-picked kunchenguid#743 (bound stale wakes for parked crew) reads FM_CLASSIFY_CAPTAIN_HELD_VERB_DEFAULT, a constant upstream introduced in its decision-hold work (kunchenguid#593) that this fork does not carry. Add only that one constant ('captain-held', upstream's value) rather than importing the subsystem. This fork surfaces captain-held state from the backlog hold via logbook, not a status-file verb, so status_is_paused_or_captain_held's held branch is inert today but forward-compatible; the dead-agent-gated pause fix stays fully active. Also align AGENTS.md's fm-review-diff description with the picked kunchenguid#722: the helper now always fetches refs/pull/<n>/head fresh, with recorded pr_head= as an offline-only fallback.
SchokoShake
left a comment
There was a problem hiding this comment.
Reviewed with Lookout.
| # FM_CLASSIFY_CAPTAIN_HELD_VERB. This fleet surfaces captain-held state from the | ||
| # backlog hold via logbook rather than a status-file verb, so the check's | ||
| # captain-held branch is inert today but stays forward-compatible. | ||
| FM_CLASSIFY_CAPTAIN_HELD_VERB_DEFAULT='captain-held' |
There was a problem hiding this comment.
captain-held is wired end-to-end here (verb + classifier + watcher branch + tests), but per your own note nothing in this fleet actually writes a captain-held: status today — the branch is inert / forward-compatible. Flagging it for an explicit merge decision: ship the speculative path now, or hold it until the logbook→status-verb source exists? No change requested if the forward-compat is deliberate.
There was a problem hiding this comment.
Keeping it as-is — this is deliberate forward-compat, per your "no change requested if the forward-compat is deliberate."
The captain-held verb is faithful to upstream kunchenguid#743 on this fork. This fleet surfaces captain-held state through the logbook/backlog hold rather than a status-file verb, so the status_is_paused_or_captain_held captain-held branch is inert today, but the verb + classifier + watcher branch + tests are wired end-to-end so a future logbook→status-verb source works without a follow-up change. No code change.
| esac | ||
| cmdline_hex=$(od -An -v -tx1 "$proc_root/$pid/cmdline" 2>/dev/null | tr -d '[:space:]') || return 1 | ||
| [ -n "$cmdline_hex" ] || return 1 | ||
| printf 'linux-starttime=%s cmdline-hex=%s\n' "$starttime" "$cmdline_hex" |
There was a problem hiding this comment.
Two things worth confirming on the new identity format:
- Upgrade transition: the string shape flips from the
ps lstartform tolinux-starttime=… cmdline-hex=…. A watcher that recorded its identity before this lands is re-read in the new form afterward, so it mismatches and is evicted/reclaimed once across the upgrade. Fine if a one-time re-arm is acceptable. - Partial /proc read: if
stat/cmdlineare readable but parsing fails (a zombie's empty cmdline, a short stat line), the functionreturn 1s instead of falling back tops. Confirm the lock-reclaim path treats an empty identity as 'reclaim', not 'error'.
There was a problem hiding this comment.
Both confirmed in 6025f7d — comments only, no behavior change.
Upgrade transition: correct as you describe. A watcher whose identity was recorded in the old ps lstart form mismatches exactly once when re-read in the new linux-starttime=… cmdline-hex=… form, so it is reclaimed and re-armed a single time across the upgrade — benign and self-healing. Documented at the top of fm_pid_identity.
Partial /proc read: traced the callers, and the failed read resolves to reclaim, not error, everywhere it matters. When stat/cmdline are readable but parsing fails (short stat line, zombie's empty cmdline), fm_pid_identity returns non-zero without a ps fallback — as you noted. Its lock-path caller fm_watcher_lock_matches_pid does current_identity=$(fm_pid_identity "$pid") || return 1, i.e. no match, and every consumer maps no-match to "not healthy → reclaim": fm_watcher_healthy returns non-zero, and fm-watch-arm.sh then re-arms (its arm path skips attach and starts a fresh watcher; its --restart path clears the lock via clear_stale_recorded_watcher_lock). None treats it as a hard error, so a failed identity read always biases toward reclaim — never toward wrongly keeping a live holder or retaining a dead one.
Since that is the intended fail-safe, I documented it in fm_watcher_lock_matches_pid (no code change) and added a regression test, test_partial_proc_identity_read_resolves_to_reclaim: it points FM_PROC_ROOT_OVERRIDE at a fake /proc with a too-short stat for a genuinely live pid, then asserts fm_pid_identity fails and both fm_watcher_lock_matches_pid and fm_watcher_healthy report reclaim (not healthy).
| # Fetch into a private ref so a later base-branch fetch cannot clobber the | ||
| # compare tip via FETCH_HEAD, and so we never review a stale local object. | ||
| git -C "$WT" fetch --quiet origin \ | ||
| "+refs/pull/$n/head:refs/fm-review/pull/$n/head" >/dev/null 2>&1 || return 1 |
There was a problem hiding this comment.
The PR head is fetched into a persistent private ref refs/fm-review/pull/<n>/head that nothing ever prunes. In a long-lived pooled clone that reviews many PRs over time, these accumulate (one per distinct PR number). Functionally harmless — the + force-update keeps re-review correct — but consider deleting the ref after the rev-parse, or documenting a periodic cleanup, to avoid unbounded ref growth.
There was a problem hiding this comment.
Fixed in 6025f7d. fetch_pull_head now captures the resolved SHA and then deletes the private ref (git -C "$WT" update-ref -d refs/fm-review/pull/<n>/head) immediately after the rev-parse, including on a parse failure. Nothing lingers, so the one-ref-per-distinct-PR-number growth in a long-lived pooled clone is gone.
Behavior is otherwise identical: the resolved SHA keeps the fetched object reachable for the rest of the (short-lived) run — well inside any gc prune window — so the diff base and re-review correctness are unchanged. Added a regression test, test_pr_head_fetch_leaves_no_lingering_ref, which fetches a PR head and asserts the diff still resolves +pr-fixed with no remaining refs/fm-review/* ref.
Address PR #9 review. fm-review-diff.sh: fetch_pull_head fetched refs/pull/<n>/head into a persistent refs/fm-review/pull/<n>/head that nothing pruned, so a long-lived pooled clone accumulated one ref per distinct PR number over time. The ref was only ever a clobber-proof fetch target; capture the resolved SHA (which keeps the fetched object reachable for the rest of the short-lived run) and delete the ref immediately, even on a parse failure. Diff base and re-review behavior are unchanged. Add a regression test asserting no refs/fm-review ref lingers after a review. fm-wake-lib.sh: document, with no behavior change, that (a) changing the process-identity string shape re-arms a pre-upgrade watcher exactly once (benign and self-healing), and (b) an empty or failed identity read deliberately resolves to no-match -> reclaim in every caller, never a hard error, so a partial /proc read biases toward reclaim. Add a regression test proving a partial /proc read on a live watcher reads as reclaim, not a wrongly-kept holder.
|
Closing per captain decision. Superseded by the logbook v2 de-fork plan (2026-08-05). P1 rebuilds fork Not lost: these fixes arrive with the upstream merge at P1. |
Intent
Integrate three surgical upstream firstmate bug-fix commits (upstream PR kunchenguid#743 bound stale wakes for parked crew, kunchenguid#752 make watcher process identity immune to Linux wall-clock changes, kunchenguid#722 fetch current PR head for review diffs) into this fork as PR #9. This round is a review-response commit on top of the existing branch that addresses the captain's three inline review comments on that PR; it is not a new feature.
bin/fm-review-diff.sh (the one behavioral fix): fetch_pull_head previously fetched refs/pull//head into a persistent private ref refs/fm-review/pull//head that nothing ever pruned, so a long-lived pooled clone accumulated one such ref per distinct PR number over time. The private ref only ever served as a clobber-proof fetch target; the resolved SHA is what the rest of the short-lived run actually uses. Fix: capture the SHA, then delete the private ref immediately (even on a parse failure). Diff-base selection and re-review correctness are deliberately unchanged; the only change is that no ref lingers. A new regression test asserts no refs/fm-review ref remains after a review.
bin/fm-wake-lib.sh (documentation only, NO behavior change): two clarifying comments the captain asked to confirm. (a) The process-identity string shape changed from the ps-lstart form to the linux-starttime/cmdline-hex form; a watcher whose identity was recorded before the upgrade mismatches exactly once and is re-armed a single time, which is a benign, self-healing one-time re-arm, now documented in a comment. (b) I traced fm_pid_identity's lock-path callers and confirmed that an empty stored identity, or a failed live read (a partial /proc read such as a zombie's empty cmdline or a short stat line, where fm_pid_identity returns non-zero WITHOUT a ps fallback), deliberately resolves to no-match in fm_watcher_lock_matches_pid, which every caller (fm_watcher_healthy, and fm-watch-arm.sh's healthy and --restart paths) maps to "not healthy -> reclaim", never a hard error. That is correct fail-safe behavior, so it is documented with a comment and no code change. A new regression test proves a partial /proc read on a live watcher reads as reclaim, not a wrongly-kept holder.
bin/fm-classify-lib.sh captain-held verb: DELIBERATELY KEPT with no change. The captain asked whether to ship the speculative forward-compat path now or hold it, and said no change is requested if the forward-compat is deliberate. It is deliberate and faithful to upstream fix(watcher): bound stale wakes for parked crew kunchenguid/firstmate#743 on this fork: this fleet surfaces captain-held state via the logbook/backlog hold rather than a status-file verb, so the FM_CLASSIFY_CAPTAIN_HELD_VERB branch is inert on this fleet today but is wired end-to-end for forward-compatibility. Do not flag it as dead code; keeping it is the captain's explicit decision.
Constraints: this repository has no GitHub CI, so "no CI checks reported" means review-ready, never "CI green". The commit uses the captain's own git identity and adds no agent co-author.
What Changed
fm-watch.sh(with the keyed contract infm-classify-lib.shandfm-wake-lib.sh) on harness-agent liveness so a declaredpaused:crew surfaces once and then rides a bounded resurface cadence instead of waking on every idle poll; a live-agent declared pause now costs one extra surface, documented indocs/architecture.mdand covered by the new triage tests./procstarttime/cmdline instead of theps -lstartwall-clock form so a system clock change no longer invalidates the recorded watcher lock, and documented that a partial/procread or a stale pre-upgrade identity resolves to reclaim (a single benign self-healing re-arm) rather than a wrongly-kept holder.fm-review-diff.shto fetch the currentrefs/pull/<n>/headas the diff base and delete the private fetch ref immediately after reading its SHA (even on parse failure), so a long-lived pooled clone no longer accumulates one lingeringrefs/fm-reviewref per reviewed PR.Risk Assessment
✅ Low: Three surgical, well-bounded bug fixes each backed by a targeted regression test, with the only behavioral shift (a live paused crew surfacing once) being explicitly documented and test-locked as intended.
Testing
Baseline suite already passed; on top of that I ran the three directly-relevant test files (fm-review-diff, fm-watcher-lock, fm-watch-triage), all green, then proved the sole behavioral fix at product level with a before/after CLI transcript showing the pre-fix code leaking one refs/fm-review ref per distinct PR reviewed into a long-lived pooled clone (3 accumulated) while the fixed code leaves zero and still resolves the correct PR-head diff each time; I also confirmed the deliberately-kept captain-held verb is wired end-to-end rather than dead code. No visual/UI artifact applies because this change is entirely a shell CLI/library fix with no rendered surface. Working tree left clean; transient scenario dirs removed, evidence preserved.
Evidence: Before/after end-to-end ref-leak demonstration (CLI transcript)
# BEFORE THE FIX (parent commit 2306cd2 — leaks one ref/PR) Simulating a long-lived pooled clone reviewing PRs #9, #42, #7 over time: review PR #9 -> diff shows: +fix-for-pr-9 | refs/fm-review count now: 1 review PR #42 -> diff shows: +fix-for-pr-42 | refs/fm-review count now: 2 review PR #7 -> diff shows: +fix-for-pr-7 | refs/fm-review count now: 3 Leftover private refs in the pooled clone after 3 reviews: refs/fm-review/pull/42/head -> 9456ab5 refs/fm-review/pull/7/head -> 213b9d8 refs/fm-review/pull/9/head -> 96c4771 # AFTER THE FIX (target commit 6025f7d — deletes the ref) Same scenario, same pooled clone reviewing PRs #9, #42, #7 over time: review PR #9 -> diff shows: +fix-for-pr-9 | refs/fm-review count now: 0 review PR #42 -> diff shows: +fix-for-pr-42 | refs/fm-review count now: 0 review PR #7 -> diff shows: +fix-for-pr-7 | refs/fm-review count now: 0 Leftover private refs in the pooled clone after 3 reviews: (none — refs/fm-review is empty; nothing leaked)Evidence: Reproducible demo script
Evidence: Combined regression-test transcript (both new tests)
ok - fm-review-diff deletes the private PR-head ref after reading its SHA ok - a partial /proc identity read resolves to reclaim, never a wrongly-kept live holderPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-watch.sh:383- Behavioral change (intended, documented): as a side effect of the fix(watcher): bound stale wakes for parked crew kunchenguid/firstmate#743 agent-liveness gating in pause_state_class, an ordinary crew that declarespaused:while its harness agent is still ALIVE (the common case — claude/grok/etc. stay running between turns, so fm_backend_tmux_agent_alive reportsalive) is now classifiednoneand surfaced once by surface_nonterminal_stale on the first stale poll, then absorbed onto the bounded PAUSE_RESURFACE_SECS cadence. Previously (crew_absorb_class returnedpaused) that first idle was absorbed silently with zero wakes. The existing test test_nonterminal_stale_paused_absorbed_then_resurfaced had to add FM_FAKE_TMUX_CURRENT_COMMAND=zsh (forcing a dead-agent read) to keep its silent-absorb assertion passing, which confirms the live-agent path now surfaces once. This is documented in docs/architecture.md ('Live or inconclusive liveness remains fail-open at that initial surface') and asserted by test_exited_declared_pause_is_bounded_but_live_gate_surfaces, so it is deliberate — flagged only so the captain confirms the one-extra-wake-per-declared-pause tradeoff is acceptable for the paused noise-reduction feature.✅ **Test** - passed
✅ No issues found.
command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"bash tests/fm-review-diff.test.sh— all 6 pass, incl. newfm-review-diff deletes the private PR-head ref after reading its SHAbash tests/fm-watcher-lock.test.sh— all pass, incl. newa partial /proc identity read resolves to reclaim, never a wrongly-kept live holderbash tests/fm-watch-triage.test.sh— all pass (covers the #743 bound-stale-wakes and captain-verb classification paths)End-to-end before/after demoref-leak-e2e.sh: reviewed PRs #9, #42, #7 in one pooled clone with the parent (leaking) vs target (fixed) fm-review-diff.sh; parent leaked 3 refs, target leaked 0 while each diff still showed the fetched PR headgrep FM_CLASSIFY_CAPTAIN_HELD_VERB bin/fm-classify-lib.sh— confirmed the verb constant is defined and consumed by status_is_paused_or_captain_held (wired, not dead)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.