Repository navigation
fix(bin): keep armed merge polls and status cursors valid across remounts and respawns - #8150
AgardnerAU wants to merge 7 commits into
Conversation
…nd relaunches A merge poll registration recorded each file as device:inode, and APFS renumbers the device at every reboot, so every armed poll failed validation at once. Recorded identities now match by inode, with the file proven live on the state directory's own filesystem first. This replaces the watcher's locked re-record step, which is no longer needed, and also covers pending retirement receipts. The status presentation cursor, the open-decisions cursor, the seen markers, and the home-append ledger compared status file identities including the device, so a reboot replayed every task's whole history. Every status identity comparison now goes through one device-blind helper, mirrored in the Pi branch dispatcher. The custom check trust binding records only a content hash and needed no change. fm-spawn now ends every republished task record with the pr= block that the metadata parser requires as the tail: a relaunch writes its lifecycle keys ahead of it, and a fresh spawn over a ship or scout's existing record keeps the block, so the armed poll keeps naming the task's still-open PR. A rejected state check now names its cause in the wake, such as a task record with no pr= line, a key after the pr= block, a replaced file, or an unregistered custom check.
…d permissions). Rule that was broken: a published task record must keep owner-only mode (0600), whatever umask the caller inherits. In this file, `complete` (bin/fm-captain-hold.sh:1679) is the only path that stages and publishes a replacement for state/<id>.meta. The other staged files in that script already use `umask 077`. Fix: the staging redirection now runs in a subshell under `umask 077`, so $meta_tmp is created with 0600 before fm_backlog_atomic_transition publishes it. Test: I extended test_completion_attestation_keeps_an_armed_merge_poll_verifiable in tests/fm-captain-hold-lifecycle.test.sh. It sets the record to 0600, runs `complete --none` under `umask 022`, and asserts that the record is still exactly 0600 (`find -perm 0600`). The existing checks still pass: the pr= block stays last and the armed poll still authenticates. Before the fix, this test failed with the record at -rw-r--r--. After the fix it passes, and the full tests/fm-captain-hold-lifecycle.test.sh passes (54 ok, 0 not ok). `shellcheck -x` is clean on both files. As the user decided, I did not change ci-2
…34) that FM_PR_POLL_REJECTION in bin/fm-pr-lib.sh and FM_CUSTOM_CHECK_REJECTION in bin/fm-check-lib.sh are set but never read. Both are output variables that bin/fm-watch.sh reads after it sources the library, which shellcheck cannot see. I added the repository's usual `# shellcheck disable=SC2034 # Read by the sourcing watcher (bin/fm-watch.sh) on rejection.` comment above the flagged line in each file. FM_PR_META_REJECTION, the other new variable, is read inside its own library and needs no comment. Before the change, shellcheck 0.11.0 showed the same two warnings locally. After it, `shellcheck -x bin/fm-pr-lib.sh bin/fm-check-lib.sh bin/fm-watch.sh` passes with no warnings. Behavior portable parallel 1 is not caused by this PR, and I made no code change for it. Its only failing test is tests/fm-pi-primary-types.test.sh, with TS2339 errors ('prompt' does not exist on BeforeAgentStartEvent) in fm-branch-supervision.ts and fm-primary-pi-watch.ts. This PR does not change those files. The upstream main CI run at the base commit 6407052 (run 38316792015, job 115035229020) fails this same test with the same two errors. I did not run the behaviour tests locally; the change only adds the two comments
[Medium impact] The changes affect merge-poll checks, task-record publishing, and status history in watcher-driven workflows. Correct the contradictory rejection fixture before merging. Reviews (1) · Last reviewed commit: "no-mistakes(document): Document merge po..." · Reviewed by Greptile |
| printf 'control_relaunch_tx=tx-1\n' >> "$state/task-a.meta" | ||
| expected='task-a.check.sh (merge poll: the task record has key control_relaunch_tx after its pr= block)' |
There was a problem hiding this comment.
The key-after-pr case expects rejection for control_relaunch_tx, but fm_pr_metadata_identity_parse explicitly allows that key after pr=. The watcher accepts the poll instead of producing the expected rejection, so test_rejection_names_its_cause fails. With the PR still open and no stop check, it can reach the 60-second guard first.
Append a forbidden key such as model and update the expected cause.
| printf 'control_relaunch_tx=tx-1\n' >> "$state/task-a.meta" | |
| expected='task-a.check.sh (merge poll: the task record has key control_relaunch_tx after its pr= block)' | |
| printf 'model=opus\n' >> "$state/task-a.meta" | |
| expected='task-a.check.sh (merge poll: the task record has key model after its pr= block)' |
|
Speaking as Kun's firstmate: thank you @AgardnerAU. This looks like a clean re-raise of #6249 on current main. It also takes care of the remaining point there: What I checked (tip My verdict. Contract-class: new-default. The poll authentication rule changes (device-blind instead of re-recording a shifted device), a fresh spawn over an existing record now keeps its Waiting on you for two things:
One housekeeping question, your call: if #8150 replaces #6249, feel free to close #6249 or say so here, so we track a single PR. (The red "Full suite" check is our gate for outside PRs, not something you need to fix.) |
|
This fix is now carried in #6249. |
What Changed
bin/fm-pr-lib.sh) now matches a registration's recorded sidecar and check identities by inode only, through the newfm_pr_recorded_identity_matches. Each file must still pass the live private-file check against the state directory's current device. This replaces the device-shift re-record path (fm_pr_poll_registration_device_shifted/_rerecord_device) and the watcher'srerecord_device_shifted_pr_pollretry. Status file cursors, markers and snapshots inbin/fm-classify-lib.sh,fm-wake-lib.sh,fm-wake-drain.sh,fm-branch-outcome.shand the Pi branch-dispatch extension now compare identities without the device field (_fm_status_ident_same). Because of this, a state volume remount that renumbersst_devno longer resets cursors or replays a task's history, and the reported status signature also ignores the device.bin/fm-spawn.shnow carries the existingpr=/pr_head=block forward as the last part of the republished task record. It does this on a relaunch, and also on a fresh spawn over an existing ship or scout record. It uses the newfm_pr_metadata_block_print, so an armed merge poll still authenticates. Secondmates are excluded.check: rejected unauthenticated state checks: <path> (<cause>)). The causes come from the newFM_PR_POLL_REJECTION,FM_PR_META_REJECTIONandFM_CUSTOM_CHECK_REJECTIONvalues. These are set by the poll, task record and custom check validators inbin/fm-pr-lib.shandbin/fm-check-lib.sh.docs/architecture.mdand the related tests are updated to match.🤖 Generated with Claude Code
Risk Assessment
Testing
I ran the real watcher in disposable lab homes. A merge poll armed before a simulated remount (only the recorded device number changed) still authenticated and ran its forge check. When the fake PR was merged, the watcher reported the merge and retired the poll. A byte-identical check that replaced the original file was refused and never ran, and the wake named the cause. An unregistered custom check and a task record with a key after its pr= block were also refused, each with its cause in the wake. The new targeted tests passed: relaunch and traced relaunch, respawn, completion attestation, unchanged status after a device renumber, and the presentation cursor after a volume renumber. One concurrency test in the relaunch file failed with a 5-second wait timeout while five suites ran at once. It passed when I ran the file alone, so that was load, not a defect. The watch-triage, captain-hold and solo relaunch runs stopped at my time caps with 0 failures; the new tests in them had already passed. Nothing in this change has a visual surface, so the evidence is the CLI transcript.
pr view https://github.com/o/r/pull/11 --json state; no rejection; poll still armedcheck: .../t-merged.check.sh: merged, check file removed(merge poll: the sidecar or check is not the file its registration was armed with); gh log is emptyrogue.check.sh (custom check: it is not registered (bin/fm-check-register.sh))t-meta.check.sh (merge poll: the task record has key model after its pr= block)ok - ... lands ahead of the pr= block ...,ok - a respawn keeps the task's pr= block ...ok - a volume renumber keeps the presentation cursor while a replaced file still starts unread; test-fm-watch-triage.log `ok - an unchanged reported status survi…Evidence: Live watcher transcript (S1-S5)
Source: Live watcher transcript (S1-S5)
Evidence: Live lab driver script
Source: Live lab driver script
Evidence: Rejection wakes with causes
Evidence: Relaunch suite rerun alone
Source: Relaunch suite rerun alone
Evidence: Backlog atomicity (respawn keeps pr= block)
Source: Backlog atomicity (respawn keeps pr= block)
Evidence: Wake drain (volume renumber does not replay history)
Source: Wake drain (volume renumber does not replay history)
Pipeline
Updates from git push no-mistakes
⏭️ **Intent** - skipped
Step was skipped.
🔧 **Rebase** - 5 issues found → auto-fixed ✅
bin/fm-pr-lib.sh- merge conflict rebasing onto origin/mainbin/fm-spawn.sh- merge conflict rebasing onto origin/mainbin/fm-watch.sh- merge conflict rebasing onto origin/maintests/fm-control-relaunch.test.sh- merge conflict rebasing onto origin/maintests/fm-pr-check-security.test.sh- merge conflict rebasing onto origin/main🔧 Fix applied.
✅ Re-checked - no issues remain.
bin/fm-classify-lib.sh:1754- status_observed_signature now removes the device from the identity before it encodes the r1 signature. Every .seen-* or heartbeat marker written by the earlier code stores a signature that still includes the device. After the upgrade, each such marker therefore fails to match once in status_presentation_marker_reported_matches. This can cause one extra wake-scan hit per status file through fm_wake_signal_seen_current (bin/fm-wake-lib.sh:3084). This is the same effect one remount had before the fix. Presented history is not replayed, because the classified and cursor offsets already compare without the device. The next report commit repairs each marker. This is a one-time migration cost, and no action is needed unless a silent upgrade matters.tests/fm-control-relaunch.test.sh:616- test_relaunch_serializes_concurrent_durable_metadata_publication failed once ('relaunch did not reach trace delivery') while five suites ran at once. It waits at most 5 seconds (500 x 0.01s), so load can break it. It passed when the file ran alone. This was not caused by this change.pr view https://github.com/o/r/pull/11 --json state; no rejection; poll still armedcheck: .../t-merged.check.sh: merged, check file removed(merge poll: the sidecar or check is not the file its registration was armed with); gh log is emptyrogue.check.sh (custom check: it is not registered (bin/fm-check-register.sh))t-meta.check.sh (merge poll: the task record has key model after its pr= block)ok - ... lands ahead of the pr= block ...,ok - a respawn keeps the task's pr= block ...ok - a volume renumber keeps the presentation cursor while a replaced file still starts unread; test-fm-watch-triage.log `ok - an unchanged reported status survi…bin/fm-lab-home.sh createto make disposable lab homes (one for each scenario), then the realbin/fm-watch.shwith onlyghfaked: driver at ~/.no-mistakes/evidence/01M6KA9VHD117BB35E0VVCKKSD/driver/live-remount.shS1: armed merge poll whose registration records a renumbered device, with the PR openS2: renumbered poll with the PR mergedS3: byte-identical check replaced (new inode) after the renumberS4: unregistered custom checkS5: task record with keymodelafter its pr= blockbash tests/fm-control-relaunch.test.sh(once in parallel, once alone)bash tests/fm-backlog-atomicity.test.shbash tests/fm-wake-drain-unread-status.test.shbash tests/fm-watch-triage.test.sh(stopped at a 900s cap with 0 failures; the new renumber test passed)bash tests/fm-captain-hold-lifecycle.test.sh(stopped at a 900s cap with 0 failures; the new attestation test passed)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.