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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16669-sentinel-never-open-a-revert-when-main-s → main 0 commits fork
3 files
changed +64
−3
src/checks/red_main.ts +6 −1
| @@ -88,7 +88,12 @@ const lastMain = (from: string): string => ` | ||
| 88 | 88 | * A summary of a cell stop (`apps/contain.ts`), a budget kill (`kernel/budgets.ts`), a check that |
| 89 | 89 | * stalled (`checks/stall.ts`) or one the forge's stopping cut off: the machine's, not a pull's. |
| 90 | 90 | */ |
| 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); | |
| 92 | 97 | |
| 93 | 98 | function toRed(row: Row): RedMain | undefined { |
| 94 | 99 | if (row.state !== "failed") return undefined; |
src/checks/revert_red.ts +31 −2
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | import type { App } from "../app.ts"; |
| 13 | 13 | import { revertPull } from "../actions/revert.ts"; |
| 14 | import { getIssueById } from "../core/issues.ts"; | |
| 14 | import { addComment, getIssueById } from "../core/issues.ts"; | |
| 15 | 15 | import { getPull, type Pull } from "../core/pulls.ts"; |
| 16 | 16 | import { getRepoById } from "../core/repos.ts"; |
| 17 | 17 | import { getUserById } from "../core/users.ts"; |
| @@ -19,7 +19,7 @@ import { runGit } from "../git/env.ts"; | ||
| 19 | 19 | import { repoDir } from "../git/repos.ts"; |
| 20 | 20 | import { isSafeOid } from "../git/guard.ts"; |
| 21 | 21 | 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"; | |
| 23 | 23 | |
| 24 | 24 | /** The reds being answered now: a check finishing twice at once proposes once. */ |
| 25 | 25 | const working = new Set<string>(); |
| @@ -80,6 +80,34 @@ export function revertBody(pull: Pick<Pull, "number">, red: RedMain): string { | ||
| 80 | 80 | 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.`; |
| 81 | 81 | } |
| 82 | 82 | |
| 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 | ||
| 83 | 111 | /** |
| 84 | 112 | * Called when a default-branch check of `repoId` has finished: opens the |
| 85 | 113 | * 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 | ||
| 90 | 118 | working.add(repoId); |
| 91 | 119 | try { |
| 92 | 120 | const red = redMain(app.db, repoId); |
| 121 | if (red !== undefined && ranOutOfTime(red.summary)) noteTimeout(app, red); | |
| 93 | 122 | if (red === undefined || red.limit || manifestError(red) !== undefined) return undefined; |
| 94 | 123 | const green = greenBefore(app, repoId, red.branch, red.runId); |
| 95 | 124 | if (green === undefined) return undefined; |
test/revert-red.test.ts +27
| @@ -11,6 +11,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 11 | 11 | import { mergePull, openPull } from "../src/actions/pulls.ts"; |
| 12 | 12 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 13 | 13 | import { proposeRevert } from "../src/checks/revert_red.ts"; |
| 14 | import { createIssue, listComments } from "../src/core/issues.ts"; | |
| 14 | 15 | import { getPull, listPulls, type Pull } from "../src/core/pulls.ts"; |
| 15 | 16 | import type { Repo } from "../src/core/repos.ts"; |
| 16 | 17 | import { createRun } from "../src/core/runs.ts"; |
| @@ -128,6 +129,32 @@ describe("a red main after one landing proposes its revert", () => { | ||
| 128 | 129 | expect(reverts()).toHaveLength(0); |
| 129 | 130 | }); |
| 130 | 131 | |
| 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 | ||
| 131 | 158 | test("a landing that added a migration pin opens none: its revert would delete the pin (#16637)", async () => { |
| 132 | 159 | await mainCheck("ok"); |
| 133 | 160 | await land("one", "beta\n", [{ path: "src/core/migration-pins/20261128100000-walks.pin", content: "abc\n" }]); |
new above
offline