Repository navigation
chore: update pull request - #69
Merged
Merged
Conversation
When a task with an armed PR poll is relaunched, the relaunch rewrites state/<id>.check.sh with a new inode, invalidating the existing .pr-poll-registration which binds the old dev:inode pair. The watcher then rejects the check script as unauthenticated. This commit adds fm_pr_poll_rearm() to fm-pr-lib.sh, which reads the task's pr= metadata from .meta and re-prepares/publishes fresh poll artifacts whose registration matches the new check.sh identity. It is called from fm-control.sh do_relaunch() after the replacement agent is confirmed alive, only when a .pr-poll-registration already exists. A regression test verifies: armed poll -> check.sh replaced -> poll invalid -> re-arm -> poll valid again.
Relaunching a task with fm-control.sh relaunch has been observed to leave its state/<id>.check.sh rejected by the watcher as unauthenticated (relaunch of pt-preview18-readback-release), stalling the merge watch until someone manually re-ran bin/fm-pr-check.sh <id> <url>. do_relaunch now re-arms an existing PR poll registration after a confirmed relaunch, restoring umask around the re-arm call and surfacing a warning instead of silently swallowing a failed re-arm. fm_pr_poll_rearm only republishes when the existing artifacts actually fail validation, skips entirely when a retirement receipt is present so an already-merged PR's poll is not resurrected, and never destroys a still-valid poll on a failed republish attempt. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XPmdzTCgtmvYneDHKGyBr1
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
Fix a firstmate bug: relaunching a task with fm-control.sh relaunch invalidates that task's PR merge poll registration, because the poll registration binds a dev:inode pair that the relaunch rewrites. The watcher then rejects state/.check.sh as unauthenticated and stops polling for the merge until someone manually re-runs bin/fm-pr-check.sh .
What Changed
Final changed paths and statuses:
Risk Assessment
✅ Low: A minimal, well-bounded reordering fix in two meta writers that restores the terminal-identity invariant the PR poll already depends on, covered by a behavior-asserting regression test that exercises both writers on the real relaunch path.
Testing
Baseline
bin/fm-test-run.sh --changed --exclude-family real-herdr-gatedhad already passed; I re-ran the two targeted suites (fm-control-relaunch,fm-tmux-agent-liveness) and both pass, clearing the round-1 flake. For end-user evidence I drove a realfm-control.sh relaunchon a task with a genuinely armed PR poll and captured the resulting task record and poll-validation result: with the base-commit spawn script the record ends withcontrol_relaunch_tx=/traceparent=afterpr=/pr_head=and the poll fails authentication (the reported bug), while on HEAD those keys precede the identity lines and the poll still authenticates. No UI surface is involved, so the artifact is a CLI/state transcript.Evidence: Post-relaunch task record and PR-poll validation, before vs after the fix
Source: Post-relaunch task record and PR-poll validation, before vs after the fix
AFTER FIX: ...control_relaunch_tx=, traceparent=, pr=, pr_head= -> fm_pr_poll_artifacts_valid: PASS BEFORE FIX: ...pr=, pr_head=, control_relaunch_tx=, traceparent= -> fm_pr_poll_artifacts_valid: FAILPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 5 issues found → auto-fixed (2) ✅
bin/fm-pr-lib.sh:1064- Re-arm does not fix the reported bug and destroys the poll artifacts on the real relaunch path. The actual invalidation afterfm-control.sh relaunchis not a check.sh dev:inode rewrite (nothing in fm-spawn.sh touches state/<id>.check.sh) — it is the meta rewrite: fm-spawn.sh:3059-3122 emits preserve_relaunch_meta (which carriespr=/pr_head=forward) and then appendscontrol_relaunch_tx=after them whenever SPAWN_CONTROL_PARENT=1 (always true for an fm-control relaunch, fm-spawn.sh:1151). fm_pr_metadata_identity_parse (bin/fm-pr-lib.sh:320-326) sets post_pr_invalid=1 for any non-whitelisted line afterpr=, so it returns 1, fm_pr_poll_artifacts_valid fails, and the watcher rejects the check as unauthenticated. Trace the new code with that state: rearm's gate at :1050 sees the poll as invalid, prepare succeeds, then fm_pr_poll_publish_prepared's final fm_pr_poll_artifacts_valid (fm-pr-lib.sh:574) still fails on the same bad meta, so fm_pr_poll_revoke_final deletes state/<id>.check.sh, .pr-poll and .pr-poll-registration. Result: before this change the relaunched task kept a (rejected but present) registration; after it, the poll is deleted outright, the fm-control guard[ -f $STATE/$ID.pr-poll-registration ]will never re-attempt on a later relaunch, and the merge watch is still stalled. Earliest shared boundary that makes the invariant hold: keeppr=/pr_head=last in the relaunch meta (emit control_relaunch_tx before preserve_relaunch_meta, or re-order so no non-whitelisted key follows pr=), or whitelist control_relaunch_tx= in fm_pr_metadata_identity_parse.tests/fm-pr-check-security.test.sh:1302- The regression test does not reproduce the reported failure. It fabricates the hypothesized cause by hand (mva new check.sh over state/task-a.check.sh to change its inode) instead of driving a relaunch-shaped meta rewrite, and write_poll_meta leavespr=as the last meta line — exactly the state the real fm-control relaunch does not produce. So the test passes against the actual post-relaunch state's cause never being exercised: withcontrol_relaunch_tx=appended afterpr=, fm_pr_poll_rearm would fail and revoke all artifacts, and no assertion here would notice. Add a case that starts from the meta fm-spawn actually publishes on a control-owned relaunch.bin/fm-pr-lib.sh:1055- fm_pr_poll_rearm reads the PR URL withgrep '^pr=' | tail -1(last occurrence) while the authority it must satisfy, fm_pr_metadata_identity_parse, uses the FIRST pr= line and rejects the file outright if there is more than one (fm-pr-lib.sh:300-301, :325). With a meta containing two pr= lines, rearm would republish artifacts bound to the second URL, then publish's validation fails on the first, and revoke_final wipes the poll. Read the URL through fm_pr_metadata_identity_parse (FM_PR_META_URL) instead of an independent grep so the two agree by construction.bin/fm-control.sh:869- When the task's meta has nopr=line but a stale .pr-poll-registration exists, fm_pr_poll_rearm returns 1 and every relaunch prints the 'poll registration may be gone' warning even though there was never a poll URL to restore. Distinguishing 'nothing to re-arm' from 'restore failed' (separate return code) would keep the warning meaningful.bin/fm-control.sh:864- Simplification: the umask save/restore wrapper around the call exists only because fm_pr_poll_prepare setsumask 077globally and never restores it — a leak in the callee that previously did not matter because fm-pr-check.sh is a short-lived process. No intent requirement needs the caller-side save/restore; restoring the umask inside fm_pr_poll_prepare (its own concern) removes the need for it at every future in-process call site.🔧 Fix: fix(spawn): keep pr= last in relaunch meta so poll stays armed
2 issues (1 warning, 1 info) still open:
bin/fm-spawn.sh:3271- The same failure the intent targets is still reachable through a sibling meta writer in this same script. spawn_record_traceparent (bin/fm-spawn.sh:3258-3281) rewrites state/<id>.meta asawk -F= '$1 != "traceparent"' meta > tmpfollowed byprintf 'traceparent=%s\n' >> tmp, so traceparent= always lands as the LAST line. It runs on the relaunch path (called at :3292 whenever SPAWN_TRACEPARENT is non-empty, i.e. trace context resolves on via config/trace-context or FM_TRACE_CONTEXT). Concrete sequence: task rl30 has an armed poll with pr=/pr_head= terminal;fm-control.sh relaunch rl30with trace context enabled writes a correctly ordered meta (the new ordering fix), then spawn_record_traceparent appends traceparent= after pr_head=; fm_pr_metadata_identity_parse (bin/fm-pr-lib.sh:320-322) hits the default case with seen_pr=1, sets post_pr_invalid=1 and returns 1, so fm_pr_poll_artifacts_valid fails and the watcher rejects the poll as unauthenticated — exactly the reported bug, just gated behind trace context being on. The new regression test does not enable trace context, so it passes with this hole open. Smallest honest remedy inside the existing writer: have spawn_record_traceparent insert traceparent= before the pr=/pr_head= identity lines (e.g. emit non-pr lines, then traceparent=, then the carried pr lines) so the terminal-identity invariant is enforced by every meta writer, and extend the new test with a trace-context-enabled relaunch case.bin/fm-captain-hold.sh:1114- Same invariant, different writer, outside this change's scope: fm-captain-hold.sh appendsdecisions_reviewed=1anddecision_keys=to a task meta with>>, which would land after pr=/pr_head= for a task that also has an armed PR poll and silently de-authenticate it. Not introduced by this change and not required for the stated intent; noting it because the terminal-identity invariant now has at least three independent writers and no shared enforcement point.🔧 Fix: fix(spawn): keep pr= last when recording traceparent
✅ Re-checked - no issues remain.
🔧 **Test** - 1 issue found → auto-fixed ✅
bin/fm-test-run.sh --changed --exclude-family real-herdr-gated🔧 Fix: test(tmux): use argv0-independent spinner for liveness stand-ins
✅ Re-checked - no issues remain.
bin/fm-test-run.sh --changed --exclude-family real-herdr-gatedbash tests/fm-control-relaunch.test.sh(includes newtest_relaunch_keeps_the_pr_poll_authenticated, trace context enabled) — all passbash tests/fm-tmux-agent-liveness.test.sh— passes clean, confirming the round-1 failure was a flake unrelated to this changeFail-before/pass-after: re-ran the same relaunch scenario with base-commitbin/fm-spawn.shrestored —not ok - the relaunch invalidated the task's PR merge poll; restored the fixed file and the worktree afterwards (git statusclean)Manual evidence capture: dumpedstate/rl30.metaand the.check.sh/.pr-poll/.pr-poll-registrationartifacts plusfm_pr_poll_artifacts_validresult after a realfm-control.sh relaunchin both configurations✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.