Skip to content

fix(bin): reclaim reused-pid locks and fix crew-state, OPEN DECISIONS and remote second-mate bugs - #260

Merged
sKeLe100 merged 7 commits into
mainfrom
fm/pick-clean-bundle
Nov 14, 2026
Merged

sKeLe100 merged 7 commits into
mainfrom
fm/pick-clean-bundle

Conversation

@sKeLe100

@sKeLe100 sKeLe100 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Intent

Upstream pick 2 of 4 the captain approved ("Send all four"): the clean six-commit bundle - lock reclaim after pid reuse, two crew-state truth fixes, the OPEN DECISIONS key fix and two remote second-mate fixes.

What Changed

  • Wake/watcher lock handling (bin/fm-wake-lib.sh, bin/fm-wake-drain.sh) now reclaims locks whose recorded pid has been reused by an unrelated process. bin/fm-crew-state.sh gets two crew-state truth fixes, covered by expanded tests/fm-crew-state.test.sh and a new case in tests/fm-watcher-lock.test.sh.
  • bin/fm-send.sh fixes the OPEN DECISIONS key handling: it names the closing key and keeps the message when --resolve-key refuses. New coverage is in tests/fm-send-resolve-key.test.sh.
  • Remote second-mate fixes in bin/fm-remote-job-lib.sh, bin/fm-remote-job-worker.sh, bin/fm-remote-secondmate-control.sh, bin/fm-nm-run-lib.sh and bin/fm-on.sh. Remote second-mate steers are now sent over stdin and the login identity is preserved in remote job environments. The related tests and docs (docs/architecture.md, docs/configuration.md, docs/remote-secondmates.md) are updated.

Risk Assessment

✅ Low: The change is a bounded bundle of six upstream fixes. I traced the lock start-time check, the crew-state run attribution, the OPEN DECISIONS key and the send-stdin path, and found no concrete defect. I did not read the test files or the docs in detail.

Testing

The baseline configured command passed. I then ran the eight test scripts covering each fix directly (lock reclaim after pid reuse, crew-state daemon status and newest-run attribution, OPEN DECISIONS closing key and --resolve-key refusal, remote second-mate stdin steers and login identity). All exited 0. These tests execute the real scripts in disposable homes; there is no separate UI surface. A harmless 'rm: Permission denied' cleanup message appeared in the restart test output. No source changes were made. The exit-144 background notification was my own waiter loop, which I killed.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Lock reclaim after pid reuse: real watcher-lock scripts reclaim a lock whose dead holder's pid was reused ✅ pass live bash tests/fm-watcher-lock.test.sh exit 0
Crew-state truth: daemon requires positive running status; newest run attribution kept; conflicting legacy records report unknown ✅ pass live bash tests/fm-crew-state.test.sh exit 0
OPEN DECISIONS closing key named and --resolve-key refusal keeps the message ✅ pass live bash tests/fm-send-resolve-key.test.sh exit 0
Remote second-mate steers go over stdin and login identity is preserved in remote job env ✅ pass live fm-send-remote-delivery, fm-remote-job, fm-secondmate-restart, fm-wake-queue, fm-classify-corr-token tests all exit 0

Notes for reviewers

  • Remote steering protocol changes in this bundle. Remote second-mate steers now go over stdin in a versioned protocol (the "send remote second mate steers over stdin" commit). PC02's code root must update in step with this change; firstmate handles that after merge.
  • Live validation wording. An earlier run on this branch reported live validation as inconclusive (0 of 4 scenarios driven live). A human decision accepted that verdict as-is. The final run's "live" column above rests on the suite runs listed under Test, not on a separate live harness driving the product.
  • Upstream commits not in this PR. Other commits from the upstream triage are out of scope here; the full upstream sync runs separately on its own branch.

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Lock reclaim after pid reuse: real watcher-lock scripts reclaim a lock whose dead holder's pid was reused ✅ pass live bash tests/fm-watcher-lock.test.sh exit 0
Crew-state truth: daemon requires positive running status; newest run attribution kept; conflicting legacy records report unknown ✅ pass live bash tests/fm-crew-state.test.sh exit 0
OPEN DECISIONS closing key named and --resolve-key refusal keeps the message ✅ pass live bash tests/fm-send-resolve-key.test.sh exit 0
Remote second-mate steers go over stdin and login identity is preserved in remote job env ✅ pass live fm-send-remote-delivery, fm-remote-job, fm-secondmate-restart, fm-wake-queue, fm-classify-corr-token tests all exit 0
  • bin/fm-test-run.sh --changed --exclude-family real-herdr-gated --exclude-quarantined --pc02-if-idle
  • bash tests/fm-watcher-lock.test.sh
  • bash tests/fm-crew-state.test.sh
  • bash tests/fm-send-resolve-key.test.sh
  • bash tests/fm-send-remote-delivery.test.sh
  • bash tests/fm-remote-job.test.sh
  • bash tests/fm-secondmate-restart.test.sh
  • bash tests/fm-wake-queue.test.sh
  • bash tests/fm-classify-corr-token.test.sh
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

