Repository navigation
fix: preserve merge polls across task metadata updates - #1
Merged
Merged
Conversation
A task record's PR identity block - its single `pr=` line and any
`pr_head=` line - must stay terminal: fm_pr_metadata_identity_parse
refuses every other key that follows it, which is what makes an append
to a record whose merge poll is already armed evident rather than
silent.
Four writers broke that invariant by appending their own key last, so a
task that had recorded a PR lost merge detection entirely: the poll
stopped validating, fm-watch.sh reclassified it as an unregistered
check, and every check interval woke firstmate with a rejection instead
of polling for the merge. Both symptoms read as noise.
OPTION C, with one owner rather than four writers remembering.
Option B - relaxing the parse to ignore unknown keys after `pr=` - is
refused. The ordering rule is the only structural check the record
carries: unlike the sidecar and the poll source, a record must stay
mutable across a relaunch and so cannot be bound by hash. Option A -
asking each writer to keep the block last - is what already failed;
four writers forgot, and the parse's existing `x_*` exception shows the
same invariant being retrofitted one key at a time. A blast radius of
four argues against per-writer discipline, not for it. So the strict
parse is kept byte-for-byte and the discipline moves into a single
helper the writers call.
bin/fm-pr-lib.sh, which owns the contract, gains
fm_pr_meta_terminal_restage: it moves the identity block back to the end
of a staged record and changes nothing else. Each writer calls it before
publishing:
- bin/fm-spawn.sh writes `control_relaunch_tx=` after carrying the
previous record forward on a relaunch (the proven case, reached
through `bin/fm-control.sh <id> relaunch`)
- bin/fm-spawn.sh appends `traceparent=` when recording a carrier
- bin/fm-captain-hold.sh appended `decisions_reviewed=` and
`decision_keys=` when attesting a reviewed inventory; that raw
in-place append is now a staged rewrite renamed under the meta lock
the command already holds, preserving the record's mode
- bin/fm-promote.sh writes `kind=`/`mode=`/`yolo=` last
The writer set is closed, established by enumerating every path that can
make a file become `state/<id>.meta`: direct redirection, mv/cp, and
`fm_backlog_atomic_transition publish`. The remainder are accounted for
rather than assumed: bin/fm-pr-check.sh builds the block last by
construction; bin/fm-x-lib.sh appends only `x_*` keys, which the parse
already tolerates in any position; and bin/fm-spawn.sh's remote
secondmate record carries no PR.
Nothing about what the merge poll trusts changes: the parse, the sidecar
and poll-source hash and identity bindings, and the check registration
model are all untouched.
Regressions fail without the fix: a relaunch, a relaunch that records a
carrier, a promotion, and a completion attestation each leave an armed
merge poll recognisable by the watcher's own snapshot capture, plus a
direct test that the restage only moves lines.
The earlier claim that nothing about what the merge poll trusts changes was over-strong. The task-record writers now validate the record as it exists on disk before contributing any metadata, and terminal restaging validates that source again before moving lines. A record is refused when any key after pr= is neither pr_head= nor a tolerated x_* key. Refusal leaves the anomalous record unnormalised and emits a visible error naming the offending key or keys at relaunch, trace recording, promotion, and completion attestation. The poll still does not authenticate every mutable task-record field or bind the complete record by hash. Its strict parser remains the structural boundary for trailing metadata, while the existing sidecar, poll-source hashes, identity bindings, and check registration remain unchanged.
The earlier x_* wording was over-broad. Terminal validation now accepts after pr= only pr_head plus x_request, x_request_ts, x_followups, x_platform, and x_reply_max_chars, exactly matching the unchanged parser. Any other x_-prefixed key is refused, left unnormalised, and named in the visible error before a writer contributes metadata. bin/fm-x-lib.sh writes exactly those five relay keys, so it remains outside the invalid-suffix writer set and needs no change. The validator and parser still encode the five-name list separately, so drift could silently reopen this defect. A later change could give both functions one shared predicate, or add behavioral equivalence coverage for the five accepted names and an unknown control; a source-grep comparison would violate the repository test contract. This coupling is recorded but intentionally not expanded in this fix.
This was referenced Sep 25, 2026
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.
Lands the merge-poll fix into this fork so it takes effect locally without waiting on upstream.
Same commits as the upstream contribution at kunchenguid#3452, which remains open and unaffected. Upstream review there was favourable: full-diff review, attestation match, security clean, and all 14 checks green.
Merges cleanly into this fork's main - verified with a test merge, no conflicts.
Authorized by the captain 2026-09-01.