diff --git a/bin/contributor-relay.js b/bin/contributor-relay.js index 7a209dbc51..45386cb4e0 100755 --- a/bin/contributor-relay.js +++ b/bin/contributor-relay.js @@ -397,6 +397,15 @@ const PR_CLAIM_FOLLOWUP_ANCHOR = 'Your verdict says complete, but no PR for this // follow-up: a bare `complete` with no PR is booked evidence-less by the hub // (same issue), but it is not a contradiction the relay can put to the agent. const PR_CLAIM_PATTERN = /\bPRs?\b|pull[ -]request|\bopened\b/i; +// A PR the agent opened inside its own fork (see detectForkPRURLs). The anchor +// is the message's fixed opening, so followUpAnswered() can find the echo. +const FORK_PR_FOLLOWUP_ANCHOR = 'That PR is in your fork, not in '; +function buildForkPRFollowUpMessage(url, repo) { + const owner = (/^https:\/\/github\.com\/([^/]+)\//.exec(url) || [])[1] || ''; + return `${FORK_PR_FOLLOWUP_ANCHOR}${repo}, so the hive cannot see it: ${url}. ` + + `Close it, then open it again against the upstream repository with 'gh pr create --repo ${repo} --head ${owner}:' ` + + `(keep the --base the task gave you), and print the HIVE_VERDICT line again on its own line.`; +} const BYTES_PER_MIB = 1024 * 1024; const DEFAULT_HEADLESS_MAX_OUTPUT_MIB = 16; @@ -6557,6 +6566,40 @@ function detectPRURL(lines, repo) { return urls.length > 0 ? urls[0] : ''; } +// detectForkPRURLs finds this task's PR opened in the wrong place: a URL in +// / rather than in the task repo. detectPRURLs() is right +// to never credit it (a PR in another repository is never this task's PR), but +// it dropped it without a word: kylerankin/chairlift#3 was the agent's fix for +// projectbluefin/chairlift#798, opened with base and head both in the fork, and +// the issue sat at 010 for nine hours. Only the agent's own is counted — the +// fork owner is the contributor's login, or the URL is on a verdict line — so +// a researched PR in some other fork of the repo is still ignored. +function detectForkPRURLs(lines, repo, login) { + if (!Array.isArray(lines) || typeof repo !== 'string') return []; + const [owner, name] = repo.split('/'); + if (!owner || !name) return []; + const me = typeof login === 'string' ? login.trim().toLowerCase() : ''; + const URL_RE = /https:\/\/github\.com\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\/pull\/\d+/g; + const seen = new Set(); + const out = []; + for (let i = lines.length - 1; i >= 0; i--) { + const line = lines[i]; + if (typeof line !== 'string') continue; + const verdictLine = isHiveVerdictLine(line); + let m; + URL_RE.lastIndex = 0; + while ((m = URL_RE.exec(line)) !== null) { + const urlOwner = m[1].toLowerCase(); + if (m[2].toLowerCase() !== name.toLowerCase() || urlOwner === owner.toLowerCase()) continue; + if (!verdictLine && (!me || urlOwner !== me)) continue; + if (seen.has(m[0])) continue; + seen.add(m[0]); + out.push(m[0]); + } + } + return out; +} + // ── Did THIS task open that PR? (kubestellar/hive#6662) ────────────────────── // // The precedence at the completion site reads "a visible PR contradicts @@ -7313,6 +7356,10 @@ function prClaimFollowUpAnswered(lines) { return followUpAnswered(lines, PR_CLAIM_FOLLOWUP_ANCHOR); } +function forkPRFollowUpAnswered(lines) { + return followUpAnswered(lines, FORK_PR_FOLLOWUP_ANCHOR); +} + function followUpAnswered(lines, anchor) { if (!Array.isArray(lines)) return true; let echoAt = -1; @@ -8010,6 +8057,8 @@ let postVerdictReviewRequested = false; let lastTickConcernLines = new Set(); // #7862: whether this task's one PR-less-complete follow-up has been spent. let prClaimFollowUpRequested = false; +// Whether this task's one "that PR is in your fork" follow-up has been spent. +let forkPRFollowUpRequested = false; // #7907: the verdict LINE currently on the pane and when a tick first saw it. // A different line (the second verdict after a #7759 follow-up) starts a new // sighting; the same line ages toward VERDICT_SETTLE_MS. @@ -8020,6 +8069,7 @@ function resetPostVerdictReviewState() { postVerdictReviewRequested = false; lastTickConcernLines = new Set(); prClaimFollowUpRequested = false; + forkPRFollowUpRequested = false; verdictFirstSeen = null; } @@ -9325,6 +9375,8 @@ function maybeRequestPRForClaimedComplete(tmuxLines, verdict, prFinding) { if (verdict.verdict !== HIVE_VERDICT_COMPLETE) return false; if (!PR_CLAIM_PATTERN.test(verdict.reason || '')) return false; if (prClaimFollowUpRequested) return false; + // The fork follow-up already told the agent exactly where its PR went. + if (forkPRFollowUpRequested) return false; if (prFinding && prFinding.url) return false; prClaimFollowUpRequested = true; @@ -9349,6 +9401,49 @@ function maybeRequestPRForClaimedComplete(tmuxLines, verdict, prFinding) { return true; } +// ── A PR opened in the contributor's own fork ──────────────────────────────── +// +// `gh pr create` without --repo takes its base repo from the clone, and a +// clone reused across tasks can carry a default that points at the fork. The +// prompt now names --repo; this is the relay's half for an agent that still +// lands one there: the PR is never booked as the task's (detectPRURLs keeps +// that rule), but the agent is told once, while it can still act, instead of +// the task ending as if nothing shipped. Called where the agent is not +// mid-turn: as the task would finalize (verdict or idle chrome), and as the +// stall backstop is about to give up on a pane that has sat unchanged — the +// shape of the chairlift case, where the agent opened the fork PR and the +// task failed 25 minutes later on "no pane activity". Same bounds as #7862: +// once per task, budget spent before typing, finalization held until the +// agent re-prints a verdict or goes idle. +function maybeRequestUpstreamPRForForkPR(paneScanLines, tmuxLines, prFinding) { + if (!currentTask || currentTask.kind !== 'issue') return false; + if (forkPRFollowUpRequested) return false; + if (prFinding && prFinding.url) return false; + const urls = detectForkPRURLs(paneScanLines, currentTask.repo, CONTRIBUTOR_LOGIN); + if (urls.length === 0) return false; + + forkPRFollowUpRequested = true; + console.warn(`Task ${currentTask.task_id}: the agent's PR ${urls[0]} is in its fork, not in ${currentTask.repo} — ` + + `not booking it as this task's PR; asking the agent once to reopen it upstream`); + try { + tmuxSendNudge(buildForkPRFollowUpMessage(urls[0], currentTask.repo)); + } catch (e) { + console.error('Failed to send the fork-PR follow-up; continuing without it:', e.message); + return false; + } + send({ + type: 'task_progress', + seq: nextSeq(), + task_id: currentTask.task_id, + task_gen: currentTask.task_gen, + status: 'working', + summary: `Agent opened its PR in its fork (${urls[0]}), not in ${currentTask.repo}; asked it once to reopen it upstream`, + tmux_output: tmuxLines, + ...progressModelFields(), + }); + return true; +} + function progressTick() { lastProgressTick = Date.now(); if (!currentTask) return; @@ -9544,7 +9639,8 @@ function progressTick() { lastTickConcernLines = new Set(reviewMarkers ? paneScanLines.filter(l => reviewMarkers.concern.test(l)) : []); const secondVerdictPending = !!completionVerdict && ( (postVerdictReviewRequested && !postVerdictReviewAnswered(paneScanLines)) || - (prClaimFollowUpRequested && !prClaimFollowUpAnswered(paneScanLines))); + (prClaimFollowUpRequested && !prClaimFollowUpAnswered(paneScanLines)) || + (forkPRFollowUpRequested && !forkPRFollowUpAnswered(paneScanLines))); // Chrome-idle grace (#5376). classifyTmuxPane() saying IDLE_COMPLETE is now // only a hint; it must repeat across CHROME_IDLE_GRACE_TICKS ticks before it @@ -9679,6 +9775,11 @@ function progressTick() { : null; // #7862: and its one chance to back a `complete` with the PR it implies. + // A PR opened in the agent's own fork: its one chance to reopen it upstream. + // Ahead of #7862, whose "no PR exists" would be the vaguer of the two. + if (finalizing && maybeRequestUpstreamPRForForkPR(paneScanLines, tmuxLines, prFinding)) { + return; + } if (verdictCompletes && maybeRequestPRForClaimedComplete(tmuxLines, completionVerdict, prFinding)) { return; } @@ -9852,6 +9953,10 @@ function progressTick() { // immediately — see the comment above PANE_STALL_CONFIRM_TICKS for why a // single instant cannot distinguish "stuck" from "about to finish". if (paneStallConfirmed(tmuxLines)) { + // A pane frozen after the agent opened its PR in its fork is an agent + // waiting at its prompt, not a dead one: tell it before giving up. The + // typed follow-up changes the pane, which restarts the stall clock. + if (maybeRequestUpstreamPRForForkPR(paneScanLines, tmuxLines, null)) return; // The CLI may still be mid-turn on the task we are about to give up on // (observed live: a slow `gh pr create` returned, with a real PR link, // seconds after the stall verdict). Relaunch it so the NEXT task starts @@ -10852,6 +10957,10 @@ if (process.env.HIVE_RELAY_TEST_MODE === '1') { getPRClaimFollowUpRequested: () => prClaimFollowUpRequested, PR_CLAIM_FOLLOWUP_MESSAGE, PR_CLAIM_FOLLOWUP_ANCHOR, + detectForkPRURLs, + buildForkPRFollowUpMessage, + getForkPRFollowUpRequested: () => forkPRFollowUpRequested, + FORK_PR_FOLLOWUP_ANCHOR, PR_CLAIM_PATTERN, tmuxSessionHasAttachedClient, tmuxSessionHumanPresence, diff --git a/bin/contributor-relay.test.js b/bin/contributor-relay.test.js index 4df32ce910..5ba05853c0 100644 --- a/bin/contributor-relay.test.js +++ b/bin/contributor-relay.test.js @@ -16248,6 +16248,98 @@ test('#7862 detectPRURLs synthesizes a candidate from "PR #N" on the verdict lin } finally { teardown(relay); } }); +// ── A PR opened in the contributor's own fork ──────────────────────────────── +// +// projectbluefin/chairlift#798: the agent opened kylerankin/chairlift#3, head +// and base both in its fork. detectPRURLs() rightly never credited it, but +// nothing told the agent, and the task failed 25 minutes later on a frozen +// pane while the issue sat at 010 for nine hours. + +test('detectForkPRURLs finds the agent\'s own fork PR, and only that', () => { + const relay = loadRelay({ backend: 'copilot' }); + try { + const fork = 'https://github.com/kylerankin/chairlift/pull/3'; + assert.deepStrictEqual(relay.detectForkPRURLs([`Created ${fork}`], 'projectbluefin/chairlift', 'kylerankin'), [fork], + 'a PR in / is the agent\'s, in the wrong place'); + assert.deepStrictEqual(relay.detectForkPRURLs([`Created ${fork}`], 'projectbluefin/chairlift', 'KyleRankin'), [fork], + 'the login compares case-insensitively'); + assert.deepStrictEqual(relay.detectForkPRURLs([`HIVE_VERDICT: complete — PR ${fork}`], 'projectbluefin/chairlift', ''), [fork], + 'on a verdict line it is the agent\'s own even when the relay does not know its login'); + assert.deepStrictEqual(relay.detectForkPRURLs(['see https://github.com/someone/chairlift/pull/9'], 'projectbluefin/chairlift', 'kylerankin'), [], + 'another fork\'s PR seen while researching is not the agent\'s'); + assert.deepStrictEqual(relay.detectForkPRURLs(['see https://github.com/kylerankin/other/pull/9'], 'projectbluefin/chairlift', 'kylerankin'), [], + 'a PR in an unrelated repository is research, as before'); + assert.deepStrictEqual(relay.detectForkPRURLs(['https://github.com/projectbluefin/chairlift/pull/808'], 'projectbluefin/chairlift', 'kylerankin'), [], + 'a PR in the task repo is detectPRURLs\' business, not this one\'s'); + assert.deepStrictEqual(relay.detectForkPRURLs([`Created ${fork}`], 'projectbluefin/chairlift', 'kylerankin'), + relay.detectForkPRURLs([`Created ${fork}`, `again ${fork}`], 'projectbluefin/chairlift', 'kylerankin'), 'deduplicated'); + assert.deepStrictEqual(relay.detectPRURLs([`HIVE_VERDICT: complete — PR ${fork}`], 'projectbluefin/chairlift'), [], + 'and it is still never a candidate for the task\'s own PR'); + assert.match(relay.buildForkPRFollowUpMessage(fork, 'projectbluefin/chairlift'), + /gh pr create --repo projectbluefin\/chairlift --head kylerankin:/); + } finally { teardown(relay); } +}); + +test('a complete whose PR is in the agent\'s fork gets one follow-up and is never booked with that PR', () => { + const fork = 'https://github.com/test-contributor/bar/pull/3'; + let pane = 'Working…'; + const relay = loadRelay({ backend: 'copilot', paneText: () => pane, prMeta: new Error('gh: offline'), env: { HIVE_CONTRIBUTOR_USERNAME: 'test-contributor' } }); + const log = console.log; const warn = console.warn; console.log = () => {}; console.warn = () => {}; + try { + dispatchTask(relay, 'ct-fork-pr', 140); + const before = relay.__tmuxSends().length; + pane = `Created ${fork}\nHIVE_VERDICT: complete — PR opened\n${IDLE_PANE}`; + relay.__crashTick(); + assert.strictEqual(relay.__sent.filter(m => m.type === 'task_complete').length, 0, 'held for the agent to move the PR'); + const sends = relay.__tmuxSends().slice(before); + assert.strictEqual(sends.filter(c => c.includes(relay.FORK_PR_FOLLOWUP_ANCHOR)).length, 1, `one fork follow-up: ${JSON.stringify(sends)}`); + assert.ok(!sends.some(c => c.includes(relay.PR_CLAIM_FOLLOWUP_ANCHOR)), 'the vaguer #7862 follow-up does not also fire'); + assert.ok(relay.__sent.some(m => m.type === 'task_progress' && /in its fork/.test(m.summary || ''))); + assert.strictEqual(relay.getForkPRFollowUpRequested(), true); + + // Mid-turn under the echoed follow-up: nothing finalizes, nothing repeats. + const msg = relay.buildForkPRFollowUpMessage(fork, 'foo/bar'); + pane = `Created ${fork}\nHIVE_VERDICT: complete — PR opened\n> ${msg}\nWorking…`; + relay.__crashTick(); + assert.strictEqual(relay.__sent.filter(m => m.type === 'task_complete').length, 0); + assert.strictEqual(relay.__tmuxSends().filter(c => c.includes(relay.FORK_PR_FOLLOWUP_ANCHOR)).length, 1, 'no second follow-up'); + + // The agent reopened it upstream and re-printed the verdict. + pane = `Created ${fork}\nHIVE_VERDICT: complete — PR opened\n> ${msg}\nCreated https://github.com/foo/bar/pull/205\nHIVE_VERDICT: complete — PR opened\n${IDLE_PANE}`; + relay.__crashTick(); + const completed = relay.__sent.filter(m => m.type === 'task_complete'); + assert.strictEqual(completed.length, 1); + assert.strictEqual(completed[0].pr_url, 'https://github.com/foo/bar/pull/205', 'the upstream PR is the task\'s, never the fork one'); + } finally { console.log = log; console.warn = warn; teardown(relay); } +}); + +test('a pane frozen after a fork PR gets the follow-up instead of the stall failure', () => { + const fork = 'https://github.com/test-contributor/bar/pull/3'; + let capture = `Created ${fork}\nwaiting`; + const relay = loadRelay({ backend: 'agy', paneText: () => capture, env: { HIVE_CONTRIBUTOR_USERNAME: 'test-contributor' } }); + const warn = console.warn; console.warn = () => {}; + try { + relay.setCliReady(true); + assignTask(relay, 't-fork-stall'); + relay.__stallTick(); + relay.__agePaneStallClock(relay.PANE_STALL_TIMEOUT_MS + 1); + relay.__stallTick(); + relay.__agePaneStallClock(relay.PANE_STALL_TIMEOUT_MS + 1); + const before = relay.__tmuxSends().length; + relay.__stallTick(); // would confirm the stall and fail the task + assert.strictEqual(relay.__sent.filter(m => m.type === 'task_failed').length, 0, 'the waiting agent is told, not failed'); + assert.strictEqual(relay.__tmuxSends().slice(before).filter(c => c.includes(relay.FORK_PR_FOLLOWUP_ANCHOR)).length, 1); + assert.strictEqual(relay.getCurrentTask() && relay.getCurrentTask().task_id, 't-fork-stall'); + + // Spent once: a pane that freezes again is failed as before. + relay.__agePaneStallClock(relay.PANE_STALL_TIMEOUT_MS + 1); + relay.__stallTick(); + relay.__agePaneStallClock(relay.PANE_STALL_TIMEOUT_MS + 1); + relay.__stallTick(); + assert.strictEqual(relay.__sent.filter(m => m.type === 'task_failed').length, 1, 'one follow-up per task, then the backstop stands'); + } finally { console.warn = warn; teardown(relay); } +}); + // ── hivecommons/hive#13146: the `wrong_base` verdict ───────────────────────── test('#13146 wrong_base carries a release branch without becoming already-done', () => { diff --git a/changelog.d/fixed-contributor-pr-in-fork.md b/changelog.d/fixed-contributor-pr-in-fork.md new file mode 100644 index 0000000000..e26e99595a --- /dev/null +++ b/changelog.d/fixed-contributor-pr-in-fork.md @@ -0,0 +1 @@ +- A contributor agent working from a fork could open its fix PR inside its own fork (head and base both in the fork), because the task prompt never told `gh pr create` which repository to target and a clone reused across tasks can default to the fork. The relay rightly never credited that PR, but dropped it without a word, so the issue stayed actionable with the fix invisible (projectbluefin/chairlift#798 waited nine hours behind kylerankin/chairlift#3). The prompt now names `--repo ` (and `--head :` from a fork) and asks the agent to confirm the PR URL is under the upstream repo; the relay tells the agent once to reopen a PR it finds in the agent's fork, when the task would finalize or before the stall backstop fails a pane frozen after it, and logs it as a warning. diff --git a/src/docs/contributor-relay.md b/src/docs/contributor-relay.md index 6f299104bf..122d59b2c4 100644 --- a/src/docs/contributor-relay.md +++ b/src/docs/contributor-relay.md @@ -1638,7 +1638,7 @@ What the GraphQL read does not cover: The hub logs `PR verification: REST read was rate limited; pull request read through GraphQL instead` (info) when the GraphQL read settled the lookup, and `PR verification: REST read was rate limited and the GraphQL fallback did not settle it; result is the REST failure` (warning, with both errors) when it did not. `/api/gh-rate-limits` lists the read under caller `hive:pullrequest_verify` on endpoint `/graphql`. -The relay's side of the contract is to make the claim *checkable* before it is sent, which is what the fixes below do: it holds a `complete` that claims a PR none can be attributed to and asks for the PR or a `no_work_needed` ([#7862](https://github.com/hivecommons/hive/issues/7862)); it treats `no_work_needed` as authoritative when both sentinels appear ([#7861](https://github.com/hivecommons/hive/issues/7861)); the prompt fixes the sentinel's *timing* — opening the PR is finishing, do not wait on CI ([#7858](https://github.com/hivecommons/hive/issues/7858)); and review notes the advisor leaves under the final verdict are recorded on the PR and in the summary rather than lost ([#7759](https://github.com/hivecommons/hive/issues/7759), [#7879](https://github.com/hivecommons/hive/issues/7879)). Whether verdict handling joins the `src/formal/contribute-lease/` model's scope is an open architect/maintainer decision tracked on #7864; the table above is the informal spec such a model would have to agree with. +The relay's side of the contract is to make the claim *checkable* before it is sent, which is what the fixes below do: it holds a `complete` that claims a PR none can be attributed to and asks for the PR or a `no_work_needed` ([#7862](https://github.com/hivecommons/hive/issues/7862)); when the agent opened its PR in its own fork instead of the task repo (`/`, or such a URL on the verdict line), it never books that PR as the task's but tells the agent once to reopen it with `gh pr create --repo `, both as the task would finalize and before the stall backstop gives up on a pane frozen after it (projectbluefin/chairlift#798); the task prompt itself names `--repo ` for the PR, and `--head :` from a fork; it treats `no_work_needed` as authoritative when both sentinels appear ([#7861](https://github.com/hivecommons/hive/issues/7861)); the prompt fixes the sentinel's *timing* — opening the PR is finishing, do not wait on CI ([#7858](https://github.com/hivecommons/hive/issues/7858)); and review notes the advisor leaves under the final verdict are recorded on the PR and in the summary rather than lost ([#7759](https://github.com/hivecommons/hive/issues/7759), [#7879](https://github.com/hivecommons/hive/issues/7879)). Whether verdict handling joins the `src/formal/contribute-lease/` model's scope is an open architect/maintainer decision tracked on #7864; the table above is the informal spec such a model would have to agree with. ### A wrong base is routing evidence, not already-done evidence diff --git a/src/pkg/dashboard/contribute_task_pr_repo_test.go b/src/pkg/dashboard/contribute_task_pr_repo_test.go new file mode 100644 index 0000000000..10fb4bc4dc --- /dev/null +++ b/src/pkg/dashboard/contribute_task_pr_repo_test.go @@ -0,0 +1,43 @@ +package dashboard + +import ( + "strings" + "testing" +) + +// TestBuildTaskPrompt_NamesTheUpstreamRepoForThePR pins the base REPO of the +// contributor's PR (projectbluefin/chairlift#798: the agent opened +// kylerankin/chairlift#3, base and head both in its fork, because nothing told +// gh which repo to open it in and the reused clone defaulted to the fork). +// Every access mode × base mode names --repo , the fork case also +// names --head :, and the self-check names the upstream PR URL. +func TestBuildTaskPrompt_NamesTheUpstreamRepoForThePR(t *testing.T) { + const repo = "projectbluefin/chairlift" + for _, tc := range []struct { + name string + canPush bool + base string + }{ + {"fork, declared base", false, "main"}, + {"fork, no declared base", false, ""}, + {"push access, declared base", true, "main"}, + {"push access, no declared base", true, ""}, + } { + t.Run(tc.name, func(t *testing.T) { + prompt := buildTaskPromptBodyForAccess(repo, repo+"#798", "make the only model active", "", tc.base, tc.canPush, "") + if !strings.Contains(prompt, "gh pr create --repo "+repo) { + t.Errorf("prompt does not name the upstream repo for gh pr create: %q", prompt) + } + if !strings.Contains(prompt, "https://github.com/"+repo+"/pull/") { + t.Errorf("self-check does not name the upstream PR URL prefix: %q", prompt) + } + head := strings.Contains(prompt, "--head :") + if head != !tc.canPush { + t.Errorf("--head : present = %v, want %v (fork case only): %q", head, !tc.canPush, prompt) + } + if tc.base != "" && !strings.Contains(prompt, "gh pr create --base "+tc.base) { + t.Errorf("declared base lost: %q", prompt) + } + }) + } +} diff --git a/src/pkg/dashboard/contribute_task_prompt.go b/src/pkg/dashboard/contribute_task_prompt.go index 9825d65c2f..63c4379709 100644 --- a/src/pkg/dashboard/contribute_task_prompt.go +++ b/src/pkg/dashboard/contribute_task_prompt.go @@ -469,9 +469,9 @@ func buildTaskPromptBodyWithHintsAndIssueRead(repoFull, issueRef, title, sourceH "fall back to its default branch ('gh repo view %s --json defaultBranchRef'). "+ "Run 'git fetch upstream' and start your work branch from that base with "+ "'git checkout -b upstream/'. Open the PR against "+ - "the same branch, and confirm before you report done that its base is the branch "+ - "the repository asks for. ", - repoFull, repoFull) + "the same branch, and confirm before you report done that its URL starts with "+ + "'https://github.com/%s/pull/' and its base is the branch the repository asks for. ", + repoFull, repoFull, repoFull) if b := strings.TrimSpace(baseBranch); b != "" { baseHint = fmt.Sprintf( "Base this work on the '%s' branch of %s. The checkout may be left on a "+ @@ -480,8 +480,9 @@ func buildTaskPromptBodyWithHintsAndIssueRead(repoFull, issueRef, title, sourceH "with 'git show-ref --verify --quiet refs/remotes/upstream/%s', and start "+ "your work branch from the base with 'git checkout -b upstream/%s'. "+ "Open the PR against the same branch with 'gh pr create --base %s', and confirm "+ - "the PR's base is '%s' before you report done. ", - b, repoFull, b, b, b, b) + "before you report done that the PR's URL starts with 'https://github.com/%s/pull/' "+ + "and its base is '%s'. ", + b, repoFull, b, b, b, repoFull, b) } repoOwner, _, _ := strings.Cut(repoFull, "/") if repoOwner == "" { @@ -496,7 +497,19 @@ func buildTaskPromptBodyWithHintsAndIssueRead(repoFull, issueRef, title, sourceH "if that directory already has a clone from a prior task, 'cd' into it "+ "and 'git fetch upstream' instead of re-forking). ", repoOwner, repoFull, repoFull) - pushHint := "Push your branch to your fork's 'origin' remote, then open a PR from your fork. " + // The PR's base REPO, spelled out (chairlift#798 → kylerankin/chairlift#3). + // Without --repo, gh picks the base repo from the clone, and a clone reused + // across tasks can carry a default that points at the fork: the PR then + // opens fork-to-fork, the relay rightly never credits it, and the issue + // waits on a fix nobody can see. Same shape as the reference-repo path in + // pkg/scheduler/kickmessage.go. + pushHint := fmt.Sprintf( + "Push your branch to your fork's 'origin' remote, then open the PR against %s "+ + "itself, never against your fork: 'gh pr create --repo %s --head :' "+ + "(read your login with 'gh api user --jq .login'), together with any --base named above. "+ + "A clone reused from a prior task may have its default repo set to your fork, and "+ + "without --repo gh opens the PR there. ", + repoFull, repoFull) if canPush { checkoutHint = fmt.Sprintf( "You have push access to the upstream repo, so do not fork it. "+ @@ -507,7 +520,10 @@ func buildTaskPromptBodyWithHintsAndIssueRead(repoFull, issueRef, title, sourceH "into it and ensure the 'upstream' remote points to %s before running "+ "'git fetch upstream'). ", repoOwner, repoFull, repoFull, repoFull) - pushHint = "Push your branch to the 'upstream' remote, then open a PR from that branch. " + pushHint = fmt.Sprintf( + "Push your branch to the 'upstream' remote, then open a PR from that branch with "+ + "'gh pr create --repo %s', together with any --base named above. ", + repoFull) } // #7790: the reused checkout's WORKING TREE, not just its branch. The // reuse-the-clone clause above says "fetch"; the base-branch clause below