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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15349-the-lane-stopped-finding-counts-every-op → main 0 commits fork
3 files
changed +111
−20
src/crew/sentinel_lane.ts +8 −4
| @@ -6,12 +6,14 @@ | ||
| 6 | 6 | * A stop that is only the review queue (green pulls waiting on a person to |
| 7 | 7 | * merge, no one cause failing many) is the owner's ask on /flow, not a defect |
| 8 | 8 | * 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). | |
| 9 | 11 | */ |
| 10 | 12 | |
| 11 | 13 | import type { App } from "../app.ts"; |
| 12 | 14 | import type { Repo } from "../core/repos.ts"; |
| 13 | 15 | 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"; | |
| 15 | 17 | import { closeCaughtUp } from "./sentinel_main_ahead.ts"; |
| 16 | 18 | import type { Finding } from "./sentinel.ts"; |
| 17 | 19 | |
| @@ -36,8 +38,10 @@ export function laneStopped(a: LaneAlarm): Finding[] { | ||
| 36 | 38 | * alarm {@link laneStopped} read. |
| 37 | 39 | */ |
| 38 | 40 | 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`; | |
| 42 | 46 | closeCaughtUp(app, repo, actor, active, now, LANE_KEY, cleared); |
| 43 | 47 | } |
src/flow/alarm_lane.ts +40 −14
| @@ -48,10 +48,12 @@ export interface LaneAlarm { | ||
| 48 | 48 | * has stopped. |
| 49 | 49 | */ |
| 50 | 50 | 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; | |
| 51 | 53 | /** |
| 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. | |
| 55 | 57 | */ |
| 56 | 58 | readonly onPeople?: boolean; |
| 57 | 59 | } |
| @@ -157,15 +159,25 @@ function ownRepoId(db: Database): string | undefined { | ||
| 157 | 159 | return owner && name ? getRepo(db, owner, name)?.id : undefined; |
| 158 | 160 | } |
| 159 | 161 | |
| 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 | */ | |
| 161 | 166 | export interface Queue { |
| 162 | 167 | /** |
| 163 | 168 | * Numbers of the open pulls whose newest finished check passed on their current head since |
| 164 | 169 | * `since`, oldest first. |
| 165 | 170 | */ |
| 166 | 171 | 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; | |
| 167 | 177 | /** Open pulls whose newest finished check failed. */ |
| 168 | 178 | readonly red: number; |
| 179 | /** Open pulls with no finished check, or whose newest was cancelled: no verdict yet. */ | |
| 180 | readonly unchecked: number; | |
| 169 | 181 | } |
| 170 | 182 | |
| 171 | 183 | /** |
| @@ -177,10 +189,10 @@ export interface Queue { | ||
| 177 | 189 | */ |
| 178 | 190 | export function reviewQueue(db: Database, repoId: string, since: string): Queue { |
| 179 | 191 | 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]>( | |
| 181 | 193 | `SELECT i.number, r.state, r.commit_oid, r.finished_at, p.head_oid |
| 182 | 194 | 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 | |
| 184 | 196 | WHERE r2.issue_id = i.id AND r2.kind = 'check' AND r2.state IN ('ok','failed','cancelled') |
| 185 | 197 | ORDER BY r2.finished_at DESC, r2.id DESC LIMIT 1) |
| 186 | 198 | 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 | ||
| 189 | 201 | .all(repoId); |
| 190 | 202 | const green: number[] = []; |
| 191 | 203 | let red = 0; |
| 204 | let stale = 0; | |
| 205 | let unchecked = 0; | |
| 192 | 206 | for (const r of rows) { |
| 193 | 207 | 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++; | |
| 195 | 211 | } |
| 196 | return { green, red }; | |
| 212 | return { green, stale, red, unchecked }; | |
| 197 | 213 | } |
| 198 | 214 | |
| 199 | 215 | /** At most this many green pulls are named. */ |
| @@ -203,6 +219,10 @@ const named = (numbers: readonly number[]): string => | ||
| 203 | 219 | |
| 204 | 220 | const count = (n: number, noun: string) => `${n} ${noun}${n === 1 ? "" : "s"}`; |
| 205 | 221 | |
| 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 | ||
| 206 | 226 | export function laneAlarm(db: Database, now: Date, forge: { readonly ceilingUsd: number | null } = { ceilingUsd: null }): LaneAlarm { |
| 207 | 227 | const quiet = { fired: false, says: "Pulls are landing, or there is nothing to land, or the crew is paused on purpose." } as const; |
| 208 | 228 | const repoId = ownRepoId(db); |
| @@ -245,7 +265,11 @@ export function laneAlarm(db: Database, now: Date, forge: { readonly ceilingUsd: | ||
| 245 | 265 | parts.push(`${count(g, "pull")} passed ${g === 1 ? "its check and waits" : "their checks and wait"} on a person to merge: ${named(queue.green)}`); |
| 246 | 266 | facts.push(`${count(g, "pull")} green, waiting on a person to merge: ${named(queue.green)}`); |
| 247 | 267 | } |
| 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)}`); | |
| 249 | 273 | if (shared !== undefined) { |
| 250 | 274 | line = line ?? shared.line; |
| 251 | 275 | 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: | ||
| 254 | 278 | ); |
| 255 | 279 | facts.push(`forge failure on ${count(shared.pulls.size, "pull")} within the hour since ${shared.since}: ${shared.line}`); |
| 256 | 280 | } |
| 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 }; | |
| 262 | 288 | } |
test/flow-alarm-lane.test.ts +63 −2
| @@ -9,6 +9,7 @@ import { createUser } from "../src/core/users.ts"; | ||
| 9 | 9 | import { getRun } from "../src/core/runs.ts"; |
| 10 | 10 | import { ownLandingStopped } from "../src/checks/gate_stopped.ts"; |
| 11 | 11 | import { hunt } from "../src/crew/sentinel.ts"; |
| 12 | import { laneStopped } from "../src/crew/sentinel_lane.ts"; | |
| 12 | 13 | import { firedAlarms } from "../src/flow/alarms.ts"; |
| 13 | 14 | import { forgeFailed, laneAlarm, laneMinutes, maskLine } from "../src/flow/alarm_lane.ts"; |
| 14 | 15 | import { id } from "../src/kernel/id.ts"; |
| @@ -216,14 +217,16 @@ describe("a stop that is the review queue's (#14337)", () => { | ||
| 216 | 217 | expect(open()).toHaveLength(1); |
| 217 | 218 | }); |
| 218 | 219 | |
| 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", () => { | |
| 220 | 221 | reset(); |
| 221 | 222 | pull("closed", 200); |
| 222 | 223 | const p = pull("open"); |
| 223 | 224 | passed(p, 120); |
| 224 | 225 | failed(p, 100, "gate: rule broke"); |
| 226 | failed(pull("open"), 90, "gate: other rule broke"); | |
| 225 | 227 | const a = laneAlarm(app.db, NOW); |
| 226 | 228 | expect(a.green).toBe(0); |
| 229 | expect(a.queue?.red).toBe(2); | |
| 227 | 230 | expect(a.onPeople).toBe(false); |
| 228 | 231 | hunt(app, "trevato/forge", NOW.getTime()); |
| 229 | 232 | expect(open()).toHaveLength(1); |
| @@ -234,25 +237,68 @@ describe("a stop that is the review queue's (#14337)", () => { | ||
| 234 | 237 | pull("closed", 200); |
| 235 | 238 | passed(pull("open"), 120, "old-head"); |
| 236 | 239 | passed(pull("open"), 250); |
| 240 | failed(pull("open"), 100, "gate: rule broke"); | |
| 241 | failed(pull("open"), 90, "gate: other rule broke"); | |
| 237 | 242 | const a = laneAlarm(app.db, NOW); |
| 238 | 243 | expect(a.fired).toBe(true); |
| 239 | 244 | expect(a.green).toBe(0); |
| 245 | expect(a.queue?.stale).toBe(2); | |
| 240 | 246 | expect(a.onPeople).toBe(false); |
| 241 | 247 | hunt(app, "trevato/forge", NOW.getTime()); |
| 242 | 248 | expect(open()).toHaveLength(1); |
| 243 | 249 | }); |
| 244 | 250 | |
| 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 | ||
| 245 | 288 | test("an open lane issue closes, saying the queue waits on a person, once a pull goes green", () => { |
| 246 | 289 | reset(); |
| 247 | 290 | pull("closed", 200); |
| 248 | 291 | const p = pull("open"); |
| 292 | const q = pull("open"); | |
| 249 | 293 | failed(p, 100, "gate: rule broke"); |
| 294 | failed(q, 95, "gate: other rule broke"); | |
| 250 | 295 | hunt(app, "trevato/forge", NOW.getTime()); |
| 251 | 296 | expect(open()).toHaveLength(1); |
| 252 | 297 | passed(p, 50); |
| 298 | passed(q, 45); | |
| 253 | 299 | hunt(app, "trevato/forge", NOW.getTime() + 60_000); |
| 254 | 300 | 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"); | |
| 256 | 302 | }); |
| 257 | 303 | }); |
| 258 | 304 | |
| @@ -270,6 +316,21 @@ describe("one cause failing many pulls", () => { | ||
| 270 | 316 | expect(forgeFailed(app.db, getRun(app.db, runs[0]!), NOW.getTime())).toBe(true); |
| 271 | 317 | }); |
| 272 | 318 | |
| 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 | ||
| 273 | 334 | test("four pulls, or five over two hours, or a named test, are the pull's own", () => { |
| 274 | 335 | reset(); |
| 275 | 336 | pull("closed", 10); |
new above
offline