Repository navigation
fix(bin): reclaim reused-pid locks and fix crew-state, OPEN DECISIONS and remote second-mate bugs - #260
Merged
Conversation
* 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)
(cherry picked from commit 8ba34f1)
* 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
force-pushed
the
fm/pick-clean-bundle
branch
from
November 14, 2026 02:50
9e3b1fc to
d1275bd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.shgets two crew-state truth fixes, covered by expandedtests/fm-crew-state.test.shand a new case intests/fm-watcher-lock.test.sh.bin/fm-send.shfixes the OPEN DECISIONS key handling: it names the closing key and keeps the message when--resolve-keyrefuses. New coverage is intests/fm-send-resolve-key.test.sh.bin/fm-remote-job-lib.sh,bin/fm-remote-job-worker.sh,bin/fm-remote-secondmate-control.sh,bin/fm-nm-run-lib.shandbin/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.
Notes for reviewers
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.
bin/fm-test-run.sh --changed --exclude-family real-herdr-gated --exclude-quarantined --pc02-if-idlebash tests/fm-watcher-lock.test.shbash tests/fm-crew-state.test.shbash tests/fm-send-resolve-key.test.shbash tests/fm-send-remote-delivery.test.shbash tests/fm-remote-job.test.shbash tests/fm-secondmate-restart.test.shbash tests/fm-wake-queue.test.shbash tests/fm-classify-corr-token.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.