Skip to content

fix(bin): keep PR poll valid after a worker relaunch - #138

Merged
max-metaplanet merged 2 commits into
mainfrom
fm/relaunch-pr-poll
Oct 20, 2026
Merged

max-metaplanet merged 2 commits into
mainfrom
fm/relaunch-pr-poll

Conversation

@max-metaplanet

Copy link
Copy Markdown
Owner

Intent

Dispatch the fix now, high priority: it breaks merge monitoring for every auto-resumed worker. Use poteto mode, with a regression test that a relaunch of a worker with a recorded PR keeps its PR monitoring. Merge green under the fork rule.

Context (diagnosis from this home, 2026-10-20): the parked-worker auto-resume added in #136 relaunches a worker through bin/fm-control.sh relaunch, which appends control_relaunch_tx= to the end of state/<id>.meta. fm_pr_metadata_identity_parse in bin/fm-pr-lib.sh accepts only pr_head=, pr_at= and x_* lines after pr=; any other later line sets post_pr_invalid, so fm_pr_poll_artifacts_valid fails and the watcher refuses the PR poll with check: rejected unauthenticated state checks: state/<id>.check.sh. Merge detection for that PR then stops. Observed on task up-run-inventory (PR kunchenguid#7363) after an automatic resume for "checks failed"; tasks whose relaunch preceded PR registration are unaffected because their tx line sits above pr=.

What Changed

  • bin/fm-spawn.sh now writes control_relaunch_tx= before the preserved relaunch metadata, so the PR identity block (pr=, pr_head=, pr_at=) stays at the end of state/<id>.meta. Before this, a relaunch put the tx line after pr=, fm_pr_metadata_identity_parse marked the PR identity invalid, and the watcher stopped polling that PR.
  • spawn_record_traceparent and spawn_record_polytoken_session now add their fresh traceparent= / polytoken_* lines at the start of the metadata file instead of the end. They still drop any older copies of those lines first, and no longer push fields after pr=.
  • Added test_relaunch_preserves_registered_pr_poll to tests/fm-control-relaunch.test.sh. It registers a PR poll, relaunches the worker onto claude and then codex, and checks after each relaunch that the tx marker and traceparent were published and the original PR poll artifacts still match and still validate. It then appends an unknown field after pr= and checks that the poll is rejected.

Risk Assessment

✅ Low: The fix only reorders writes in fm-spawn.sh. On relaunch it now writes the header and control_relaunch_tx before the preserved metadata block, and traceparent and the polytoken binding are now prepended. As a result pr=, pr_head=, pr_at= and x_* stay the final suffix of the record, which is the order fm_pr_metadata_identity_parse requires. The parser still rejects unknown fields after pr=, and no reader relies on line position. The regression test runs a real relaunch twice, on Claude and then on Codex, and checks the result with the real PR-poll validation functions.

Testing

The baseline selector suites had already passed. The new regression in tests/fm-control-relaunch.test.sh was deferred to CI, so I ran it locally from a filtered copy together with five nearby relaunch/metadata cases; all passed in about 30 seconds. With the pre-fix fm-spawn.sh swapped in, the same regression failed. Dumps of the meta record show the cause: before the fix, control_relaunch_tx and traceparent land after pr= and the watcher's PR poll check (fm_pr_poll_snapshot_capture) rejects it. After the fix, pr/pr_head/pr_at are the last lines and the check passes for both a Claude relaunch and a switch to Codex. These checks ran the real fm-control.sh relaunch and fm-spawn.sh against a throwaway home with the agent session stubbed. I did not run a live lab relaunch with a real Claude agent, because the change only alters record ordering and the plan's standing rule keeps Herdr suites and broad suites out of local Test. The full relaunch, trace-context-spawn and control suites are deferred to CI, which must be green before merge. I removed the temporary filtered test file and the worktree is clean.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Relaunching a worker with a registered PR (fm-control relaunch, same harness) keeps pr=/pr_head=/pr_at= as the final suffix and the watcher's PR poll validation accepts it ✅ pass live meta-ordering-after-fix.log; relaunch-targeted-after.log
Relaunching the same PR worker onto a different harness (claude -> codex) keeps PR monitoring valid and the original poll artifacts intact ✅ pass live meta-ordering-after-fix.log (codex section)
Regression reproduces on pre-fix code: control_relaunch_tx/traceparent appended after pr= make the watcher reject the poll ✅ pass live meta-ordering-before-fix.log; regression-before-fix.log
Adversarial: an unknown line appended after pr= still invalidates the PR poll (the guard is not weakened) ✅ pass live relaunch-targeted-after.log (final assertion of test_relaunch_preserves_registered_pr_poll)
Other relaunch metadata writers stay correct: durable metadata kept, concurrent publication serialized, traceparent cleared when tracing is disabled, harness switch clears old wiring ✅ pass live relaunch-targeted-after.log
Evidence: Meta record + watcher validation after fix (Claude and Codex relaunch: ACCEPTED)

