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

The lane-stopped finding counts every open pull by state and files nothing for the crew when no pull is red #15356

Merged opened this

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

Merged

scout/forge:scout/15349-the-lane-stopped-finding-counts-every-op → main 0 commits fork

  • Merged. scout/15349-the-lane-stopped-finding-counts-every-op was merged into main as 9a19784.

Review

Sign in to review this change.
3 files changed +111 −20
src/crew/sentinel_lane.ts +8 −4
@@ -6,12 +6,14 @@
66 * A stop that is only the review queue (green pulls waiting on a person to
77 * merge, no one cause failing many) is the owner's ask on /flow, not a defect
88 * for the crew: no builder can merge, so filing it only parks a run (#14337).
9 * So is a stop with at most one red pull and no shared failure: the rest are
10 * stale or unchecked, which a person merges or re-checks (#15349).
911 */
1012
1113 import type { App } from "../app.ts";
1214 import type { Repo } from "../core/repos.ts";
1315 import type { User } from "../core/users.ts";
14 import type { LaneAlarm } from "../flow/alarm_lane.ts";
16 import { type LaneAlarm, queueWords } from "../flow/alarm_lane.ts";
1517 import { closeCaughtUp } from "./sentinel_main_ahead.ts";
1618 import type { Finding } from "./sentinel.ts";
1719
@@ -36,8 +38,10 @@ export function laneStopped(a: LaneAlarm): Finding[] {
3638 * alarm {@link laneStopped} read.
3739 */
3840 export function closeLaneMoving(app: App, repo: Repo, actor: User, active: ReadonlySet<string>, now: number, a: LaneAlarm): void {
39 const cleared = a.onPeople === true
40 ? `No one failure is stopping pulls: ${a.green} green ${a.green === 1 ? "pull waits" : "pulls wait"} on a person to merge, which is the owner's ask on /flow, not the crew's to fix`
41 : "The lane moved: a pull merged and no one failure is stopping many";
41 const cleared = a.onPeople !== true
42 ? "The lane moved: a pull merged and no one failure is stopping many"
43 : a.queue !== undefined && a.queue.green.length <= a.queue.red
44 ? `No one failure is stopping pulls and at most one is red (${queueWords(a.queue)}): the stop is a person's to merge or re-check, not the crew's to fix`
45 : `No one failure is stopping pulls: ${a.green} green ${a.green === 1 ? "pull waits" : "pulls wait"} on a person to merge, which is the owner's ask on /flow, not the crew's to fix`;
4246 closeCaughtUp(app, repo, actor, active, now, LANE_KEY, cleared);
4347 }
src/flow/alarm_lane.ts +40 −14
@@ -48,10 +48,12 @@ export interface LaneAlarm {
4848 * has stopped.
4949 */
5050 readonly green?: number | undefined;
51 /** The open pulls by state: green, stale, red and never checked; set when the alarm fired. */
52 readonly queue?: Queue | undefined;
5153 /**
52 * Whether the stop is the review queue's: green pulls wait on a person,
53 * outnumber the red ones, and no one cause is failing many. The owner is asked; the crew has
54 * nothing to fix (#14337).
54 * Whether the stop is the people's: no one cause is failing many, and
55 * either green pulls outnumber the red ones (#14337) or at most one pull
56 * is red (#15349). The owner is asked; the crew has nothing to fix.
5557 */
5658 readonly onPeople?: boolean;
5759 }
@@ -157,15 +159,25 @@ function ownRepoId(db: Database): string | undefined {
157159 return owner && name ? getRepo(db, owner, name)?.id : undefined;
158160 }
159161
160 /** The open pulls a person could merge now, by number, and how many open pulls are red. */
162 /**
163 * Every open pull in one of four states: the ones a person could merge now, by number, and counts
164 * of the rest.
165 */
161166 export interface Queue {
162167 /**
163168 * Numbers of the open pulls whose newest finished check passed on their current head since
164169 * `since`, oldest first.
165170 */
166171 readonly green: readonly number[];
172 /**
173 * Open pulls whose newest finished check passed, but on a head that moved or before `since`: they
174 * need a re-check.
175 */
176 readonly stale: number;
167177 /** Open pulls whose newest finished check failed. */
168178 readonly red: number;
179 /** Open pulls with no finished check, or whose newest was cancelled: no verdict yet. */
180 readonly unchecked: number;
169181 }
170182
171183 /**
@@ -177,10 +189,10 @@ export interface Queue {
177189 */
178190 export function reviewQueue(db: Database, repoId: string, since: string): Queue {
179191 const rows = db
180 .query<{ number: number; state: string; commit_oid: string; finished_at: string; head_oid: string }, [string]>(
192 .query<{ number: number; state: string | null; commit_oid: string | null; finished_at: string | null; head_oid: string }, [string]>(
181193 `SELECT i.number, r.state, r.commit_oid, r.finished_at, p.head_oid
182194 FROM issue i JOIN pull p ON p.issue_id = i.id
183 JOIN run r ON r.id = (SELECT r2.id FROM run r2
195 LEFT JOIN run r ON r.id = (SELECT r2.id FROM run r2
184196 WHERE r2.issue_id = i.id AND r2.kind = 'check' AND r2.state IN ('ok','failed','cancelled')
185197 ORDER BY r2.finished_at DESC, r2.id DESC LIMIT 1)
186198 WHERE i.repo_id = ?1 AND i.kind = 'pull' AND i.state = 'open'
@@ -189,11 +201,15 @@ export function reviewQueue(db: Database, repoId: string, since: string): Queue
189201 .all(repoId);
190202 const green: number[] = [];
191203 let red = 0;
204 let stale = 0;
205 let unchecked = 0;
192206 for (const r of rows) {
193207 if (r.state === "failed") red++;
194 else if (r.state === "ok" && r.head_oid !== "" && r.commit_oid === r.head_oid && r.finished_at >= since) green.push(r.number);
208 else if (r.state !== "ok") unchecked++;
209 else if (r.head_oid !== "" && r.commit_oid === r.head_oid && (r.finished_at ?? "") >= since) green.push(r.number);
210 else stale++;
195211 }
196 return { green, red };
212 return { green, stale, red, unchecked };
197213 }
198214
199215 /** At most this many green pulls are named. */
@@ -203,6 +219,10 @@ const named = (numbers: readonly number[]): string =>
203219
204220 const count = (n: number, noun: string) => `${n} ${noun}${n === 1 ? "" : "s"}`;
205221
222 /** The four counts of the open pulls, in one line. */
223 export const queueWords = (q: Queue): string =>
224 `${q.green.length} green since the last merge, ${q.stale} stale (passed on an older head or before the last merge), ${q.red} red, ${q.unchecked} never checked`;
225
206226 export function laneAlarm(db: Database, now: Date, forge: { readonly ceilingUsd: number | null } = { ceilingUsd: null }): LaneAlarm {
207227 const quiet = { fired: false, says: "Pulls are landing, or there is nothing to land, or the crew is paused on purpose." } as const;
208228 const repoId = ownRepoId(db);
@@ -245,7 +265,11 @@ export function laneAlarm(db: Database, now: Date, forge: { readonly ceilingUsd:
245265 parts.push(`${count(g, "pull")} passed ${g === 1 ? "its check and waits" : "their checks and wait"} on a person to merge: ${named(queue.green)}`);
246266 facts.push(`${count(g, "pull")} green, waiting on a person to merge: ${named(queue.green)}`);
247267 }
248 } else since = shared!.since;
268 } else {
269 since = shared!.since;
270 queue = reviewQueue(db, repoId, last ?? "");
271 }
272 facts.push(`open pulls: ${queueWords(queue)}`);
249273 if (shared !== undefined) {
250274 line = line ?? shared.line;
251275 if (stopped && shared.masked !== maskLine(line)) facts.push(`failed ${count(shared.pulls.size, "pull")} within the hour: ${shared.line}`);
@@ -254,9 +278,11 @@ export function laneAlarm(db: Database, now: Date, forge: { readonly ceilingUsd:
254278 );
255279 facts.push(`forge failure on ${count(shared.pulls.size, "pull")} within the hour since ${shared.since}: ${shared.line}`);
256280 }
257 // The queue's stop only when green pulls outnumber red ones: one green
258 // pull among many unrelated reds is still the crew's to hear about.
259 const green = queue?.green.length;
260 const onPeople = shared === undefined && queue !== undefined && queue.green.length > queue.red;
261 return { fired: true, since, says: `${parts.join(". ")}.`.replace(/\.\.$/, "."), line, forge: shared !== undefined, facts, green, onPeople };
281 // The people's stop when green pulls outnumber red ones, or when at most
282 // one pull is red: one green pull among many unrelated reds is still the
283 // crew's to hear about, but one red among stale and unchecked pulls is not
284 // a defect any builder can fix (#15349).
285 const green = queue.green.length;
286 const onPeople = shared === undefined && (queue.green.length > queue.red || queue.red <= 1);
287 return { fired: true, since, says: `${parts.join(". ")}.`.replace(/\.\.$/, "."), line, forge: shared !== undefined, facts, green, queue, onPeople };
262288 }
test/flow-alarm-lane.test.ts +63 −2
@@ -9,6 +9,7 @@ import { createUser } from "../src/core/users.ts";
99 import { getRun } from "../src/core/runs.ts";
1010 import { ownLandingStopped } from "../src/checks/gate_stopped.ts";
1111 import { hunt } from "../src/crew/sentinel.ts";
12 import { laneStopped } from "../src/crew/sentinel_lane.ts";
1213 import { firedAlarms } from "../src/flow/alarms.ts";
1314 import { forgeFailed, laneAlarm, laneMinutes, maskLine } from "../src/flow/alarm_lane.ts";
1415 import { id } from "../src/kernel/id.ts";
@@ -216,14 +217,16 @@ describe("a stop that is the review queue's (#14337)", () => {
216217 expect(open()).toHaveLength(1);
217218 });
218219
219 test("a newer red check makes a pull not green, and with none green the crew is told", () => {
220 test("a newer red check makes a pull not green, and with none green and two red the crew is told", () => {
220221 reset();
221222 pull("closed", 200);
222223 const p = pull("open");
223224 passed(p, 120);
224225 failed(p, 100, "gate: rule broke");
226 failed(pull("open"), 90, "gate: other rule broke");
225227 const a = laneAlarm(app.db, NOW);
226228 expect(a.green).toBe(0);
229 expect(a.queue?.red).toBe(2);
227230 expect(a.onPeople).toBe(false);
228231 hunt(app, "trevato/forge", NOW.getTime());
229232 expect(open()).toHaveLength(1);
@@ -234,25 +237,68 @@ describe("a stop that is the review queue's (#14337)", () => {
234237 pull("closed", 200);
235238 passed(pull("open"), 120, "old-head");
236239 passed(pull("open"), 250);
240 failed(pull("open"), 100, "gate: rule broke");
241 failed(pull("open"), 90, "gate: other rule broke");
237242 const a = laneAlarm(app.db, NOW);
238243 expect(a.fired).toBe(true);
239244 expect(a.green).toBe(0);
245 expect(a.queue?.stale).toBe(2);
240246 expect(a.onPeople).toBe(false);
241247 hunt(app, "trevato/forge", NOW.getTime());
242248 expect(open()).toHaveLength(1);
243249 });
244250
251 test("30 open, 1 red and 0 green with no shared failure is the people's: no finding, all four counts said (#15349)", () => {
252 reset();
253 pull("closed", 200);
254 for (let i = 0; i < 10; i++) passed(pull("open"), 250 + i);
255 for (let i = 0; i < 19; i++) pull("open");
256 failed(pull("open"), 100, "gate: rule broke");
257 const a = laneAlarm(app.db, NOW);
258 expect(a.fired).toBe(true);
259 expect(a.forge).toBe(false);
260 expect(a.queue).toEqual({ green: [], stale: 10, red: 1, unchecked: 19 });
261 expect(a.facts).toContain("30 pulls open");
262 expect(a.facts).toContain(
263 "open pulls: 0 green since the last merge, 10 stale (passed on an older head or before the last merge), 1 red, 19 never checked",
264 );
265 expect(a.onPeople).toBe(true);
266 expect(laneStopped(a)).toEqual([]);
267 hunt(app, "trevato/forge", NOW.getTime());
268 expect(open()).toHaveLength(0);
269 // The owner still sees it on /flow.
270 expect(lane()).toHaveLength(1);
271 });
272
273 test("an open lane issue closes, saying at most one is red, once the reds drop to one", () => {
274 reset();
275 pull("closed", 200);
276 const p = pull("open");
277 failed(p, 100, "gate: rule broke");
278 failed(pull("open"), 95, "gate: other rule broke");
279 hunt(app, "trevato/forge", NOW.getTime());
280 expect(open()).toHaveLength(1);
281 passed(p, 50, "old-head");
282 hunt(app, "trevato/forge", NOW.getTime() + 60_000);
283 expect(open()).toHaveLength(0);
284 expect(closing()).toContain("at most one is red (0 green since the last merge, 1 stale");
285 expect(closing()).toContain("1 red, 0 never checked");
286 });
287
245288 test("an open lane issue closes, saying the queue waits on a person, once a pull goes green", () => {
246289 reset();
247290 pull("closed", 200);
248291 const p = pull("open");
292 const q = pull("open");
249293 failed(p, 100, "gate: rule broke");
294 failed(q, 95, "gate: other rule broke");
250295 hunt(app, "trevato/forge", NOW.getTime());
251296 expect(open()).toHaveLength(1);
252297 passed(p, 50);
298 passed(q, 45);
253299 hunt(app, "trevato/forge", NOW.getTime() + 60_000);
254300 expect(open()).toHaveLength(0);
255 expect(closing()).toContain("1 green pull waits on a person to merge");
301 expect(closing()).toContain("2 green pulls wait on a person to merge");
256302 });
257303 });
258304
@@ -270,6 +316,21 @@ describe("one cause failing many pulls", () => {
270316 expect(forgeFailed(app.db, getRun(app.db, runs[0]!), NOW.getTime())).toBe(true);
271317 });
272318
319 test("a shared failure still files the finding, with the four counts, even when the lane has stopped (#15349)", () => {
320 reset();
321 pull("closed", 200);
322 const pulls = Array.from({ length: 5 }, () => pull("open"));
323 pulls.forEach((p, i) => failed(p, 5 + i, LINE.replace("16.0", `${i + 11}.5`)));
324 const a = laneAlarm(app.db, NOW);
325 expect(a.forge).toBe(true);
326 expect(a.onPeople).toBe(false);
327 expect(a.facts).toContain("open pulls: 0 green since the last merge, 0 stale (passed on an older head or before the last merge), 5 red, 0 never checked");
328 expect(laneStopped(a).map((f) => f.key)).toEqual(["lane-stopped"]);
329 hunt(app, "trevato/forge", NOW.getTime());
330 const filed = app.db.query<{ n: number }, []>(`SELECT COUNT(*) AS n FROM issue WHERE state = 'open' AND title LIKE 'Sentinel: One failure is stopping many pulls%'`).get()!.n;
331 expect(filed).toBe(1);
332 });
333
273334 test("four pulls, or five over two hours, or a named test, are the pull's own", () => {
274335 reset();
275336 pull("closed", 10);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs