Repository navigation
fix(bin): keep PR poll valid after a worker relaunch - #138
Merged
Merged
Conversation
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.
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
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 appendscontrol_relaunch_tx=to the end ofstate/<id>.meta.fm_pr_metadata_identity_parseinbin/fm-pr-lib.shaccepts onlypr_head=,pr_at=andx_*lines afterpr=; any other later line setspost_pr_invalid, sofm_pr_poll_artifacts_validfails and the watcher refuses the PR poll withcheck: 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 abovepr=.What Changed
bin/fm-spawn.shnow writescontrol_relaunch_tx=before the preserved relaunch metadata, so the PR identity block (pr=,pr_head=,pr_at=) stays at the end ofstate/<id>.meta. Before this, a relaunch put the tx line afterpr=,fm_pr_metadata_identity_parsemarked the PR identity invalid, and the watcher stopped polling that PR.spawn_record_traceparentandspawn_record_polytoken_sessionnow add their freshtraceparent=/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 afterpr=.test_relaunch_preserves_registered_pr_polltotests/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 afterpr=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.shwas 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-fixfm-spawn.shswapped in, the same regression failed. Dumps of the meta record show the cause: before the fix,control_relaunch_txandtraceparentland afterpr=and the watcher's PR poll check (fm_pr_poll_snapshot_capture) rejects it. After the fix,pr/pr_head/pr_atare the last lines and the check passes for both a Claude relaunch and a switch to Codex. These checks ran the realfm-control.sh relaunchandfm-spawn.shagainst 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.Evidence: Meta record + watcher validation after fix (Claude and Codex relaunch: ACCEPTED)
Source: Meta record + watcher validation after fix (Claude and Codex relaunch: ACCEPTED)
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)
Evidence: Targeted relaunch cases on the fix
Source: Targeted relaunch cases on the fix
Evidence: Regression failing before fix
Source: Regression failing before fix
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.
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_TESTBaseline configured test command (classifier local_scripts, incl. tests/fm-polytoken-harness.test.sh) — already passedbash 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 okSame regression with basegit show f4f20006:bin/fm-spawn.shswapped in — fails as expected, file restored withgit checkout -- bin/fm-spawn.shInstrumented regression dumping state/rl-pr.meta and the watcher'sfm_pr_poll_snapshot_captureverdict after each relaunch, before and after the fix✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.