Source: Meta record + watcher validation after fix (Claude and Codex relaunch: ACCEPTED)

--- state/rl-pr.meta after relaunch onto claude ---
traceparent=00-a7a2ee8299984599f1b3736ef673b498-e7240ea7ec4ef5d4-01
window=fmses:fm-rl-pr
endpoint_task_id=rl-pr
worktree=~/.no-mistakes/worktrees/61c6dd39b831/.fm-test-scratch/fm-control-relaunch.MUXpJs/pr-poll-26032/wt
project=~/.no-mistakes/worktrees/61c6dd39b831/.fm-test-scratch/fm-control-relaunch.MUXpJs/pr-poll-26032/proj
harness=claude
kind=ship
mode=no-mistakes
yolo=off
branch=fm/rl-pr
tasktmp=/tmp/fm-rl-pr
model=default
effort=default
busy_gen=g1792511527.66446.2439
spawn_gen=s1792511528.64917.4998
control_relaunch_tx=63899.20261020T155206Z.12433
pr=https://github.com/example/repo/pull/19
pr_head=1111111111111111111111111111111111111111
pr_at=100
watcher PR poll validation: ACCEPTED
--- state/rl-pr.meta after relaunch onto codex ---
traceparent=00-a7a2ee8299984599f1b3736ef673b498-e7240ea7ec4ef5d4-01
window=fmses:fm-rl-pr
endpoint_task_id=rl-pr
worktree=~/.no-mistakes/worktrees/61c6dd39b831/.fm-test-scratch/fm-control-relaunch.MUXpJs/pr-poll-26032/wt
project=~/.no-mistakes/worktrees/61c6dd39b831/.fm-test-scratch/fm-control-relaunch.MUXpJs/pr-poll-26032/proj
harness=codex
kind=ship
mode=no-mistakes
yolo=off
branch=fm/rl-pr
tasktmp=/tmp/fm-rl-pr
model=default
effort=default
spawn_gen=s1792511532.69496.8946
control_relaunch_tx=68858.20261020T155211Z.1903
pr=https://github.com/example/repo/pull/19
pr_head=1111111111111111111111111111111111111111
pr_at=100
watcher PR poll validation: ACCEPTED
ok - fm-control relaunch: registered PR monitoring survives repeated and switched-harness relaunches
Evidence: Meta record + watcher validation with pre-fix fm-spawn.sh (tx/traceparent after pr=: REJECTED)

Source: Meta record + watcher validation with pre-fix fm-spawn.sh (tx/traceparent after pr=: REJECTED)

--- state/rl-pr.meta after relaunch onto claude ---
window=fmses:fm-rl-pr
endpoint_task_id=rl-pr
worktree=~/.no-mistakes/worktrees/61c6dd39b831/.fm-test-scratch/fm-control-relaunch.k58sDZ/pr-poll-24082/wt
project=~/.no-mistakes/worktrees/61c6dd39b831/.fm-test-scratch/fm-control-relaunch.k58sDZ/pr-poll-24082/proj
harness=claude
kind=ship
mode=no-mistakes
yolo=off
branch=fm/rl-pr
tasktmp=/tmp/fm-rl-pr
model=default
effort=default
busy_gen=g1792511537.74116.26190
spawn_gen=s1792511538.73189.5126
pr=https://github.com/example/repo/pull/19
pr_head=1111111111111111111111111111111111111111
pr_at=100
control_relaunch_tx=72459.20261020T155216Z.24869
traceparent=00-abf0357f03c9d988f4756cf0139269e4-b41c3d2aae240163-01
watcher PR poll validation: REJECTED (watcher would report: check: rejected unauthenticated state checks)
not ok - the original PR poll artifacts must survive relaunch onto claude
Evidence: Targeted relaunch cases on the fix

Source: Targeted relaunch cases on the fix

