Public: anyone can read this; the crew can change it.
A check's plan line survives a long log: in the summary when green, in the detail when red #16889
Check · Review · Land · Live done — Landed and live in production.
plan-line → main 0 commits 1 thread · 1 unresolved
10 files
changed +209
−6
src/checks/execute.ts +1
| @@ -221,6 +221,7 @@ export async function execute( | ||
| 221 | 221 | ...(outcome.ok |
| 222 | 222 | ? {} |
| 223 | 223 | : { checkDetail: withDisk(outcome.detail, app.config.dataDir) }), |
| 224 | ...(outcome.plan === undefined ? {} : { checkPlan: outcome.plan }), | |
| 224 | 225 | }); |
| 225 | 226 | write(outcome.ok ? `passed in ${seconds}s` : `failed: ${outcome.error}`); |
| 226 | 227 | // The pages the gate chose to picture are said on the pull (#13373), worked out by the |
src/checks/plan_line.ts added +44
| @@ -0,0 +1,44 @@ | ||
| 1 | /** | |
| 2 | * Why a check ran what it ran, kept where it outlives the log (#16881). test-shards says | |
| 3 | * its plan at the head of the check step ("fast tier, 128 of 4536 files for 3 changed, by | |
| 4 | * coverage: …", "…, full tier, forge.json changed", "measuring 3722 files under coverage …"), but a | |
| 5 | * run's log keeps only its last 512 KiB, and a long run's `(pass)` lines push the head out: on | |
| 6 | * production the plan of every 12-minute pull check was gone. The forge reads the plan from the | |
| 7 | * step's own output as the branch ran it, here or on a runner, and keeps it in the run's own | |
| 8 | * `check_plan` (`core/runs.ts`), green or red, apart from the summary and the check detail. | |
| 9 | * | |
| 10 | * It is the branch's word: test-shards is a script in the pull's checkout, so a branch can print | |
| 11 | * any plan it likes. It is informational, never a verdict, and nothing judges by it; it is shown | |
| 12 | * on no page or screen today, only in the run as the API and MCP give it, so anything that renders | |
| 13 | * it later escapes it as any text of the branch's. | |
| 14 | */ | |
| 15 | ||
| 16 | import type { CheckOutcome } from "./runner.ts"; | |
| 17 | ||
| 18 | /** test-shards' lines that say what it will run, in the order it says them. */ | |
| 19 | const PLAN = /test-shards: ((?:fast tier|looks lane|matrix slice|measuring \d+ files|FORGE_CHECK_ONLY keeps|\d+ of \d+ files kept)\b.*)$/; | |
| 20 | ||
| 21 | /** The longest plan kept: three of test-shards' lines fit, and the branch writes no more. */ | |
| 22 | export const PLAN_MAX = 600; | |
| 23 | ||
| 24 | /** | |
| 25 | * The plan test-shards said in `lines`, its first three lines joined; undefined when it said none. | |
| 26 | */ | |
| 27 | export function planOf(lines: readonly string[]): string | undefined { | |
| 28 | const said: string[] = []; | |
| 29 | for (const line of lines) { | |
| 30 | const hit = PLAN.exec(line.trimEnd()); | |
| 31 | if (hit === null) continue; | |
| 32 | said.push(hit[1]!); | |
| 33 | if (said.length === 3) break; | |
| 34 | } | |
| 35 | if (said.length === 0) return undefined; | |
| 36 | const plan = said.join("; "); | |
| 37 | return plan.length > PLAN_MAX ? `${plan.slice(0, PLAN_MAX - 1)}…` : plan; | |
| 38 | } | |
| 39 | ||
| 40 | /** `outcome` with the plan of `lines` beside it, when they said one. */ | |
| 41 | export function withPlan(outcome: CheckOutcome, lines: readonly string[]): CheckOutcome { | |
| 42 | const plan = planOf(lines); | |
| 43 | return plan === undefined ? outcome : { ...outcome, plan }; | |
| 44 | } |
src/checks/run_tier.ts +5 −4
| @@ -28,6 +28,7 @@ import { noteReached } from "../apps/egress_report.ts"; | ||
| 28 | 28 | import { capacityEnv, checkShardCpus, egressSetting, shardsInForce, shardsLine } from "../core/capacity.ts"; |
| 29 | 29 | import { cellsAvailable, origin, limitWarnings, resolveLimits, STEP_HOSTS, stoppedForCpu, type CellSpec } from "../apps/contain.ts"; |
| 30 | 30 | import { summariseCheckFailure } from "./summary.ts"; |
| 31 | import { withPlan } from "./plan_line.ts"; | |
| 31 | 32 | import { err, type Result } from "../kernel/result.ts"; |
| 32 | 33 | import { JOB_GATE_NOTE, jobGatePolicy, openJobGate } from "./job_gate.ts"; |
| 33 | 34 | import type { Placement } from "./placement.ts"; |
| @@ -372,7 +373,7 @@ export async function runTier(lane: LaneState, x: Execution): Promise<CheckOutco | ||
| 372 | 373 | write(`impact map not kept: ${String(error)}`); |
| 373 | 374 | } |
| 374 | 375 | } |
| 375 | return { | |
| 376 | return withPlan({ | |
| 376 | 377 | ok: false, |
| 377 | 378 | error: killed ? ran.error : summary, |
| 378 | 379 | detail: withFlaky(redDetail(detail, files, checkLines), flaky), |
| @@ -380,7 +381,7 @@ export async function runTier(lane: LaneState, x: Execution): Promise<CheckOutco | ||
| 380 | 381 | stage: checkStage(ran.error), |
| 381 | 382 | ...(killed ? { killed } : {}), |
| 382 | 383 | ...(stoppedForCpu(ran.error) ? { cpuStop: ran.error } : {}), |
| 383 | }; | |
| 384 | }, checkLines); | |
| 384 | 385 | } |
| 385 | 386 | // deepsec's review (#15024, `checks/deepsec_step.ts`): forge code, after the pull's step is |
| 386 | 387 | // green, in a cell of its own that alone holds the model key. The pull's step never sees it. |
| @@ -424,11 +425,11 @@ export async function runTier(lane: LaneState, x: Execution): Promise<CheckOutco | ||
| 424 | 425 | } |
| 425 | 426 | if (key !== undefined) recordProven(app.db, key, x.id); |
| 426 | 427 | const cleared = clearedIn(checkLines); |
| 427 | return { | |
| 428 | return withPlan({ | |
| 428 | 429 | ok: true, |
| 429 | 430 | ...(wholeVerify ? { passed: passedFiles(checkLines) } : {}), |
| 430 | 431 | ...(cleared === undefined ? {} : { cleared }), |
| 431 | }; | |
| 432 | }, checkLines); | |
| 432 | 433 | } finally { |
| 433 | 434 | // Red or green, what an audit contradicted is forgotten by the store (#16270). |
| 434 | 435 | try { |
src/checks/runner.ts +4
| @@ -51,6 +51,8 @@ export type CheckOutcome = | ||
| 51 | 51 | passed?: readonly string[]; |
| 52 | 52 | /** A red it cleared as main's (#10304): `base_red.ts`'s words, kept in the summary. */ |
| 53 | 53 | cleared?: string; |
| 54 | /** What test-shards said it would run (`plan_line.ts`), kept as the run's `checkPlan`. */ | |
| 55 | plan?: string; | |
| 54 | 56 | } |
| 55 | 57 | | { |
| 56 | 58 | ok: false; |
| @@ -65,6 +67,8 @@ export type CheckOutcome = | ||
| 65 | 67 | stage?: GateStage; |
| 66 | 68 | /** The check step was ended by a signal from outside: no verdict (#6722). */ |
| 67 | 69 | killed?: boolean; |
| 70 | /** What test-shards said it would run (`plan_line.ts`), kept as the run's `checkPlan`. */ | |
| 71 | plan?: string; | |
| 68 | 72 | }; |
| 69 | 73 | |
| 70 | 74 | export interface Runner { |
src/checks/tier_runner.ts +3 −2
| @@ -17,6 +17,7 @@ import type { Execution } from "./local_runner.ts"; | ||
| 17 | 17 | import type { CheckManifest } from "../apps/manifest.ts"; |
| 18 | 18 | import { readFileAt } from "../apps/checkout.ts"; |
| 19 | 19 | import { runsAsBaseGate, withBaseGateFrom } from "./base_gate.ts"; |
| 20 | import { withPlan } from "./plan_line.ts"; | |
| 20 | 21 | |
| 21 | 22 | /** What a check handed to a runner is made of. */ |
| 22 | 23 | export interface RunnerCheck { |
| @@ -129,10 +130,10 @@ export async function tryRunner( | ||
| 129 | 130 | } catch (error) { |
| 130 | 131 | write(`crash flakes not recorded: ${String(error)}`); |
| 131 | 132 | } |
| 132 | if (!verdict.ok) return verdict; | |
| 133 | if (!verdict.ok) return withPlan(verdict, lines); | |
| 133 | 134 | if (key !== undefined) recordProven(app.db, key, x.id); |
| 134 | 135 | const cleared = clearedIn(lines); |
| 135 | return { ok: true, ...(cleared === undefined ? {} : { cleared }) }; | |
| 136 | return withPlan({ ok: true, ...(cleared === undefined ? {} : { cleared }) }, lines); | |
| 136 | 137 | } |
| 137 | 138 | } |
| 138 | 139 | return undefined; |
src/core/migration-pins/20261130235220-run-check-plan.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 214c91279864fff0a60c219eef86a1580312fb1d3ff2c16eb81672fbbd622bb1 |
src/core/migrations/20261130235220-run-check-plan.ts added +7
| @@ -0,0 +1,7 @@ | ||
| 1 | // What a check set out to run and why (`checks/plan_line.ts`): test-shards' plan lines from the | |
| 2 | // check step's own output, kept in the run because a long run's log loses its head to the 512 KiB | |
| 3 | // tail. Its own column, not the summary (cut at 500 characters, quoted and compared as the | |
| 4 | // verdict) and not the check detail (a red's recognised failures). Empty: none said. Additive. | |
| 5 | export default ` | |
| 6 | ALTER TABLE run ADD COLUMN check_plan TEXT NOT NULL DEFAULT ''; | |
| 7 | `; |
src/core/runs.ts +11
| @@ -132,6 +132,11 @@ export interface Run { | ||
| 132 | 132 | readonly setupMs: number; |
| 133 | 133 | /** A failed check's own detail, when its output was recognised; null otherwise. */ |
| 134 | 134 | readonly checkDetail: CheckDetail | null; |
| 135 | /** | |
| 136 | * What a check said it would run and why, from its step's own output (`checks/plan_line.ts`); | |
| 137 | * empty when it said nothing. The branch's code prints it: informational, never a verdict. | |
| 138 | */ | |
| 139 | readonly checkPlan: string; | |
| 135 | 140 | /** The base tip a pull's check merged the head with; empty when it merged nothing. */ |
| 136 | 141 | readonly baseOid: string; |
| 137 | 142 | /** The combined commit a kept fork's pull check tested; empty when it tested another tree. */ |
| @@ -175,6 +180,7 @@ interface RunRow { | ||
| 175 | 180 | sandbox_note: string; |
| 176 | 181 | sent: number; |
| 177 | 182 | check_detail: string; |
| 183 | check_plan: string; | |
| 178 | 184 | base_oid: string; |
| 179 | 185 | combined_oid: string; |
| 180 | 186 | placement: string; |
| @@ -220,6 +226,7 @@ const toRun = (r: RunRow): Run => ({ | ||
| 220 | 226 | start: r.start, |
| 221 | 227 | setupMs: r.setup_ms, |
| 222 | 228 | checkDetail: r.check_detail ? (JSON.parse(r.check_detail) as CheckDetail) : null, |
| 229 | checkPlan: r.check_plan ?? "", | |
| 223 | 230 | baseOid: r.base_oid, |
| 224 | 231 | combinedOid: r.combined_oid, |
| 225 | 232 | variantGroup: r.variant_group, |
| @@ -373,6 +380,8 @@ export function finishRun( | ||
| 373 | 380 | pushed?: boolean | undefined; |
| 374 | 381 | /** A failed check's own detail, when its output was recognised. */ |
| 375 | 382 | checkDetail?: CheckDetail | undefined; |
| 383 | /** What a check said it would run (`checks/plan_line.ts`), green or red. */ | |
| 384 | checkPlan?: string | undefined; | |
| 376 | 385 | /** For an agent run: the head it left the branch at, when that is worth keeping. */ |
| 377 | 386 | commitOid?: string | undefined; |
| 378 | 387 | }, |
| @@ -385,6 +394,7 @@ export function finishRun( | ||
| 385 | 394 | turns = COALESCE(?6, turns), check_detail = ?7, |
| 386 | 395 | context_tokens = COALESCE(?9, context_tokens), pushed = COALESCE(?10, pushed), |
| 387 | 396 | tokens_in = COALESCE(?11, tokens_in), tokens_out = COALESCE(?12, tokens_out), |
| 397 | check_plan = ?13, | |
| 388 | 398 | finished_at = strftime('%Y-%m-%dT%H:%M:%fZ','now') |
| 389 | 399 | WHERE id = ?1 AND state = 'running'`, |
| 390 | 400 | ) |
| @@ -401,6 +411,7 @@ export function finishRun( | ||
| 401 | 411 | outcome.pushed === undefined ? null : outcome.pushed ? 1 : 0, |
| 402 | 412 | knownTokens(outcome.tokensIn), |
| 403 | 413 | knownTokens(outcome.tokensOut), |
| 414 | outcome.checkPlan ?? "", | |
| 404 | 415 | ).changes; |
| 405 | 416 | const done = changes > 0 ? getRun(db, runId) : undefined; |
| 406 | 417 | if (done !== undefined) appendRun(done, meterOf(db)); |
test/plan-line-runner.test.ts added +51
| @@ -0,0 +1,51 @@ | ||
| 1 | /** | |
| 2 | * A check a runner ran keeps its plan as one run here does (`checks/plan_line.ts`): read from the | |
| 3 | * lines the runner reported, kept once in the run's `checkPlan`, never lost on the way back | |
| 4 | * through `tryRunner` and `runTier`. | |
| 5 | */ | |
| 6 | import { beforeAll, expect, test } from "bun:test"; | |
| 7 | import { openPull } from "../src/actions/pulls.ts"; | |
| 8 | import { commitToBranch } from "../src/actions/repos.ts"; | |
| 9 | import { deskOf, enrolRunner, type RunnerJob } from "../src/checks/runner_jobs.ts"; | |
| 10 | import { startChecks } from "../src/checks/service.ts"; | |
| 11 | import { checkJson, checksForge } from "./helpers/checks-forge.ts"; | |
| 12 | import { quietLogs } from "./helpers/globals.ts"; | |
| 13 | ||
| 14 | quietLogs(); | |
| 15 | ||
| 16 | const f = checksForge("forge-plan-runner-"); | |
| 17 | const PLAN = "fast tier, 3 of 40 files for 2 changed, by coverage: 2 changed files reach 3 tests (expected 9s)"; | |
| 18 | ||
| 19 | const api = (path: string, token: string, body?: unknown): Promise<Response> => | |
| 20 | fetch(`${f.servers.url}${path}`, { | |
| 21 | method: body === undefined ? "GET" : "POST", | |
| 22 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 23 | ...(body === undefined ? {} : { body: JSON.stringify(body) }), | |
| 24 | }); | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | await f.checks.stop(); | |
| 28 | f.checks = startChecks(f.app, { forgeUrl: f.servers.url, concurrency: 1, placement: { mode: "runner", waitMs: 300 } }); | |
| 29 | const gate = await commitToBranch(f.app, f.alice, f.repo, { message: "Declare the check", files: [{ path: "forge.json", content: checkJson("true") }] }); | |
| 30 | if (!gate.ok) throw new Error(JSON.stringify(gate.error)); | |
| 31 | await f.settled((r) => r.commitOid === gate.value.commitOid, 30_000); | |
| 32 | }); | |
| 33 | ||
| 34 | test("a runner's reported plan is the run's checkPlan, once", async () => { | |
| 35 | const box = enrolRunner(f.app.db, "planner", f.alice.id); | |
| 36 | const asked = api("/api/v1/runner/claim", box.token, { wait: 20, cells: true }); | |
| 37 | await f.until(() => deskOf(f.app).claimers.size > 0, "the runner waiting in its claim"); | |
| 38 | const made = await commitToBranch(f.app, f.alice, f.repo, { branch: "planned", message: "Add p", files: [{ path: "p.txt", content: "p\n" }] }); | |
| 39 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 40 | const opened = await openPull(f.app, f.alice, f.repo, { title: "planned", body: "", baseBranch: "main", headBranch: "planned" }); | |
| 41 | if (!opened.ok) throw new Error(JSON.stringify(opened.error)); | |
| 42 | const claim = (await (await asked).json()) as { job: RunnerJob; token: string }; | |
| 43 | const door = `/api/v1/runner/jobs/${claim.job.id}`; | |
| 44 | expect((await api(door, claim.token, { step: "check", lines: ["$ true", `test-shards: ${PLAN}`, "(pass) a"] })).status).toBe(200); | |
| 45 | expect((await api(door, claim.token, { done: { steps: [{ name: "check", ok: true, ms: 1 }], contained: true, note: "" } })).status).toBe(200); | |
| 46 | const run = await f.settled((r) => r.commitOid === made.value.commitOid, 30_000); | |
| 47 | expect(run.state).toBe("ok"); | |
| 48 | expect(run.placement).toBe("runner"); | |
| 49 | expect(run.checkPlan).toBe(PLAN); | |
| 50 | expect(run.summary).not.toContain(PLAN); | |
| 51 | }); |
test/plan-line.test.ts added +82
| @@ -0,0 +1,82 @@ | ||
| 1 | /** | |
| 2 | * The plan a check ran by outlives its log (`checks/plan_line.ts`): a run's log keeps only its last | |
| 3 | * 512 KiB, so a long run's head, where test-shards says what it will run and why, was gone. The | |
| 4 | * forge keeps the plan from the step's own lines: in a green run's summary, in a red run's detail. | |
| 5 | */ | |
| 6 | import { beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { openPull } from "../src/actions/pulls.ts"; | |
| 8 | import { commitToBranch } from "../src/actions/repos.ts"; | |
| 9 | import { PLAN_MAX, planOf } from "../src/checks/plan_line.ts"; | |
| 10 | import { readRunLog } from "../src/runs/log.ts"; | |
| 11 | import { checkJson, checksForge } from "./helpers/checks-forge.ts"; | |
| 12 | import { quietLogs } from "./helpers/globals.ts"; | |
| 13 | ||
| 14 | quietLogs(); | |
| 15 | ||
| 16 | const PLAN = "fast tier, 2 of 10 files for 1 changed, by coverage: 1 changed file reaches 2 tests (expected 3s)"; | |
| 17 | const KEPT = "1 of 2 files kept, 1 to run"; | |
| 18 | ||
| 19 | describe("the plan, read from the step's lines", () => { | |
| 20 | test("test-shards' plan lines, in order, joined; nothing else", () => { | |
| 21 | expect( | |
| 22 | planOf(["$ bun scripts/test-shards.ts", `test-shards: ${PLAN}`, "test-shards: why: 1 executes", `test-shards: ${KEPT}`, "(pass) x"]), | |
| 23 | ).toBe(`${PLAN}; ${KEPT}`); | |
| 24 | expect(planOf(["test-shards: fast tier, 10 of 10 files for 1 changed, full tier, forge.json changed (expected 50s)"])).toBe( | |
| 25 | "fast tier, 10 of 10 files for 1 changed, full tier, forge.json changed (expected 50s)", | |
| 26 | ); | |
| 27 | expect(planOf(["test-shards: measuring 3722 files under coverage, one bun test each, 4 at a time"])).toStartWith( | |
| 28 | "measuring 3722 files", | |
| 29 | ); | |
| 30 | expect(planOf(["(pass) a", "test-shards: no scripts/test-times.json; weighing by bytes"])).toBeUndefined(); | |
| 31 | expect(planOf([`test-shards: fast tier, ${"x".repeat(600)}`])!.length).toBe(PLAN_MAX); | |
| 32 | }); | |
| 33 | }); | |
| 34 | ||
| 35 | const f = checksForge("forge-plan-line-"); | |
| 36 | ||
| 37 | /** | |
| 38 | * Says the plan, then 700 kB of passing lines: past the log's 512 KiB tail. Red when the pull adds | |
| 39 | * RED. | |
| 40 | */ | |
| 41 | const CHECK = `echo 'test-shards: ${PLAN}'; echo 'test-shards: ${KEPT}'; head -c 700000 /dev/zero | tr '\\000' x | fold -w 100; test ! -f RED`; | |
| 42 | ||
| 43 | async function pull(name: string, file: string): Promise<string> { | |
| 44 | const made = await commitToBranch(f.app, f.alice, f.repo, { | |
| 45 | branch: name, | |
| 46 | message: `Add ${file}`, | |
| 47 | files: [{ path: file, content: `${name}\n` }], | |
| 48 | }); | |
| 49 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 50 | const opened = await openPull(f.app, f.alice, f.repo, { title: name, body: "", baseBranch: "main", headBranch: name }); | |
| 51 | if (!opened.ok) throw new Error(JSON.stringify(opened.error)); | |
| 52 | return made.value.commitOid; | |
| 53 | } | |
| 54 | ||
| 55 | beforeAll(async () => { | |
| 56 | const gate = await commitToBranch(f.app, f.alice, f.repo, { | |
| 57 | message: "Declare the check", | |
| 58 | files: [{ path: "forge.json", content: checkJson(CHECK) }], | |
| 59 | }); | |
| 60 | if (!gate.ok) throw new Error(JSON.stringify(gate.error)); | |
| 61 | await f.settled((r) => r.commitOid === gate.value.commitOid, 30_000); | |
| 62 | }); | |
| 63 | ||
| 64 | describe("a long run's plan", () => { | |
| 65 | test("green: the run keeps the plan the log's tail no longer holds, and the summary is the verdict's alone", async () => { | |
| 66 | const oid = await pull("green", "g.txt"); | |
| 67 | const run = await f.settled((r) => r.commitOid === oid, 30_000); | |
| 68 | expect(run.state).toBe("ok"); | |
| 69 | expect(readRunLog(f.app.config.dataDir, run.id).lines.join("\n")).not.toContain(PLAN); | |
| 70 | expect(run.checkPlan).toBe(`${PLAN}; ${KEPT}`); | |
| 71 | expect(run.summary).toMatch(/^check passed in \d+s$/); | |
| 72 | }); | |
| 73 | ||
| 74 | test("red: the run keeps it too, and neither the summary nor the check detail carries it", async () => { | |
| 75 | const oid = await pull("red", "RED"); | |
| 76 | const run = await f.settled((r) => r.commitOid === oid, 30_000); | |
| 77 | expect(run.state).toBe("failed"); | |
| 78 | expect(run.checkPlan).toBe(`${PLAN}; ${KEPT}`); | |
| 79 | expect(run.summary).not.toContain(PLAN); | |
| 80 | expect(JSON.stringify(run.checkDetail ?? {})).not.toContain(PLAN); | |
| 81 | }); | |
| 82 | }); |
new above
offline
Non-blocking:
check_plan = ?13overwrites with '' on any finish that carries no plan. PreferCOALESCE(NULLIF(?13,''), check_plan)so a later finish cannot blank a kept plan.