Repository navigation
fix(bin): open direct-PR tasks' PRs on origin, not a fork's parent - #16
Merged
Merged
Conversation
`gh pr create` with no `-R` defaults to a fork's PARENT repository. The direct-PR definition of done named no repository, so every direct-PR task in a fork clone could open its PR on a repository nobody authorized. The direct-PR block now resolves the target from the copy's own `origin` - owner/repository from the remote URL, base branch from refs/remotes/origin/HEAD - and names both on a `gh-axi pr create -R <owner>/<repo> --base <default branch>`, and ship rule one keeps the push on `origin`. fm_dod_pr_url_on_origin refuses a done whose PR is on any other repository, ahead of every acceptance path so bin/fm-pr-check.sh cannot register one either. Scoped to where origin decides the target: a no-mistakes PR is published by the pipeline's own configured push target and local-only opens no PR, a Gerrit change keeps its published-tree check, and an origin URL that names no forge is no proof either way and falls through to the named-head gate unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-metaplanet
added a commit
that referenced
this pull request
Oct 6, 2026
Carried from fork commit 2a7f0d1 (#16). bin/fm-dod-lib.sh merges both sides rather than choosing. Upstream has since added a configurable ship-branch prefix and a named base branch, so the generated instructions keep upstream's `$branch` and `$pr_base` instead of this commit's hard-coded `fm/<id>` and default-branch assumption, and the resolution steps gain a line saying to use the named base when the delivery contract declares one. The draft read-back keeps upstream's `gh-axi pr view`, because this commit used raw `gh` for it and this repo's own rule is to reach the forge through `gh-axi`. Rule one keeps upstream's base-branch-aware target and gains this commit's origin-only bound. Both renderings were checked with and without a named base. AGENTS.md keeps upstream's pointer: upstream moved this section into the `ship-landing` skill, so the sentence this commit reworded is reworded there. tests/fm-brief.test.sh and tests/fm-dod-lib.test.sh keep both sides' test groups, which cover independent behaviour. In each file the conflict boundary fell inside an upstream test, so its closing brace is restored at the junction.
max-metaplanet
added a commit
that referenced
this pull request
Oct 6, 2026
The origin-resolution steps carried from #16 were written when a fork task always based its PR on the project default, so they spell the create's placeholder `--base <default branch>`. Upstream has since added named base branches, and the same block now also tells the worker to use the base the Delivery contract names instead of the default, so the old placeholder contradicts the two instructions around it whenever a base is named. Spell the placeholder `<base branch>` in both the brief's create step and the refusal message that tells a worker how to reopen a PR on origin, and move the assertion that pins it with them.
max-metaplanet
added a commit
that referenced
this pull request
Oct 6, 2026
…line The merge of #16 onto this base took the fork's phrasing of the direct-PR opening sentence, which names `origin` as the push target but drops upstream's mention of `gh-axi` as the tool that opens the PR. Upstream's named-base-branch test pins that phrase, so it failed, and the fork loses a fact the repository otherwise requires everywhere. Keep both: push to `origin`, open the PR with `gh-axi`. The base-branch clause that follows is unchanged, and the origin-resolution steps below it still carry the fork's reason for naming the repository on the create.
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
A direct-PR worker on the max-metaplanet/firstmate fork opened its PR against the upstream parent repository (kunchenguid#5555) because
gh pr createdefaults to a fork's parent repository when no-Ris given. Nobody approved an upstream PR; it was closed within minutes and reopened on the fork. The no-mistakes path is not affected, because it targets origin. The direct-PR definition of done in bin/fm-brief.sh names no repository, so every direct-PR task in a fork clone is exposed. Fix: the direct-PR scaffold resolves the PR target from origin and instructsgh pr create -R <origin owner/repo> --base <default branch>, and the done-gate verifies the reported PR URL belongs to that repository.What Changed
bin/fm-dod-lib.shnow has the worker work out the PR target fromoriginbefore opening anything. It reads the<owner>/<repo>fromgit remote get-url originand the default branch fromrefs/remotes/origin/HEAD, falling back togit remote show originif that ref isn't set. It then opens the PR withgh-axi pr create -R <owner>/<repo> --base <default branch> --head fm/<id>. Ship rule 1 also now forbids pushing to any remote other thanorigin.fm_dod_pr_url_on_originruns before every acceptance path infm_dod_accept_ship_done. It refuses a direct-PRdone:whose PR URL points to a different repository than the copy'sorigin, so the wrong PR is never recorded aspr=. The refusal message names both likely causes: the PR was opened on the wrong repository, ororiginstill uses a renamed repository's old name.originhas no forge URL.tests/fm-dod-lib.test.shandtests/fm-brief.test.shcover this.AGENTS.mdanddocs/architecture.mdnow describe the new done-gate refusal.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change covers both halves of the intent and leaves the other delivery modes alone. The direct-PR brief now tells the worker to run
gh-axi pr create -R <owner>/<repo> --base <default branch>, with both values resolved from origin. The done gate refuses a direct-PR done whose PR's owner/repo differs from origin's before any path can accept or record it. no-mistakes, local-only, Gerrit and origins that name no forge fall through to the existing checks as before. The two fix rounds do what was asked: the comparison now uses only the owner/repo path, so SSH host aliases and ssh.github.com origins accept their own PR while the fork-parent PR is still refused, and the refusal message names both possible causes and gives thegit remote set-url originremedy.Testing
Ran the real
fm-brief.shandfm-pr-check.shCLIs in throwaway FM_HOME dirs under /tmp, with realghreading the actual incident PR kunchenguid#5555 and fork PR #15. Scratch git copies stood in for the worker copies, and the push was simulated by setting the remote-tracking ref locally. All 10 gate scenarios behaved as the intent requires. The base commit accepted and recorded the upstream PR, so the regression is reproduced. The two targeted test files also pass. The temp dirs were removed and the worktree is clean. Herdr lab was not needed because no Herdr lifecycle changed. There is no UI surface, so CLI transcripts are the evidence.gh-axi pr create -R <owner>/<repo> --base <default branch>; rule 1 limits pushes to origingit remote set-url originremedyEvidence: Direct-PR brief Definition of Done as scaffolded
Source: Direct-PR brief Definition of Done as scaffolded
Evidence: fm-pr-check.sh live transcript for scenarios A-J
Source: fm-pr-check.sh live transcript for scenarios A-J
Evidence: Base commit accepts the upstream PR (regression reproduced)
Source: Base commit accepts the upstream PR (regression reproduced)
Evidence: Incident refusal (scenario A)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (2) ✅
bin/fm-dod-lib.sh:745- The gate can refuse a legitimate PR.fm_dod_origin_forge_identitytakes the host literally from the remote URL, whilefm_pr_url_parsealways reports GitHub's host asgithub.com. An origin that goes through an SSH host alias or GitHub's port-443 SSH endpoint therefore never matches its own PR. Examples:git@github-443:owner/repo.git(this machine's ~/.ssh/config definesHost github-443) andssh://[email protected]:443/owner/repo.git. Concrete case: origingit@github-443:max-metaplanet/firstmate.gitgives origin identitygithub-443/max-metaplanet/firstmate. The worker's correct PRhttps://github.com/max-metaplanet/firstmate/pull/Ngivesgithub.com/max-metaplanet/firstmate. The strings differ, so the function returns 1 and the done is refused. The refusal tells the worker to rungh-axi pr create -R max-metaplanet/firstmate, which is the repository the PR is already on, so the worker cannot get unstuck. The fork failure this change targets is always a difference in owner/repo path, not in host. Fix: compare paths only, or when the hosts differ but the paths match, treat the result as 'no proof' (return 0) instead of a mismatch. This keeps upstream-fork detection and removes the false refusal.🔧 Fix applied.
1 info still open:
bin/fm-dod-lib.sh:754- The gate can refuse a legitimate PR when origin still uses a repository's old name.fm_dod_forge_path_equalcompares only the owner/repo text in origin's URL. GitHub keeps accepting the old URL of a renamed or transferred repository by redirecting it, but the PR URL it prints uses the new name. Example: origin is[email protected]:oldowner/proj.gitand the repository was transferred tonewowner/proj. The worker runsgh-axi pr create -R oldowner/proj, gets backhttps://github.com/newowner/proj/pull/N, and the done is refused. The refusal message then tells the worker to create the PR onoldowner/projagain, so the worker cannot get unstuck. This is rare, and runninggit remote set-urlworks around it. Fixing it properly would mean asking the forge for the repository's canonical name, which goes beyond this change, so it needs the author's decision.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
gh-axi pr create -R <owner>/<repo> --base <default branch>; rule 1 limits pushes to origingit remote set-url originremedyFM_HOME=<tmp> bin/fm-brief.sh fork-task firstmate --mode direct-PRand--mode no-mistakes, then read the scaffolded Definition of DoneFM_HOME=<tmp> bin/fm-pr-check.sh live-task <pr-url>against a scratch git copy with a real origin URL and a direct-PR meta file, using real gh, for 10 origin/PR/mode combinations (A-J)Same incident scenario (A) against agit archive 65fc15dextraction of the base commit, to show the regressionbash tests/fm-dod-lib.test.sh(targeted: the new origin-binding cases)bash tests/fm-brief.test.sh(targeted: test_direct_pr_dod_binds_the_pr_target_to_origin)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.