Public: anyone can read this; the crew can change it.

Sentinel: never open a revert when main's full check ended by its time limit #16670

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/16669-sentinel-never-open-a-revert-when-main-s → main 0 commits fork

  • Merged. scout/16669-sentinel-never-open-a-revert-when-main-s was merged into main as b3e341f.

Review

Sign in to review this change.
3 files changed +64 −3
src/checks/red_main.ts +6 −1
@@ -88,7 +88,12 @@ const lastMain = (from: string): string => `
8888 * A summary of a cell stop (`apps/contain.ts`), a budget kill (`kernel/budgets.ts`), a check that
8989 * stalled (`checks/stall.ts`) or one the forge's stopping cut off: the machine's, not a pull's.
9090 */
91 const LIMIT = /^(?:check failed: )?(?:stopped: |budget:|check stalled:|the forge was stopped under this check)/;
91 const LIMIT =
92 /^(?:check failed: )?(?:stopped: |budget:|check stalled:|the forge was stopped under this check|\S+ took longer than \d+s)/;
93
94 /** Whether the check ended by its time limit (its budget, or a step's own), not by a test. */
95 export const ranOutOfTime = (summary: string): boolean =>
96 /^(?:check failed: )?(?:budget:|\S+ took longer than \d+s)/.test(summary);
9297
9398 function toRed(row: Row): RedMain | undefined {
9499 if (row.state !== "failed") return undefined;
src/checks/revert_red.ts +31 −2
@@ -11,7 +11,7 @@
1111
1212 import type { App } from "../app.ts";
1313 import { revertPull } from "../actions/revert.ts";
14 import { getIssueById } from "../core/issues.ts";
14 import { addComment, getIssueById } from "../core/issues.ts";
1515 import { getPull, type Pull } from "../core/pulls.ts";
1616 import { getRepoById } from "../core/repos.ts";
1717 import { getUserById } from "../core/users.ts";
@@ -19,7 +19,7 @@ import { runGit } from "../git/env.ts";
1919 import { repoDir } from "../git/repos.ts";
2020 import { isSafeOid } from "../git/guard.ts";
2121 import { pinsLandedBy } from "./pinned_landing.ts";
22 import { manifestError, redMain, type RedMain } from "./red_main.ts";
22 import { manifestError, ranOutOfTime, redMain, type RedMain } from "./red_main.ts";
2323
2424 /** The reds being answered now: a check finishing twice at once proposes once. */
2525 const working = new Set<string>();
@@ -80,6 +80,34 @@ export function revertBody(pull: Pick<Pull, "number">, red: RedMain): string {
8080 return `Reverts #${pull.number}, the one pull landed since main was last green.\n\nMain is red at ${red.commitOid.slice(0, 7)}: ${what}.\n\nProposed by the forge; a person lands it.`;
8181 }
8282
83 /**
84 * A main check that ran out of time opens no revert: it says so, once per run, on the open
85 * main-runtime issue ("Main's full check …") if there is one (#16669).
86 */
87 function noteTimeout(app: App, red: RedMain): void {
88 const repo = getRepoById(app.db, red.repoId);
89 if (repo === undefined) return;
90 const issue = app.db
91 .query<{ id: string }, [string]>(
92 `SELECT id FROM issue WHERE repo_id = ?1 AND kind = 'issue' AND state = 'open'
93 AND title LIKE 'Main''s full check%' ORDER BY number DESC LIMIT 1`,
94 )
95 .get(red.repoId);
96 if (issue === null) return;
97 const mark = `run ${red.runId}`;
98 const seen = app.db
99 .query<{ n: number }, [string, string]>(
100 "SELECT COUNT(*) AS n FROM comment WHERE issue_id = ?1 AND instr(body, ?2) > 0",
101 )
102 .get(issue.id, mark)!.n;
103 if (seen > 0) return;
104 addComment(app.db, {
105 issueId: issue.id,
106 authorId: repo.ownerId,
107 body: `Main's check ended by its time limit at ${red.commitOid.slice(0, 7)} (${mark}: ${red.summary.replace(/^check failed: /, "")}). No revert was opened: a time limit is the machine's, not a pull's.`,
108 });
109 }
110
83111 /**
84112 * Called when a default-branch check of `repoId` has finished: opens the
85113 * revert pull if the rules above hold. Returns it, or undefined when none
@@ -90,6 +118,7 @@ export async function proposeRevert(app: App, repoId: string): Promise<Pull | un
90118 working.add(repoId);
91119 try {
92120 const red = redMain(app.db, repoId);
121 if (red !== undefined && ranOutOfTime(red.summary)) noteTimeout(app, red);
93122 if (red === undefined || red.limit || manifestError(red) !== undefined) return undefined;
94123 const green = greenBefore(app, repoId, red.branch, red.runId);
95124 if (green === undefined) return undefined;
test/revert-red.test.ts +27
@@ -11,6 +11,7 @@ import { createApp, type App } from "../src/app.ts";
1111 import { mergePull, openPull } from "../src/actions/pulls.ts";
1212 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1313 import { proposeRevert } from "../src/checks/revert_red.ts";
14 import { createIssue, listComments } from "../src/core/issues.ts";
1415 import { getPull, listPulls, type Pull } from "../src/core/pulls.ts";
1516 import type { Repo } from "../src/core/repos.ts";
1617 import { createRun } from "../src/core/runs.ts";
@@ -128,6 +129,32 @@ describe("a red main after one landing proposes its revert", () => {
128129 expect(reverts()).toHaveLength(0);
129130 });
130131
132 test("a step's own time limit opens no revert and comments once on the open main-runtime issue (#16669)", async () => {
133 const issue = createIssue(app.db, {
134 repoId: repo.id,
135 authorId: alice.id,
136 title: "Main's full check keeps running long",
137 body: "runtime",
138 });
139 if (!issue.ok) throw new Error("issue");
140 await mainCheck("ok");
141 await land("slow", "slow\n");
142 await mainCheck("failed", [], "check failed: check took longer than 2400s");
143 expect(await proposeRevert(app, repo.id)).toBeUndefined();
144 expect(await proposeRevert(app, repo.id)).toBeUndefined();
145 expect(reverts()).toHaveLength(0);
146 const notes = listComments(app.db, issue.value.id);
147 expect(notes).toHaveLength(1);
148 expect(notes[0]!.body).toContain("No revert was opened");
149 });
150
151 test("a named failing test still opens the revert", async () => {
152 await mainCheck("ok");
153 await land("bad", "bad\n");
154 await mainCheck("failed", ["parses the thing"], "check failed: 1 test failed");
155 expect(await proposeRevert(app, repo.id)).toBeDefined();
156 });
157
131158 test("a landing that added a migration pin opens none: its revert would delete the pin (#16637)", async () => {
132159 await mainCheck("ok");
133160 await land("one", "beta\n", [{ path: "src/core/migration-pins/20261128100000-walks.pin", content: "abc\n" }]);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs