Public: anyone can read this; the crew can change it.
Sentinel: stop picking pulls whose branch only a person can push (every such… #16512
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16510-sentinel-stop-picking-pulls-whose-branch → main 0 commits fork 3 threads · 3 unresolved
7 files
changed +128
−2
src/core/pulls_ceiling.ts +11 −2
| @@ -19,6 +19,15 @@ export const PULLS_CEILING_REASON = | ||
| 19 | 19 | */ |
| 20 | 20 | export const PULLS_HELD_NOTE = "New builds wait for reviews."; |
| 21 | 21 | |
| 22 | /** | |
| 23 | * An open pull only its author can move (#16510): a person's, from a branch of the repository | |
| 24 | * itself (`crew/authors_pull.ts` says it in code). No builder can push it, so it never counts | |
| 25 | * toward the ceiling: it holds nothing back that a review or a builder could shrink. Over `issue` | |
| 26 | * and `pull`. | |
| 27 | */ | |
| 28 | const WAITS_FOR_AUTHOR = `(NOT COALESCE((SELECT is_agent FROM user WHERE user.id = issue.author_id), 0) | |
| 29 | AND COALESCE((SELECT head_repo_id FROM pull WHERE pull.issue_id = issue.id), issue.repo_id) = issue.repo_id)`; | |
| 30 | ||
| 22 | 31 | const key = (repoId: string) => `crew.openPullsCeiling.${repoId}`; |
| 23 | 32 | |
| 24 | 33 | export function openPullsCeiling(db: Database, repoId: string): number { |
| @@ -54,7 +63,7 @@ export function pullsCeilingHold(db: Database, repoId: string): string | null { | ||
| 54 | 63 | const row = db |
| 55 | 64 | .query<{ value: string | null; open: number }, [string, string]>( |
| 56 | 65 | `SELECT (SELECT value FROM forge_setting WHERE key = ?1) AS value, |
| 57 | (SELECT COUNT(*) FROM issue WHERE repo_id = ?2 AND kind = 'pull' AND state = 'open') AS open`, | |
| 66 | (SELECT COUNT(*) FROM issue WHERE repo_id = ?2 AND kind = 'pull' AND state = 'open' AND NOT ${WAITS_FOR_AUTHOR}) AS open`, | |
| 58 | 67 | ) |
| 59 | 68 | .get(key(repoId), repoId); |
| 60 | 69 | const ceiling = ceilingOf(row?.value); |
| @@ -66,7 +75,7 @@ export function pullsCeilingHold(db: Database, repoId: string): string | null { | ||
| 66 | 75 | /** Every repository held now, as [repo id, cause]: only repositories with open pulls are walked. */ |
| 67 | 76 | export function pullsCeilingHeld(db: Database): { repoId: string; cause: string }[] { |
| 68 | 77 | const rows = db |
| 69 | .query<{ repo_id: string; c: number }, []>("SELECT repo_id, COUNT(*) AS c FROM issue WHERE kind = 'pull' AND state = 'open' GROUP BY repo_id") | |
| 78 | .query<{ repo_id: string; c: number }, []>(`SELECT repo_id, COUNT(*) AS c FROM issue WHERE kind = 'pull' AND state = 'open' AND NOT ${WAITS_FOR_AUTHOR} GROUP BY repo_id`) | |
| 70 | 79 | .all(); |
| 71 | 80 | const held: { repoId: string; cause: string }[] = []; |
| 72 | 81 | for (const r of rows) { |
src/crew/dispatch.ts +3
| @@ -45,6 +45,7 @@ import { | ||
| 45 | 45 | listComments, |
| 46 | 46 | type Issue, |
| 47 | 47 | } from "../core/issues.ts"; |
| 48 | import { authorsInRepoPull } from "./authors_pull.ts"; | |
| 48 | 49 | import { closesFromBody, getPull, pullDir, type Pull } from "../core/pulls.ts"; |
| 49 | 50 | import { claimedClones, sweepIdleDependencies, sweepOrphanClones, sweepStaleClones } from "./orphans.ts"; |
| 50 | 51 | import { pruneRunFiles } from "../runs/prune.ts"; |
| @@ -178,6 +179,8 @@ function conflictSummary(app: App, runId: unknown): boolean { | ||
| 178 | 179 | async function bringUpAfterNoMerge(app: App, repo: Repo, issue: Issue, agent: Agent): Promise<void> { |
| 179 | 180 | const pull = getPull(app.db, repo.id, issue.number); |
| 180 | 181 | if (!pull) return; |
| 182 | // Only its author, a person, can push it: it waits, and is not re-picked to fail in 0s (#16510). | |
| 183 | if (authorsInRepoPull(pull)) return; | |
| 181 | 184 | if (await resolveListConflicts(app, repo, pull)) return; |
| 182 | 185 | if (activeRunFor(app.db, "agent", issue.id) !== undefined) return; |
| 183 | 186 | queueAgentRun(app, repo, issue, agent, "conflict", undefined, { |
test/crew-merge-conflict.test.ts +19
| @@ -111,6 +111,25 @@ describe("the crew, with a pull that does not merge", () => { | ||
| 111 | 111 | expect(automaticRunsSince(app.db, pull.id, "1970-01-01T00:00:00.000Z")).toBe(CHECK_FAILED_LIMIT); |
| 112 | 112 | }); |
| 113 | 113 | |
| 114 | test("a person's in-repo pull that does not merge queues no run, though an agent holds it (#16510)", async () => { | |
| 115 | const branch = `person-${++n}`; | |
| 116 | await commit("main", "src/p.ts", "- base\n"); | |
| 117 | await commit(branch, "src/p.ts", "- theirs\n"); | |
| 118 | const o = await openPull(app, alice, repo, { title: branch, baseBranch: "main", headBranch: branch }); | |
| 119 | if (!o.ok) throw new Error(String(o.error)); | |
| 120 | app.db.run("UPDATE issue SET assignee_id = ?1 WHERE id = ?2", [bot.id, o.value.id]); | |
| 121 | await commit("main", "src/p.ts", "- ours\n"); | |
| 122 | const person = getPull(app.db, repo.id, o.value.number)!; | |
| 123 | expect(person.authorIsAgent).toBe(false); | |
| 124 | expect(person.crossRepo).toBe(false); | |
| 125 | redForConflict(person); | |
| 126 | // An agent's pull after it is decided after: seeing its run means the person's red was seen. | |
| 127 | const theirs = await conflicted("src/q.ts"); | |
| 128 | redForConflict(theirs); | |
| 129 | await until(() => conflictRuns(theirs).length > 0); | |
| 130 | expect(conflictRuns(person)).toHaveLength(0); | |
| 131 | }); | |
| 132 | ||
| 114 | 133 | test("a clash only in docs/MCP.md keeps both sides with no run", async () => { |
| 115 | 134 | const pull = await conflicted("docs/MCP.md"); |
| 116 | 135 | redForConflict(pull); |
test/merged-reads.test.ts +2
| @@ -63,6 +63,8 @@ test("pullsCeilingHold: no row with no pulls is not held; a 0 ceiling never hold | ||
| 63 | 63 | const repoId = made.value.id; |
| 64 | 64 | const key = `crew.openPullsCeiling.${repoId}`; |
| 65 | 65 | const owner = u.value; |
| 66 | // The crew's pulls count; a person's own from an in-repo branch does not (#16510). | |
| 67 | app.db.query("UPDATE user SET is_agent = 1 WHERE id = ?1").run(owner.id); | |
| 66 | 68 | drop(key); |
| 67 | 69 | expect(pullsCeilingHold(app.db, repoId)).toBeNull(); |
| 68 | 70 | const open = (n: number) => { |
test/open-pulls-ceiling.test.ts +2
| @@ -73,6 +73,8 @@ beforeAll(async () => { | ||
| 73 | 73 | if (!pushed.ok) throw new Error(JSON.stringify(pushed.error)); |
| 74 | 74 | const pull = await openPull(app, alice, fresh(), { title: `Pull ${n}`, baseBranch: "main", headBranch: `b${n}` }); |
| 75 | 75 | if (!pull.ok) throw new Error(JSON.stringify(pull.error)); |
| 76 | // The crew's pulls count; a person's own from an in-repo branch does not (#16510). | |
| 77 | app.db.query("UPDATE issue SET author_id = ?1 WHERE id = ?2").run(builder.user.id, pull.value.id); | |
| 76 | 78 | pulls.push(getIssueById(app.db, pull.value.id)!); |
| 77 | 79 | } |
| 78 | 80 | }); |
test/pull-ceiling-picks.test.ts +2
| @@ -95,6 +95,8 @@ beforeAll(async () => { | ||
| 95 | 95 | headBranch: "waiting", |
| 96 | 96 | }); |
| 97 | 97 | if (!pull.ok) throw new Error(String(pull.error)); |
| 98 | // The crew's pull counts; a person's own from an in-repo branch does not (#16510). | |
| 99 | app.db.query("UPDATE issue SET author_id = ?1 WHERE id = ?2").run(builder.value.user.id, pull.value.id); | |
| 98 | 100 | setOpenPullsCeiling(app.db, repo.id, 1, alice.id); |
| 99 | 101 | const opened = openIssue(app, alice, fresh(), { title: "Rename a note" }); |
| 100 | 102 | if (!opened.ok) throw new Error(String(opened.error)); |
test/waits-for-author.test.ts added +89
| @@ -0,0 +1,89 @@ | ||
| 1 | /** | |
| 2 | * A person's pull from a branch of the repository itself (#16510): no builder can push it, so the | |
| 3 | * dispatcher starts no builder run on it (it used to fail in 0s, again and again), a review still | |
| 4 | * runs, and it does not count toward the open-pull ceiling. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 12 | import { openIssue } from "../src/actions/issues.ts"; | |
| 13 | import { setPullsCeiling } from "../src/actions/planner_switch.ts"; | |
| 14 | import { openPull } from "../src/actions/pulls.ts"; | |
| 15 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 16 | import { getAgentByName, type Agent } from "../src/core/agents.ts"; | |
| 17 | import { getIssueById, type Issue } from "../src/core/issues.ts"; | |
| 18 | import { pullsCeilingHold } from "../src/core/pulls_ceiling.ts"; | |
| 19 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 20 | import { createUser, type User } from "../src/core/users.ts"; | |
| 21 | import { queueAgentRun } from "../src/crew/dispatch.ts"; | |
| 22 | import { quietLogs } from "./helpers/globals.ts"; | |
| 23 | import { seatAs } from "./helpers/seat.ts"; | |
| 24 | ||
| 25 | quietLogs(); | |
| 26 | ||
| 27 | let dataDir: string; | |
| 28 | let app: App; | |
| 29 | let alice: User; | |
| 30 | let repo: Repo; | |
| 31 | let builder: Agent; | |
| 32 | let reviewer: Agent; | |
| 33 | let issue: Issue; | |
| 34 | let mine: Issue; | |
| 35 | ||
| 36 | const fresh = () => getRepoById(app.db, repo.id)!; | |
| 37 | ||
| 38 | beforeAll(async () => { | |
| 39 | dataDir = await mkdtemp(join(tmpdir(), "forge-waits-author-")); | |
| 40 | app = createApp({ dataDir, port: 0 }); | |
| 41 | const a = await createUser(app.db, { | |
| 42 | origin: "seed", trusted: true, username: "alice", email: "[email protected]", | |
| 43 | password: "a-good-passphrase", adminIfFirst: true, | |
| 44 | }); | |
| 45 | if (!a.ok) throw new Error(a.error); | |
| 46 | alice = a.value; | |
| 47 | const made = await createRepo(app, alice, { name: "notes", visibility: "public" }); | |
| 48 | if (!made.ok) throw new Error(String(made.error)); | |
| 49 | repo = made.value; | |
| 50 | const first = await commitToBranch(app, alice, repo, { message: "Start", files: [{ path: "package.json", content: `{"name":"notes"}\n` }] }); | |
| 51 | if (!first.ok) throw new Error(JSON.stringify(first.error)); | |
| 52 | for (const name of ["b1", "r1"]) { | |
| 53 | const m = await createAgent(app, alice, { username: name }); | |
| 54 | if (!m.ok) throw new Error(String(m.error)); | |
| 55 | expect(addToCrew(app, alice, repo, name).ok).toBe(true); | |
| 56 | } | |
| 57 | builder = getAgentByName(app.db, "b1")!; | |
| 58 | reviewer = getAgentByName(app.db, "r1")!; | |
| 59 | expect(seatAs(app.db, repo.id, reviewer.user.id, "reviewer")).toBe(true); | |
| 60 | const opened = openIssue(app, alice, fresh(), { title: "Rename a note" }); | |
| 61 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 62 | issue = opened.value; | |
| 63 | const pushed = await commitToBranch(app, alice, fresh(), { branch: "fix", message: "Fix", files: [{ path: "f.md", content: "x\n" }] }); | |
| 64 | if (!pushed.ok) throw new Error(JSON.stringify(pushed.error)); | |
| 65 | const pull = await openPull(app, alice, fresh(), { title: "Owner fix", baseBranch: "main", headBranch: "fix" }); | |
| 66 | if (!pull.ok) throw new Error(JSON.stringify(pull.error)); | |
| 67 | mine = getIssueById(app.db, pull.value.id)!; | |
| 68 | }); | |
| 69 | ||
| 70 | afterAll(async () => { | |
| 71 | await rm(dataDir, { recursive: true, force: true }); | |
| 72 | }); | |
| 73 | ||
| 74 | describe("a pull that waits for its author", () => { | |
| 75 | test("a review and a person's ask still run", () => { | |
| 76 | expect(queueAgentRun(app, fresh(), mine, reviewer, "review")).toBeDefined(); | |
| 77 | }); | |
| 78 | ||
| 79 | test("it does not hold a new build back", () => { | |
| 80 | setPullsCeiling(app, alice, fresh(), "1"); | |
| 81 | expect(pullsCeilingHold(app.db, repo.id)).toBeNull(); | |
| 82 | expect(queueAgentRun(app, fresh(), issue, builder, "assigned")).toBeDefined(); | |
| 83 | }); | |
| 84 | ||
| 85 | test("an agent's pull still counts", () => { | |
| 86 | app.db.query("UPDATE issue SET author_id = ?1 WHERE id = ?2").run(builder.user.id, mine.id); | |
| 87 | expect(pullsCeilingHold(app.db, repo.id)).toBe("paused: 1 of 1 pulls open"); | |
| 88 | }); | |
| 89 | }); |
new above
offline
This skip has no test. Add one that fails when the line is removed.