{"file":"worker/project/queue-driver.ts","version":318,"total":148,"from":1,"to":148,"lines":[{"n":1,"text":"// The merge queue's checker loop (#39): one round takes a batch from the","atom":"a0","author":"init","version":0},{"n":2,"text":"// front of the queue, runs the project's check on shared with the batch on","atom":"a0","author":"init","version":0},{"n":3,"text":"// top, and lands it or finds the publish that turned it red. The check itself","atom":"a0","author":"init","version":0},{"n":4,"text":"// is behind an interface (a CI runner on the server, a function in tests),","atom":"a334","author":"infra-split","version":37},{"n":5,"text":"// so this file holds only the rules agreed on #39:","atom":"a0","author":"init","version":0},{"n":6,"text":"//","atom":"a0","author":"init","version":0},{"n":7,"text":"// - A batch is everything waiting, in order (Christopher, Oct 14: no cap; it was 8).","atom":"a2333","author":"onboard","version":209},{"n":8,"text":"// - Pass: every publish in the batch lands, each as its own version.","atom":"a0","author":"init","version":0},{"n":9,"text":"// - Fail: halve prefixes to find the passing prefix and the first publish","atom":"a0","author":"init","version":0},{"n":10,"text":"//   that fails on top of it. That failing prefix is run once more; only a","atom":"a0","author":"init","version":0},{"n":11,"text":"//   second failure pulls the publish. The passing prefix lands at once.","atom":"a0","author":"init","version":0},{"n":12,"text":"// - A timeout is a check failure. A box failure (never started, box lost,","atom":"a0","author":"init","version":0},{"n":13,"text":"//   no exit code) pulls nobody: the run is retried once, then the queue pauses.","atom":"a0","author":"init","version":0},{"n":14,"text":"// - While shared is red, prefixes are tried one publish longer at a time,","atom":"a0","author":"init","version":0},{"n":15,"text":"//   and the first that passes lands: it holds the fix, with whatever came","atom":"a0","author":"init","version":0},{"n":16,"text":"//   before it. Nobody is pulled, since on a red base every prefix fails.","atom":"a0","author":"init","version":0},{"n":17,"text":"import type { Blobs, Modes, PullReason } from \"./project.ts\";","atom":"a0","author":"init","version":0},{"n":18,"text":"","atom":"a0","author":"init","version":0},{"n":19,"text":"export interface Candidate {","atom":"a0","author":"init","version":0},{"n":20,"text":"\treadonly ids: number[];","atom":"a0","author":"init","version":0},{"n":21,"text":"\treadonly files: Record<string, string>;","atom":"a0","author":"init","version":0},{"n":22,"text":"\treadonly modes: Modes;","atom":"a0","author":"init","version":0},{"n":23,"text":"\treadonly blobs: Blobs;","atom":"a0","author":"init","version":0},{"n":24,"text":"\treadonly tree: string;","atom":"a0","author":"init","version":0},{"n":25,"text":"}","atom":"a0","author":"init","version":0},{"n":26,"text":"","atom":"a0","author":"init","version":0},{"n":27,"text":"export type CheckResult =","atom":"a0","author":"init","version":0},{"n":28,"text":"\t| { readonly kind: \"pass\" }","atom":"a0","author":"init","version":0},{"n":29,"text":"\t/** The check failed or ran past its limit. `output` is its end, for the publisher. */","atom":"a0","author":"init","version":0},{"n":30,"text":"\t| { readonly kind: \"fail\"; readonly output?: string }","atom":"a0","author":"init","version":0},{"n":31,"text":"\t/** The box failed: the run never started, the box was lost, or there was no exit code. */","atom":"a0","author":"init","version":0},{"n":32,"text":"\t| { readonly kind: \"box\"; readonly reason: string };","atom":"a0","author":"init","version":0},{"n":33,"text":"","atom":"a0","author":"init","version":0},{"n":34,"text":"export interface Checker {","atom":"a0","author":"init","version":0},{"n":35,"text":"\tcheck(candidate: Candidate): Promise<CheckResult>;","atom":"a0","author":"init","version":0},{"n":36,"text":"}","atom":"a0","author":"init","version":0},{"n":37,"text":"","atom":"a0","author":"init","version":0},{"n":38,"text":"/** The engine calls the loop needs: Project has them all. */","atom":"a0","author":"init","version":0},{"n":39,"text":"export interface QueueEngine {","atom":"a0","author":"init","version":0},{"n":40,"text":"\tqueue(): { items: { id: number }[] };","atom":"a0","author":"init","version":0},{"n":41,"text":"\tqueueChecking(n: number): number[];","atom":"a0","author":"init","version":0},{"n":42,"text":"\tqueueCandidate(n: number): Candidate;","atom":"a0","author":"init","version":0},{"n":43,"text":"\tqueueLand(n: number, time: number): { versions: { id: number; version: number }[] };","atom":"a0","author":"init","version":0},{"n":44,"text":"\tqueuePull(id: number, reason: Exclude<PullReason, \"depends\">, time: number, output?: string): { pulled: number[] };","atom":"a0","author":"init","version":0},{"n":45,"text":"}","atom":"a0","author":"init","version":0},{"n":46,"text":"","atom":"a0","author":"init","version":0},{"n":47,"text":"export interface RoundOptions {","atom":"a0","author":"init","version":0},{"n":48,"text":"\t/** Whether shared's newest version fails the check now. */","atom":"a0","author":"init","version":0},{"n":49,"text":"\treadonly sharedRed?: boolean;","atom":"a0","author":"init","version":0},{"n":50,"text":"\treadonly now?: () => number;","atom":"a0","author":"init","version":0},{"n":51,"text":"}","atom":"a0","author":"init","version":0},{"n":52,"text":"","atom":"a0","author":"init","version":0},{"n":53,"text":"export type RoundResult =","atom":"a0","author":"init","version":0},{"n":54,"text":"\t| { readonly kind: \"idle\" }","atom":"a0","author":"init","version":0},{"n":55,"text":"\t| { readonly kind: \"landed\"; readonly versions: { id: number; version: number }[]; readonly checks: number }","atom":"a0","author":"init","version":0},{"n":56,"text":"\t| {","atom":"a0","author":"init","version":0},{"n":57,"text":"\t\t\treadonly kind: \"pulled\";","atom":"a0","author":"init","version":0},{"n":58,"text":"\t\t\treadonly versions: { id: number; version: number }[];","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\t\treadonly pulled: number[];","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\t\treadonly output?: string;","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\t\treadonly checks: number;","atom":"a0","author":"init","version":0},{"n":62,"text":"\t  }","atom":"a0","author":"init","version":0},{"n":63,"text":"\t/** Shared is red and no prefix of the batch made it pass: nothing landed, nobody pulled. */","atom":"a0","author":"init","version":0},{"n":64,"text":"\t| { readonly kind: \"held\"; readonly checks: number; readonly output?: string }","atom":"a0","author":"init","version":0},{"n":65,"text":"\t/** The box failed twice in a row: nothing landed, nobody pulled. */","atom":"a0","author":"init","version":0},{"n":66,"text":"\t| { readonly kind: \"paused\"; readonly reason: string; readonly checks: number }","atom":"a0","author":"init","version":0},{"n":67,"text":"\t/**","atom":"a0","author":"init","version":0},{"n":68,"text":"\t * Shared changed while the box checked (a drop, or a push with plain git),","atom":"a0","author":"init","version":0},{"n":69,"text":"\t * so what it checked isn't what would land: nothing landed, nobody pulled.","atom":"a0","author":"init","version":0},{"n":70,"text":"\t * Run the round again.","atom":"a0","author":"init","version":0},{"n":71,"text":"\t */","atom":"a0","author":"init","version":0},{"n":72,"text":"\t| { readonly kind: \"moved\"; readonly checks: number };","atom":"a0","author":"init","version":0},{"n":73,"text":"","atom":"a0","author":"init","version":0},{"n":74,"text":"class Moved extends Error {}","atom":"a0","author":"init","version":0},{"n":75,"text":"","atom":"a0","author":"init","version":0},{"n":76,"text":"class Paused extends Error {","atom":"a0","author":"init","version":0},{"n":77,"text":"\treadonly reason: string;","atom":"a0","author":"init","version":0},{"n":78,"text":"\tconstructor(reason: string) {","atom":"a0","author":"init","version":0},{"n":79,"text":"\t\tsuper(reason);","atom":"a0","author":"init","version":0},{"n":80,"text":"\t\tthis.reason = reason;","atom":"a0","author":"init","version":0},{"n":81,"text":"\t}","atom":"a0","author":"init","version":0},{"n":82,"text":"}","atom":"a0","author":"init","version":0},{"n":83,"text":"","atom":"a0","author":"init","version":0},{"n":84,"text":"/** Run one round of the queue. Call it again while it answers `landed` or `pulled` and the queue isn't empty. */","atom":"a0","author":"init","version":0},{"n":85,"text":"export async function queueRound(","atom":"a0","author":"init","version":0},{"n":86,"text":"\tengine: QueueEngine,","atom":"a0","author":"init","version":0},{"n":87,"text":"\tchecker: Checker,","atom":"a0","author":"init","version":0},{"n":88,"text":"\toptions: RoundOptions = {},","atom":"a0","author":"init","version":0},{"n":89,"text":"): Promise<RoundResult> {","atom":"a0","author":"init","version":0},{"n":90,"text":"\tconst waiting = engine.queue().items.length;","atom":"a0","author":"init","version":0},{"n":91,"text":"\tif (waiting === 0) return { kind: \"idle\" };","atom":"a0","author":"init","version":0},{"n":92,"text":"\tconst now = options.now ?? Date.now;","atom":"a0","author":"init","version":0},{"n":93,"text":"\tconst n = waiting;","atom":"a2333","author":"onboard","version":209},{"n":94,"text":"\tlet checks = 0;","atom":"a0","author":"init","version":0},{"n":95,"text":"\tlet output: string | undefined;","atom":"a0","author":"init","version":0},{"n":96,"text":"\t/** The tree each prefix was checked as: a land or a pull goes ahead only on that same tree. */","atom":"a334","author":"infra-split","version":37},{"n":97,"text":"\tconst checked = new Map<number, string>();","atom":"a0","author":"init","version":0},{"n":98,"text":"\tconst same = (k: number): void => {","atom":"a0","author":"init","version":0},{"n":99,"text":"\t\tif (engine.queueCandidate(k).tree !== checked.get(k)) throw new Moved();","atom":"a0","author":"init","version":0},{"n":100,"text":"\t};","atom":"a0","author":"init","version":0},{"n":101,"text":"\tconst land = (k: number) => {","atom":"a0","author":"init","version":0},{"n":102,"text":"\t\tsame(k);","atom":"a0","author":"init","version":0},{"n":103,"text":"\t\treturn engine.queueLand(k, now()).versions;","atom":"a0","author":"init","version":0},{"n":104,"text":"\t};","atom":"a0","author":"init","version":0},{"n":105,"text":"\t/** Whether shared with the first `k` queued on top passes; a box failure is retried once. */","atom":"a0","author":"init","version":0},{"n":106,"text":"\tconst passes = async (k: number): Promise<boolean> => {","atom":"a0","author":"init","version":0},{"n":107,"text":"\t\tlet last: CheckResult | undefined;","atom":"a0","author":"init","version":0},{"n":108,"text":"\t\tfor (let tries = 0; tries < 2; tries++) {","atom":"a0","author":"init","version":0},{"n":109,"text":"\t\t\tchecks++;","atom":"a0","author":"init","version":0},{"n":110,"text":"\t\t\tconst candidate = engine.queueCandidate(k);","atom":"a0","author":"init","version":0},{"n":111,"text":"\t\t\tchecked.set(k, candidate.tree);","atom":"a0","author":"init","version":0},{"n":112,"text":"\t\t\tlast = await checker.check(candidate);","atom":"a0","author":"init","version":0},{"n":113,"text":"\t\t\tif (last.kind !== \"box\") break;","atom":"a0","author":"init","version":0},{"n":114,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":115,"text":"\t\tif (last!.kind === \"box\") throw new Paused(last!.reason);","atom":"a0","author":"init","version":0},{"n":116,"text":"\t\tif (last!.kind === \"fail\") output = last!.output;","atom":"a0","author":"init","version":0},{"n":117,"text":"\t\treturn last!.kind === \"pass\";","atom":"a0","author":"init","version":0},{"n":118,"text":"\t};","atom":"a0","author":"init","version":0},{"n":119,"text":"\tengine.queueChecking(n);","atom":"a0","author":"init","version":0},{"n":120,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":121,"text":"\t\tif (options.sharedRed) {","atom":"a0","author":"init","version":0},{"n":122,"text":"\t\t\tfor (let k = 1; k <= n; k++) if (await passes(k)) return { kind: \"landed\", versions: land(k), checks };","atom":"a0","author":"init","version":0},{"n":123,"text":"\t\t\treturn { kind: \"held\", checks, ...(output !== undefined ? { output } : {}) };","atom":"a0","author":"init","version":0},{"n":124,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":125,"text":"\t\tif (await passes(n)) return { kind: \"landed\", versions: land(n), checks };","atom":"a0","author":"init","version":0},{"n":126,"text":"\t\t// Shared alone passes; shared plus all n fails. Find the longest passing prefix.","atom":"a0","author":"init","version":0},{"n":127,"text":"\t\tlet good = 0;","atom":"a0","author":"init","version":0},{"n":128,"text":"\t\tlet bad = n;","atom":"a0","author":"init","version":0},{"n":129,"text":"\t\twhile (bad - good > 1) {","atom":"a0","author":"init","version":0},{"n":130,"text":"\t\t\tconst mid = Math.floor((good + bad) / 2);","atom":"a0","author":"init","version":0},{"n":131,"text":"\t\t\tif (await passes(mid)) good = mid;","atom":"a0","author":"init","version":0},{"n":132,"text":"\t\t\telse bad = mid;","atom":"a0","author":"init","version":0},{"n":133,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":134,"text":"\t\t// The failing prefix fails twice before anyone is pulled.","atom":"a0","author":"init","version":0},{"n":135,"text":"\t\tif (await passes(bad)) return { kind: \"landed\", versions: land(bad), checks };","atom":"a0","author":"init","version":0},{"n":136,"text":"\t\tconst culprit = engine.queue().items[bad - 1]!.id;","atom":"a0","author":"init","version":0},{"n":137,"text":"\t\tsame(bad);","atom":"a0","author":"init","version":0},{"n":138,"text":"\t\tconst versions = good > 0 ? land(good) : [];","atom":"a0","author":"init","version":0},{"n":139,"text":"\t\tconst { pulled } = engine.queuePull(culprit, \"failed\", now(), output);","atom":"a0","author":"init","version":0},{"n":140,"text":"\t\treturn { kind: \"pulled\", versions, pulled, checks, ...(output !== undefined ? { output } : {}) };","atom":"a0","author":"init","version":0},{"n":141,"text":"\t} catch (e) {","atom":"a0","author":"init","version":0},{"n":142,"text":"\t\tif (e instanceof Paused) return { kind: \"paused\", reason: e.reason, checks };","atom":"a0","author":"init","version":0},{"n":143,"text":"\t\tif (e instanceof Moved) return { kind: \"moved\", checks };","atom":"a0","author":"init","version":0},{"n":144,"text":"\t\tthrow e;","atom":"a0","author":"init","version":0},{"n":145,"text":"\t} finally {","atom":"a0","author":"init","version":0},{"n":146,"text":"\t\tengine.queueChecking(0);","atom":"a0","author":"init","version":0},{"n":147,"text":"\t}","atom":"a0","author":"init","version":0},{"n":148,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a334","author":"infra-split","message":"","time":1791546813593,"timeIso":"2026-10-09T11:53:33.593Z","publish":{"draft":null,"version":37,"agent":"infra-split","message":"Comments and test names give each reason in plain words, without naming who raised it\n\nNotes like \"(#37, Builder 5)\" or \"(AVCS - Security)\" become \"(#37)\" or go, and a private commit hash after a name goes with it. Issue numbers and references such as git's CVE-2019-1353 stay. Only comments and test names change; no behavior changes.","time":1791547035956,"timeIso":"2026-10-09T11:57:15.956Z"}},{"atom":"a2333","author":"onboard","message":"","time":1792034198455,"timeIso":"2026-10-15T03:16:38.455Z","publish":{"draft":null,"version":209,"agent":"onboard","message":"Merge queue: no cap on a batch (Christopher, 10:10 PM CT Oct 14; Agent VCS's job). A batch is everything waiting, in order; it was 8 at a time. RoundOptions.cap is gone: no caller passed one (abso's index.ts and customer-queue-round.ts pass only sharedRed). A failing batch still halves to the push that fails. The customer queue's 32-checks-per-continuation bound is unchanged: halving a few hundred waiting pushes takes about a dozen. Tests: worker/project/test/queue-driver.test.ts (10), with ten landing on one check and a failing tenth-place batch past the old cap.","time":1792034198989,"timeIso":"2026-10-15T03:16:38.989Z"}}]}