Skip to content

fix: keep registered merge polls armed across template updates - #339

Merged
dnth merged 3 commits into
mainfrom
fm/fm-upstream-port-c-mergepoll
Nov 27, 2026
Merged

dnth merged 3 commits into
mainfrom
fm/fm-upstream-port-c-mergepoll

Conversation

@dnth

@dnth dnth commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Ports upstream PR 8069's generation binding: a registered merge poll stays valid when the poll template changes, because the published check is authenticated against the generation it was registered with instead of against today's bin/fm-pr-poll.sh.

 fm_pr_poll_prepare() {
-  [ -f "$template" ] || return 1
+  [ -f "$template" ] && [ ! -L "$template" ] || return 1

 fm_pr_poll_artifacts_valid() {
   ...
-  cmp -s "$template" "$check" || return 1
+  # The repository entry point is checked here. The registration authenticates
+  # the published copy below.
+  [ -f "$template" ] && [ ! -L "$template" ] || return 1
   fm_pr_poll_data_parse "$data" || return 1
   template_hash=$(fm_pr_sha256 "$check") || return 1
   ...
   [ "$FM_PR_REG_TEMPLATE_HASH" = "$template_hash" ] || return 1
   [ "$FM_PR_REG_CHECK_IDENTITY" = "$check_identity" ] || return 1

Execution is unchanged: the watcher runs the current repository poll with the validated sidecar identity and never runs the registered state-file bytes, so a poll armed under an older generation executes today's code.

Trust boundary

Question Before After
What authenticates the check? byte equality with today's template, plus its registered hash and file identity its registered template hash and file identity
What runs? current repository poll current repository poll (unchanged)
Altered check bytes refused refused
Runnable name whose registration is missing refused refused
Poll armed before a template update silently disarmed keeps running

The only widening is which generation of the poll script a registration may name. Who can arm a poll is unchanged: a private state/ artifact set written by the local user, and a poll still needs a canonical registration, matching sidecar data, matching task metadata, and the check's exact recorded inode identity. The current template must still be an existing, non-symlink regular file, and arming now refuses a symlinked template before it touches the live poll artifacts.

Fork divergences from upstream 8069

  • bin/fm-pr-lib.sh keeps its single combined fm_pr_poll_artifacts_valid (state, id, template, metadata mode) instead of upstream's split content/identity validators and device-shift helper; the port is the generation predicate inside that function.
  • Upstream's control_relaunch_tx metadata-ordering change is not ported: this fork's fm_pr_metadata_identity_parse is order-independent (fork PR 137), so relaunch metadata already parses.
  • The separate custom-check trust layer (bin/fm-check-register.sh, <id>.check-trust, bin/fm-check-lib.sh) is untouched; it governs intentional custom checks, not PR merge polls.
  • Not in upstream: fm_pr_poll_prepare rejects a symlinked template before publication, because this fork's publish-then-validate path would otherwise revoke a previously armed poll when a re-arm starts against a symlinked template.

Evidence

  • Before: the new template-update test against the pre-change head fails at the registration check.
    not ok - an intact registered generation was rejected after the template changed
    Same suite on the pre-change head, kept as private task evidence.
    After: the poll-security suite passes on the change head, including test_registered_poll_survives_template_update (open cycle keeps the poll armed, merged cycle wakes with the current repository poll) and test_altered_or_unregistered_checks_stay_refused (four cases; the watcher refuses and never queries the forge). Partner suites fm-pr-check-handoff, fm-check-unregister, and fm-landing pass in the pipeline's test step.

Merge Danger

Door: two-way. Reverting restores byte equality; no data migration and no state rewrite.

Blast Radius: every armed PR merge poll - watcher polling, landing records, todo projection, retirement, and teardown.

Remaining review findings

Finding Disposition
reject-unreadable-poll-template declined for this PR: an unreadable deployed template passes the file-type check, so merge detection would stall without a rejection wake until permissions are restored. The permitted fix round was spent on the two findings above.

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 warnings
  • ⚠️ bin/fm-pr-lib.sh:615 - A re-arm can delete an existing merge poll when the repository template is a symlink. This is uncommon, but deterministic if an operator temporarily symlinks the template and runs the normal re-arm command. Preparation follows the symlink at bin/fm-pr-lib.sh:470 and :511, publication replaces the three live artifacts at :546, :564, and :585, and the new check at :615 rejects the symlink and triggers revocation at :591. Restoring the regular template then leaves nothing for the watcher to resume. Reject symlinks in shared preparation before publication and keep the final validation check. This protects both the task re-arm at bin/fm-pr-check.sh:237 and the landing re-arm at bin/fm-landing.sh:115.
  • ⚠️ tests/fm-pr-check-security.test.sh:1586 - AC2 requires that a check that “was never registered” be refused under both template generations. Both fixture branches at tests/fm-pr-check-security.test.sh:1586 and :1590 omit the poll data sidecar as well as the registration. Every run can therefore pass at :1603 and :1615 even if the validator starts accepting valid poll data without a registration. Give both fixtures valid matching poll data and metadata, omit only the registration, and retain the watcher rejection and no-forge-call assertions. This isolates the registration requirement for the real partial-publication case.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ bin/fm-pr-lib.sh:615 - A re-arm can delete an existing merge poll when the repository template is a symlink. This is uncommon, but deterministic if an operator temporarily symlinks the template and runs the normal re-arm command. Preparation follows the symlink at bin/fm-pr-lib.sh:470 and :511, publication replaces the three live artifacts at :546, :564, and :585, and the new check at :615 rejects the symlink and triggers revocation at :591. Restoring the regular template then leaves nothing for the watcher to resume. Reject symlinks in shared preparation before publication and keep the final validation check. This protects both the task re-arm at bin/fm-pr-check.sh:237 and the landing re-arm at bin/fm-landing.sh:115.
  • ⚠️ bin/fm-pr-lib.sh:615 - After a local deployment leaves the regular poll template unreadable to the watcher account, the new file-type check accepts an intact registration. Bash then fails to open the script, and the watcher discards the error, so every poll cycle skips the forge query without a rejection wake until permissions are restored. This is uncommon but deterministic. The old comparison rejected unreadable templates. Restore the readability check in the shared validator. Round 1 added early symlink rejection at bin/fm-pr-lib.sh:470, where preparation already reads the template at :511. The shared check also covers publication at bin/fm-pr-lib.sh:591 and bin/fm-pr-check.sh:270, snapshot capture and revalidation at bin/fm-pr-lib.sh:643 and :662, stale receipt handling at :859, watcher dispatch and deferral at bin/fm-watch.sh:3307 and :3322, and the armed-poll checks at bin/fm-landing.sh:173 and bin/fm-todo-project.sh:476.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Upgrade the local watcher while a synthetic PR is open, then observe a merge wake without re-arming ✅ pass live Firstmate merge-poll CLI and watcher transcript, Base reproduction and Upgrade
Alter a synthetic PR check registered under the previous template and see the local watcher refuse it ✅ pass live Firstmate merge-poll CLI and watcher transcript, altered check from previous template generation
Alter a synthetic PR check registered under the current template and see the local watcher refuse it ✅ pass live Firstmate merge-poll CLI and watcher transcript, altered check from current template generation
Present a previous-generation synthetic PR check with valid metadata and sidecar but no registration and see the local watcher refuse it ✅ pass live Firstmate merge-poll CLI and watcher transcript, missing-registration check from previous template generation
Present a current-generation synthetic PR check with valid metadata and sidecar but no registration and see the local watcher refuse it ✅ pass live Firstmate merge-poll CLI and watcher transcript, missing-registration check from current template generation
Re-arm a synthetic task PR using a symlinked template and see the original poll resume after restoring the regular file ✅ pass live Firstmate merge-poll CLI and watcher transcript, Symlink guard for task-a
Re-arm a synthetic landing PR using a symlinked template and see the original poll resume after restoring the regular file ✅ pass live Firstmate merge-poll CLI and watcher transcript, Symlink guard for land-fixture-1-abcd1234
  • bash tests/fm-pr-check-security.test.sh
  • bash tests/fm-pr-check-handoff.test.sh
  • bash tests/fm-check-unregister.test.sh
  • bash tests/fm-landing.test.sh
  • Ran fm-pr-check.sh &lt;id&gt; https://github.com/o/r/pull/1, fm-watch.sh, and fm-wake-drain.sh in disposable copies of the base and target commits with synthetic forge responses. Captured CLI output, watcher exit statuses, forge calls, template execution, and poll-file preservation.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

dnth added 3 commits November 27, 2026 20:19
A registered poll now binds to the template generation it was armed from
through the check's own recorded hash and file identity, instead of
requiring byte equality with today's bin/fm-pr-poll.sh. Any Firstmate
update that changed the poll template used to silently disarm every
registered merge poll.

Execution is unchanged: the watcher still runs the current repository
poll with the validated sidecar data and never executes the registered
check bytes, so a poll armed under an older generation runs today's code.
The current template must still be a regular non-symlink repository file.

Ports upstream PR 8069's generation binding.
@dnth
dnth merged commit 4d2f721 into main Nov 27, 2026
21 checks passed
@dnth
dnth deleted the fm/fm-upstream-port-c-mergepoll branch November 27, 2026 13:12
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