Skip to content

fix(bin): allow attended merges for cleaned-up GitHub PRs - #70

Merged
peterOC26 merged 3 commits into
mainfrom
fm/fm-merge-closed-task-pr-m1
Nov 20, 2026
Merged

peterOC26 merged 3 commits into
mainfrom
fm/fm-merge-closed-task-pr-m1

Conversation

@peterOC26

@peterOC26 peterOC26 commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Intent

Q2244 ALL (2026-11-18, main chat): "q2244 all. feel free to do whatever you think is the good idea amd is safe" - use the Claude allowance before its reset on three Claude-only jobs.
This job is part of option C: build this held Firstmate fix now, with Claude writing the code.
bin/fm-pr-merge.sh cannot merge a PR whose job was already closed and cleaned up: on 2026-10-31 the captain approved merging docs-only PR https://github.com/peterOC26/PurpleVoice_GSD_Claude/pull/239, but the merge script refused with "task metadata is unavailable" because job pv-sydney-trial-run-r2 had been cleaned up first. There is no guarded path for a PR that outlived its job.

What Changed

  • Add --closed-task for attended GitHub PR merges after task cleanup, requiring an expected head and preserving the merge, captain-hold, away-posture, and queue safeguards.
  • Skip task metadata and merge-poll recording for this path while reporting confirmed merges to supervision.
  • Document the flow and add coverage for successful merges and refusal conditions.

Risk Assessment

✅ Low: The new --closed-task path is narrow and only adds checks: it works only for attended GitHub merges and needs a pinned approved head. It refuses when the task record still exists, when a merge queue may be in play, when the away-posture record exists, and with --attended-override, --update-branch or --auto (that last one through reject_protected_forge_args). It skips only the code that reads and writes the task record, and it still applies the live green, mergeable and captain-hold guards.

Testing

The focused closed-task regression selectors passed. The final live run used the real merge script and gh with synthetic PR data on localhost: the stale head was refused, and the approved head merged with a supervision outcome and no recreated task metadata or poll. The emulator response was adjusted to match the CLI’s GraphQL contract before the final run; git diff --check was clean.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
Merge synthetic green GitHub PR kunchenguid#239 with --closed-task after task cleanup; the CLI verifies the merge and records its supervision outcome without recreating task metadata or a poll. ✅ pass live Live merge through real GitHub CLI and localhost API emulator
Supply a stale approved head for synthetic GitHub PR kunchenguid#239 with --closed-task; the script refuses and sends no merge mutation. ✅ pass live Live merge through real GitHub CLI and localhost API emulator
Evidence: Live merge through real GitHub CLI and localhost API emulator

Source: Live merge through real GitHub CLI and localhost API emulator

Live local scenario: real /usr/bin/gh and synthetic GitHub API over localhost-only HTTPS proxy
Synthetic PR #239; approved head: c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1 ; check ci=SUCCESS; branch rules: none

Stale-head refusal exit: 1
Stale-head response: error: refusing to merge https://github.com/example/repo/pull/239
  - the live head is "c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1", not the expected head c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2
Merge mutations before refusal: 0

Approved-head merge exit: 0
CLI response: verified: https://github.com/example/repo/pull/239 is merged (state=MERGED, merged=true, isInMergeQueue=false)
verified: https://github.com/example/repo/pull/239 is open and mergeable, with every unwaived required check reported and every unwaived check green at head c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1
Persisted supervision row: 1795158121	1	check	merged-task-x1-https://github.com/example/repo/pull/239	check: merge landed: task-x1 https://github.com/example/repo/pull/239
Local API merge mutation:
  POST /graphql -> 200 GraphQL merge mutation
