Public: anyone can read this; the crew can change it.
A gate's checkout is not removed under it: three gates on #7608 went red on files missing from their own working tree #16742
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/7634-a-gate-s-checkout-is-not-removed-under-i → main 0 commits fork 2 threads · 2 unresolved
4 files
changed +120
−3
src/checks/gate_run.ts +2 −1
| @@ -30,7 +30,8 @@ async function gateOnce( | ||
| 30 | 30 | const done = await runTier(lane, { |
| 31 | 31 | bare, |
| 32 | 32 | repo, |
| 33 | id: gateRunId(commitOid), | |
| 33 | // Its own checkout: another gate of the same tip (a rerun) must not export over or remove it. | |
| 34 | id: `${gateRunId(commitOid)}-${crypto.randomUUID().slice(0, 8)}`, | |
| 34 | 35 | commitOid, |
| 35 | 36 | pull, |
| 36 | 37 | tier: "full", |
src/checks/run_tier.ts +12 −1
| @@ -45,6 +45,16 @@ import { deepsecStep } from "./deepsec_step.ts"; | ||
| 45 | 45 | import { pickSubscription } from "../core/subscriptions.ts"; |
| 46 | 46 | import { checksRoot, reclaimIfFull, removeRunDir } from "./sweep.ts"; |
| 47 | 47 | |
| 48 | /** | |
| 49 | * What a check says when its own checkout was removed under it: the machine's fault, not the | |
| 50 | * pull's. | |
| 51 | */ | |
| 52 | export const LOST_CHECKOUT = "the check's checkout was removed while it ran (infrastructure, not the pull)"; | |
| 53 | ||
| 54 | /** A failed setup whose checkout is gone is infrastructure: nothing of the pull was judged. */ | |
| 55 | const lostCheckout = (dir: string, outcome: CheckOutcome): CheckOutcome => | |
| 56 | !outcome.ok && !existsSync(dir) ? { ok: false, error: LOST_CHECKOUT, infrastructure: true } : outcome; | |
| 57 | ||
| 48 | 58 | /** |
| 49 | 59 | * Run one tier of one check: resolve the commit and the manifest it runs by, give it to a runner |
| 50 | 60 | * or run it here in a cell, and answer the verdict. The steps it is made of are `tier_*.ts`. |
| @@ -296,7 +306,7 @@ export async function runTier(lane: LaneState, x: Execution): Promise<CheckOutco | ||
| 296 | 306 | const installed = await setupFromSnapshot(app, x, repo.id, dir, manifest.install, write, () => |
| 297 | 307 | runInstall(lane, { dir, env, cell, repo, runId: run.id, manifest, write, signal }), |
| 298 | 308 | ); |
| 299 | if (installed !== undefined) return installed; | |
| 309 | if (installed !== undefined) return lostCheckout(dir, installed); | |
| 300 | 310 | // The check step's own lines are kept beside what `write` already |
| 301 | 311 | // logs, so a failure can be summarised once here — never by reading |
| 302 | 312 | // the log back, on this run or any later render of it. `runStep` |
| @@ -323,6 +333,7 @@ export async function runTier(lane: LaneState, x: Execution): Promise<CheckOutco | ||
| 323 | 333 | { run, repo, bare, dir, env, cell, manifest, tip, inJob: job !== undefined, checkLines, write, signal }, |
| 324 | 334 | ran, |
| 325 | 335 | ); |
| 336 | if (!ran.ok && !existsSync(dir)) return { ok: false, error: LOST_CHECKOUT, infrastructure: true }; | |
| 326 | 337 | if (!ran.ok) { |
| 327 | 338 | const { summary, detail } = summariseCheckFailure( |
| 328 | 339 | checkLines, |
src/checks/sweep.ts +1 −1
| @@ -79,7 +79,7 @@ export const checksRoot = (dataDir: string): string => join(dataDir, "checks"); | ||
| 79 | 79 | const STORES: ReadonlySet<string> = new Set([IMPACT_DIR, KEPT_DIR, TIMES_DIR, "learned", "gates", "gate-last.json"]); |
| 80 | 80 | |
| 81 | 81 | /** A gate's checkout (`gateRunId`): it has no run, only its `check_gate` row. */ |
| 82 | const GATE_DIR = /^gate-([0-9a-f]{12})$/; | |
| 82 | const GATE_DIR = /^gate-([0-9a-f]{12})(?:-[0-9a-f]{8})?$/; | |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Whether a gate's checkout, this forge's or a peer's during a roll, is younger than a gate may |
test/check-gate-own-checkout.test.ts added +105
| @@ -0,0 +1,105 @@ | ||
| 1 | /** | |
| 2 | * Two gates of the same commit running together each keep their own checkout (#7634): the second's | |
| 3 | * export and cleanup used to remove the directory the first was still running in, and the first | |
| 4 | * went red on a file missing from its own working tree. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { existsSync } from "node:fs"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { openPull } from "../src/actions/pulls.ts"; | |
| 13 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 14 | import { startChecks, type ChecksHandle } from "../src/checks/service.ts"; | |
| 15 | import { LOST_CHECKOUT } from "../src/checks/run_tier.ts"; | |
| 16 | import { sweepCheckouts } from "../src/checks/sweep.ts"; | |
| 17 | import { GATE_DEADLINE_MS } from "../src/checks/queue.ts"; | |
| 18 | import { createUser } from "../src/core/users.ts"; | |
| 19 | ||
| 20 | let dataDir: string; | |
| 21 | let app: App; | |
| 22 | let checks: ChecksHandle; | |
| 23 | const cells = process.env["FORGE_CELLS"]; | |
| 24 | ||
| 25 | beforeAll(async () => { | |
| 26 | process.env["FORGE_CELLS"] = "off"; | |
| 27 | dataDir = await mkdtemp(join(tmpdir(), "forge-owndir-")); | |
| 28 | app = createApp({ dataDir, port: 0 }); | |
| 29 | checks = startChecks(app, { forgeUrl: "http://127.0.0.1:1", concurrency: 2 }); | |
| 30 | }); | |
| 31 | ||
| 32 | afterAll(async () => { | |
| 33 | await checks.stop(); | |
| 34 | app.close(); | |
| 35 | if (cells === undefined) delete process.env["FORGE_CELLS"]; | |
| 36 | else process.env["FORGE_CELLS"] = cells; | |
| 37 | await rm(dataDir, { recursive: true, force: true }); | |
| 38 | }); | |
| 39 | ||
| 40 | let alice: Awaited<ReturnType<typeof createUser>> | undefined; | |
| 41 | async function seedPull(name: string, full: string) { | |
| 42 | alice ??= await createUser(app.db, { | |
| 43 | origin: "seed", | |
| 44 | trusted: true, | |
| 45 | username: "alice", | |
| 46 | email: "[email protected]", | |
| 47 | password: "a-good-passphrase", | |
| 48 | adminIfFirst: true, | |
| 49 | }); | |
| 50 | const u = alice; | |
| 51 | if (!u.ok) throw new Error(u.error); | |
| 52 | const made = await createRepo(app, u.value, { name, visibility: "public" }); | |
| 53 | if (!made.ok) throw new Error(String(made.error)); | |
| 54 | const repo = made.value; | |
| 55 | const seeded = await commitToBranch(app, u.value, repo, { | |
| 56 | message: "Start", | |
| 57 | files: [ | |
| 58 | { path: "forge.json", content: JSON.stringify({ check: { run: "true", full } }) }, | |
| 59 | { path: "package.json", content: "{}\n" }, | |
| 60 | ], | |
| 61 | }); | |
| 62 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 63 | const branched = await commitToBranch(app, u.value, repo, { | |
| 64 | branch: "feature", | |
| 65 | message: "Feature", | |
| 66 | files: [{ path: "b.txt", content: "b\n" }], | |
| 67 | }); | |
| 68 | if (!branched.ok) throw new Error(JSON.stringify(branched.error)); | |
| 69 | const opened = await openPull(app, u.value, repo, { title: "F", baseBranch: "main", headBranch: "feature" }); | |
| 70 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 71 | return { repo, pull: opened.value, oid: branched.value.commitOid }; | |
| 72 | } | |
| 73 | ||
| 74 | test("a second gate of the same commit leaves the first its checkout and its verdict", async () => { | |
| 75 | const { repo, pull, oid } = await seedPull("own", "sleep 1; test -f package.json && echo OWN-GREEN"); | |
| 76 | const first = checks.gate(repo, pull, oid); | |
| 77 | const second = checks.gate(repo, pull, oid); | |
| 78 | const [a, b] = await Promise.all([first, second]); | |
| 79 | expect(a.lines.join("\n")).not.toContain(LOST_CHECKOUT); | |
| 80 | expect(a.ok).toBe(true); | |
| 81 | expect(a.lines.join("\n")).toContain("OWN-GREEN"); | |
| 82 | // The second is its own gate in its own checkout: it runs the same command and is green itself. | |
| 83 | expect(b.lines.join("\n")).toContain("OWN-GREEN"); | |
| 84 | expect(b.ok).toBe(true); | |
| 85 | }); | |
| 86 | ||
| 87 | test("a gate whose checkout is removed under it is infrastructure, not a red", async () => { | |
| 88 | const { repo, pull, oid } = await seedPull("lost", 'rm -rf "$PWD"; exit 1'); | |
| 89 | const done = await checks.gate(repo, pull, oid); | |
| 90 | expect(done.ok).toBe(false); | |
| 91 | // `interrupted` is how a gate says the code was not judged: the pull is recorded no red. | |
| 92 | expect(done.interrupted).toBe(true); | |
| 93 | expect(done.error).toBe(LOST_CHECKOUT); | |
| 94 | }); | |
| 95 | ||
| 96 | test("the sweep reaps an old gate checkout by its suffix and keeps a young one", async () => { | |
| 97 | const old = join(dataDir, "checks", "gate-0123456789ab-deadbeef"); | |
| 98 | await Bun.write(join(old, "package.json"), "{}"); | |
| 99 | await sweepCheckouts(app, Date.now() + GATE_DEADLINE_MS + 60_000); | |
| 100 | expect(existsSync(old)).toBe(false); | |
| 101 | const young = join(dataDir, "checks", "gate-0123456789ab-cafebabe"); | |
| 102 | await Bun.write(join(young, "package.json"), "{}"); | |
| 103 | await sweepCheckouts(app); | |
| 104 | expect(existsSync(young)).toBe(true); | |
| 105 | }); |
new above
offline
Untested: nothing makes
dirvanish mid-run, so this branch andlostCheckoutabove can be deleted without any test failing. Add a test that removes the checkout while the gate runs and expectsinfrastructure: truewithLOST_CHECKOUT.