Skip to content

fix(bin): keep an armed merge poll authenticated after later task-record writes - #2

Merged
bastotec merged 7 commits into
mainfrom
fm/fm-merge-poll-trust
Sep 15, 2026
Merged

bastotec merged 7 commits into
mainfrom
fm/fm-merge-poll-trust

Conversation

@bastotec

@bastotec bastotec commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

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 checks naming 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_parse in bin/fm-pr-lib.sh now checks PR identity wherever it appears in the task record instead of treating everything after pr= as suspect: exactly one pr= line must carry a canonical URL and every pr_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 gains control_relaunch_tx=, decisions_reviewed=, or decision_keys= no longer revokes a live merge poll with check: rejected unauthenticated state checks.
  • tests/fm-pr-check-security.test.sh adds coverage for an armed poll surviving later record appends through to a MERGED notification, for the identity refusals (duplicate pr=, malformed URL, bad pr_head=), and for the registered-poll trust boundary across a tampered program, a replaced file, and a second home.
  • The branch also carries the merged fork main, which adds the recover-missing control verb (bin/fm-control.sh, bin/fm-control-lib.sh, fm_backend_tmux_recreate_session in bin/backends/tmux.sh, tests/fm-control-recover-missing.test.sh); docs/agent-control.md was resolved to keep both that verb's documentation and this repair's test-coverage line for tests/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.

  • Live validation: ✅ go - 8 of 8 scenarios driven live against the product
