Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
v0.60.206.0 ci: bound and retry the Playwright browser install; one shared bounded runner that ends the whole process group
garrytan0711429680fe
diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex feeb3dc8cf..fad2bb63dd 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -924,8 +924,9 @@ jobs:timeout-minutes: 8run: bun ../scripts/ci-bun-install.ts --frozen-lockfile --ignore-scriptsworking-directory: admin- - name: Install the pinned Chromium browser and OS dependencies- run: bunx playwright install --with-deps chromium+ - 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- name: Build the shipped admin assetsrun: bun run build:admin- name: Exercise owner administration and native OAuth in Chromiumdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex f8547a9fbc..ca33461579 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,26 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [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.++### 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-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.+- **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.+ - 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.+ - Usage errors exit 2.+ - A workflow check requires the Playwright step to be bounded, with a step cap that covers both attempts.+ - 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**Every `search` and `query` response now says where its time went.**diff --git a/VERSION b/VERSIONindex 865fddfbb1..f75b97b9a7 100644--- a/VERSION+++ b/VERSION@@ -1 +1 @@-0.60.205.0+0.60.206.0diff --git a/scripts/ci-bounded-run.ts b/scripts/ci-bounded-run.tsnew file mode 100644index 0000000000..689ab148b5--- /dev/null+++ b/scripts/ci-bounded-run.ts@@ -0,0 +1,80 @@+#!/usr/bin/env bun+/**+ * Run one CI setup command with a per-attempt bound and one retry.+ *+ * A network-bound setup step (`bun install`, Playwright's browser and OS+ * dependency install) normally takes seconds, and on a bad registry, mirror or+ * 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.+ *+ * Usage: bun scripts/ci-bounded-run.ts --attempt-s <n> [--retry-s <n>] [--hint <text>] -- <command> [args...]+ */+import { spawn } from 'node:child_process';++export interface BoundedRun {+ argv: string[];+ /** The command as the annotations name it. */+ label: string;+ attemptSeconds: number;+ retrySeconds: number;+ /** Why a stall is unusual for this command, appended to the stall line. */+ hint?: string;+ graceSeconds?: number;+}++const ATTEMPTS = 2;++function attempt(run: BoundedRun): Promise<{ code: number | null; stalled: boolean }> {+ const grouped = process.platform !== 'win32';+ const child = spawn(run.argv[0]!, run.argv.slice(1), { stdio: ['ignore', 'inherit', '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;+ signal('SIGTERM');+ kill = setTimeout(() => signal('SIGKILL'), (run.graceSeconds ?? 10) * 1000);+ }, run.attemptSeconds * 1000);+ 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 }); });+ });+}++export async function runBounded(run: BoundedRun): Promise<number> {+ 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) {+ console.error(`::error::${run.label} ${why} on attempt ${n} of ${ATTEMPTS}; giving up`);+ return 1;+ }+ console.error(`::warning::${run.label} attempt ${n} ${why}; retrying in ${run.retrySeconds}s`);+ await Bun.sleep(run.retrySeconds * 1000);+ }+}++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 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...]');+ process.exit(2);+ }+ process.exit(await runBounded({ argv, label: argv.join(' '), attemptSeconds, retrySeconds: Number(option('--retry-s') ?? 10), hint: option('--hint') }));+}diff --git a/scripts/ci-bun-install.ts b/scripts/ci-bun-install.tsindex a842f0696c..3c1ae6cd0e 100644--- a/scripts/ci-bun-install.ts+++ b/scripts/ci-bun-install.ts@@ -11,8 +11,8 @@* printed it: the output is inherited, and a failure that is not a stall (a* frozen-lockfile mismatch, an unreachable registry) is retried once and then* reported with Bun's exit code. It uses no dependency, because it runs before- * they are installed, and spawns asynchronously, so it behaves the same on- * Linux, macOS and Windows.+ * they are installed. The bound, retry and process-group handling live in+ * `scripts/ci-bounded-run.ts`, which other setup steps share.** Usage: bun scripts/ci-bun-install.ts [bun install flags...]* Environment (defaults are the CI values; the test overrides them):@@ -20,30 +20,13 @@* GBRAIN_CI_INSTALL_RETRY_SLEEP_S pause before the retry in seconds, default 10* GBRAIN_CI_INSTALL_BUN the Bun executable to run, default this one*/-export {};+import { runBounded } from './ci-bounded-run.ts';-const ATTEMPTS = 2;const flags = process.argv.slice(2);-const attemptSeconds = Number(process.env.GBRAIN_CI_INSTALL_ATTEMPT_S ?? 180);-const retrySeconds = Number(process.env.GBRAIN_CI_INSTALL_RETRY_SLEEP_S ?? 10);-const bun = process.env.GBRAIN_CI_INSTALL_BUN || process.execPath;-const command = ['bun', 'install', ...flags].join(' ');--for (let attempt = 1; ; attempt++) {- const started = Date.now();- const child = Bun.spawn([bun, 'install', ...flags], { stdin: 'ignore', stdout: 'inherit', stderr: 'inherit' });- let stalled = false;- const timer = setTimeout(() => { stalled = true; child.kill('SIGKILL'); }, attemptSeconds * 1000);- const code = await child.exited;- clearTimeout(timer);- if (code === 0 && !stalled) process.exit(0);- const why = stalled- ? `stalled: no result after ${attemptSeconds}s (a registry or network stall; the install normally takes seconds)`- : `exited ${code} after ${Math.round((Date.now() - started) / 1000)}s`;- if (attempt >= ATTEMPTS) {- console.error(`::error::${command} ${why} on attempt ${attempt} of ${ATTEMPTS}; giving up`);- process.exit(1);- }- console.error(`::warning::${command} attempt ${attempt} ${why}; retrying in ${retrySeconds}s`);- await Bun.sleep(retrySeconds * 1000);-}+process.exit(await runBounded({+ argv: [process.env.GBRAIN_CI_INSTALL_BUN || process.execPath, 'install', ...flags],+ label: ['bun', 'install', ...flags].join(' '),+ attemptSeconds: Number(process.env.GBRAIN_CI_INSTALL_ATTEMPT_S ?? 180),+ retrySeconds: Number(process.env.GBRAIN_CI_INSTALL_RETRY_SLEEP_S ?? 10),+ hint: 'a registry or network stall; the install normally takes seconds',+}));diff --git a/test/scripts/ci-bounded-run.test.ts b/test/scripts/ci-bounded-run.test.tsnew file mode 100644index 0000000000..91e6e17868--- /dev/null+++ b/test/scripts/ci-bounded-run.test.ts@@ -0,0 +1,96 @@+/**+ * 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.+ */+import { afterEach, describe, expect, test } from 'bun:test';+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync, chmodSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { load } from 'js-yaml';+import { runBounded } from '../../scripts/ci-bounded-run.ts';++const ROOT = join(import.meta.dir, '..', '..');+const SCRIPT = join(ROOT, 'scripts', 'ci-bounded-run.ts');+const alive = (pid: number) => { try { process.kill(pid, 0); return true; } catch { return false; } };++describe.skipIf(process.platform === 'win32')('scripts/ci-bounded-run.ts', () => {+ const dirs: string[] = [];+ afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }); });+ const scratch = () => { const dir = mkdtempSync(join(tmpdir(), 'gbrain-ci-bounded-')); dirs.push(dir); return dir; };++ /** A command whose attempts follow `plan` (stall, fail or ok), leaving a backgrounded grandchild on a stall. */+ function stub(dir: string, plan: string[]): string {+ writeFileSync(join(dir, 'plan'), `${plan.join('\n')}\n`);+ const path = join(dir, 'setup');+ writeFileSync(path, `#!/bin/sh+n=$(cat '${dir}/count' 2>/dev/null || echo 0); n=$((n + 1)); echo "$n" > '${dir}/count'+case "$(sed -n "\${n}p" '${dir}/plan')" in+ stall) sleep 60 & echo $! >> '${dir}/grandchildren'; sleep 60 ;;+ fail) echo 'E: Unable to fetch some archives' >&2; exit 100 ;;+ *) echo 'done'; exit 0 ;;+esac+`);+ chmodSync(path, 0o755);+ return path;+ }++ async function cli(args: string[]) {+ const proc = Bun.spawn([process.execPath, SCRIPT, ...args], { stdout: 'pipe', stderr: 'pipe' });+ const [stdout, stderr, exitCode] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]);+ return { exitCode, stdout, stderr, annotations: stderr.split('\n').filter(line => /^::(warning|error)::/.test(line)) };+ }++ test('a stalled attempt is ended with its whole process group, named, and the retry succeeds', async () => {+ const dir = scratch();+ const r = await cli(['--attempt-s', '1', '--retry-s', '0', '--hint', 'normally seconds', '--', stub(dir, ['stall', 'ok'])]);+ expect(r.exitCode).toBe(0);+ expect(r.stdout).toContain('done');+ expect(r.annotations).toEqual([`::warning::${join(dir, 'setup')} attempt 1 stalled: no result after 1s (normally seconds); retrying in 0s`]);+ const [grandchild] = readFileSync(join(dir, 'grandchildren'), 'utf8').trim().split('\n').map(Number);+ expect(alive(grandchild!)).toBe(false);+ }, 30_000);++ test('two stalls stop with a named error; a failure that is not a stall keeps its exit code', async () => {+ const stalls = scratch();+ const r = await cli(['--attempt-s', '1', '--retry-s', '0', '--', stub(stalls, ['stall', 'stall'])]);+ expect(r.exitCode).toBe(1);+ expect(r.annotations.at(-1)).toBe(`::error::${join(stalls, 'setup')} stalled: no result after 1s on attempt 2 of 2; giving up`);+ for (const pid of readFileSync(join(stalls, 'grandchildren'), 'utf8').trim().split('\n').map(Number)) expect(alive(pid)).toBe(false);+ const fails = scratch();+ const f = await cli(['--attempt-s', '5', '--retry-s', '0', '--', stub(fails, ['fail', 'fail'])]);+ expect(f.exitCode).toBe(1);+ expect(f.stderr).toContain('E: Unable to fetch some archives');+ expect(f.annotations[1]).toMatch(/exited 100 after \d+s on attempt 2 of 2; giving up$/);+ }, 30_000);++ test('a child that ignores SIGTERM is killed after the grace period', async () => {+ const dir = scratch();+ const path = join(dir, 'stubborn');+ writeFileSync(path, `#!/bin/sh\ntrap '' TERM\necho $$ >> '${dir}/pids'\nwhile :; do sleep 1; done\n`);+ chmodSync(path, 0o755);+ const started = Date.now();+ const code = await runBounded({ argv: [path], label: 'stubborn', attemptSeconds: 1, retrySeconds: 0, graceSeconds: 1 });+ expect(code).toBe(1);+ expect((Date.now() - started) / 1000).toBeLessThan(10);+ for (const pid of readFileSync(join(dir, 'pids'), 'utf8').trim().split('\n').map(Number)) expect(alive(pid)).toBe(false);+ }, 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);+ });+});++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 }> }> };+ 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!);+ expect(match).not.toBeNull();+ const worst = 2 * Number(match![1]) + Number(match![2]) + 2 * 10;+ expect(step['timeout-minutes']! * 60).toBeGreaterThan(worst);+ expect(job['timeout-minutes']).toBe(12);+ expect(existsSync(join(ROOT, 'scripts/ci-bounded-run.ts'))).toBe(true);+});