Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(e2e): the Tier 2 OpenClaw install waits out a registry race (ETARGET/E404) on its own back-off

garrytanebfb714e3852
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index ac498804a3..7c023b1f65 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -608,22 +608,15 @@ jobs:
esac
fi
- name: Install OpenClaw
- # Bound + retry the install: a transient npm/registry stall here used to
- # hang unbounded and (since the v0.42.50.0 job timeout) burn the entire
- # 30m Tier 2 budget before failing — even though the install normally
- # finishes in well under a minute. `timeout` kills a hung attempt fast;
- # up to 3 attempts ride out a flaky registry. Step cap is a backstop.
+ # Bound + retry the install (scripts/ci-install-openclaw.sh): a transient
+ # npm/registry stall here used to hang unbounded and (since the v0.42.50.0
+ # job timeout) burn the entire 30m Tier 2 budget before failing — even
+ # though the install normally finishes in well under a minute. `timeout`
+ # kills a hung attempt fast; up to 3 attempts ride out a flaky registry,
+ # and a registry race (ETARGET/E404 on a dependency version published
+ # moments ago) gets up to 4 attempts 20/40/80 s apart. Step cap is a backstop.
timeout-minutes: 8
- run: |
- for attempt in 1 2 3; do
- if timeout 120 npm install -g [email protected]; then
- exit 0
- fi
- echo "::warning::openclaw install attempt $attempt failed or timed out; retrying in 10s" >&2
- sleep 10
- done
- echo "::error::openclaw install failed after 3 attempts" >&2
- exit 1
+ run: scripts/ci-install-openclaw.sh
- name: Configure OpenClaw MCP
run: |
mkdir -p ~/.openclaw
diff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.md
index 2b964da46a..40f01c3653 100644
--- a/docs/architecture/key-files/ci-health-and-test-guards.md
+++ b/docs/architecture/key-files/ci-health-and-test-guards.md
@@ -14,6 +14,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `scripts/release-restamp.ts` + `scripts/lib/restamp.ts` — `bun run release:restamp`, run when a PR is next to merge. The CLI refuses a dirty tree, fetches `origin/master`, captures the branch CHANGELOG entry and migration inventory, merges master with a merge commit (version-only stamp hunks, `CHANGELOG.md` and the `GENERATED_PATHS` files resolve mechanically; anything else stops), sets VERSION to master's PATCH + 1, renumbers branch-only migrations from master's latest + 1 (filename, export name and `version:` literal only; `migrationPayloadKey` proves the rest is token-identical and refuses a copy of a published migration or an edited published one), rewrites `STAMPS` (the CLAUDE.md "Version locations" Required rows) plus CHANGELOG and TODOS, runs `DEFAULT_STEPS`, lists branch-added lines that still name an old number (`findLeftoverRefs`, never rewritten), runs `DEFAULT_CHECKS` and commits once. Stops save `.git/gbrain-restamp.json` for `--continue` / `--abort`; `--dry-run` prints the plan, `--no-commit` stages. Generators run through `offlineEnv` (no database URLs, no provider keys). Tests: `test/scripts/release-restamp.test.ts` (fixture repos with the real migration generator; also pins CLAUDE.md table coverage and docs anchors).
- `scripts/ci-manifest-diff.sh` — parsed-JSON classification of manifest diffs for CI scoping: `version-only` (only the top-level `version` differs), `dependency-change` (any dependency field differs), `dependency-scope` (whether a changed-file list touches lockfiles, `patches/` or dependency fields) and `drop-version-only` (filters version-only `package.json` and `openclaw.plugin.json` entries out of a changed-file list, so a release bump does not widen the native scope). Used by test.yml's `changes` job (before `scripts/ci-native-scope.sh`) and its dependency-audit scope step. Tests: `test/scripts/ci-manifest-diff.test.ts`.
- `scripts/ci-dependency-audit.sh` — runs `bun audit` for the root and `admin/` lockfiles. It blocks (`BLOCKING=true`) on pushes, schedules and dispatches, on lockfile, `patches/` or dependency-field changes, with the `dependency-audit` label, or when the diff cannot be read; elsewhere an advisory is a `::warning::` naming why the run does not block.
+- `scripts/ci-install-openclaw.sh` — e2e.yml's Tier 2 `Install OpenClaw` step. Each `npm install -g openclaw@<pin>` attempt is bounded (`timeout 120`); a failure whose npm log carries `code ETARGET` or `E404` is a registry race (a dependency version published but not yet visible for every package of its release, the 2026-10-12 master Tier 2 red on `@aws-sdk/credential-provider-node@^3.972.86`) and is retried up to 4 attempts 20/40/80 s apart; any other failure keeps the 3 attempts 10 s apart. Nothing else is retried, and the last attempt fails the step with npm's own log. Knobs (`OPENCLAW_SPEC`, `OPENCLAW_INSTALL_ATTEMPT_S`, `OPENCLAW_INSTALL_RETRY_SLEEP_S`, `OPENCLAW_INSTALL_RACE_SLEEPS_S`) exist for the test: `test/scripts/ci-install-openclaw.test.ts` installs a one-file package from a loopback registry (`test/helpers/npm-stub-registry.ts`) that answers ETARGET or E404 to the first three packument requests, forever, or publishes for an impossible `os` (`EBADPLATFORM`, the generic path). The lockfile route (a committed `package-lock.json` per pin) was weighed and not taken: two pins live in the workflows (`e2e.yml` 2026.4.9, `native-locks.yml` 2026.9.4), every bump would regenerate a multi-hundred-kilobyte lockfile, and the race the retry waits out is a propagation delay of minutes.
- `scripts/e2e-provider-key-notice.sh` — e2e.yml's visible-skip step: when `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` is empty, prints a `::warning::` and step-summary line naming the empty secret and the owner-only fix, so a green keyless run is never read as keyed coverage. Exits 0 always.
- `scripts/scale/watchdog.ts` — out-of-process phase watchdog for the scale harness. `scripts/scale/run.ts` re-runs itself as a child; the supervisor times the `import`, `extract`, `vectors` and `budgets` phases from the child's `[scale] phase <name> start` lines and kills the child's process group at 1.5x the phase's gate ceiling (`scripts/scale/gates.ts` `phaseLimitsMs`), names the phase, elapsed time and last progress line, then removes the brain home and scale database. `GBRAIN_SCALE_PHASE_LIMIT_MS_<PHASE>` overrides one limit; `GBRAIN_SCALE_SUPERVISED` is the internal handshake. Tests: `test/scripts/scale-watchdog.test.ts`.
- `scripts/check-test-env-opt-ins.ts` + `test/helpers/operator-env-policy.ts` — the opt-in naming rule. The policy (`STRIP_PREFIX`, `KEEP_EXACT`, `KEEP_PREFIX`, `RENAMED`, `isStripped`) is shared by `test/helpers/operator-env-preload.ts`, which deletes stripped `GBRAIN_*` names before any test loads and stops the run with the rename command when an old opt-in name is set, and by the guard (`check:test-env-opt-ins`, in `verify`), which parses test files and fails on a test that gates execution on a stripped name. Test opt-ins are `GBRAIN_TEST_<AREA>_<WHAT>`, paid ones `GBRAIN_TEST_LIVE_<WHAT>`. The same guard fails `test_env_snapshot_module_scope`: a `delete` of or assignment to `process.env.GBRAIN_PGLITE_SNAPSHOT` outside every function body in a file the unit matrix loads (`*.serial.test.ts`, `test/e2e/` and `*-preload.ts` are exempt: own process, or process-wide by design). `scripts/test-shard.sh` runs a whole shard in one bun process, so such a change persists for every later file and each of their PGLite engines cold-boots (~3 s); the accepted shape is save+delete in `beforeAll`, restore in `afterAll`, or `test/helpers/with-snapshot.ts` per test. Tests: `test/scripts/test-env-opt-ins-guard.test.ts`, `test/operator-env-preload.test.ts`.
diff --git a/scripts/ci-install-openclaw.sh b/scripts/ci-install-openclaw.sh
new file mode 100755
index 0000000000..20d10de077
--- /dev/null
+++ b/scripts/ci-install-openclaw.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+# Tier 2 (e2e.yml) installs the OpenClaw CLI with `npm install -g`, which resolves
+# every transitive dependency fresh against the registry. Two things go wrong there:
+#
+# * a registry or network stall hangs an attempt (before the per-attempt
+# `timeout` it burned the whole 30 m Tier 2 budget), so each attempt is
+# bounded and a failed one is retried after a short pause;
+# * a dependency published moments ago is not yet visible for every package of
+# its release (`npm error code ETARGET` / `E404` for a version that exists a
+# minute later: @aws-sdk/credential-provider-node@^3.972.86 on the 2026-10-12
+# master Tier 2 run). The flat 10 s retries were over in half a minute and
+# missed the window, so a registry race gets its own longer back-off.
+#
+# Any other failure keeps the generic retries. Nothing else is retried or hidden:
+# after the last attempt the step fails with npm's own log.
+#
+# Environment (defaults are the CI values; the test overrides them):
+# OPENCLAW_SPEC package spec, default [email protected]
+# OPENCLAW_INSTALL_ATTEMPT_S per-attempt timeout, default 120
+# OPENCLAW_INSTALL_RETRY_SLEEP_S pause after a generic failure, default 10 (3 attempts)
+# OPENCLAW_INSTALL_RACE_SLEEPS_S pauses after a registry race, default "20 40 80" (4 attempts)
+set -uo pipefail
+
+spec="${OPENCLAW_SPEC:[email protected]}"
+attempt_timeout="${OPENCLAW_INSTALL_ATTEMPT_S:-120}"
+retry_sleep="${OPENCLAW_INSTALL_RETRY_SLEEP_S:-10}"
+race_sleeps="${OPENCLAW_INSTALL_RACE_SLEEPS_S:-20 40 80}"
+log="$(mktemp "${TMPDIR:-/tmp}/openclaw-install.XXXXXX")"
+trap 'rm -f "$log"' EXIT
+
+generic_failures=0
+race_failures=0
+attempt=0
+while :; do
+ attempt=$((attempt + 1))
+ if timeout "$attempt_timeout" npm install -g "$spec" 2>&1 | tee "$log"; then
+ exit 0
+ fi
+ if grep -Eq 'npm (error|ERR!) code E(TARGET|404)\b' "$log"; then
+ race_failures=$((race_failures + 1))
+ # shellcheck disable=SC2086
+ set -- $race_sleeps
+ if [ "$race_failures" -gt "$#" ]; then
+ echo "::error::openclaw install: the registry still does not serve a version $spec resolves to after $race_failures attempts (ETARGET/E404)" >&2
+ exit 1
+ fi
+ eval "pause=\${$race_failures}"
+ echo "::warning::openclaw install attempt $attempt hit a registry race (ETARGET/E404: a dependency version is not visible yet); retrying in ${pause}s" >&2
+ else
+ generic_failures=$((generic_failures + 1))
+ if [ "$generic_failures" -ge 3 ]; then
+ echo "::error::openclaw install failed after $attempt attempts" >&2
+ exit 1
+ fi
+ pause="$retry_sleep"
+ echo "::warning::openclaw install attempt $attempt failed or timed out; retrying in ${pause}s" >&2
+ fi
+ sleep "$pause"
+done
diff --git a/test/helpers/npm-stub-registry.ts b/test/helpers/npm-stub-registry.ts
new file mode 100644
index 0000000000..31de29ee7e
--- /dev/null
+++ b/test/helpers/npm-stub-registry.ts
@@ -0,0 +1,58 @@
+/**
+ * A loopback npm registry serving one tiny package, for installer scripts under test.
+ *
+ * The packument request can be made to fail first: `race: { kind: 'ETARGET' | 'E404', times }`
+ * answers the first `times` packument requests the way a registry does while a release is
+ * still propagating (a packument without the requested version, or no packument at all), then
+ * serves the real one. `platform: 'unsupported'` publishes the version for an operating system
+ * that does not exist (`EBADPLATFORM`), a failure no retry should wait out.
+ */
+import { createHash } from 'node:crypto';
+import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+
+export const STUB_PACKAGE = 'gbrain-openclaw-probe';
+export const STUB_VERSION = '1.0.0';
+
+export interface StubRegistryOptions { dir: string; race?: { kind: 'ETARGET' | 'E404'; times: number }; platform?: 'unsupported' }
+
+export async function startStubRegistry(options: StubRegistryOptions) {
+ const pkgDir = join(options.dir, 'pkg');
+ mkdirSync(pkgDir, { recursive: true });
+ writeFileSync(join(pkgDir, 'package.json'), JSON.stringify({ name: STUB_PACKAGE, version: STUB_VERSION, bin: { [STUB_PACKAGE]: 'bin.js' } }));
+ writeFileSync(join(pkgDir, 'bin.js'), '#!/usr/bin/env node\nconsole.log("probe");\n');
+ const packed = Bun.spawnSync(['npm', 'pack', '--silent', '--pack-destination', options.dir], { cwd: pkgDir,
+ env: { ...process.env, npm_config_cache: join(options.dir, 'pack-cache'), npm_config_update_notifier: 'false' } });
+ if (packed.exitCode) throw new Error(`npm pack: ${packed.stderr.toString()}`);
+ const tarball = readFileSync(join(options.dir, packed.stdout.toString().trim()));
+ const integrity = `sha512-${createHash('sha512').update(tarball).digest('base64')}`;
+ let packumentRequests = 0, tarballRequests = 0;
+ const server = Bun.serve({
+ hostname: '127.0.0.1', port: 0,
+ fetch(request) {
+ const path = new URL(request.url).pathname;
+ if (path === `/${STUB_PACKAGE}`) {
+ packumentRequests++;
+ const racing = options.race && packumentRequests <= options.race.times;
+ if (racing && options.race!.kind === 'E404') return Response.json({ error: 'Not found' }, { status: 404 });
+ const version = racing ? '0.9.0' : STUB_VERSION;
+ return Response.json({ name: STUB_PACKAGE, 'dist-tags': { latest: version }, versions: { [version]: {
+ name: STUB_PACKAGE, version, bin: { [STUB_PACKAGE]: 'bin.js' }, ...(options.platform ? { os: ['gbrain-nowhere'] } : {}),
+ dist: { tarball: `http://127.0.0.1:${server.port}/${STUB_PACKAGE}/-/${STUB_PACKAGE}-${version}.tgz`, integrity } } } });
+ }
+ if (path.endsWith('.tgz')) { tarballRequests++; return new Response(tarball, { headers: { 'content-type': 'application/octet-stream' } }); }
+ return new Response('not found', { status: 404 });
+ },
+ });
+ return {
+ url: `http://127.0.0.1:${server.port}/`,
+ requests: () => ({ packument: packumentRequests, tarball: tarballRequests }),
+ stop: () => server.stop(true),
+ };
+}
+
+/** Environment that points npm's global install at the stub registry and a throwaway prefix. */
+export function stubNpmEnv(registryUrl: string, dir: string): Record<string, string> {
+ return { npm_config_registry: registryUrl, npm_config_prefix: join(dir, 'prefix'), npm_config_cache: join(dir, 'cache'),
+ npm_config_audit: 'false', npm_config_fund: 'false', npm_config_update_notifier: 'false', npm_config_loglevel: 'error' };
+}
diff --git a/test/scripts/ci-install-openclaw.test.ts b/test/scripts/ci-install-openclaw.test.ts
new file mode 100644
index 0000000000..e7d060e079
--- /dev/null
+++ b/test/scripts/ci-install-openclaw.test.ts
@@ -0,0 +1,61 @@
+/**
+ * scripts/ci-install-openclaw.sh: the Tier 2 OpenClaw install retries a registry race
+ * (ETARGET/E404, a dependency version published but not yet visible) on its own longer
+ * back-off, keeps the short generic retries for everything else, and stays bounded.
+ *
+ * A loopback registry serves one tiny package; the script installs it into a throwaway
+ * npm prefix with every pause set to zero.
+ */
+import { afterEach, describe, expect, test } from 'bun:test';
+import { existsSync, mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { STUB_PACKAGE, STUB_VERSION, type StubRegistryOptions, startStubRegistry, stubNpmEnv } from '../helpers/npm-stub-registry.ts';
+
+const SCRIPT = join(import.meta.dir, '..', '..', 'scripts', 'ci-install-openclaw.sh');
+
+describe('scripts/ci-install-openclaw.sh', () => {
+ const cleanups: Array<() => void> = [];
+ afterEach(() => { for (const cleanup of cleanups.splice(0)) cleanup(); });
+
+ async function run(options: Omit<StubRegistryOptions, 'dir'>) {
+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-openclaw-install-'));
+ const registry = await startStubRegistry({ dir, ...options });
+ cleanups.push(() => { registry.stop(); rmSync(dir, { recursive: true, force: true }); });
+ const proc = Bun.spawn(['bash', SCRIPT], { stdout: 'pipe', stderr: 'pipe', env: {
+ ...process.env, ...stubNpmEnv(registry.url, dir),
+ OPENCLAW_SPEC: `${STUB_PACKAGE}@${STUB_VERSION}`, OPENCLAW_INSTALL_RETRY_SLEEP_S: '0', OPENCLAW_INSTALL_RACE_SLEEPS_S: '0 0 0',
+ } });
+ const [stdout, stderr, exitCode] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]);
+ const warnings = stderr.split('\n').filter(line => line.startsWith('::warning::') || line.startsWith('::error::'));
+ return { exitCode, stdout, warnings, requests: registry.requests(), installed: existsSync(join(dir, 'prefix', 'bin', STUB_PACKAGE)) };
+ }
+
+ test.each([['ETARGET'], ['E404']] as const)('a %s race on the first three attempts is waited out and the fourth installs', async (kind) => {
+ const result = await run({ race: { kind, times: 3 } });
+ expect(result).toMatchObject({ exitCode: 0, installed: true });
+ expect(result.warnings).toHaveLength(3);
+ for (const warning of result.warnings) expect(warning).toMatch(/^::warning::openclaw install attempt \d hit a registry race/);
+ expect(result.requests.packument).toBeGreaterThanOrEqual(4);
+ expect(result.requests.tarball).toBe(1);
+ }, 120_000);
+
+ test('a race that never resolves stops after four attempts with its own error', async () => {
+ const result = await run({ race: { kind: 'ETARGET', times: Number.MAX_SAFE_INTEGER } });
+ expect(result).toMatchObject({ exitCode: 1, installed: false });
+ expect(result.warnings.filter(line => line.includes('hit a registry race'))).toHaveLength(3);
+ expect(result.warnings.at(-1)).toMatch(/^::error::openclaw install: the registry still does not serve .* after 4 attempts \(ETARGET\/E404\)/);
+ expect(result.requests.tarball).toBe(0);
+ }, 120_000);
+
+ test('a failure that is not a registry race keeps the three generic attempts', async () => {
+ const result = await run({ platform: 'unsupported' });
+ expect(result).toMatchObject({ exitCode: 1, installed: false });
+ expect(result.stdout).toContain('EBADPLATFORM');
+ expect(result.warnings).toEqual([
+ '::warning::openclaw install attempt 1 failed or timed out; retrying in 0s',
+ '::warning::openclaw install attempt 2 failed or timed out; retrying in 0s',
+ '::error::openclaw install failed after 3 attempts',
+ ]);
+ }, 120_000);
+});