Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(admin-browser): stall means silence, one total budget, and cache the Playwright browsers; a crawling CDN download finishes instead of restarting from 0%

garrytan1dedeba27d34
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index fad2bb63dd..566fab49ae 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -924,9 +924,24 @@ jobs:
timeout-minutes: 8
run: bun ../scripts/ci-bun-install.ts --frozen-lockfile --ignore-scripts
working-directory: admin
+ # The browser download comes from Playwright's CDN, which has served it at
+ # 250 KB/s (.204, #6613); restoring it keeps most runs off the CDN. The key
+ # is the browser revisions the installed Playwright pins.
+ - name: Restore the pinned Chromium browser
+ id: playwright-browsers
+ uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
+ with:
+ path: ~/.cache/ms-playwright
+ key: playwright-browsers-${{ runner.os }}-${{ hashFiles('node_modules/playwright-core/browsers.json') }}
- name: Install the pinned Chromium browser and OS dependencies (bounded, retried once)
timeout-minutes: 9
- run: bun scripts/ci-bounded-run.ts --attempt-s 240 --retry-s 10 --hint "an apt mirror or browser CDN stall; this normally takes 15-50s" -- bunx playwright install --with-deps chromium
+ run: bun scripts/ci-bounded-run.ts --idle-s 120 --total-s 480 --retry-s 10 --hint "an apt mirror or browser CDN stall; this normally takes 15-50s" -- bunx playwright install --with-deps chromium
+ - name: Save the pinned Chromium browser
+ if: steps.playwright-browsers.outputs.cache-hit != 'true'
+ uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
+ with:
+ path: ~/.cache/ms-playwright
+ key: ${{ steps.playwright-browsers.outputs.cache-primary-key }}
- name: Build the shipped admin assets
run: bun run build:admin
- name: Exercise owner administration and native OAuth in Chromium
diff --git a/CHANGELOG.md b/CHANGELOG.md
index af6cecbf71..ecfd94b262 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,23 +12,35 @@ identifiers and attribution are available in the pre-removal Git revision
## [0.60.206.0] - 2026-10-13
-**CI's Playwright browser install is bounded and retried once, like `bun install` (#6594).** On master .204's Test run, the `admin-browser` job (115229768224) was cancelled at its 12-minute job timeout. `bunx playwright install --with-deps chromium` spent about 4 minutes fetching Ubuntu packages, then crawled through the Chrome download until the timeout hit. That step usually takes 15 to 50 s; across the last dozen runs it ranged from 15 s to 740 s. The bounded-run logic from #6594 is now one shared script, and it ends a stalled attempt together with every process the attempt started.
+**CI's Playwright browser install stops on a real stall, finishes a slow download instead of restarting it, and usually skips the CDN.** On master .204 and .205, the `admin-browser` job was cancelled at its 12-minute job timeout. `bunx playwright install --with-deps chromium` crawled through the Chrome download, which Playwright's CDN was serving at about 250 KB/s. A plain per-attempt cap doesn't fix that. The first version of this PR used a 240 s cap and failed on its own CI: the download was still moving (10%, then 30%), and Playwright doesn't resume downloads, so each retry started over from 0%. So a stall now means silence, the whole step has one time budget, and the downloaded browsers are cached. The bounded-run logic from #6594 is now one shared script, and it ends a stalled attempt together with every process the attempt started.
### Itemized changes
-- **`scripts/ci-bounded-run.ts`** (new): `--attempt-s <n> [--retry-s <n>] [--hint <text>] -- <command…>`. It runs the command in its own process group. When an attempt is still running at its bound, it sends SIGTERM to the whole group and SIGKILL after a 10 s grace period. SIGTERM goes first so that `sudo apt-get`, which sudo can't forward a SIGKILL to, still gets the signal. The command is retried once, and a second failure stops the step with `::error::<command> stalled: no result after <n>s (<hint>) on attempt 2 of 2; giving up`. A failure that isn't a stall keeps its own output, is retried once, and is reported with its exit code.
+- **`scripts/ci-bounded-run.ts`** (new): `(--attempt-s <n> | --total-s <n>) [--idle-s <n>] [--retry-s <n>] [--hint <text>] -- <command…>`.
+ - It runs the command in its own process group. An attempt is stalled when it is still running at `--attempt-s`, or when it has printed nothing on stdout or stderr for `--idle-s`.
+ - A stalled attempt gets SIGTERM to the whole group, then SIGKILL after a 10 s grace period. SIGTERM goes first so that `sudo apt-get`, which sudo can't forward a SIGKILL to, still gets the signal.
+ - It retries once, and a second stall stops the step with `::error::<command> stalled: no output for <n>s (<hint>) on attempt 2 of 2; giving up` (or `no result after <n>s` for the attempt cap).
+ - `--total-s` caps every attempt and pause together. An attempt still printing progress runs until the budget ends instead of being restarted, then stops with `::error::<command> was still running when its <n>s budget ran out`. No retry starts without time left for it.
+ - A failure that isn't a stall keeps its own output, is retried once, and is reported with its exit code.
- **`scripts/ci-bun-install.ts`** now delegates to it, with the same environment knobs and the same annotation text. One behavior change: a stalled install's child processes now end with it. Before, only the direct child got SIGKILL, so a backgrounded grandchild outlived the attempt.
-- **`admin-browser` (`test.yml`):** `bun scripts/ci-bounded-run.ts --attempt-s 240 --retry-s 10 … -- bunx playwright install --with-deps chromium`, with a `timeout-minutes: 9` step cap, which covers two attempts, the pause and both grace periods. The job timeout stays at 12 minutes. A retry starts with whatever attempt 1 already finished: apt packages that got installed and a browser that got downloaded stay in place.
+- **`admin-browser` (`test.yml`):**
+ - `bun scripts/ci-bounded-run.ts --idle-s 120 --total-s 480 --retry-s 10 … -- bunx playwright install --with-deps chromium`, with a `timeout-minutes: 9` step cap. Playwright prints a progress line every 10% of a download, so 120 s of silence is a stall. The job timeout stays at 12 minutes.
+ - `~/.cache/ms-playwright` is restored before the install and saved after a miss. The cache key is `node_modules/playwright-core/browsers.json`, the browser revisions the installed Playwright pins. On a hit, Playwright finds the browsers and skips the download; the apt dependencies still install.
- **`test/progress.test.ts` cpu_ms diagnostics (no assertion change):** the `< 100` ms check on the idle tick failed once at 101 ms on Bun 1.4.3 CI. Side-by-side probes on 1.4.2 and 1.4.3 ruled out the two version suspects: `process.threadCpuUsage` is still per-thread, and `Atomics.wait` still parks rather than spins. The cause is still unknown, so the assertion and its bound are unchanged. A failure now reports where the CPU went: the thread CPU inside the 200 ms `Atomics.wait` against the tick calls around it, plus the process's minor and major page faults, involuntary context switches and all-thread CPU during the wait. Forcing 110 ms of allocation inside the window shows the split as `112.5 ms inside the 200 ms Atomics.wait, 0.5 ms in the tick calls around it; … 1580 minor and 0 major page faults, 14 involuntary context switches`.
- **Proof:**
- - Forced stall: a real `bunx playwright install chromium`, with `PLAYWRIGHT_DOWNLOAD_HOST` pointed at a loopback server that accepts connections and never answers, and an 8 s bound. It was ended twice and stopped with the named error after 17 s, exit 1, with no Playwright process left behind.
- - `test/scripts/ci-bounded-run.test.ts` uses real stalling commands:
- - A stall leaves a backgrounded grandchild; the grandchild is gone after the attempt is ended, and the retry succeeds.
+ - Slow but progressing CDN: a loopback proxy relays the real `cdn.playwright.dev` files at a throttled rate, and `bunx playwright install chromium` runs against it.
+ - Old bound (`--attempt-s 30`): both attempts were killed at 0%, and the step failed after 61 s.
+ - New flags (`--idle-s 20 --total-s 300`): the download finished in 86 s, with Chrome, FFmpeg and the headless shell all installed.
+ - Silent host: `PLAYWRIGHT_DOWNLOAD_HOST` pointed at a loopback server that accepts connections and never answers, with `--idle-s 8`. It warned, retried, and stopped with the named `no output for 8s` error after 18 s, exit 1, with no Playwright process left behind.
+ - `test/scripts/ci-bounded-run.test.ts` uses real commands that stall or crawl:
+ - A stalled attempt's backgrounded grandchild is killed with its group, and the retry succeeds.
- Two stalls give the named error.
- A non-stall failure keeps exit code 100 and its stderr.
- A child that ignores SIGTERM is killed after the grace period.
+ - A silent attempt is a stall at the idle bound; one that prints every 0.5 s against a 1 s idle bound finishes with no annotation.
+ - An attempt still printing when the budget runs out is ended and named, with no retry.
- Usage errors exit 2.
- - A workflow check requires the Playwright step to be bounded, with a step cap that covers both attempts.
+ - A workflow check requires the Playwright step to use the idle bound and a budget that fits its step cap, between a cache restore and a save keyed on Playwright's pinned browser revisions.
- The old `ci-bun-install.ts` left a stalled attempt's backgrounded grandchild running; the new one does not.
## [0.60.205.0] - 2026-10-13
diff --git a/scripts/ci-bounded-run.ts b/scripts/ci-bounded-run.ts
index 689ab148b5..5de2dd891a 100644
--- a/scripts/ci-bounded-run.ts
+++ b/scripts/ci-bounded-run.ts
@@ -7,15 +7,18 @@
* CDN connection it can crawl until the job timeout cancels it, with nothing
* naming the cause (.195's 805 s `bun install` on darwin-x64; .204's 12-minute
* `playwright install --with-deps chromium` on admin-browser). This runs the
- * command in its own process group, ends an attempt still running at its
- * bound (SIGTERM to the group, so `sudo apt-get` under it is relayed the
- * signal, then SIGKILL after a grace period), retries once after a pause, and
- * on a second failure stops with a named `::error::`. A failure that is not a
- * stall is retried once too and then reported with the command's exit code;
- * its output is inherited unchanged. No dependency: it runs before they are
- * installed.
+ * command in its own process group and ends an attempt (SIGTERM to the group,
+ * so `sudo apt-get` under it is relayed the signal, then SIGKILL after a grace
+ * period) when it stalls: still running at `--attempt-s`, or silent on stdout
+ * and stderr for `--idle-s`. A stalled attempt is retried once after a pause,
+ * and a second failure stops with a named `::error::`. `--total-s` caps every
+ * attempt and pause together, so a slow download that keeps printing progress
+ * runs to the budget instead of being restarted from zero, and no retry starts
+ * without time left for it. A failure that is not a stall is retried once too
+ * and then reported with the command's exit code. No dependency: it runs
+ * before they are installed.
*
- * Usage: bun scripts/ci-bounded-run.ts --attempt-s <n> [--retry-s <n>] [--hint <text>] -- <command> [args...]
+ * Usage: bun scripts/ci-bounded-run.ts (--attempt-s <n> | --total-s <n>) [--idle-s <n>] [--retry-s <n>] [--hint <text>] -- <command> [args...]
*/
import { spawn } from 'node:child_process';
@@ -23,7 +26,12 @@ export interface BoundedRun {
argv: string[];
/** The command as the annotations name it. */
label: string;
- attemptSeconds: number;
+ /** Wall-clock bound on one attempt. */
+ attemptSeconds?: number;
+ /** An attempt that prints nothing on stdout or stderr for this long is stalled. */
+ idleSeconds?: number;
+ /** Wall-clock budget for every attempt and pause together; no retry starts once it is spent. */
+ totalSeconds?: number;
retrySeconds: number;
/** Why a stall is unusual for this command, appended to the stall line. */
hint?: string;
@@ -32,33 +40,51 @@ export interface BoundedRun {
const ATTEMPTS = 2;
-function attempt(run: BoundedRun): Promise<{ code: number | null; stalled: boolean }> {
+type Ending = 'exit' | 'attempt' | 'idle' | 'budget';
+
+function attempt(run: BoundedRun, boundMs: number, budgetBound: boolean): Promise<{ code: number | null; ending: Ending }> {
const grouped = process.platform !== 'win32';
- const child = spawn(run.argv[0]!, run.argv.slice(1), { stdio: ['ignore', 'inherit', 'inherit'], detached: grouped });
+ const watched = run.idleSeconds !== undefined;
+ const child = spawn(run.argv[0]!, run.argv.slice(1), { stdio: ['ignore', watched ? 'pipe' : 'inherit', watched ? 'pipe' : 'inherit'], detached: grouped });
const signal = (name: NodeJS.Signals) => {
try { if (grouped && child.pid) process.kill(-child.pid, name); else child.kill(name); } catch { /* the group is gone */ }
};
- let stalled = false, kill: ReturnType<typeof setTimeout> | undefined;
- const bound = setTimeout(() => {
- stalled = true;
+ let ending: Ending = 'exit', kill: ReturnType<typeof setTimeout> | undefined, idle: ReturnType<typeof setTimeout> | undefined;
+ const end = (why: Ending) => {
+ if (ending !== 'exit') return;
+ ending = why;
signal('SIGTERM');
kill = setTimeout(() => signal('SIGKILL'), (run.graceSeconds ?? 10) * 1000);
- }, run.attemptSeconds * 1000);
+ };
+ const bound = Number.isFinite(boundMs) ? setTimeout(() => end(budgetBound ? 'budget' : 'attempt'), boundMs) : undefined;
+ const quiet = () => { clearTimeout(idle); idle = setTimeout(() => end('idle'), run.idleSeconds! * 1000); };
+ if (watched) {
+ quiet();
+ child.stdout!.on('data', chunk => { process.stdout.write(chunk); quiet(); });
+ child.stderr!.on('data', chunk => { process.stderr.write(chunk); quiet(); });
+ }
+ const settle = () => { clearTimeout(bound); clearTimeout(kill); clearTimeout(idle); };
return new Promise(resolve => {
- child.once('error', () => { clearTimeout(bound); clearTimeout(kill); resolve({ code: 127, stalled }); });
- child.once('exit', code => { clearTimeout(bound); clearTimeout(kill); if (stalled) signal('SIGKILL'); resolve({ code, stalled }); });
+ child.once('error', () => { settle(); resolve({ code: 127, ending }); });
+ child.once('exit', code => { settle(); if (ending !== 'exit') signal('SIGKILL'); resolve({ code, ending }); });
});
}
export async function runBounded(run: BoundedRun): Promise<number> {
+ const deadline = run.totalSeconds !== undefined ? Date.now() + run.totalSeconds * 1000 : Infinity;
+ const hint = run.hint ? ` (${run.hint})` : '';
for (let n = 1; ; n++) {
const started = Date.now();
- const { code, stalled } = await attempt(run);
- if (code === 0 && !stalled) return 0;
- const why = stalled
- ? `stalled: no result after ${run.attemptSeconds}s${run.hint ? ` (${run.hint})` : ''}`
- : `exited ${code} after ${Math.round((Date.now() - started) / 1000)}s`;
- if (n >= ATTEMPTS) {
+ const attemptMs = run.attemptSeconds !== undefined ? run.attemptSeconds * 1000 : Infinity;
+ const { code, ending } = await attempt(run, Math.min(attemptMs, deadline - started), deadline - started <= attemptMs);
+ if (code === 0 && ending === 'exit') return 0;
+ const why = {
+ exit: `exited ${code} after ${Math.round((Date.now() - started) / 1000)}s`,
+ attempt: `stalled: no result after ${run.attemptSeconds}s${hint}`,
+ idle: `stalled: no output for ${run.idleSeconds}s${hint}`,
+ budget: `was still running when its ${run.totalSeconds}s budget ran out${hint}`,
+ }[ending];
+ if (n >= ATTEMPTS || deadline - Date.now() <= run.retrySeconds * 1000) {
console.error(`::error::${run.label} ${why} on attempt ${n} of ${ATTEMPTS}; giving up`);
return 1;
}
@@ -70,11 +96,13 @@ export async function runBounded(run: BoundedRun): Promise<number> {
if (import.meta.main) {
const args = process.argv.slice(2), split = args.indexOf('--');
const option = (name: string) => { const i = args.indexOf(name); return i >= 0 && i < split ? args[i + 1] : undefined; };
+ const seconds = (name: string) => { const v = option(name); return v === undefined ? undefined : Number(v); };
const argv = split >= 0 ? args.slice(split + 1) : [];
- const attemptSeconds = Number(option('--attempt-s'));
- if (!argv.length || !(attemptSeconds > 0)) {
- console.error('usage: bun scripts/ci-bounded-run.ts --attempt-s <n> [--retry-s <n>] [--hint <text>] -- <command> [args...]');
+ const attemptSeconds = seconds('--attempt-s'), idleSeconds = seconds('--idle-s'), totalSeconds = seconds('--total-s');
+ const valid = [attemptSeconds, idleSeconds, totalSeconds].every(v => v === undefined || v > 0);
+ if (!argv.length || !valid || (attemptSeconds === undefined && totalSeconds === undefined)) {
+ console.error('usage: bun scripts/ci-bounded-run.ts (--attempt-s <n> | --total-s <n>) [--idle-s <n>] [--retry-s <n>] [--hint <text>] -- <command> [args...]');
process.exit(2);
}
- process.exit(await runBounded({ argv, label: argv.join(' '), attemptSeconds, retrySeconds: Number(option('--retry-s') ?? 10), hint: option('--hint') }));
+ process.exit(await runBounded({ argv, label: argv.join(' '), attemptSeconds, idleSeconds, totalSeconds, retrySeconds: Number(option('--retry-s') ?? 10), hint: option('--hint') }));
}
diff --git a/test/scripts/ci-bounded-run.test.ts b/test/scripts/ci-bounded-run.test.ts
index 91e6e17868..628c38f8b9 100644
--- a/test/scripts/ci-bounded-run.test.ts
+++ b/test/scripts/ci-bounded-run.test.ts
@@ -1,8 +1,10 @@
/**
* scripts/ci-bounded-run.ts: a CI setup command runs in its own process group,
- * an attempt still running at its bound is ended (SIGTERM to the group, then
- * SIGKILL after the grace period), retried once, and a second failure stops
- * with a named `::error::`. Each case runs a real command that really stalls.
+ * an attempt that stalls (still running at its bound, or silent for the idle
+ * bound) is ended (SIGTERM to the group, then SIGKILL after the grace period),
+ * retried once, and a second failure stops with a named `::error::`. A slow
+ * attempt that keeps printing runs to the total budget instead of being
+ * restarted. Each case runs a real command that really stalls or crawls.
*/
import { afterEach, describe, expect, test } from 'bun:test';
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync, chmodSync } from 'node:fs';
@@ -77,20 +79,58 @@ esac
for (const pid of readFileSync(join(dir, 'pids'), 'utf8').trim().split('\n').map(Number)) expect(alive(pid)).toBe(false);
}, 30_000);
+ test('a silent attempt is a stall at the idle bound; a slow one that keeps printing is not', async () => {
+ const silent = scratch();
+ const r = await cli(['--idle-s', '1', '--total-s', '20', '--retry-s', '0', '--', stub(silent, ['stall', 'ok'])]);
+ expect(r.exitCode).toBe(0);
+ expect(r.stdout).toContain('done');
+ expect(r.annotations).toEqual([`::warning::${join(silent, 'setup')} attempt 1 stalled: no output for 1s; retrying in 0s`]);
+ const crawl = join(scratch(), 'crawl');
+ writeFileSync(crawl, `#!/bin/sh\nfor p in 10 20 30 40; do sleep 0.5; echo "$p% of 186.8 MiB"; done\necho installed\n`);
+ chmodSync(crawl, 0o755);
+ const c = await cli(['--idle-s', '1', '--total-s', '20', '--retry-s', '0', '--', crawl]);
+ expect(c.exitCode).toBe(0);
+ expect(c.stdout).toBe('10% of 186.8 MiB\n20% of 186.8 MiB\n30% of 186.8 MiB\n40% of 186.8 MiB\ninstalled\n');
+ expect(c.annotations).toEqual([]);
+ }, 30_000);
+
+ test('an attempt still printing when the total budget runs out is ended and named, with no retry', async () => {
+ const dir = scratch();
+ const path = join(dir, 'endless');
+ writeFileSync(path, `#!/bin/sh\necho start >> '${dir}/starts'\nwhile :; do echo progress; sleep 0.3; done\n`);
+ chmodSync(path, 0o755);
+ const started = Date.now();
+ const r = await cli(['--idle-s', '2', '--total-s', '2', '--retry-s', '0', '--hint', 'a slow CDN', '--', path]);
+ expect(r.exitCode).toBe(1);
+ expect(r.annotations).toEqual([`::error::${path} was still running when its 2s budget ran out (a slow CDN) on attempt 1 of 2; giving up`]);
+ expect(readFileSync(join(dir, 'starts'), 'utf8')).toBe('start\n');
+ expect((Date.now() - started) / 1000).toBeLessThan(10);
+ }, 30_000);
+
test('usage errors exit 2 without running anything', async () => {
expect((await cli(['--', 'true'])).exitCode).toBe(2);
expect((await cli(['--attempt-s', '5'])).exitCode).toBe(2);
+ expect((await cli(['--idle-s', '5', '--', 'true'])).exitCode).toBe(2);
+ expect((await cli(['--total-s', '0', '--', 'true'])).exitCode).toBe(2);
});
});
-test('the Playwright install is bounded, and its step cap covers both attempts', () => {
- const doc = load(readFileSync(join(ROOT, '.github/workflows/test.yml'), 'utf8')) as { jobs: Record<string, { 'timeout-minutes': number; steps: Array<{ run?: string; 'timeout-minutes'?: number }> }> };
+test('the Playwright install is bounded by silence and a total budget that fits its step cap, and its browser is cached', () => {
+ type Step = { id?: string; uses?: string; if?: string; run?: string; with?: Record<string, string>; 'timeout-minutes'?: number };
+ const doc = load(readFileSync(join(ROOT, '.github/workflows/test.yml'), 'utf8')) as { jobs: Record<string, { 'timeout-minutes': number; steps: Step[] }> };
const job = doc.jobs['admin-browser']!;
- const step = job.steps.find(entry => entry.run?.includes('playwright install'))!;
- const match = /^bun scripts\/ci-bounded-run\.ts --attempt-s (\d+) --retry-s (\d+) .*-- bunx playwright install --with-deps chromium$/.exec(step.run!);
+ const at = job.steps.findIndex(entry => entry.run?.includes('playwright install'));
+ const step = job.steps[at]!;
+ const match = /^bun scripts\/ci-bounded-run\.ts --idle-s (\d+) --total-s (\d+) --retry-s \d+ .*-- bunx playwright install --with-deps chromium$/.exec(step.run!);
expect(match).not.toBeNull();
- const worst = 2 * Number(match![1]) + Number(match![2]) + 2 * 10;
- expect(step['timeout-minutes']! * 60).toBeGreaterThan(worst);
+ expect(Number(match![1])).toBeLessThan(Number(match![2]));
+ expect(step['timeout-minutes']! * 60).toBeGreaterThan(Number(match![2]) + 10);
expect(job['timeout-minutes']).toBe(12);
- expect(existsSync(join(ROOT, 'scripts/ci-bounded-run.ts'))).toBe(true);
+ const restore = job.steps[at - 1]!, save = job.steps[at + 1]!;
+ expect(restore.uses).toMatch(/^actions\/cache\/restore@/);
+ expect(restore.with!.path).toBe('~/.cache/ms-playwright');
+ expect(restore.with!.key).toContain("hashFiles('node_modules/playwright-core/browsers.json')");
+ expect(save.uses).toMatch(/^actions\/cache\/save@/);
+ expect(save.if).toBe(`steps.${restore.id}.outputs.cache-hit != 'true'`);
+ expect(save.with).toEqual({ path: restore.with!.path!, key: `\${{ steps.${restore.id}.outputs.cache-primary-key }}` });
});