Repository navigation
feat: refuse duplicate GitHub-issue ship dispatches - #60
Conversation
Add optional repeatable --issue to ship spawns so the task records the normalized GitHub issue it covers. Before any worktree or endpoint is created, refuse when a live task in this home or an open PR already claims that issue. GitHub unreachability skips the PR check loudly and still honors local fleet overlap; omitting --issue leaves the spawn path unchanged.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughAdds ChangesIssue duplicate guardrail
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: 🟡 Moderate · up to This change adds issue claims and blocks detected duplicate ship dispatches, but the reservation is released before worker launch is fully established and relaunch uses a separate lock. Concurrent or recovery-related dispatches can still start two workers for the same issue, so merge requires coordination of this handoff or explicit owner acceptance. Sequence Diagram(s)sequenceDiagram
participant Operator
participant fm_spawn as fm-spawn.sh
participant Guard as fm_issue_guard_preflight
participant State as Home state
participant gh_axi as gh-axi
participant Endpoint as Endpoint window
Operator->>fm_spawn: Start ship spawn with --issue
fm_spawn->>Guard: Normalize and preflight refs
Guard->>State: Check live task metadata
Guard->>gh_axi: List open PRs
gh_axi-->>Guard: PR claim data or failure
Guard-->>fm_spawn: Refusal or normalized refs
fm_spawn->>Endpoint: Create endpoint after successful preflight
fm_spawn->>State: Record issues= metadata
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 46.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Refs #1 Refs #42 Refs #60 Refs #65 Refs #73 Refs #74 Refs #107 Refs #109 Refs #117 ## What I walked In a throwaway `.scratch-c4-walk/home` and local Git repository: ``` $ FM_HOME=.scratch-c4-walk/home bin/fm-merge-local.sh walk-clean merged fm/walk-clean into local main (aa84759 -> 1b9c678) in /Users/evanagee/.treehouse/firstmate-df5ff1/9/firstmate/.scratch-c4-walk/project $ git -C .scratch-c4-walk/project log -1 --format=%s main clean local landing ``` ``` $ FM_HOME=.scratch-c4-walk/home FM_GH_BIN=.scratch-c4-walk/fake-gh bin/fm-flow.sh walk status matched rulesets: main-protection=1 (rules: pull_request,required_status_checks) review=2 (rules: pull_request) registry posture: [no-mistakes-prod-only +yolo] main-protection ruleset 1 enforcement: active main-protection ruleset gates: pull_request + required_status_checks present review ruleset 2 enforcement: active stored previous posture: <none> verdict: full ``` ``` $ FM_HOME=.scratch-c4-walk/home bin/fm-merge-local.sh walk-outage fm/walk-outage error: task walk-outage is mode=no-mistakes; a PR-bound task lands locally only while GitHub is unreachable (state/.github-down present) merge its PR with bin/fm-pr-merge.sh after approval exit=1 ``` The flow status used a local fake that returned read-only ruleset data. No GitHub request, PR, or push was made. ## Port record The root already had guarded `fm-pr-merge.sh` and `fm-merge-local.sh`, canonical v2 PR poll registration and repair, GitLab merge verification, task control locks, leases, captain holds, and persisted merge authority. During the final rebase, the root also gained the outage landing skill unchanged. I kept those root implementations. The port adds auto-arm, reviewer chase, review-thread gating, issue claims and post-merge closing, GitHub outage landing and return sync, and the project flow switch around them. I dropped the fork's obsolete `captain-merge` token, `fm-pr-check-migrate.sh`, and C3 delivery timing, backfill, and token ledger changes. The root's captain-hold authority and repairable poll publication cover those seams.
Intent
Add a dispatch-time guardrail to firstmate that prevents two workers from being started on the same GitHub issue.
Record covered issue(s) on the task: add an optional, repeatable --issue flag to bin/fm-spawn.sh. A is a GitHub issue identity: accept both owner/repo#123 and a bare #123/123 (resolve a bare number against the task already-known project repo). Record the normalized issue ref(s) in the task state/.meta under a new field (for example issues=owner/repo#123,owner/repo#124). If no --issue is passed, behavior is unchanged (the field is simply absent). Update the fm-spawn.sh header/help to document the flag and the meta field, and document the meta field wherever meta fields are documented.
Refuse a spawn that duplicates a claimed issue. Before a ship spawn completes, run a preflight that checks whether any of the --issue refs is already claimed by: a live task in this home (scan state/*.meta for the same normalized issue ref on a task whose worker is still present), or an open pull request in that repo that references the issue (use gh-axi; match the issue number). If a claim is found, the spawn must refuse with a clear, plain-English message naming the exact claiming task id or PR URL, and must NOT create the worktree or launch anything. This is a hard stop, not a warning. Exit non-zero.
The refusal must fail closed on local fleet overlap and fail open on GitHub reachability: if the fleet scan runs but the open-PR check cannot reach GitHub, refuse only on the fleet-scan match and clearly report that the PR check was skipped (do not silently pass, and do not hard-fail the whole spawn just because GitHub is unreachable, since local fleet overlap is the primary case). State this boundary in the help. Matching is by normalized issue ref. Two different issues in the same PR body must not collide. A closed/merged PR does not claim anything. A torn-down task meta must not linger as a false claim (teardown already removes state/.meta; confirm that and rely on it). No --issue passed means no claim recorded and no duplicate check for that spawn. Do not add issue tracking to scout or secondmate spawns unless it falls out naturally; the target is ship dispatch.
Acceptance: fm-spawn.sh --issue #123 (and owner/repo#123) records the normalized ref in meta. A second ship spawn naming an issue already recorded on a live task refuses with a message naming that task, creates no worktree, and exits non-zero. A ship spawn naming an issue that an open PR in the repo references refuses with a message naming that PR URL. When GitHub is unreachable, the spawn still refuses on a local fleet match and reports the PR check was skipped; with no local match it proceeds and says the PR check was skipped. A spawn with no --issue behaves exactly as before. New behavior has tests colocated per repo convention. Header/help and meta-field docs updated. shellcheck clean.
Follow-up, do not do in this change, only note in the PR: firstmate itself should start passing --issue at every issue-backed dispatch, and its dispatch instructions should require it. This task only builds the mechanism and leaves it optional so nothing breaks.
What Changed
--issue <ref>on ship spawns inbin/fm-spawn.sh. Refs acceptowner/repo#123or bare#123/123(resolved against the project origin), and the normalized values are recorded asissues=instate/<id>.meta. Omitting the flag leaves the spawn path and meta unchanged. Scout, secondmate, and relaunch refuse--issue; relaunch keeps any priorissues=through meta preservation.--issuehard-stops on a live local-fleet claim of the same normalized ref or an open PR that claims that issue, naming the claiming task id or PR URL. Local overlap fails closed; GitHub unreachability skips the PR check with a loud notice and still proceeds when the fleet is clear. Cross-repo#nmentions in a PR do not collide.bin/fm-issue-guard-lib.sh, documentissues=in spawn help anddocs/configuration.md, and add colocatedtests/fm-spawn-issue-guard.test.sh.Follow-up (not in this change): firstmate should start passing
--issueat every issue-backed dispatch, and dispatch instructions should require it. This PR only adds the optional mechanism.Risk Assessment
✅ Low: The duplicate-issue guard is well-bounded, the prior cross-repo #n collision is closed in the text matcher, and remaining behavior matches the stated spawn-time contract.
Testing
Ran the colocated fm-spawn-issue-guard suite and replayed the same ship-spawn paths through real fm-spawn.sh; every required acceptance path passed, including normalized issues= recording, hard-stop refusals that name the claiming task or PR URL with no worktree, fail-open GitHub skip notices, and the follow-up that acme/infra#7 does not claim this repo's #7.
Evidence: Captain-visible spawn-guard CLI transcript
Source: Captain-visible spawn-guard CLI transcript
Evidence: Captain-visible refusal and skip messages
Source: Captain-visible refusal and skip messages
error: spawn refused: issue acme/widget#7 is already claimed by live task issue-live-a3 in this home; resolve or tear down that task before dispatching another worker on it error: spawn refused: issue acme/widget#7 is already referenced by open PR https://github.com/acme/widget/pull/4; dispatch only after that PR merges or closes notice: open-PR duplicate check could not reach GitHub and was skipped; the spawn is clear only against this home's local fleet, not against open PRs in acme/widget issues=acme/other#99,acme/widget#7,acme/widget#8Evidence: fm-spawn-issue-guard test-run log
Source: fm-spawn-issue-guard test-run log
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
bin/fm-issue-guard-lib.sh:215- fm_issue_guard_open_pr_claim treats any#<n>token as a claim for this repo's issue n. A concrete miss: listing open PRs for acme/widget while checking issue 7, with bodyDepends on acme/infra#7, matches#7([^0-9]|$)and refuses the spawn naming that PR URL even though the mention is a different normalized ref. That violates matching by normalized issue ref (two different issues must not collide). Tighten the scan so#ncounts only when it is not aowner/repo#nform, and still count same-repoacme/widget#nand bare#n.🔧 Fix: Ignore cross-repo hash mentions in PR claims
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
./bin/fm-test-run.sh tests/fm-spawn-issue-guard.test.shmanual evidence run of realbin/fm-spawn.shwith fake tmux/gh-axi for record, no-flag, local-fleet refusal, open-PR refusal, cross-repo#7non-claim, same-repo slug claim, and GitHub-down skip paths✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Summary by CodeRabbit
New Features
--issueflag for ship spawns, supporting multiple issue references.Bug Fixes
Documentation