Repository navigation
fix(bin): keep an armed merge poll authenticated after later task-record writes - #2
Merged
Merged
Conversation
… later key The watcher re-authenticates a PR merge poll on every cycle, and part of that is a cross-check against the task's own durable record. That cross-check refused any key it did not recognise appearing after the record's `pr=` line, so an armed poll was revoked the moment a supported writer appended one: `bin/fm-control.sh relaunch` records `control_relaunch_tx=` at the tail, and `bin/fm-captain-hold.sh` appends `decisions_reviewed=` and `decision_keys=`. Arming could never see it. `bin/fm-pr-check.sh` rewrites the record so `pr=` and `pr_head=` are its last lines, so the refusal only ever surfaced later, in the watcher, as `check: rejected unauthenticated state checks` - the poll never ran, and the missing merge notification was indistinguishable from an unmerged pull request. State the guarantee as a property of the whole record instead of its tail: every non-blank line is a readable `key=value` record, exactly one `pr=` line carries a canonical URL, and at most one `pr_head=` carries a valid head wherever it appears. An unrecognised key carries no PR identity, so it is no longer treated as tampering. The content fingerprints and the file-identity bindings are unchanged. This is stricter than before on lines ahead of `pr=`, which the old tail-only rule never inspected, and it makes arming apply the same rule the watcher will, so a record that cannot be read is refused where an operator sees it.
…eck security test
Brings in the already-landed recover-missing work so this repair's pull request can be built and checked against the current base. The only overlap was the Verification list in docs/agent-control.md, where both changes edit adjacent bullets; the resolution keeps the landed fm-control-recover-missing.test.sh entry and this repair's updated fm-control-relaunch.test.sh entry. No code from either change is altered by this merge.
…nd recover-missing
bastotec
added a commit
that referenced
this pull request
Sep 16, 2026
…ord writes (#2) * fix(bin): keep an armed merge poll valid when the task record gains a later key The watcher re-authenticates a PR merge poll on every cycle, and part of that is a cross-check against the task's own durable record. That cross-check refused any key it did not recognise appearing after the record's `pr=` line, so an armed poll was revoked the moment a supported writer appended one: `bin/fm-control.sh relaunch` records `control_relaunch_tx=` at the tail, and `bin/fm-captain-hold.sh` appends `decisions_reviewed=` and `decision_keys=`. Arming could never see it. `bin/fm-pr-check.sh` rewrites the record so `pr=` and `pr_head=` are its last lines, so the refusal only ever surfaced later, in the watcher, as `check: rejected unauthenticated state checks` - the poll never ran, and the missing merge notification was indistinguishable from an unmerged pull request. State the guarantee as a property of the whole record instead of its tail: every non-blank line is a readable `key=value` record, exactly one `pr=` line carries a canonical URL, and at most one `pr_head=` carries a valid head wherever it appears. An unrecognised key carries no PR identity, so it is no longer treated as tampering. The content fingerprints and the file-identity bindings are unchanged. This is stricter than before on lines ahead of `pr=`, which the old tail-only rule never inspected, and it makes arming apply the same rule the watcher will, so a record that cannot be read is refused where an operator sees it. * no-mistakes(review): drop unreachable pr_head cap, report unreadable record at arming * no-mistakes(review): drop whole-record key strictness, restore test umask * no-mistakes(document): note armed merge poll coverage in relaunch suite docs * no-mistakes(lint): inline single-case loop flagged by SC2043 in PR-check security test * no-mistakes(document): refresh relaunch suite header for merge-poll and recover-missing
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
The captain authorized this repair in their own words: "Yes, please start that repair."
What they are fixing, stated as the operator experiences it: a pull request is registered for automatic merge notification, the registration reports success, and then no notification ever arrives when the PR merges. Instead the supervisor is woken with
check: rejected unauthenticated state checksnaming that task's own poll program. Because the poll never runs, silence is indistinguishable from "not merged yet", so anyone waiting on a merge has to check it by hand. This affects every home, not one task.The captain's boundaries: preserve the existing content-fingerprint and file-identity safety boundaries. Fix the false rejection; do not weaken trust validation to make the rejection go away. Add regression coverage for a valid registered poll, a tampered poll, a replaced file, and cross-home behavior. Ship it through the Firstmate repository's normal delivery path and report the PR when checks are green. Do not merge.
This is deliberately a separate change from the recover-missing work (a control verb recovering a task whose terminal is gone), and must not be folded into it.
The captain then decided this branch should be updated against the already-landed controlled-fork main, resolving the docs/agent-control.md overlap narrowly by preserving both the accepted recover-missing documentation and this repair's accurate test coverage, keeping this a separate repair rather than folding it into the earlier one.
What Changed
fm_pr_metadata_identity_parseinbin/fm-pr-lib.shnow checks PR identity wherever it appears in the task record instead of treating everything afterpr=as suspect: exactly onepr=line must carry a canonical URL and everypr_head=line must carry a valid head, while keys the parser does not know are skipped rather than counted as tampering. Content-fingerprint and file-identity checks (link count, device, program bytes) are unchanged, so a record that later gainscontrol_relaunch_tx=,decisions_reviewed=, ordecision_keys=no longer revokes a live merge poll withcheck: rejected unauthenticated state checks.tests/fm-pr-check-security.test.shadds coverage for an armed poll surviving later record appends through to a MERGED notification, for the identity refusals (duplicatepr=, malformed URL, badpr_head=), and for the registered-poll trust boundary across a tampered program, a replaced file, and a second home.recover-missingcontrol verb (bin/fm-control.sh,bin/fm-control-lib.sh,fm_backend_tmux_recreate_sessioninbin/backends/tmux.sh,tests/fm-control-recover-missing.test.sh);docs/agent-control.mdwas resolved to keep both that verb's documentation and this repair's test-coverage line fortests/fm-control-relaunch.test.sh.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The repair is a small, well-bounded rewrite of one metadata parser that removes exactly the unknown-key-after-pr= rule that caused the false rejection, leaves the content-fingerprint and device:inode bindings untouched, still refuses every PR-identity ambiguity, and ships behavior-level regression coverage for all four cases the intent requires.
Testing
Stood the toolkit up the way an operator does - register a PR for merge notification with bin/fm-pr-check.sh, let a relaunch and a captain review append to the task record, then run bin/fm-watch.sh against a stubbed MERGED forge - and captured the same run against the base commit for comparison: base refuses the poll as an unauthenticated state check and delivers no notification, the branch delivers
merged. Five adversarial variants (tampered program bytes, a different file with identical bytes, the poll lifted into a second home, a second pr= line, a malformed pr_head=) were each driven through the real watcher and all stayed refused with no merge reported, while the registering home still reported the merge. The two suites this change touches were run in full and pass, including the new armed-poll, identity-refusal, trust-boundary and relaunch tests. This is a CLI/supervisor change with no rendered UI surface, so the evidence is CLI transcripts rather than screenshots. One pre-existing flake in the security suite (a 10s watcher alarm in the bounded-watcher helper) failed twice under load and then passed consistently; it does not involve the changed parser.scenario-merge-notification.shagainst the branch:fm-pr-check.shexits 0,control_relaunch_tx=/decisions_reviewed=/decision_keys=appended,fm-watch.shprints `check: .../task-a.check.sh:…check: rejected unauthenticated state checks: .../task-a.check.sh, no merge line - see merge-notification-before-after.txtscenario-trust-boundary.shtampered case: watcher reports the refusal, nomergedline and notampered-bytes-ranoutput despite gh reporting MERGED - see poll-trust-boundary.txtscenario-trust-boundary.shreplaced case: replacement verified byte-identical to bin/fm-pr-poll.sh, watcher still reports the refusal and no merge - see poll-trust-boundary.txtscenario-trust-boundary.shcross-home case: home B reports the refusal, home A reportstask-a.check.sh: merged- see poll-trust-boundary.txtscenario-trust-boundary.shsecond-pr and bad-head cases: both refused by fm-watch.sh with no merge reported - see poll-trust-boundary.txt; alsotest_task_record_identity_refusalsbin/fm-test-run.sh tests/fm-control-relaunch.test.sh-ok - fm-control relaunch: an armed merge poll survives the record rewrite, which drives the real bin/fm-control.sh relaunch and re-checks the…bin/fm-test-run.sh tests/fm-pr-check-security.test.shexit=0 (33 tests incl. the three new ones) andbin/fm-test-run.sh tests/fm-control-relaunch.test.shexit=0Evidence: Merge notification before/after: base commit refuses the poll, branch reports the merge
Source: Merge notification before/after: base commit refuses the poll, branch reports the merge
Evidence: Trust boundaries still refuse: tampered, replaced, cross-home, ambiguous PR identity
Source: Trust boundaries still refuse: tampered, replaced, cross-home, ambiguous PR identity
Evidence: Driver used to stand the product up (fixture home, real fm-pr-check.sh arming, bounded fm-watch.sh)
Source: Driver used to stand the product up (fixture home, real fm-pr-check.sh arming, bounded fm-watch.sh)
Evidence: Merge-notification scenario script
Source: Merge-notification scenario script
Evidence: Trust-boundary scenario script
Source: Trust-boundary scenario script
Evidence: Watcher output on the branch after a relaunch-style task-record append
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
.agents/skills/harness-adapters/SKILL.md- branch carries 1 commit(s) that exist on your local main branch but were never pushed to origin/main; these may be unintended bundled work (proposed PR changes 16 file(s)):Confirm these commits belong in this PR before approving, or manually separate the intended work onto origin/main before gating.
✅ **Review** - passed
✅ No issues found.
tests/fm-pr-check-security.test.sh:1802- Flaky under load:test_persistent_secondmate_retirement_is_poll_onlyin tests/fm-pr-check-security.test.sh failed twice with an empty stderr (persistent secondmate merged watcher failed:), which is the 10salarminrun_watcher_boundedfiring rather than a product error. It then passed 6/6 in isolation and in two full-file runs of the suite; the same test on base commit 8b10b61 passed 4/4. Not caused by this change - the change touches only the metadata parser - but it can make this suite fail intermittently in CI.scenario-merge-notification.shagainst the branch:fm-pr-check.shexits 0,control_relaunch_tx=/decisions_reviewed=/decision_keys=appended,fm-watch.shprints `check: .../task-a.check.sh:…check: rejected unauthenticated state checks: .../task-a.check.sh, no merge line - see merge-notification-before-after.txtscenario-trust-boundary.shtampered case: watcher reports the refusal, nomergedline and notampered-bytes-ranoutput despite gh reporting MERGED - see poll-trust-boundary.txtscenario-trust-boundary.shreplaced case: replacement verified byte-identical to bin/fm-pr-poll.sh, watcher still reports the refusal and no merge - see poll-trust-boundary.txtscenario-trust-boundary.shcross-home case: home B reports the refusal, home A reportstask-a.check.sh: merged- see poll-trust-boundary.txtscenario-trust-boundary.shsecond-pr and bad-head cases: both refused by fm-watch.sh with no merge reported - see poll-trust-boundary.txt; alsotest_task_record_identity_refusalsbin/fm-test-run.sh tests/fm-control-relaunch.test.sh-ok - fm-control relaunch: an armed merge poll survives the record rewrite, which drives the real bin/fm-control.sh relaunch and re-checks the…bin/fm-test-run.sh tests/fm-pr-check-security.test.shexit=0 (33 tests incl. the three new ones) andbin/fm-test-run.sh tests/fm-control-relaunch.test.shexit=0Manual end-to-end before/after:ROOT=<base-8b10b61 checkout> scenario-merge-notification.shvsROOT=<branch worktree> scenario-merge-notification.sh(realbin/fm-pr-check.sh+bin/fm-watch.sh)Manual adversarial driverscenario-trust-boundary.sh(tampered bytes, identical-bytes replacement, cross-home copy, secondpr=, malformedpr_head=), all throughbin/fm-watch.shbin/fm-test-run.sh tests/fm-pr-check-security.test.sh(includes the newtest_armed_poll_survives_later_task_record_appends,test_task_record_identity_refusals,test_registered_poll_trust_boundary)bin/fm-test-run.sh tests/fm-control-relaunch.test.sh(includes the newtest_relaunch_keeps_an_armed_merge_poll_authenticated)Flake triage: single-test reruns oftest_persistent_secondmate_retirement_is_poll_onlyon the branch (6 passes after 2 load-induced failures) and on base commit 8b10b61 (4 passes)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.