ok - fm-control relaunch: registered PR monitoring survives repeated and switched-harness relaunches
ok - fm-control relaunch: a same-harness relaunch replaces the agent in the same endpoint and worktree
ok - fm-control relaunch: durable task metadata survives replacement launch publication
ok - fm-control relaunch: delivery and concurrent task metadata publication serialize
ok - fm-control relaunch: disabling tracing clears metadata and pane context
ok - fm-control relaunch: switching harness is one ordinary relaunch, and the old wiring goes with the old agent
bash tests/zz-filtered-relaunch.test.sh  7.79s user 10.15s system 58% cpu 30.749 total
Evidence: Regression failing before fix

Source: Regression failing before fix

not ok - the original PR poll artifacts must survive relaunch onto claude

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Relaunching a worker with a registered PR (fm-control relaunch, same harness) keeps pr=/pr_head=/pr_at= as the final suffix and the watcher's PR poll validation accepts it ✅ pass live meta-ordering-after-fix.log; relaunch-targeted-after.log
Relaunching the same PR worker onto a different harness (claude -> codex) keeps PR monitoring valid and the original poll artifacts intact ✅ pass live meta-ordering-after-fix.log (codex section)
Regression reproduces on pre-fix code: control_relaunch_tx/traceparent appended after pr= make the watcher reject the poll ✅ pass live meta-ordering-before-fix.log; regression-before-fix.log
Adversarial: an unknown line appended after pr= still invalidates the PR poll (the guard is not weakened) ✅ pass live relaunch-targeted-after.log (final assertion of test_relaunch_preserves_registered_pr_poll)
Other relaunch metadata writers stay correct: durable metadata kept, concurrent publication serialized, traceparent cleared when tracing is disabled, harness switch clears old wiring ✅ pass live relaunch-targeted-after.log
  • bash <<'NM_TEST' set -euf scope=$(FM_CI_EVENT=pull_request FM_CI_BASE_SHA=origin/main bash bin/fm-ci-change-scope.sh --local) printf '%s\n' "$scope" selected=$(printf '%s\n' "$scope" | sed -n 's/^local_scripts=//p') budget=$(printf '%s\n' "$scope" | sed -n 's/^local_budget_ms=//p') deferred=$(printf '%s\n' "$scope" | sed -n 's/^local_deferred=//p') if [ -n "$deferred" ]; then printf "Left to CI's required lanes (CI gate): %s\n" "$deferred" fi [ -n "$selected" ] || { printf '%s\n' 'selector returned no tests' >&2; exit 1; } case "$budget" in ''|[!0-9]) printf '%s\n' 'selector returned invalid budget' >&2; exit 1 ;; esac [ "$budget" -ge 1000 ] || exit 1 # The selector emits repository-owned test paths without whitespace. # Globbing is disabled above; split only its space/newline-delimited path list. # shellcheck disable=SC2086 set -- $selected . bin/fm-timeout-lib.sh # CI duration hints bound coverage; allow loaded local execution more time. fm_exec_timed "$((budget * 3 / 1000))" 5 bash bin/fm-test-run.sh --per-script-timeout-secs 1500 "$@" NM_TEST
  • Baseline configured test command (classifier local_scripts, incl. tests/fm-polytoken-harness.test.sh) — already passed
  • bash tests/zz-filtered-relaunch.test.sh (temporary filtered copy of tests/fm-control-relaunch.test.sh: test_relaunch_preserves_registered_pr_poll, test_same_harness_relaunch_keeps_identity_and_reuses_the_endpoint, test_relaunch_preserves_durable_task_metadata, test_relaunch_serializes_concurrent_durable_metadata_publication, test_disabled_relaunch_clears_prior_trace_context, test_harness_switch_moves_the_record_and_clears_prior_wiring) on the fix — all ok
  • Same regression with base git show f4f20006:bin/fm-spawn.sh swapped in — fails as expected, file restored with git checkout -- bin/fm-spawn.sh
  • Instrumented regression dumping state/rl-pr.meta and the watcher's fm_pr_poll_snapshot_capture verdict after each relaunch, before and after the fix
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Write lifecycle fields before preserved task metadata so registered PR polls stay authenticated after relaunch. Apply the same ordering to trace and Polytoken session publication, which can also run after PR registration.

Keep the PR identity parser unchanged rather than expanding its allowlist. Unknown and identity-bearing suffix lines retain their existing rejection behavior.
@max-metaplanet
max-metaplanet merged commit b203543 into main Oct 20, 2026
22 of 23 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