zestysoft and others added 6 commits November 13, 2026 20:57
* fix(bin): reclaim a lock whose dead holder's pid was reused

The generic lock in fm-wake-lib.sh judged a record stale only by asking
whether its pid was alive. Once the holder died and the kernel handed that
pid to an unrelated process, the lock read as held forever and every
acquirer spun and gave up - each watcher re-arm paid for it while trying
to append to the cycle ledger.

Acquisition now records the holder's start time beside its pid, and a
record whose live pid no longer has that start time is stale, so the
ordinary stale-owner takeover reclaims it and reports the pid it took over.
Start time alone is the key because a holder may exec another program,
which keeps its pid and start time but replaces its command line. A record
without a start time, or a pid whose start time cannot be read, keeps the
old pid-liveness answer. The bounded wait's handoff drops the helper's
start time before the pid changes hands and records the caller's after.

Refs #7885

* no-mistakes(document): Note reused-pid lock staleness in FM_LOCK_STALE_AFTER

(cherry picked from commit 417cec2)
* fix: prefer current run over stale overview row

* fix: preserve newest run precedence over stale status

* no-mistakes(document): Document live-run precedence in crew-state attribution

* fix: use ledger order for same-minute run precedence

* test: cover both overview orders for same-minute run attribution

Document and pin newer-first (recorded AXI) and historical-first overview
orders. Same-minute ledger timestamps use row order as the tie-break so an
older live bare status cannot hide a newer completed run.

* no-mistakes(review): Treat failed as overridable terminal overview status

* no-mistakes(review): Fix equal-head live run precedence with identity ordering

* no-mistakes(document): Updated run identity ordering documentation

* no-mistakes(lint): Fix ShellCheck export warning

* no-mistakes(review): Prove same-head ordering or report unknown

* no-mistakes(review): Guard failed selected-run reads and drop dead same-head ordering

* no-mistakes(ci): I fixed both Greptile findings (ci-1, ci-2) in bin/fm-crew-state.sh. The change is in the working tree. I did not commit it, push it, or reply to the Greptile threads, because those steps belong to the outer pipeline. ci-1. Invariant: a live run from bare `axi status` may replace a terminal overview selection only when it is proven newer than every other run on the same branch. Previously the code compared it only against the selected run. Now crew-state reads each other candidate with `axi status --run <id>` and compares the live run against each one: - If another candidate is also live, it reports `unknown`, "competing live runs". This keeps the competing-live-runs check. - If two runs share a head and a ULID timestamp, it reports `unknown`, "same-head run ordering unverified", as before. - It promotes the live run only when it is proven newer than all other candidates. - If the live run is newer than the selected run but not proven newer than some other candidate, it reports `unknown`, "run ordering unverified", and names every run id. This means neither the stale selected run nor the live run can hide a newer failed run. This branch is the one judgement call: without it, the stale "done" row A would still hide C's failure. - In all other cases the overview's selection stands. The lib helper is now a pairwise compare called `fm_nm_run_is_newer_than` (it was `fm_nm_run_is_newer_than_selected`). The selected run's detail from the loop is reused when the read succeeded, as in the round-1 fix. I updated the sentence in docs/architecture.md to match. ci-2. Invariant: the `no-mistakes runs` ledger is read only to order runs with different heads. It is now fetched lazily, at most once, and only when a candidate's head differs from the live run's head. Same-head ULID comparisons never call it. Regression test: `test_live_run_newer_than_selection_does_not_hide_newer_failed_run` covers A (stale completed, listed first), C (newer failed) and B (live, created between them). All three share one head and use ULID ids. It expects `state: unknown`, C's id in the output, and no `state: working`. Before the fix it fails: with the fixed code stashed it printed `state: working ... run: 01M1...` (run B). On the original base 3fbace9 the overview would select A, so the output would be `done`, which also fails the `unknown` check. I did not run that base case. Verification: `bash tests/fm-crew-state.test.sh` passes in full ("all fm-crew-state tests passed", the new test included). `shellcheck` on the three changed shell files reports only the existing info-level SC1091 "not following sourced file" notes. No end-to-end run against a live no-mistakes daemon was possible here. I checked the change with the crew-state test harness and its fake `no-mistakes` CLI

---------

