Skip to content

fix(bin): open direct-PR tasks' PRs on origin, not a fork's parent - #16

Merged
max-metaplanet merged 5 commits into
mainfrom
fm/direct-pr-fork-target
Sep 26, 2026
Merged

max-metaplanet merged 5 commits into
mainfrom
fm/direct-pr-fork-target

Conversation

@max-metaplanet

@max-metaplanet max-metaplanet commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Intent

A direct-PR worker on the max-metaplanet/firstmate fork opened its PR against the upstream parent repository (kunchenguid#5555) because gh pr create defaults to a fork's parent repository when no -R is 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 instructs gh pr create -R <origin owner/repo> --base <default branch>, and the done-gate verifies the reported PR URL belongs to that repository.

What Changed

  • The direct-PR delivery contract in bin/fm-dod-lib.sh now has the worker work out the PR target from origin before opening anything. It reads the <owner>/<repo> from git remote get-url origin and the default branch from refs/remotes/origin/HEAD, falling back to git remote show origin if that ref isn't set. It then opens the PR with gh-axi pr create -R <owner>/<repo> --base <default branch> --head fm/<id>. Ship rule 1 also now forbids pushing to any remote other than origin.
  • New fm_dod_pr_url_on_origin runs before every acceptance path in fm_dod_accept_ship_done. It refuses a direct-PR done: whose PR URL points to a different repository than the copy's origin, so the wrong PR is never recorded as pr=. The refusal message names both likely causes: the PR was opened on the wrong repository, or origin still uses a renamed repository's old name.
    • The comparison uses only the owner/repo path, ignoring case, so SSH host aliases still match.
    • The check is skipped for Gerrit changes, for modes other than direct-PR, and when origin has no forge URL.
  • New tests in tests/fm-dod-lib.test.sh and tests/fm-brief.test.sh cover this. AGENTS.md and docs/architecture.md now 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 the git remote set-url origin remedy.

Testing

Ran the real fm-brief.sh and fm-pr-check.sh CLIs in throwaway FM_HOME dirs under /tmp, with real gh reading 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.

  • Live validation: ✅ go - 11 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Direct-PR brief tells the worker to resolve the owner/repo and base branch from origin and to run gh-axi pr create -R &lt;owner&gt;/&lt;repo&gt; --base &lt;default branch&gt;; rule 1 limits pushes to origin ✅ pass live direct-pr-brief-dod.txt
No-mistakes brief does not carry the direct-PR create instruction ✅ pass live fm-brief.sh --mode no-mistakes: 0 matches for 'pr create -R'
Incident: fork origin max-metaplanet/firstmate reports done on upstream kunchenguid#5555; fm-pr-check refuses, records no pr= and arms nothing ✅ pass live fm-pr-check-live-transcript.txt scenario A; base commit accepted it (fm-pr-check-base-commit-regression.txt)
Fork origin reports its own PR #15; accepted, pr= recorded and poll armed ✅ pass live fm-pr-check-live-transcript.txt scenario B
Origin through SSH host alias git@github-443:... accepts its own github.com PR ✅ pass live fm-pr-check-live-transcript.txt scenario C
Origin ssh://[email protected]:443/... accepts its own github.com PR ✅ pass live fm-pr-check-live-transcript.txt scenario D
HTTPS origin whose owner/repo case differs from the PR URL is accepted ✅ pass live fm-pr-check-live-transcript.txt scenario E
Origin with no forge (local path) falls through to the named-head gate: accepted when HEAD is pushed, refused with the named-head reason when it is not ✅ pass live fm-pr-check-live-transcript.txt scenarios F and G
Origin still uses a renamed repo's old name: refused, and the message names both causes and gives the git remote set-url origin remedy ✅ pass live fm-pr-check-live-transcript.txt scenario H
No-mistakes mode is not gated by origin (the pipeline owns the push target) ✅ pass live fm-pr-check-live-transcript.txt scenario I
Correct repository but unpushed HEAD is still refused by the existing named-head gate ✅ pass live fm-pr-check-live-transcript.txt scenario J
Evidence: Direct-PR brief Definition of Done as scaffolded

Source: Direct-PR brief Definition of Done as scaffolded

Delivery contract: mode=direct-PR
This task ships **direct-PR**: you raise the PR yourself, without the no-mistakes pipeline.
The task is complete only when committed on your branch.
When it is implemented and committed, push your branch to `origin` and open a PR there that is ready for review, not a draft.
Resolve the PR target from `origin` first and name it on the create - never leave the repository for `gh` to pick, because `gh pr create` with no `-R` defaults to a FORK's parent repository, and on a fork clone that opens the PR on a repository nobody authorized:
1. `git remote get-url origin` - the `<owner>/<repo>` it names is your PR target, and `origin` is the only remote you push to.
2. `git symbolic-ref --quiet --short refs/remotes/origin/HEAD` - drop the leading `origin/` for your base branch; when it prints nothing, read the `HEAD branch:` line of `git remote show origin`.
3. `git push -u origin fm/fork-task`, then `gh-axi pr create -R <owner>/<repo> --base <default branch> --head fm/fork-task --title ... --body ...`.
Before you report done, read the PR back from the forge and confirm it is not a draft (`gh pr view <url> --json isDraft` must print false); if it is a draft, mark it ready with `gh-axi pr ready`.
A draft cannot be merged, so a done report on one leaves the merge unasked.
Then append `done [at=<epoch>]: PR {url}` to the status file and stop.
That `done:` is accepted only when the PR is on the repository `origin` names and this copy's HEAD - your latest commit - is pushed to your PR branch; the check tests that commit, not merely that a branch moved.
A PR raised on any other repository is refused rather than recorded, so if the target you resolved is not the one you expected, append `blocked [at=<epoch>]: {what origin names}` instead of opening it.
If you deliberately keep the PR a draft, append `paused [at=<epoch>]: {why the draft is held}` instead of done.
Do NOT run /no-mistakes. The configured merge authority decides whether to merge the PR; firstmate relays the outcome.
25:1. Never push to the default branch and never push to any remote but `origin` (push only your `fm/fork-task` branch, to `origin`). Never merge a PR.
Evidence: fm-pr-check.sh live transcript for scenarios A-J

Source: fm-pr-check.sh live transcript for scenarios A-J

## scenario: A-fork-origin-upstream-pr
$ git remote get-url origin  -> [email protected]:max-metaplanet/firstmate.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/A-fork-origin-upstream-pr bin/fm-pr-check.sh live-task https://github.com/kunchenguid/firstmate/pull/5555
error: the PR https://github.com/kunchenguid/firstmate/pull/5555 is on github.com/kunchenguid/firstmate, not this copy's origin github.com/max-metaplanet/firstmate: either the PR was opened on the wrong repository - open it on origin with `gh-axi pr create -R max-metaplanet/firstmate --base <default branch>`, because `gh pr create` with no -R targets a fork's parent repository - or origin still uses a renamed or transferred repository's old name - run `git remote set-url origin <the repository's current URL>` and report again
exit=1
recorded meta pr= line: (none)

## scenario: B-fork-origin-own-pr
$ git remote get-url origin  -> [email protected]:max-metaplanet/firstmate.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/B-fork-origin-own-pr bin/fm-pr-check.sh live-task https://github.com/max-metaplanet/firstmate/pull/15
armed: state/live-task.check.sh
exit=0
recorded meta pr= line: pr=https://github.com/max-metaplanet/firstmate/pull/15

## scenario: C-ssh-host-alias-github-443
$ git remote get-url origin  -> git@github-443:max-metaplanet/firstmate.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/C-ssh-host-alias-github-443 bin/fm-pr-check.sh live-task https://github.com/max-metaplanet/firstmate/pull/15
armed: state/live-task.check.sh
exit=0
recorded meta pr= line: pr=https://github.com/max-metaplanet/firstmate/pull/15

## scenario: D-ssh-github-com-443
$ git remote get-url origin  -> ssh://[email protected]:443/max-metaplanet/firstmate.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/D-ssh-github-com-443 bin/fm-pr-check.sh live-task https://github.com/max-metaplanet/firstmate/pull/15
armed: state/live-task.check.sh
exit=0
recorded meta pr= line: pr=https://github.com/max-metaplanet/firstmate/pull/15

## scenario: E-https-origin-case-diff
$ git remote get-url origin  -> https://github.com/Max-Metaplanet/FirstMate.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/E-https-origin-case-diff bin/fm-pr-check.sh live-task https://github.com/max-metaplanet/firstmate/pull/15
armed: state/live-task.check.sh
exit=0
recorded meta pr= line: pr=https://github.com/max-metaplanet/firstmate/pull/15

## scenario: F-no-forge-origin-pushed
$ git remote get-url origin  -> /tmp/some/local/bare.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/F-no-forge-origin-pushed bin/fm-pr-check.sh live-task https://github.com/kunchenguid/firstmate/pull/5555
armed: state/live-task.check.sh
exit=0
recorded meta pr= line: pr=https://github.com/kunchenguid/firstmate/pull/5555

## scenario: G-no-forge-origin-unpushed
$ git remote get-url origin  -> /tmp/some/local/bare.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/G-no-forge-origin-unpushed bin/fm-pr-check.sh live-task https://github.com/kunchenguid/firstmate/pull/5555
error: named head 8b0ae8529566730267fd55af9eb6209a79ea3d28 is unreachable outside the worker copy
exit=1
recorded meta pr= line: (none)

## scenario: H-renamed-repo-origin
$ git remote get-url origin  -> [email protected]:oldowner/firstmate.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/H-renamed-repo-origin bin/fm-pr-check.sh live-task https://github.com/max-metaplanet/firstmate/pull/15
error: the PR https://github.com/max-metaplanet/firstmate/pull/15 is on github.com/max-metaplanet/firstmate, not this copy's origin github.com/oldowner/firstmate: either the PR was opened on the wrong repository - open it on origin with `gh-axi pr create -R oldowner/firstmate --base <default branch>`, because `gh pr create` with no -R targets a fork's parent repository - or origin still uses a renamed or transferred repository's old name - run `git remote set-url origin <the repository's current URL>` and report again
exit=1
recorded meta pr= line: (none)

## scenario: I-no-mistakes-mode-upstream-pr
$ git remote get-url origin  -> [email protected]:max-metaplanet/firstmate.git
$ mode=no-mistakes  FM_HOME=/tmp/fmlive.6E0j/I-no-mistakes-mode-upstream-pr bin/fm-pr-check.sh live-task https://github.com/kunchenguid/firstmate/pull/5555
armed: state/live-task.check.sh
exit=0
recorded meta pr= line: pr=https://github.com/kunchenguid/firstmate/pull/5555

## scenario: J-fork-origin-own-pr-unpushed
$ git remote get-url origin  -> [email protected]:max-metaplanet/firstmate.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/J-fork-origin-own-pr-unpushed bin/fm-pr-check.sh live-task https://github.com/max-metaplanet/firstmate/pull/15
error: named head 76de40131ef5a137431259dbebaa7b45d158153c is unreachable outside the worker copy
exit=1
recorded meta pr= line: (none)
Evidence: Base commit accepts the upstream PR (regression reproduced)

Source: Base commit accepts the upstream PR (regression reproduced)

## BASE COMMIT 65fc15d scenario: BASE-A-fork-origin-upstream-pr
$ git remote get-url origin  -> [email protected]:max-metaplanet/firstmate.git
$ mode=direct-PR  FM_HOME=/tmp/fmlive.6E0j/BASE-A-fork-origin-upstream-pr bin/fm-pr-check.sh live-task https://github.com/kunchenguid/firstmate/pull/5555
armed: state/live-task.check.sh
exit=0
recorded meta pr= line: pr=https://github.com/kunchenguid/firstmate/pull/5555
Evidence: Incident refusal (scenario A)
error: the PR https://github.com/kunchenguid/firstmate/pull/5555 is on github.com/kunchenguid/firstmate, not this copy's origin github.com/max-metaplanet/firstmate: either the PR was opened on the wrong repository - open it on origin with `gh-axi pr create -R max-metaplanet/firstmate --base <default branch>` ... - or origin still uses a renamed or transferred repository's old name - run `git remote set-url origin <the repository's current URL>` and report again
exit=1
recorded meta pr= line: (none)

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_identity takes the host literally from the remote URL, while fm_pr_url_parse always reports GitHub's host as github.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 defines Host github-443) and ssh://[email protected]:443/owner/repo.git. Concrete case: origin git@github-443:max-metaplanet/firstmate.git gives origin identity github-443/max-metaplanet/firstmate. The worker's correct PR https://github.com/max-metaplanet/firstmate/pull/N gives github.com/max-metaplanet/firstmate. The strings differ, so the function returns 1 and the done is refused. The refusal tells the worker to run gh-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_equal compares 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.git and the repository was transferred to newowner/proj. The worker runs gh-axi pr create -R oldowner/proj, gets back https://github.com/newowner/proj/pull/N, and the done is refused. The refusal message then tells the worker to create the PR on oldowner/proj again, so the worker cannot get unstuck. This is rare, and running git remote set-url works 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.

  • Live validation: ✅ go - 11 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Direct-PR brief tells the worker to resolve the owner/repo and base branch from origin and to run gh-axi pr create -R &lt;owner&gt;/&lt;repo&gt; --base &lt;default branch&gt;; rule 1 limits pushes to origin ✅ pass live direct-pr-brief-dod.txt
No-mistakes brief does not carry the direct-PR create instruction ✅ pass live fm-brief.sh --mode no-mistakes: 0 matches for 'pr create -R'
Incident: fork origin max-metaplanet/firstmate reports done on upstream kunchenguid#5555; fm-pr-check refuses, records no pr= and arms nothing ✅ pass live fm-pr-check-live-transcript.txt scenario A; base commit accepted it (fm-pr-check-base-commit-regression.txt)
Fork origin reports its own PR #15; accepted, pr= recorded and poll armed ✅ pass live fm-pr-check-live-transcript.txt scenario B
Origin through SSH host alias git@github-443:... accepts its own github.com PR ✅ pass live fm-pr-check-live-transcript.txt scenario C
Origin ssh://[email protected]:443/... accepts its own github.com PR ✅ pass live fm-pr-check-live-transcript.txt scenario D
HTTPS origin whose owner/repo case differs from the PR URL is accepted ✅ pass live fm-pr-check-live-transcript.txt scenario E
Origin with no forge (local path) falls through to the named-head gate: accepted when HEAD is pushed, refused with the named-head reason when it is not ✅ pass live fm-pr-check-live-transcript.txt scenarios F and G
Origin still uses a renamed repo's old name: refused, and the message names both causes and gives the git remote set-url origin remedy ✅ pass live fm-pr-check-live-transcript.txt scenario H
No-mistakes mode is not gated by origin (the pipeline owns the push target) ✅ pass live fm-pr-check-live-transcript.txt scenario I
Correct repository but unpushed HEAD is still refused by the existing named-head gate ✅ pass live fm-pr-check-live-transcript.txt scenario J
  • FM_HOME=&lt;tmp&gt; bin/fm-brief.sh fork-task firstmate --mode direct-PR and --mode no-mistakes, then read the scaffolded Definition of Done
  • FM_HOME=&lt;tmp&gt; bin/fm-pr-check.sh live-task &lt;pr-url&gt; 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 a git archive 65fc15d extraction of the base commit, to show the regression
  • bash 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.

max-metaplanet and others added 5 commits September 26, 2026 00:06
`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.
@max-metaplanet
max-metaplanet merged commit 2a7f0d1 into main Sep 26, 2026
19 checks passed
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.
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