Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/decisions/ci-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -1094,14 +1094,22 @@ workflow.


Discovery has a fixed 30-second wall-clock maximum for the native child to exit
and both output pipes to drain (`browserInventory`, `scripts/proof-inputs.ts:55-113`),
and both output pipes to drain (`browserInventory`, `scripts/proof-inputs.ts:56-127`),
in local preflight and hosted metadata. The maintainer selected
option A under [#2380](https://github.com/schlessera/brain-kit/issues/2380) on
2026-10-22: #2326's cold discovery sample took 14,811 ms in the pinned offline
image with two CPUs, so 30 seconds allows approximately twice that observed
duration. Hosted metadata steps had completed in 6–11 seconds. This bounded
margin does not guarantee completion under arbitrary CPU starvation; a stuck
child can take up to 15 seconds longer to fail than under the previous maximum.
A failure receipt records the discovery child's CPU time and involuntary
context switches beside its wall time, with the runner's parallelism and load
average, so a timeout names its phase: CPU near the deadline is slow discovery,
CPU far below it is a runner that withheld CPU or I/O
([#4149](https://github.com/schlessera/brain-kit/issues/4149)). The #4149
timeout came before these fields and was a starved runner: its checkout and
install also ran about five times slower than usual, and the same candidate
tree discovered in about 5 seconds in the pinned image with two CPUs.
Process controls inject a short deadline and assert the default separately;
the integration test allows additional time for ownership scanning and cleanup.
Discovery failure still rejects unsuccessful inventories: selection then keeps
Expand Down
16 changes: 15 additions & 1 deletion scripts/proof-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* proof jobs and the merge path. */
import { createHash } from "node:crypto";
import { mkdirSync, readFileSync, rmSync, statSync } from "node:fs";
import { availableParallelism, loadavg } from "node:os";
import { dirname, join, relative } from "node:path";

export interface Spec { project: string; file: string; }
Expand Down Expand Up @@ -101,8 +102,21 @@ export async function browserInventory(root: string, deadlineMs = 30000): Promis
} catch (error) {
stopDiscovery();
await p.exited;
// The leader's CPU time against wall time names the starved phase (#4149):
// CPU near the deadline is slow discovery; far below it, the host withheld
// CPU or I/O. Involuntary switches and load average corroborate contention.
// Bun reports these as BigInt despite its `number` types; reading them never
// replaces the discovery failure this receipt explains.
let cpu: { userMs: number; systemMs: number; involuntarySwitches: number } | null = null;
try {
const usage = p.resourceUsage();
if (usage) cpu = { userMs: Math.round(Number(usage.cpuTime.user) / 1000), systemMs: Math.round(Number(usage.cpuTime.system) / 1000),
involuntarySwitches: Number(usage.contextSwitches.involuntary) };
} catch { cpu = null; }
const receipt = { elapsedMs: Math.round(performance.now() - started), deadlineMs, timedOut,
exitCode: p.exitCode, signal: p.signalCode ?? null, ...(cleanupError ? { cleanupError } : {}), stdout, stderr, inventory: inventoryPublication(output) };
exitCode: p.exitCode, signal: p.signalCode ?? null, ...(cleanupError ? { cleanupError } : {}), cpu,
host: { parallelism: availableParallelism(), loadavg: loadavg().map(load => Math.round(load * 100) / 100) },
stdout, stderr, inventory: inventoryPublication(output) };
throw new Error(`Vitest file discovery failed: ${JSON.stringify(receipt)}\n${error instanceof Error ? error.message : String(error)}`);
} finally {
clearTimeout(timer);
Expand Down
15 changes: 15 additions & 0 deletions tests/browser-inventory-process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ test.each([false, true])("native watchdog reports publication %s and reaps the d
expect(receipt.elapsedMs).toBeGreaterThanOrEqual(900);
expect(receipt.elapsedMs).toBeLessThan(5000);
});
// #4149: a hosted timeout must say whether discovery was computing or the
// runner starved it, instead of leaving the cause to be inferred from stderr.
test.each([
["waiting", "setInterval(()=>{},1000);"],
["computing", "for(;;){}"],
])("native watchdog receipt separates a %s child's CPU time from wall time", async (phase, script) => {
const { receipt } = diagnostics(await nativeControl(script, controlDeadlineMs));
expect(receipt).toMatchObject({ deadlineMs: 1000, timedOut: true, signal: "SIGKILL" });
expect(receipt.cpu).toEqual({ userMs: expect.any(Number), systemMs: expect.any(Number), involuntarySwitches: expect.any(Number) });
const cpuMs = receipt.cpu.userMs + receipt.cpu.systemMs;
if (phase === "waiting") expect(cpuMs).toBeLessThan(receipt.elapsedMs / 2);
else expect(cpuMs).toBeGreaterThan(receipt.elapsedMs / 4);
expect(receipt.host.parallelism).toBeGreaterThanOrEqual(1);
expect(receipt.host.loadavg).toHaveLength(3);
});
test("native signal remains distinct from watchdog expiration", async () => {
const { receipt } = diagnostics(await nativeControl('process.kill(process.pid,"SIGTERM");', controlDeadlineMs));
expect(receipt).toMatchObject({ deadlineMs: 1000, timedOut: false, signal: "SIGTERM", inventory: { present: false } });
Expand Down
Loading