Scenario Result Live Evidence
A registered PR merges after the task record gains later keys, and the merge notification arrives ✅ pass live scenario-merge-notification.sh against the branch: fm-pr-check.sh exits 0, control_relaunch_tx=/decisions_reviewed=/decision_keys= appended, fm-watch.sh prints `check: .../task-a.check.sh:…
Same sequence on the base commit reproduces the reported failure (no notification, unauthenticated-state-checks wake) ✅ pass live Same script with ROOT pointed at a checkout of base commit 8b10b61: check: rejected unauthenticated state checks: .../task-a.check.sh, no merge line - see merge-notification-before-after.txt
Editing a registered poll's program bytes keeps it refused and never runs the tampered code ✅ pass live scenario-trust-boundary.sh tampered case: watcher reports the refusal, no merged line and no tampered-bytes-ran output despite gh reporting MERGED - see poll-trust-boundary.txt
Swapping the registered poll for a different file with byte-identical contents is refused ✅ pass live scenario-trust-boundary.sh replaced case: replacement verified byte-identical to bin/fm-pr-poll.sh, watcher still reports the refusal and no merge - see poll-trust-boundary.txt
A whole registered poll copied into a second home is refused there while the original home still reports the merge ✅ pass live scenario-trust-boundary.sh cross-home case: home B reports the refusal, home A reports task-a.check.sh: merged - see poll-trust-boundary.txt
A task record made ambiguous about which PR it names (second pr=, malformed pr_head=) stops the merge notification ✅ pass live scenario-trust-boundary.sh second-pr and bad-head cases: both refused by fm-watch.sh with no merge reported - see poll-trust-boundary.txt; also test_task_record_identity_refusals
Relaunching a task with an armed merge poll leaves the poll authenticated ✅ pass live bin/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…
The suites this change touches pass end to end ✅ pass live bin/fm-test-run.sh tests/fm-pr-check-security.test.sh exit=0 (33 tests incl. the three new ones) and bin/fm-test-run.sh tests/fm-control-relaunch.test.sh exit=0
Evidence: 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

=============== BEFORE: base commit 8b10b61 (bug reproduced) ===============
# operator registers the PR for merge notification
armed: state/task-a.check.sh
fm-pr-check.sh: exit 0 (registration reported success)

# what the registration armed:
  task-a.check.sh
  task-a.meta
  task-a.pr-poll
  task-a.pr-poll-registration

# then the task is relaunched and the captain reviews - both append to the task record
  task record now reads:
    window=fm-task-a
    endpoint_task_id=task-a
    worktree=/tmp/fm-poll-drive/tmp/merge-notification-before/wt
    project=/tmp/fm-poll-drive/tmp/merge-notification-before/project
    kind=ship
    mode=no-mistakes
    pr=https://github.com/example/repo/pull/42
    pr_head=0123456789abcdef0123456789abcdef01234567
    control_relaunch_tx=96772.20260915T115436Z.29459
    decisions_reviewed=1
    decision_keys=nm-1-review

# the PR merges (gh reports MERGED); the supervisor's watcher runs
fm-watch.sh: exit 0
watcher told the supervisor:
  check: rejected unauthenticated state checks: /tmp/fm-poll-drive/tmp/merge-notification-before/home/state/task-a.check.sh

RESULT: NO merge notification - poll refused as unauthenticated

=============== AFTER: branch fm/fm-merge-poll-trust (0a76069) ===============
# operator registers the PR for merge notification
armed: state/task-a.check.sh
fm-pr-check.sh: exit 0 (registration reported success)

# what the registration armed:
  task-a.check.sh
  task-a.meta
  task-a.pr-poll
  task-a.pr-poll-registration

# then the task is relaunched and the captain reviews - both append to the task record
  task record now reads:
    window=fm-task-a
    endpoint_task_id=task-a
    worktree=/tmp/fm-poll-drive/tmp/merge-notification-after/wt
    project=/tmp/fm-poll-drive/tmp/merge-notification-after/project
    kind=ship
    mode=no-mistakes
    pr=https://github.com/example/repo/pull/42
    pr_head=0123456789abcdef0123456789abcdef01234567
    control_relaunch_tx=96772.20260915T115436Z.29459
    decisions_reviewed=1
    decision_keys=nm-1-review

# the PR merges (gh reports MERGED); the supervisor's watcher runs
fm-watch.sh: exit 0
watcher told the supervisor:
  check: /tmp/fm-poll-drive/tmp/merge-notification-after/home/state/task-a.check.sh: merged

RESULT: merge notification delivered
Evidence: Trust boundaries still refuse: tampered, replaced, cross-home, ambiguous PR identity

Source: Trust boundaries still refuse: tampered, replaced, cross-home, ambiguous PR identity

\### tampered: poll program bytes edited after registration
  appended to task-a.check.sh: printf tampered-bytes-ran
  fm-watch.sh exit 0
  check: rejected unauthenticated state checks: /tmp/fm-poll-drive/tmp/trust-tampered/home/state/task-a.check.sh
RESULT[tampered]: refused as unauthenticated, no merge reported

\### replaced: the registered file swapped for a different file with identical bytes
  replacement is byte-identical to bin/fm-pr-poll.sh
  fm-watch.sh exit 0
  check: rejected unauthenticated state checks: /tmp/fm-poll-drive/tmp/trust-replaced/home/state/task-a.check.sh
RESULT[replaced]: refused as unauthenticated, no merge reported

\### cross-home: a whole registered poll lifted into a second home
  copied home A's four poll artifacts into home B
  home B fm-watch.sh exit 0
  check: rejected unauthenticated state checks: /tmp/fm-poll-drive/tmp/trust-home-b~/task-a.check.sh
RESULT[cross-home]: refused as unauthenticated, no merge reported
  home A (the home that registered it) still reports:
  check: /tmp/fm-poll-drive/tmp/trust-home-a~/task-a.check.sh: merged

\### ambiguous identity: a second pr= line appended to the task record
  task record now names two pull requests (42 and 99)
  fm-watch.sh exit 0
  check: rejected unauthenticated state checks: /tmp/fm-poll-drive/tmp/trust-second-pr/home/state/task-a.check.sh
RESULT[second-pr]: refused as unauthenticated, no merge reported

\### ambiguous identity: a malformed pr_head= appended to the task record
  fm-watch.sh exit 0
  check: rejected unauthenticated state checks: /tmp/fm-poll-drive/tmp/trust-bad-head/home/state/task-a.check.sh
RESULT[bad-head]: refused as unauthenticated, no merge reported
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)

#!/usr/bin/env bash
# End-to-end driver for the merge-poll trust repair, exercised exactly the way an
# operator does: register a PR for merge notification with bin/fm-pr-check.sh,
# let ordinary writers append to the task record, then run bin/fm-watch.sh and
# see whether the merge is reported.
set -u
ROOT=${ROOT:?set ROOT to a firstmate checkout}
TMP=${TMP_ROOT:?set TMP_ROOT}
BASE_PATH=/usr/bin:/bin:/usr/sbin:/sbin

mkhome() { # <name>
  local d="$TMP/$1"
  rm -rf "$d"
  mkdir -p "$d/home/state" "$d/home/data" "$d/home/config" "$d/wt" "$d/fakebin" "$d/root/bin"
  cat > "$d/root/bin/fm-guard.sh" <<'SH'
#!/usr/bin/env bash
exit 0
SH
  chmod +x "$d/root/bin/fm-guard.sh"
  cat > "$d/fakebin/gh" <<'SH'
#!/usr/bin/env bash
case " $* " in
  *" headRefOid "*) printf '%s\n' "${FM_TEST_GH_HEAD:-0123456789abcdef0123456789abcdef01234567}" ;;
  *" state "*) printf '%s\n' "${FM_TEST_GH_STATE:-OPEN}" ;;
esac
exit 0
SH
  chmod +x "$d/fakebin/gh"
  printf 'window=fm-task-a\nendpoint_task_id=task-a\nworktree=%s\nproject=%s\nkind=ship\nmode=no-mistakes\n' \
    "$d/wt" "$d/project" > "$d/home/state/task-a.meta"
  chmod 0600 "$d/home/state/task-a.meta"
  printf '%s\n' "$d"
}

arm() { # <dir> <url>
  local d=$1 url=$2
  FM_ROOT_OVERRIDE="$d/root" FM_HOME="$d/home" PATH="$d/fakebin:$BASE_PATH" \
    "$ROOT/bin/fm-pr-check.sh" task-a "$url"
}

stop_check() { # <dir> - a trivial custom check so the watcher completes a cycle
  local d=$1
  printf '#!/usr/bin/env bash\nprintf "stop-cycle\\n"\n' > "$d/home/state/z-stop.check.sh"
  chmod 0700 "$d/home/state/z-stop.check.sh"
  FM_HOME="$d/home" "$ROOT/bin/fm-check-register.sh" z-stop >/dev/null
}

watch() { # <dir home> <dir fakebin>
  local home=$1 fakebin=$2
  perl -e 'my $pid=fork; die unless defined $pid; if (!$pid) { exec @ARGV } local $SIG{ALRM}=sub { kill "TERM", $pid; waitpid $pid, 0; exit 124 }; alarm 20; waitpid $pid, 0; alarm 0; exit($? >> 8)' \
    env FM_HOME="$home" FM_ROOT_OVERRIDE="$ROOT" FM_CHECK_INTERVAL=0 FM_CHECK_TIMEOUT=5 \
      FM_POLL=0.02 FM_HEARTBEAT=999999 FM_SIGNAL_GRACE=0 FM_TEST_GH_STATE=MERGED \
      PATH="$fakebin:$BASE_PATH" "$ROOT/bin/fm-watch.sh"
}
Evidence: Merge-notification scenario script

Source: Merge-notification scenario script

#!/usr/bin/env bash
# Scenario: a PR is registered for automatic merge notification, ordinary task
# writers then append to the task record, and the PR merges.
set -u
. /tmp/fm-poll-drive/drive.sh
label=${LABEL:-run}
d=$(mkhome "merge-notification-$label")
echo "# operator registers the PR for merge notification"
arm "$d" https://github.com/example/repo/pull/42 && echo "fm-pr-check.sh: exit 0 (registration reported success)"
echo
echo "# what the registration armed:"
ls "$d/home/state" | sed 's/^/  /'
echo
echo "# then the task is relaunched and the captain reviews - both append to the task record"
printf 'control_relaunch_tx=%s\n' '96772.20260915T115436Z.29459' >> "$d/home/state/task-a.meta"
printf 'decisions_reviewed=1\ndecision_keys=%s\n' 'nm-1-review' >> "$d/home/state/task-a.meta"
echo "  task record now reads:"
sed 's/^/    /' "$d/home/state/task-a.meta"
echo
echo "# the PR merges (gh reports MERGED); the supervisor's watcher runs"
case "${STOP_CHECK-1}" in 0) ;; *) stop_check "$d" ;; esac
watch "$d/home" "$d/fakebin" > "$d/watch.out" 2> "$d/watch.err"
rc=$?
echo "fm-watch.sh: exit $rc"
echo "watcher told the supervisor:"
sed 's/^/  /' "$d/watch.out"
[ -s "$d/watch.err" ] && { echo "stderr:"; sed 's/^/  /' "$d/watch.err"; }
echo
if grep -q 'task-a.check.sh: merged' "$d/watch.out"; then
  echo "RESULT: merge notification delivered"
elif grep -q 'rejected unauthenticated state checks' "$d/watch.out"; then
  echo "RESULT: NO merge notification - poll refused as unauthenticated"
else
  echo "RESULT: no merge notification and no refusal reported"
fi
Evidence: Trust-boundary scenario script

Source: Trust-boundary scenario script

#!/usr/bin/env bash
# Adversarial scenarios: things that must NOT be allowed to report a merge, all
# driven through the real watcher with gh stubbed MERGED, so an accepted poll
# would visibly report "merged".
set -u
. /tmp/fm-poll-drive/drive.sh

report() { # <dir> <label>
  local d=$1 label=$2
  if grep -q 'task-a.check.sh: merged' "$d/watch.out"; then
    echo "RESULT[$label]: merge REPORTED"
  elif grep -q 'rejected unauthenticated state checks' "$d/watch.out"; then
    echo "RESULT[$label]: refused as unauthenticated, no merge reported"
  else
    echo "RESULT[$label]: neither merge nor refusal: $(cat "$d/watch.out")"
  fi
}

echo "### tampered: poll program bytes edited after registration"
d=$(mkhome trust-tampered)
arm "$d" https://github.com/example/repo/pull/42 >/dev/null
printf '\nprintf "tampered-bytes-ran\\n"\n' >> "$d/home/state/task-a.check.sh"
echo "  appended to task-a.check.sh: printf tampered-bytes-ran"
watch "$d/home" "$d/fakebin" > "$d/watch.out" 2> "$d/watch.err"; echo "  fm-watch.sh exit $?"
sed 's/^/  /' "$d/watch.out"
grep -q 'tampered-bytes-ran' "$d/watch.out" && echo "  !! tampered bytes executed"
report "$d" tampered
echo

echo "### replaced: the registered file swapped for a different file with identical bytes"
d=$(mkhome trust-replaced)
arm "$d" https://github.com/example/repo/pull/42 >/dev/null
cp "$d/home/state/task-a.check.sh" "$d/replacement.check.sh"
rm -f "$d/home/state/task-a.check.sh"
mv "$d/replacement.check.sh" "$d/home/state/task-a.check.sh"
chmod 0600 "$d/home/state/task-a.check.sh"
cmp -s "$ROOT/bin/fm-pr-poll.sh" "$d/home/state/task-a.check.sh" && echo "  replacement is byte-identical to bin/fm-pr-poll.sh"
watch "$d/home" "$d/fakebin" > "$d/watch.out" 2> "$d/watch.err"; echo "  fm-watch.sh exit $?"
sed 's/^/  /' "$d/watch.out"
report "$d" replaced
echo

echo "### cross-home: a whole registered poll lifted into a second home"
a=$(mkhome trust-home-a)
b=$(mkhome trust-home-b)
arm "$a" https://github.com/example/repo/pull/42 >/dev/null
cp "$a/home/state/task-a.meta" "$a/home/state/task-a.check.sh" "$a/home/state/task-a.pr-poll" \
   "$a/home/state/task-a.pr-poll-registration" "$b/home/state/"
chmod 0600 "$b/home/state/task-a.check.sh" "$b/home/state/task-a.pr-poll" "$b/home/state/task-a.pr-poll-registration"
echo "  copied home A's four poll artifacts into home B"
watch "$b/home" "$b/fakebin" > "$b/watch.out" 2> "$b/watch.err"; echo "  home B fm-watch.sh exit $?"
sed 's/^/  /' "$b/watch.out"
report "$b" cross-home
stop_check "$a"
watch "$a/home" "$a/fakebin" > "$a/watch.out" 2> "$a/watch.err"
echo "  home A (the home that registered it) still reports:"
sed 's/^/  /' "$a/watch.out"
echo

echo "### ambiguous identity: a second pr= line appended to the task record"
d=$(mkhome trust-second-pr)
arm "$d" https://github.com/example/repo/pull/42 >/dev/null
printf 'pr=%s\n' 'https://github.com/example/repo/pull/99' >> "$d/home/state/task-a.meta"
echo "  task record now names two pull requests (42 and 99)"
watch "$d/home" "$d/fakebin" > "$d/watch.out" 2> "$d/watch.err"; echo "  fm-watch.sh exit $?"
sed 's/^/  /' "$d/watch.out"
report "$d" second-pr
echo

echo "### ambiguous identity: a malformed pr_head= appended to the task record"
d=$(mkhome trust-bad-head)
arm "$d" https://github.com/example/repo/pull/42 >/dev/null
printf 'pr_head=%s\n' 'not-a-sha' >> "$d/home/state/task-a.meta"
watch "$d/home" "$d/fakebin" > "$d/watch.out" 2> "$d/watch.err"; echo "  fm-watch.sh exit $?"
sed 's/^/  /' "$d/watch.out"
report "$d" bad-head
Evidence: Watcher output on the branch after a relaunch-style task-record append
# the PR merges (gh reports MERGED); the supervisor's watcher runs
fm-watch.sh: exit 0
watcher told the supervisor:
check: .../merge-notification-after/home/state/task-a.check.sh: merged

RESULT: merge notification delivered
- Outcome: ⚠️ 1 info across 1 run (18m41s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

⚠️ **Rebase** - 1 warning

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.

⚠️ **Test** - 1 info
  • ℹ️ tests/fm-pr-check-security.test.sh:1802 - Flaky under load: test_persistent_secondmate_retirement_is_poll_only in tests/fm-pr-check-security.test.sh failed twice with an empty stderr (persistent secondmate merged watcher failed: ), which is the 10s alarm in run_watcher_bounded firing 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.
  • Live validation: ✅ go - 8 of 8 scenarios driven live against the product
Scenario Result Live Evidence
A registered PR merges after the task record gains later keys, and the merge notification arrives ✅ pass live scenario-merge-notification.sh against the branch: fm-pr-check.sh exits 0, control_relaunch_tx=/decisions_reviewed=/decision_keys= appended, fm-watch.sh prints `check: .../task-a.check.sh:…
Same sequence on the base commit reproduces the reported failure (no notification, unauthenticated-state-checks wake) ✅ pass live Same script with ROOT pointed at a checkout of base commit 8b10b61: check: rejected unauthenticated state checks: .../task-a.check.sh, no merge line - see merge-notification-before-after.txt
Editing a registered poll's program bytes keeps it refused and never runs the tampered code ✅ pass live scenario-trust-boundary.sh tampered case: watcher reports the refusal, no merged line and no tampered-bytes-ran output despite gh reporting MERGED - see poll-trust-boundary.txt
Swapping the registered poll for a different file with byte-identical contents is refused ✅ pass live scenario-trust-boundary.sh replaced case: replacement verified byte-identical to bin/fm-pr-poll.sh, watcher still reports the refusal and no merge - see poll-trust-boundary.txt
A whole registered poll copied into a second home is refused there while the original home still reports the merge ✅ pass live scenario-trust-boundary.sh cross-home case: home B reports the refusal, home A reports task-a.check.sh: merged - see poll-trust-boundary.txt
A task record made ambiguous about which PR it names (second pr=, malformed pr_head=) stops the merge notification ✅ pass live scenario-trust-boundary.sh second-pr and bad-head cases: both refused by fm-watch.sh with no merge reported - see poll-trust-boundary.txt; also test_task_record_identity_refusals
Relaunching a task with an armed merge poll leaves the poll authenticated ✅ pass live bin/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…
The suites this change touches pass end to end ✅ pass live bin/fm-test-run.sh tests/fm-pr-check-security.test.sh exit=0 (33 tests incl. the three new ones) and bin/fm-test-run.sh tests/fm-control-relaunch.test.sh exit=0
  • Manual end-to-end before/after: ROOT=&lt;base-8b10b61 checkout&gt; scenario-merge-notification.sh vs ROOT=&lt;branch worktree&gt; scenario-merge-notification.sh (real bin/fm-pr-check.sh + bin/fm-watch.sh)
  • Manual adversarial driver scenario-trust-boundary.sh (tampered bytes, identical-bytes replacement, cross-home copy, second pr=, malformed pr_head=), all through bin/fm-watch.sh
  • bin/fm-test-run.sh tests/fm-pr-check-security.test.sh (includes the new test_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 new test_relaunch_keeps_an_armed_merge_poll_authenticated)
  • Flake triage: single-test reruns of test_persistent_secondmate_retirement_is_poll_only on 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.

… 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.
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.
@bastotec
bastotec merged commit f659839 into main Sep 15, 2026
14 of 15 checks passed
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
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.

1 participant