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

opened this From outside

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

  • Ready to merge — no conflicts with main. 88 commits will land on main.

    1 approvalthe base moved since the approval

    Checks and the preview wait for a writer to approve this head

    You need write access to merge.

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).

Review

Sign in to review this change.
4 files changed +48 −10
src/core/runs.ts +15
@@ -1535,6 +1535,21 @@ export function automaticRunsSince(
15351535 return row?.n ?? 0;
15361536 }
15371537
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
15381553 /**
15391554 * Whether a pull's red repeats without progress since `since` (a person's last word, or the
15401555 * 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";
99 import { getIssue, getIssueById } from "../core/issues.ts";
1010 import { closesFromBody, type Pull } from "../core/pulls.ts";
1111 import type { Repo } from "../core/repos.ts";
12 import { activeRunFor, automaticRunsSince } from "../core/runs.ts";
12 import { activeRunFor, automaticRunsSince, bringUpRunsSince } from "../core/runs.ts";
1313 import { getUserById } from "../core/users.ts";
1414 import { createLog } from "../kernel/log.ts";
1515 import { agentFor, lastHumanWord } from "./task.ts";
@@ -112,9 +112,15 @@ export function releaseConflicted(
112112
113113 /**
outdated

Run queries live in src/core/runs.ts (automaticRunsSince); put this count there and import it, so one place reads the run table.

114114 * 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.
118124 */
119125 export function bringUpToDate(
120126 app: App,
@@ -122,6 +128,7 @@ export function bringUpToDate(
122128 pull: Pull,
123129 files: readonly string[],
124130 episodeStart = "",
131 counts: "check tries" | "own runs" = "check tries",
125132 ): string | undefined {
126133 const issue = getIssueById(app.db, pull.id);
127134 if (!issue || issue.state !== "open") return undefined;
@@ -129,13 +136,14 @@ export function bringUpToDate(
129136 if (!agent) return undefined;
130137 if (activeRunFor(app.db, "agent", issue.id) !== undefined)
131138 return agent.user.username;
132 const tries = automaticRunsSince(
133 app.db,
134 issue.id,
139 const since =
135140 episodeStart > lastHumanWord(app, issue, agent)
136141 ? 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);
139147 if (tries >= CHECK_FAILED_LIMIT) {
140148 // Autonomous: closed, never waiting. Assisted: the person's word.
141149 releaseConflicted(
src/crew/conflict_sweep.ts +1 −1
@@ -196,7 +196,7 @@ export async function sweepConflicts(
196196 }
197197 // Its push is a check: none starts that the lane has no slot for (#4459).
198198 if (room <= 0) continue;
199 if (bringUpToDate(app, repo, pull, files, since) !== undefined) {
199 if (bringUpToDate(app, repo, pull, files, since, "own runs") !== undefined) {
200200 room--;
201201 acted++;
202202 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", () => {
199199 expect(await mergesCleanNow(app, repo, getPull(app.db, repo.id, o.value.number)!)).toBe(true);
200200 });
201201
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 });
202217 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs