Repository navigation
feat(bin): gate upstream PRs on a prior-art duplicate check - #44
Merged
Merged
Conversation
…ENTS prior-art pointer
…m-prior-art-check-r1 # Conflicts: # bin/fm-dod-lib.sh
…ncation, fixed published freshness (cherry picked from commit 48f68cf9c9879b9f03dcbb5fe838d4a1e21cfd3c)
…ture times (cherry picked from commit 7420a3171179af589e9782456525cb69069baa75)
… prior-art header (cherry picked from commit 6c80f3070bcdc6af14bf4c854b139e8229301c0f)
jazz127
added a commit
that referenced
this pull request
Sep 26, 2026
…e check fails only on the PR's merge with `house`; this branch alone passes. **Cause:** `house` (PR #44) added `fm_dod_upstream_receipt_check` to `fm_dod_accept_ship_done`. It runs before the recorded-PR early return and deliberately refuses any GitHub PR URL when the worktree is missing ("upstream prior-art receipt refused: worktree is unavailable"). This branch's new test `test_recorded_pr_with_missing_worktree_is_accepted` used a recorded GitHub PR with no worktree, so after the merge it hit house's intended refusal. The code in both is working as designed; the test's input conflicts with house's rule. **Invariant:** the worktree scratch check must not make a recorded PR fail just because its worktree is missing. The scratch check guards on the worktree existing, so the invariant holds in the code. Only the test's choice of URL crossed house's separate GitHub receipt rule. **Fix:** in `tests/fm-dod-lib.test.sh`, the test now uses a recorded Gerrit change (`https://review.example.test/c/o/r/+/5`) instead of a GitHub PR. House's receipt check doesn't apply to Gerrit, so the test still covers exactly what it was written for. No production code changed. **Verified:** - On this branch, `tests/fm-dod-lib.test.sh` passes: "all fm-dod-lib tests passed". - On a local merge with `origin/house` plus the fix, the same suite passes, including house's "external PR ready signals require receipts" test and "a recorded PR with a missing worktree is still accepted". - `bin/fm-lint.sh tests/fm-dod-lib.test.sh` is clean
This was referenced Sep 26, 2026
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
i think we should build a check somewhere into all of this that people submitting PRs to his repos have somehow checked there's no existing PRs. All his automation is swamped and we just saw like tons of dupes and probabl have done our own
Context: while inventorying two Firstmate bugs on 2026-09-26, the fleet found about ten open, unmerged upstream PRs from different contributors attacking the same "paused worker flagged as stale" bug, and several more for the Pi composer restart bug - duplicate work that swamps the maintainer's (Kun's) triage automation on kunchenguid/* repositories. The fleet itself contributes to kunchenguid/quota-axi and may one day contribute to kunchenguid/firstmate, and may have filed duplicates too. Upstream contributions from this fleet only happen on the captain's explicit order, through the fork's house-line guard for upstream contribution branches (fork PR #21) and the pending Bosun workflow (fork PR #38, not yet merged).
What Changed
Adds
bin/fm-upstream-prior-art.pywith five operations:scan,decide,check,publishandverify.scansearches the target GitHub repo for open PRs and issues, plus recent closed unmerged PRs, that look like duplicates. It builds its searches from linked issues and from keywords in the title, summary and changed symbols, and checks changed-file overlap only on the candidates that search returns. It saves a local JSON receipt that:none-found,distinctwith a reason for each candidate, oroverlapswith the captain's recorded decision.publishrechecks the receipt right before callinggh-axi pr createand adds aPrior art checkedsection to the PR body. It refuses a receipt that is missing, over one hour old, incomplete or unresolved, or whose head, diff, title or summary has changed.Adds these checks for PRs to GitHub repos the fleet does not own:
bin/fm-upstream-push-guard.shruns from a shipping task's pre-push hook. It blocks a push to a GitHub repo other than the worktree's origin unless the receipt is fresh and matches that repo and head.fm-git-strip-ai-trailers.sh installnow accepts an optional pre-push guard command and runs it before the repo's own pre-push hook.fm-spawn.shinstalls it for tasks of kindshipwhose mode is notlocal-only.fm-pr-check.shand done-acceptance infm-dod-lib.shnow runverify --publishedon the receipt. It accepts the scanned head, or a published head the forge reports as strictly ahead of it, and refuses a force-push or rewrite.Updates the delivery-contract text in
fm-dod-lib.sh:publishpath;scan,decideandcheckbefore the run starts.PRs to repos the fleet owns still use the old path.
docs/fork-house-branch.mdandAGENTS.mddocument the gate, its search limits and the pipeline push paths the pre-push hook does not cover.🤖 Generated with Claude Code
Risk Assessment
🚨 High: The new spawn-time core.hooksPath override applies to every non-local ship task and stops project hooks (husky, git-lfs pre-push) from running, and the published-head equality check likely refuses registration for normal no-mistakes upstream runs.
Testing
I ran the three focused behavioural suites (prior-art CLI with the offline fake forge, AI-trailer hook installer, DoD library); all passed. Two scenarios ran against real GitHub, read-only with nothing written to the forge: the scan of kunchenguid/firstmate and the published-head check through GitHub's compare API. The decide/check, push-guard, backstop and brief runs are offline: local runs of the real scripts over the real receipt, with the pre-push hook invoked the way git invokes it rather than pushing to GitHub. A read-only scan of kunchenguid/firstmate finished in 58s with 68 candidates, 17 of them paused-worker duplicates. Decide and check refused a missing verdict, a "distinct" claim over overlapping candidates, overlaps without a captain decision, and a branch that moved after the scan. The installed pre-push hook refused upstream pushes with no receipt or an unscanned SHA, passed owned-fork and non-GitHub pushes, and ran the project's husky-style hooks after each pass but never after a refusal.verify --publishedand the registration backstop accepted the live PR #44 head, which descends from the scanned head per GitHub's compare API, and refused diverged and behind heads. The brief blocks render /tmp/fm-<id>/prior-art.json, which matches spawn's TASK_TMP. I did not drive a real fm-spawn of a ship task in a lab primary. The scratch clone was removed; evidence is in the evidence directory.bin/fm-lab-home.sh createplus aclaudeprimary on the fm-lab tmux socket) to spawn a real ship worker. That full lif…Evidence: Live kunchenguid/firstmate scan transcript (58s, 68 candidates)
Source: Live kunchenguid/firstmate scan transcript (58s, 68 candidates)
Evidence: Paused-worker duplicate PRs/issues surfaced by the live scan
Source: Paused-worker duplicate PRs/issues surfaced by the live scan
Evidence: Live receipt for kunchenguid/firstmate
Source: Live receipt for kunchenguid/firstmate
Evidence: decide/check/verify gate matrix on the live receipt
Source: decide/check/verify gate matrix on the live receipt
Evidence: Installed pre-push guard: refusals, passes, and project-hook chaining
Source: Installed pre-push guard: refusals, passes, and project-hook chaining
Evidence: verify --published against GitHub compare (ahead/diverged/behind)
Source: verify --published against GitHub compare (ahead/diverged/behind)
Evidence: Registration/done backstop with the live PR #44 head, plus brief record path
Source: Registration/done backstop with the live PR #44 head, plus brief record path
Evidence: publish refusals before the forge write
Source: publish refusals before the forge write
Evidence: Live receipt for jazz127/firstmate (published-head scenarios)
Source: Live receipt for jazz127/firstmate (published-head scenarios)
Evidence: Focused suite logs
Source: Focused suite logs
The cited bundle holds the read-only kunchenguid/firstmate scan transcript and the published-head check with its GitHub compare responses.
evidence-artifact: /tmp/fm-firstmate-upstream-prior-art-check-r1/evidence/pr44-github-readonly-evidence.txt
evidence-command: fm-upstream-prior-art.py scan --repo kunchenguid/firstmate --title "fix: don't flag paused worker as stale" --summary-file summary.txt --record prior-art.json --base base
evidence-captured: 2026-09-26T00:57:11Z
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:4357- For every ship task that is not local-only (not just upstream ones), the new block sets the worktree configcore.hooksPathto$WT/.fm-hooks, and that directory holds onlypre-push. The pane's AI-trailer strip wrappers frombin/fm-git-strip-ai-trailers.shclearGIT_CONFIG_*, then chain togit rev-parse --git-path hooks. That now resolves to.fm-hooks, not the project's real hooks (.git/hooks, or a.huskypath set in local config). The new.fm-hooks/pre-pushdoes not chain on either. Concrete path: a project with git-lfs (.git/hooks/pre-push) or husky (core.hooksPath=.huskywith pre-commit/commit-msg) is spawned as a direct-PR or no-mistakes ship. In the worker pane,git commitskips the project's pre-commit and commit-msg hooks, andgit pushskipsgit lfs pre-push, so LFS objects are never uploaded. This silently breaks the chaining invariant that the strip installer's header documents (it keeps chaining because git-lfs installs pre-push and husky installs commit hooks). The same override also hides the prior hooks from the scratch hook'sPRIOR_PRE_PUSHchain. Fix: record the previousgit rev-parse --git-path hooksbefore overriding it. Then either make.fm-hooksa full wrapper set that execs the prior hook of the same name after the guard, or skipcore.hooksPathentirely and callfm-upstream-push-guard.shfrom the existing scratch and strip pre-push wrappers. Separately,git config extensions.worktreeConfig true(:4356) persistently rewrites the shared config of the project's main clone and is never undone at teardown.bin/fm-upstream-prior-art.py:477-verify --publishedrequires the receipt's scanned head to equal the forge's PR head exactly. In no-mistakes mode, the worker scans and checks at its own HEAD (perfm_upstream_pr_preflight_block) and then starts /no-mistakes. The pipeline's review, lint, and test rounds routinely add auto-fix commits, as they did on this branch, and push a head the worker never scanned (fm_dod_forge_head_is_named_headdocuments this).fm-pr-check.sh:126then refuses registration with "published head changed", andfm_dod_accept_ship_donerefuses done. The only repair is to fetch the pipeline head and rescan after the upstream PR already exists, and that rescan lists the worker's own PR as a candidate. So the documented no-mistakes upstream path fails in its normal case. Choosing a remedy is a policy decision: accept a forge head that descends from the receipt head without a force-push, rescope the receipt to the base and summary, or require a rescan and document it in the preflight block.bin/fm-dod-lib.sh:729- The pre-push hook (fm-spawn.sh:4359) and the registration and done backstop (fm_dod_upstream_receipt_check, :961) only look for the receipt at$TASK_TMP/prior-art.json. The worker briefs (fm_upstream_pr_publish_blockandfm_upstream_pr_preflight_block) instead tell the worker to choose<RECORD>freely. A worker who writes the receipt anywhere else passescheckandpublish, then has pushes refused and the published PR's registration refused with "missing …/prior-art.json". Fix: interpolate the task's actual record path into both blocks, in place of the<RECORD>placeholder.bin/fm-upstream-push-guard.sh:25- The push guard lowercases the target repository before passing it toverify --repo.verify_receipt(fm-upstream-prior-art.py:473) then compares it case-sensitively with thecontext.repothe scan recorded.fm_dod_upstream_receipt_checkpasses the URL's original case. So if a receipt scanned with--repo Owner/Repofor an upstream repo whose name has capitals, the push guard refuses every push. Compare case-insensitively inverify_receipt. Also,verify_argsinfm_dod_upstream_receipt_checkis not declaredlocal.🔧 Fix applied.
1 info still open:
bin/fm-upstream-push-guard.sh:25- The push guard lowercases the target repository before passing it toverify --repo.verify_receipt(fm-upstream-prior-art.py:473) then compares it case-sensitively with thecontext.repothe scan recorded.fm_dod_upstream_receipt_checkpasses the URL's original case. So if a receipt scanned with--repo Owner/Repofor an upstream repo whose name has capitals, the push guard refuses every push. Compare case-insensitively inverify_receipt. Also,verify_argsinfm_dod_upstream_receipt_checkis not declaredlocal.bin/fm-upstream-prior-art.py:15- The usage docstring says the decisions file has 'items keyed by candidate URL', butdeciderequiresitemsto be a list of objects, each withurl,verdictandreason. The worker briefs give no other format, and a URL-keyed object is refused with 'decisions must cover every candidate URL exactly once'. This happened during live testing. It fails closed, so it is not a safety issue, but workers will be confused. Suggested wording: 'items: a list of {url, verdict, reason}, one per candidate'.bin/fm-lab-home.sh createplus aclaudeprimary on the fm-lab tmux socket) to spawn a real ship worker. That full lif…bash tests/fm-upstream-prior-art.test.sh(offline fake forge; includes descendant-accepted / rewritten-refused)bash tests/fm-git-strip-ai-trailers.test.sh(includes pre-push guard chaining with husky hooksPath)bash tests/fm-dod-lib.test.shLive read-onlyfm-upstream-prior-art.py scan --repo kunchenguid/firstmateon a scratch clone with a paused-worker-stale change to bin/fm-watch.sh, timedLivedecide/check/verifyrefusal and acceptance matrix against that real receiptInstalled the real hook set withfm-git-strip-ai-trailers.sh install <hooks> <wt> bin/fm-upstream-push-guard.sh <root> <task-tmp>/prior-art.json(same args fm-spawn passes) in a clone with core.hooksPath=.husky; drove a realgit commit, a realgit pushto a local bare remote, and git-style pre-push invocations for owned fork / upstream-no-receipt / upstream-valid-receipt / upstream-unscanned-SHA / branch deletionLive read-only scan of jazz127/firstmate at 2c95ca7e, thenverify --publishedagainst GitHub's compare API for the PR #44 head (ahead), same head in mixed case, house (diverged), and parent (behind)Sourced bin/fm-dod-lib.sh and ranfm_dod_upstream_receipt_checkwith the live PR #44 URL and forge head (descendant, rewritten, missing record, owned repo)Renderedfm_upstream_pr_publish_block demo-7andfm_upstream_pr_preflight_block demo-7and compared the record path with fm-spawn's TASK_TMPpublishto kunchenguid/firstmate with a stale, a missing, and an incomplete receipt, behind a PATH shim that blocks any realpr create✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.