Task metadata recreated: False
Merge poll armed: False
API requests:
  CONNECT api.github.com:443 -> localhost emulator
  POST /graphql -> 200 GraphQL PR read
  CONNECT api.github.com:443 -> localhost emulator
  GET /repos/example/repo/branches/main -> 200 branch protection
  CONNECT api.github.com:443 -> localhost emulator
  GET /repos/example/repo/rules/branches/main?per_page=100 -> 200 no queue or required rules
  CONNECT api.github.com:443 -> localhost emulator
  GET /repos/example/repo/rules/branches/main?per_page=100 -> 200 no queue or required rules
  CONNECT api.github.com:443 -> localhost emulator
  CONNECT api.github.com:443 -> localhost emulator
  POST /graphql -> 200 WorkflowRun introspection
  POST /graphql -> 200 PR merge preflight introspection
  CONNECT api.github.com:443 -> localhost emulator
  POST /graphql -> 200 GraphQL PR read
  CONNECT api.github.com:443 -> localhost emulator
  POST /graphql -> 200 GraphQL merge mutation
  CONNECT api.github.com:443 -> localhost emulator
  POST /graphql -> 200 GraphQL PR read
Evidence: Focused closed-task regression tests

Source: Focused closed-task regression tests

ok - fm-pr-merge --closed-task merges a green PR whose task record is gone

Observed CLI response:
verified: https://github.com/example/repo/pull/239 is merged (state=MERGED, merged=true, isInMergeQueue=false)
Observed supervision row:
1795157282	1	check	merged-task-x1-https://github.com/example/repo/pull/239	check: merge landed: task-x1 https://github.com/example/repo/pull/239
Observed forge merge request:
pr merge 239 --repo example/repo --match-head-commit c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1c1 --squash
ok - fm-pr-merge --closed-task keeps the head pin, green, attended, queue, hold, and record guards
Focused driver exit status: 0

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-pr-merge.sh:1993 - In --closed-task mode, a pull request whose base branch has moved on (mergeStateStatus=BEHIND, so FM_PR_GITHUB_BEHIND=true at line 1233) gets this error: "updating its source branch requires explicit --update-branch consent on this authorized merge request". But --closed-task refuses --update-branch at lines 409-411, so following that advice only produces a second refusal with exit 2. This is a likely case for a PR that outlived its task by weeks, like the 2026-10-31 PR in the intent, when branch protection requires branches to be up to date. Concrete sequence: run fm-pr-merge.sh pv-x <url> --closed-task --expected-head H on a green PR that reads BEHIND. It exits 1 and tells the operator to add --update-branch. They rerun with --update-branch and get exit 2 with "--closed-task refuses --attended-override and --update-branch". Fix: when CLOSED_TASK=true, print a closed-task message instead. It should say the branch must be updated outside this script, and the merge rerun with --expected-head set to the new head once the captain approves it. No behavior change is needed.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
Merge synthetic green GitHub PR kunchenguid#239 with --closed-task after task cleanup; the CLI verifies the merge and records its supervision outcome without recreating task metadata or a poll. ✅ pass live Live merge through real GitHub CLI and localhost API emulator
Supply a stale approved head for synthetic GitHub PR kunchenguid#239 with --closed-task; the script refuses and sends no merge mutation. ✅ pass live Live merge through real GitHub CLI and localhost API emulator
  • git diff --check 9706deb4410ccc693f644f8d750b95eb0d83e8af..d02b66af805bf45b2dc995758dbc1d4570cb418d
  • Focused selectors from tests/fm-pr-merge.test.sh: test_closed_task_merges_a_pr_that_outlived_its_task and test_closed_task_keeps_every_guard
  • Ran the real bin/fm-pr-merge.sh and /usr/bin/gh against a localhost-only synthetic GitHub API emulator for approved-head merge and stale-head refusal.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

… gone

fm-pr-merge.sh refused any merge without task metadata, so a PR that
outlived its cleaned-up task had no guarded merge path. --closed-task is
that attended path: it requires --expected-head, keeps every live green,
head, hold, and queue guard, refuses while away or with auto-merge or
branch-update flags, and records nothing against the gone task.
@peterOC26 peterOC26 changed the title fix(bin): merge approved GitHub PRs after task cleanup fix(bin): allow attended merges for cleaned-up GitHub PRs Nov 20, 2026
@peterOC26
peterOC26 merged commit a43bc78 into main Nov 20, 2026
58 of 60 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