fix(bin): refuse teardown while a task's recorded PR is still open - #2408
Closed
joliverMI wants to merge 1 commit into
Closed
fix(bin): refuse teardown while a task's recorded PR is still open#2408joliverMI wants to merge 1 commit into
joliverMI wants to merge 1 commit into
Conversation
Tearing down a task deletes state/<id>.meta, the record bin/fm-pr-merge.sh resolves the PR through. A branch can be fully pushed and reachable from a remote (so the existing dirty/unpushed/landed checks find nothing to refuse) while its own PR still sits open, stranding a mergeable PR with no guarded path to land it - this happened twice in one night. The new check runs after the existing dirty/unpushed/landed checks inside validate_worktree_teardown_safety, so their refusal messages take precedence and never contradict this one. It fires only when a pr= is actually recorded (scout, local-only, and secondmate teardowns never record one). A gh lookup error refuses loudly too, naming the PR firstmate could not confirm, rather than tearing down blind. --force already skips the dirty/landed checks and now explicitly skips this one too, since it is the same "captain says discard" escape hatch - the usage comment spells out what that means here (the PR needs merging or closing by hand, outside fm-pr-merge.sh's guarded path).
Author
|
Withdrawn: this belongs on our own fork rather than upstream. Re-opened against joliverMI/firstmate. |
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.
Summary
Tearing down a task deletes
state/<id>.meta, which is whatbin/fm-pr-merge.shresolves the task's PR through. Two incidents an hour apart showed that a task can be torn down while its PR is still open, stranding a proven, mergeable PR with no guarded path to land it.The existing landed-work check in
validate_worktree_teardown_safetyonly inspects local git state (dirty, unpushed, or unreachable-but-landed commits). A branch that is fully pushed and reachable from a remote-tracking branch passes that check cleanly even while its own PR is still open - exactly what happened tonight.What changed
pr_open_state()next topr_is_merged()inbin/fm-teardown.sh, reusing the samegh pr view --json state,headRefOidquery shape so both share one call pattern (and existing test stubs).validate_worktree_teardown_safety, gated on a non-empty recordedpr=, so it never runs for scout/local-only/secondmate teardowns (none of which ever record one).Decisions
--force: covers this check too, explicitly documented in the header and usage comment (not incidental - it falls out of the same[ "$FORCE" != "--force" ] || return 0early return the existing checks already use).--forcealready means "the captain explicitly authorized discarding this," and bypassing the open-PR guard means accepting the PR now needs to be merged or closed by hand, outsidefm-pr-merge.sh's guarded path.fm-pr-merge.sh(once green and authorized) or close the PR on GitHub, then retry teardown.Test plan
bin/fm-lint.sh bin/fm-teardown.sh tests/fm-teardown.test.sh- clean (ShellCheck 0.11.0)bash tests/fm-teardown.test.sh- all 62 cases pass, including 4 new ones covering: open PR refuses,--forceoverrides, gh lookup error refuses (fail-safe), and confirmed-closed PR does not blockbash tests/fm-teardown-endpoint-safety.test.sh- all 7 cases still pass (no regression)test_teardown_prompts_tasks_axi_done_when_compatible,test_teardown_manual_backend_prompts_hand_edit_even_when_tasks_axi_present) that incidentally recorded apr=without caring about its state; they now pin it to a confirmed-closed stub so they stay decoupled from this new check