Co-authored-by: mehulbhagwani <[email protected]>
Co-authored-by: Pitch Perfekt Collective <[email protected]>
(cherry picked from commit 7bbf71b)
… --resolve-key refuses (#3983)

* fix(supervision): make the OPEN DECISIONS listing name the key that closes it

An operator answering a listed decision runs the command the listing itself
advises, and that command refused - discarding the steer with it.

The two folds never disagreed. Both the whole-file fold and fm-send's resolver
read the same status_open_decisions rule, and both correctly keyed
`blocked: axi run hung ... [key=no-mistakes-start]` as `default`: the key
grammar states a key before the colon or at the head of the note, so a token
trailing a summary is prose. The reader that was wrong is the third one, the
drain's OPEN DECISIONS renderer. It suppressed `[key=default]` and printed the
note verbatim, so the only bracket token a reader could see on such an entry
was the one that is NOT the key - and the entry named a key it had not folded.

Every entry now states its folded key, `default` included, so the key the
listing shows is the key its advised command closes.

An unresolvable key still refuses rather than delivering: an answer this send
cannot close would leave the decision open behind an answer the operator
believes settled it. The refusal no longer costs the message instead - it
diagnoses a key that is only mentioned inside an open decision's note, names
the keys that are actually open, and prints the resend commands with the
message quoted back verbatim.

* no-mistakes(review): Remove automatic key selection from resend advice

* no-mistakes(document): Clarify operator key selection in resend documentation

* fix(send): carry the caller's routing context into every printed resend

A refused --resolve-key preserves the operator's message by printing a
resend command, but the command could not run: it reused $0 and dropped
the routing environment. A one-shot "FM_HOME=<home> bin/fm-send.sh ..."
exports nothing to the next command, and a relative $0 is valid only from
the directory that invocation ran in, so a copied line resolved to another
home's state, to no script at all, or refused with FM_HOME unset - and the
preserved message still never reached the worker.

The unconfirmed-remote retry path already solved this. Both printed resend
paths now share that one statement of it: the absolute home always, the
state override only when this invocation was given one, and this script's
absolute path.

Covered by a test that invokes fm-send through a relative path with a
one-shot FM_HOME, then runs what it printed from a different directory
with nothing supplied - what an operator copying the line actually does.

* no-mistakes(review): remove unprovable decoy-key diagnosis, quote resend key placeholder

* no-mistakes(review): scope empty open-set claim to status file, always offer keyed resend

* no-mistakes(review): Keep already-accepted keys in the refused-key resend

* no-mistakes(review): Check every resolve key before refusing, keep order

* no-mistakes(document): Reflow fm-send resolve-key refusal header comment

(cherry picked from commit 2118038)
* fix: send remote steers over stdin

* fix: version remote stdin send protocol

* no-mistakes(document): document stdin transport for remote steer in fm-send header

* no-mistakes(ci): Two tests failed in CI. One is caused by this PR; the other is not. 1. Behavior portable serial 5: `tests/fm-secondmate-reconcile.test.sh` failed with "supervision did not deliver the durable reconcile request later". This PR caused it. The PR now sends a remote steer's body on stdin, using `fm-on.sh --stdin` with the `send-stdin` verb. This test's fake ssh started with `cat > /dev/null`, so it threw the body away before it ran the real `fm-remote-secondmate-control.sh`. `cmd_send_stdin` then read an empty message, died with "remote steer message must be nonempty", and no inbox record was written. Rule that broke: a fake ssh that runs the real remote leg must pass the caller's stdin through, as real ssh does. I checked every fake ssh that runs the real leg. `fm-send-remote-delivery.test.sh` already passes stdin through. `fm-secondmate-sync.test.sh` (`make_remote_leg_ssh_stub`) had the same discard line. The stub in `fm-send-resolve-key.test.sh` never runs the leg, so it is fine. The fix deletes the `cat > /dev/null` line in the reconcile and sync stubs. Calls made without `--stdin` still get /dev/null from fm-on, so nothing else changes. Checks run locally: the reconcile test fails before the fix with the same CI message. After the fix, the reconcile test passes (rc=0) and the sync test passes (rc=0). 2. Behavior portable serial 3: `tests/fm-wake-queue.test.sh` failed in `test_concurrent_append_and_drain` with "wake drain: queue lock could not be acquired safely". This PR did not cause it. The PR does not touch `bin/fm-wake-drain.sh`, the wake tests or the wake helpers. The failure is lock contention: 40 appenders run at the same time as a drain, on a loaded CI runner. Locally the whole test passed (70 ok, rc=0). I made no change for it. It is an existing flake in wake-queue lock acquisition and needs its own fix outside this PR. Open PR #7912 ("preserve wake grants when queue-lock acquisition fails") works in the same area

(cherry picked from commit 4415321)
* fix(remote-job): pass USER and LOGNAME to the remote job child

* no-mistakes(document): Spresniť dokumentáciu prostredia pracovníka

* test(remote-job): run the identity-unset fixture in its own process for clean lint

* no-mistakes(document): Spresniť odkazy na kontrakt prostredia

(cherry picked from commit 07409e7)
@sKeLe100
sKeLe100 force-pushed the fm/pick-clean-bundle branch from 9e3b1fc to d1275bd Compare November 14, 2026 02:50
@sKeLe100
sKeLe100 merged commit 3a2bad9 into main Nov 14, 2026
25 checks passed
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.

6 participants