Public: anyone can read this; the crew can change it.
The conflict sweep brings a pull whose check tries are spent up to date instead of closing it (#8022): bringUpToDate counts its own runs #17756
Approved, waiting for its check
number 4 in the queue: lands in about 40 min
grokbot/forge:fix/flaky-crew-merge-conflict → main 88 commits fork 1 thread · 1 unresolved
Combined with main
The preview is built from combined/17756 (e98dd68f36): main merged into this pull's head. Merging lands that branch.
The checks line says which commit the check ran on.
What happens next
This pull cannot land as it is, whatever its review says, because it changes guarded paths: src/crew/conflict_release.ts (permissions or the contract's walls), src/crew/conflict_sweep.ts (permissions or the contract's walls).
4 files
changed +48
−10
src/core/runs.ts +15
| @@ -1535,6 +1535,21 @@ export function automaticRunsSince( | ||
| 1535 | 1535 | return row?.n ?? 0; |
| 1536 | 1536 | } |
| 1537 | 1537 | |
| 1538 | /** | |
| 1539 | * Bring-up-to-date (`conflict`) runs that finished on a pull since `since`: the bound | |
| 1540 | * `bringUpToDate` keeps on them. They are no try for a red check (`automaticRunsSince`). | |
| 1541 | */ | |
| 1542 | export function bringUpRunsSince(db: Database, issueId: string, since: string): number { | |
| 1543 | const row = db | |
| 1544 | .query<{ n: number }, [string, string]>( | |
| 1545 | `SELECT COUNT(*) AS n FROM run | |
| 1546 | WHERE kind = 'agent' AND reason = 'conflict' AND issue_id = ?1 | |
| 1547 | AND created_at > ?2 AND state IN ('ok','failed')`, | |
| 1548 | ) | |
| 1549 | .get(issueId, since); | |
| 1550 | return row?.n ?? 0; | |
| 1551 | } | |
| 1552 | ||
| 1538 | 1553 | /** |
| 1539 | 1554 | * Whether a pull's red repeats without progress since `since` (a person's last word, or the |
| 1540 | 1555 | * pull's start): its newest red and the red before its builder's last rework failed the same |
src/crew/conflict_release.ts +17 −9
| @@ -9,7 +9,7 @@ import { getHold } from "../core/holds.ts"; | ||
| 9 | 9 | import { getIssue, getIssueById } from "../core/issues.ts"; |
| 10 | 10 | import { closesFromBody, type Pull } from "../core/pulls.ts"; |
| 11 | 11 | import type { Repo } from "../core/repos.ts"; |
| 12 | import { activeRunFor, automaticRunsSince } from "../core/runs.ts"; | |
| 12 | import { activeRunFor, automaticRunsSince, bringUpRunsSince } from "../core/runs.ts"; | |
| 13 | 13 | import { getUserById } from "../core/users.ts"; |
| 14 | 14 | import { createLog } from "../kernel/log.ts"; |
| 15 | 15 | import { agentFor, lastHumanWord } from "./task.ts"; |
| @@ -112,9 +112,15 @@ export function releaseConflicted( | ||
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Queue one run for the pull's agent to merge main into its branch. One |
| 115 | * waiting is enough, and the automatic tries since a person last spoke | |
| 116 | * stop at the same limit a failing check does — past it, the pull waits | |
| 117 | * for a person. | |
| 115 | * waiting is enough. A person's or a landing's ask (`counts` "check tries") | |
| 116 | * stops once the automatic tries since a person last spoke reach the limit | |
| 117 | * a failing check has: past it, the pull waits for a person (#10909). | |
| 118 | * The conflict sweep (`counts` "own runs") bounds the bring-up-to-date runs | |
| 119 | * themselves instead: a merge conflict is not a failed try (#8022), so a | |
| 120 | * pull whose check tries are spent is still brought up to date when main | |
| 121 | * moves, as `bringUpAfterNoMerge` in dispatch.ts does for the same pull's | |
| 122 | * no-merge red. Counting the reworks there closed that pull whenever the | |
| 123 | * tick's sweep reached it before the red did. | |
| 118 | 124 | */ |
| 119 | 125 | export function bringUpToDate( |
| 120 | 126 | app: App, |
| @@ -122,6 +128,7 @@ export function bringUpToDate( | ||
| 122 | 128 | pull: Pull, |
| 123 | 129 | files: readonly string[], |
| 124 | 130 | episodeStart = "", |
| 131 | counts: "check tries" | "own runs" = "check tries", | |
| 125 | 132 | ): string | undefined { |
| 126 | 133 | const issue = getIssueById(app.db, pull.id); |
| 127 | 134 | if (!issue || issue.state !== "open") return undefined; |
| @@ -129,13 +136,14 @@ export function bringUpToDate( | ||
| 129 | 136 | if (!agent) return undefined; |
| 130 | 137 | if (activeRunFor(app.db, "agent", issue.id) !== undefined) |
| 131 | 138 | return agent.user.username; |
| 132 | const tries = automaticRunsSince( | |
| 133 | app.db, | |
| 134 | issue.id, | |
| 139 | const since = | |
| 135 | 140 | episodeStart > lastHumanWord(app, issue, agent) |
| 136 | 141 | ? episodeStart |
| 137 | : lastHumanWord(app, issue, agent), | |
| 138 | ); | |
| 142 | : lastHumanWord(app, issue, agent); | |
| 143 | const tries = | |
| 144 | counts === "own runs" | |
| 145 | ? bringUpRunsSince(app.db, issue.id, since) | |
| 146 | : automaticRunsSince(app.db, issue.id, since); | |
| 139 | 147 | if (tries >= CHECK_FAILED_LIMIT) { |
| 140 | 148 | // Autonomous: closed, never waiting. Assisted: the person's word. |
| 141 | 149 | releaseConflicted( |
src/crew/conflict_sweep.ts +1 −1
| @@ -196,7 +196,7 @@ export async function sweepConflicts( | ||
| 196 | 196 | } |
| 197 | 197 | // Its push is a check: none starts that the lane has no slot for (#4459). |
| 198 | 198 | if (room <= 0) continue; |
| 199 | if (bringUpToDate(app, repo, pull, files, since) !== undefined) { | |
| 199 | if (bringUpToDate(app, repo, pull, files, since, "own runs") !== undefined) { | |
| 200 | 200 | room--; |
| 201 | 201 | acted++; |
| 202 | 202 | asked.set(pull.id, { |
test/crew-merge-conflict.test.ts +15
| @@ -199,4 +199,19 @@ describe("the crew, with a pull that does not merge", () => { | ||
| 199 | 199 | expect(await mergesCleanNow(app, repo, getPull(app.db, repo.id, o.value.number)!)).toBe(true); |
| 200 | 200 | }); |
| 201 | 201 | |
| 202 | test("the tick's sweep reaching a clash before its red brings it up to date too: spent check tries close nothing (#8022)", async () => { | |
| 203 | // Room in the lane, as in the list-doc sweep test above. | |
| 204 | for (const r of listRuns(app.db, repo.id, { kind: "agent" })) | |
| 205 | if (r.state === "queued" || r.state === "running") { | |
| 206 | claimRun(app.db, r.id); | |
| 207 | finishRun(app.db, r.id, { state: "ok", summary: "cleared" }); | |
| 208 | } | |
| 209 | app.db.run("UPDATE issue SET state = 'closed' WHERE repo_id = ?1 AND state = 'open'", [repo.id]); | |
| 210 | const pull = await conflicted("src/swept.ts"); | |
| 211 | // No red: the sweep is the first to see it (on a busy box the tick beats the red). | |
| 212 | await sweepConflicts(app, getRepoById(app.db, repo.id)!); | |
| 213 | expect(getIssueById(app.db, pull.id)?.state).toBe("open"); | |
| 214 | expect(conflictRuns(pull)).toHaveLength(1); | |
| 215 | expect(automaticRunsSince(app.db, pull.id, "1970-01-01T00:00:00.000Z")).toBe(CHECK_FAILED_LIMIT); | |
| 216 | }); | |
| 202 | 217 | }); |
new above
offline
Run queries live in src/core/runs.ts (automaticRunsSince); put this count there and import it, so one place reads the run table.