Repository navigation
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.
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified in the changed metadata-restaging paths. The shared helper preserves the strict trailing-metadata boundary, the updated writers serialize and stage their changes, and focused regressions cover the previously failing merge-poll scenarios. Reviews (1): Last reviewed commit: "no-mistakes(document): Clarify terminal ..." | Re-trigger Greptile |
|
Speaking as Kun's firstmate: first-time fork CI approved after a full-thread + full-diff review (no Inspected HEAD Contract-class: restore. Unconfigured fleet already promised that an armed merge poll stays recognizable after relaunch / metadata updates; main writers were appending after VISION.md per-rule
This wait is on CI (blocking no-mistakes), not the author or the captain. |
Intent
Fix a silent failure in firstmate's own tooling: relaunching a task disarms its merge poll.
THE DEFECT (reproduced and isolated 2026-08-31).
bin/fm-control.sh <id> relaunchappendscontrol_relaunch_tx=to the END ofstate/<id>.meta. When that task already has a PR recorded, the new key lands AFTER thepr=line.fm_pr_metadata_identity_parseinbin/fm-pr-lib.shtolerates onlypr_head=and thex_*keys afterpr=; any other key setspost_pr_invalid=1and the parse returns 1. That propagates throughfm_pr_poll_artifacts_valid->fm_pr_poll_snapshot_capture->bin/fm-watch.sh, which then classifies the task's merge poll as an unregistered check and emitscheck: rejected unauthenticated state checks: state/<id>.check.shon every check interval WITHOUT ever executing the poll.CONSEQUENCE. Merge detection is silently OFF for any task relaunched after its PR was recorded, and firstmate is woken repeatedly by a rejection instead. Both symptoms read as noise.
EVIDENCE. Observed on task focal-year-quarter. Its meta ended
pr=/pr_head=/control_relaunch_tx=. Every other binding validated cleanly - 0600 modes, single links, template byte-match againstbin/fm-pr-poll.sh, data hash, registration hashes, device:inode identities - and bisecting the gates infm_pr_poll_artifacts_validisolated the failure tofm_pr_metadata_identity_parsealone. Re-runningbin/fm-pr-check.shre-appendedpr=/pr_head=last and the poll validated again. That was a workaround applied to that task, not the fix.THE DECISION REQUIRED. Read the header of
bin/fm-pr-lib.shand understand WHY the trailing-key rule exists before touching it. It is a tamper-evidence boundary; do not simply delete or weaken the check because it is in the way. Choose deliberately between: (A) make every meta writer keeppr=/pr_head=last - fragile, each future writer must remember; (B) relax the parser to ignore unknown keys afterpr=- simplest, but forfeits whatever the strict ordering was buying, and only acceptable if ordering can be shown never to have been load-bearing; (C) keep the strict parse and have relaunch, and any other writer, rewrite meta so the PR identity block stays terminal. State the choice and the reasoning in the PR. If the evidence points somewhere none of these cover, say so and follow the evidence.CHOICE MADE: OPTION C, with one owner rather than four writers remembering. Option B was refused: the ordering rule is the only structural check the record carries, because unlike the sidecar and the poll source, a task record must stay mutable across a relaunch and so cannot be bound by hash. Option A 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) gainsfm_pr_meta_terminal_restage, which moves the identity block back to the end of a staged record and changes nothing else.REQUIRED SCOPE, all three satisfied. (1) Audit every writer of
state/<id>.metainbin/for the same pattern -fm-control.shwas the one PROVEN to append afterpr=; establish whether it is alone rather than assuming it. The writer set was established as closed by enumerating every path that can make a file becomestate/<id>.meta: direct redirection, mv/cp, andfm_backlog_atomic_transition publish. Four writers broke the invariant and now call the helper:bin/fm-spawn.shwritingcontrol_relaunch_tx=on a relaunch (the proven case, reached throughbin/fm-control.sh <id> relaunch);bin/fm-spawn.shappendingtraceparent=when recording a carrier;bin/fm-captain-hold.shappendingdecisions_reviewed=/decision_keys=when attesting a reviewed inventory, whose raw in-place append became a staged rewrite renamed under the meta lock the command already holds, preserving the record's mode; andbin/fm-promote.shwritingkind=/mode=/yolo=last. The remainder are accounted for rather than assumed:bin/fm-pr-check.shbuilds the block last by construction,bin/fm-x-lib.shappends onlyx_*keys which the parse already tolerates in any position, andbin/fm-spawn.sh's remote secondmate record carries no PR. (2) Regression coverage is mandatory: a relaunch on a task with a recorded PR must leave the merge poll validating, and the test must fail without the fix. Regressions cover a relaunch, a relaunch that records a carrier, a promotion, and a completion attestation, each asserting an armed merge poll stays recognisable by the watcher's own snapshot capture, plus a direct test that the restage only moves lines. (3) Do not change the merge-poll security model as a side effect; if the fix touches what the poll trusts, say so explicitly and justify it.TRUST BOUNDARY, stated explicitly per (3) and corrected during review. An initial claim that nothing about what the merge poll trusts changes was over-strong and was corrected. 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 neitherpr_head=nor a toleratedx_*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.A later correction narrowed over-broad
x_*wording: terminal validation accepts afterpr=onlypr_headplusx_request,x_request_ts,x_followups,x_platform, andx_reply_max_chars, exactly matching the unchanged parser. Any otherx_-prefixed key is refused, left unnormalised, and named in the visible error before a writer contributes metadata.bin/fm-x-lib.shwrites exactly those five relay keys, so it remains outside the invalid-suffix writer set and needs no change. A known and deliberately unexpanded coupling is recorded: 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, but a source-grep comparison would violate the repository test contract.OUT OF SCOPE, accepted constraints. Do not refactor the wider PR-poll or watcher machinery. Do not change teardown, spawn, or the check-registration model.
ACCEPTANCE. A task that has a PR recorded and is then relaunched still has a valid merge poll; the rejection wake no longer fires for that case; the tamper-evidence property the original check provided is either preserved or its removal is explicitly argued and accepted in the PR.
REPOSITORY CONSTRAINTS. This is firstmate's shared tracked material under
bin/, governed by thefirstmate-coding-guidelinesskill: one sentence per line, plain dash, shellcheck-clean bin scripts, colocated tests, no agent co-author, and the one-owner rule for contracts.HISTORY CONSTRAINT accepted during this work: do not rewrite history. Carry corrections in later commits and in the PR body, never by rewriting an ancestor. This is why the trust-boundary and
x_*corrections above appear as follow-up commits rather than amendments.What Changed
Risk Assessment
✅ Low: The change is well-bounded, preserves the strict parser boundary, validates live metadata before all four writer paths, and the latest restaging fix correctly preserves pre-PR pr_head lines without introducing a substantiated reachable defect.
Testing
Focused behavioral suites exercised relaunch, trace recording, promotion, completion attestation, terminal restaging, parser enforcement, and watcher snapshot recognition; they demonstrated that armed merge polls remain recognized, invalid suffixes are visibly named and preserved, and the pre-PR
pr_headregression is fixed, with all checks passing and CLI transcripts captured.Evidence: Relaunch, trace-recording, and promotion behavioral transcript
Source: Relaunch, trace-recording, and promotion behavioral transcript
Evidence: Completion-attestation behavioral transcript
Source: Completion-attestation behavioral transcript
Evidence: PR identity restaging and watcher-security transcript
Source: PR identity restaging and watcher-security transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
bin/fm-pr-lib.sh:340- Restaging moves everypr_head=line afterpr=, including one that originally preceded it and was therefore ignored by the unchanged parser. Concrete path:pr_head=not-a-shafollowed by a validpr=produces a valid armed-poll snapshot; relaunch validation accepts it, then restaging moves the invalid head afterpr=, where parsing rejects it and the writer disarms the poll. Only treatpr_head=encountered after the firstpr=as part of the terminal identity block, preserving earlier lines in place, and add a behavioral regression for this sequence.🔧 Fix: Preserve pre-PR heads during metadata restaging
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
Inspectedgit diff a5f3cbeeb71768bca2ac54c6926d314b6d27b836..2f7f4ba3ae1accb7d137a246f1e9af5b08b91d01to map changed behavior to focused tests.bash tests/fm-control-relaunch.test.sh 2>&1 | tee ~/.no-mistakes/evidence/01M1EKFNQB0VQE30YVB5A9RKD3/fm-control-relaunch-transcript.txtbash tests/fm-captain-hold-lifecycle.test.sh 2>&1 | tee ~/.no-mistakes/evidence/01M1EKFNQB0VQE30YVB5A9RKD3/fm-captain-hold-lifecycle-transcript.txtbash tests/fm-pr-check-security.test.sh 2>&1 | tee ~/.no-mistakes/evidence/01M1EKFNQB0VQE30YVB5A9RKD3/fm-pr-check-security-transcript.txtVerifiedgit status --shortwas empty after testing.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.