Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci: run unit-lane PostgreSQL arms in 12 shards sized for a 2x-slow runner

garrytanddf1f6fc7229
diff --git a/.github/workflows/persistence-validation.yml b/.github/workflows/persistence-validation.yml
index 30965c85ff..93be06b304 100644
--- a/.github/workflows/persistence-validation.yml
+++ b/.github/workflows/persistence-validation.yml
@@ -178,18 +178,18 @@ jobs:
# file; the PGLite arm also runs in the unit lane). The list is test/postgres-unit-arms.txt;
# scripts/check-postgres-lane-coverage.ts fails a new DATABASE_URL-gated arm
# until it is listed there or wrapped in a test/e2e registerPostgresTests
- # file. The eight shards (ARM_SHARDS in scripts/postgres-unit-arms.ts) are
+ # file. The twelve shards (ARM_SHARDS in scripts/postgres-unit-arms.ts) are
# balanced by measured runtime (scripts/postgres-arm-weights.json, mined from
- # this job's logs); each shard's measured sum must stay well inside the
- # step's 20 minutes (ARM_SHARD_BUDGET_MS).
+ # this job's logs); each shard's measured sum, doubled for a slow runner, must
+ # end a minute inside the step's 20 minutes (ARM_SHARD_BUDGET_MS).
unit-postgres-arms:
- name: Unit-lane PostgreSQL arms ${{ matrix.shard }}/8 / Bun ${{ matrix.bun }}
+ name: Unit-lane PostgreSQL arms ${{ matrix.shard }}/12 / Bun ${{ matrix.bun }}
runs-on: ubicloud-standard-4-ubuntu-2404
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
- shard: [1, 2, 3, 4, 5, 6, 7, 8]
+ shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
bun: ['1.4.0', '1.4.3']
# Event parity: every event, pull requests and merge-queue runs
# included, runs both supported Bun versions (docs/TESTING.md#event-parity).
@@ -230,11 +230,11 @@ jobs:
receipts_init pg-arms || exit 2
# The list lives in test/postgres-unit-arms.txt (one path per line);
# shards balance by measured runtime (scripts/postgres-arm-weights.json).
- selected=$(bun scripts/postgres-unit-arms.ts shard "$SHARD" 8)
+ selected=$(bun scripts/postgres-unit-arms.ts shard "$SHARD" 12)
files=()
while IFS= read -r file; do [ -n "$file" ] && files+=("$file"); done <<< "$selected"
if [ "${#files[@]}" -eq 0 ]; then
- echo "::error::shard $SHARD/8 selected no files from test/postgres-unit-arms.txt. Why: an empty shard would pass without running any PostgreSQL arm. Fix: run 'bun scripts/postgres-unit-arms.ts shard $SHARD 8' locally and correct the list. Docs: docs/TESTING.md#postgres-arm-lanes" >&2
+ echo "::error::shard $SHARD/8 selected no files from test/postgres-unit-arms.txt. Why: an empty shard would pass without running any PostgreSQL arm. Fix: run 'bun scripts/postgres-unit-arms.ts shard $SHARD 12' locally and correct the list. Docs: docs/TESTING.md#postgres-arm-lanes" >&2
exit 1
fi
# One bun process per file: *.serial.test.ts files require their own
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 6f2321f5ef..3845cc5c4e 100644
--- a/docs/architecture/key-files/ci-health-and-test-guards.md
+++ b/docs/architecture/key-files/ci-health-and-test-guards.md
@@ -20,7 +20,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `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`.
- `scripts/check-postgres-lane-coverage.ts` — `check:postgres-lanes` (in `verify`). TypeScript-AST scan of every `test/` file outside `test/e2e/` and `test/fixtures/` for a `DATABASE_URL`-gated PostgreSQL arm (zero-argument `testBackends()`, or a `DATABASE_URL` read used as a condition, connection argument or `database_url` value; `withEnv`-supplied URLs excluded) and a lane that runs it (a workflow step with `DATABASE_URL` naming the file, a `test/e2e/` importer, a `tests/heavy/` script, or a `scripts/e2e-backend-matrix.txt` row). `ALLOWLIST` rows name a reason and TODO; stale rows fail. A `test/postgres-unit-arms.txt` row is a lane; a malformed, duplicate, unsorted, missing-file or arm-less row fails (`postgres_arm_list_invalid`, `postgres_arm_list_stale`). `postgresArm`, `postgresLanes` and `armedFiles` are exported for the stress runner. Tests: `test/scripts/postgres-lane-coverage.test.ts`.
-- `test/postgres-unit-arms.txt` + `scripts/postgres-unit-arms.ts` + `scripts/postgres-arm-weights.json` — the one list of unit-lane files whose PostgreSQL arm has no other owner (sorted, one path per line, `#` comments). Read by persistence-validation.yml's `unit-postgres-arms` job (`shard <n> <m>`: LPT over the mined per-file weights, p75 fallback; one Bun process per file), the scheduled race hunt and the lane guard. `mine <job.log>…` rewrites the weights from a green run's shard logs (`##[group]<file>` to the next group or endgroup). Tests: `test/scripts/postgres-unit-arms.test.ts`.
+- `test/postgres-unit-arms.txt` + `scripts/postgres-unit-arms.ts` + `scripts/postgres-arm-weights.json` — the one list of unit-lane files whose PostgreSQL arm has no other owner (sorted, one path per line, `#` comments). Read by persistence-validation.yml's `unit-postgres-arms` job (`ARM_SHARDS` = 12 shards, `shard <n> <m>`: LPT over the mined per-file weights, p75 fallback; one Bun process per file; each shard's weighted sum at most `ARM_SHARD_BUDGET_MS`, 570 s, so twice that still ends a minute inside the 20-minute `ARM_STEP_TIMEOUT_MS` step), the scheduled race hunt and the lane guard. `mine <job.log>…` rewrites the weights from a green run's shard logs (`##[group]<file>` to the next group or endgroup). Tests: `test/scripts/postgres-unit-arms.test.ts`.
- `scripts/serial-files.tsv` + `scripts/lib/serial-manifest.ts` — the serial manifest: every `*.serial.test.ts` outside `test/e2e/` with its class (`R1`, `R2`, `global-state`, `exclusive`) and a reason. `checkSerialManifest` (pure) requires the manifest to match the tree exactly, classes to match what the file does (env mutation, `mock.module`, `EXCLUSIVE_FILES`) and reasons to be specific; each failure prints Why/Fix/Docs with `bash scripts/check-test-isolation.sh --as-parallel <file>` as the first step. Tests: `test/scripts/serial-files.test.ts`.
- `test/helpers/brain-template.ts` — disk-backed PGLite brains cloned from one initialized template per process and embedding shape. The template is captured right after `initSchema` with no source, writer or physical-root reservation (asserted); only the data directory is copied; each clone regenerates `brain_id`, the default source incarnation and the shared-skill token secret and serving epoch. Used by `test/helpers/connector-fixture.ts`. Tests: `test/helpers/brain-template.test.ts`.
- `scripts/test-agent-voice.sh` — `bun run test:agent-voice`: the agent-voice recipe's vitest unit suite (`recipes/agent-voice/tests/unit`), with pinned vitest and ws installed into a temporary prefix linked as the recipe's `node_modules`. Needs node, npm and registry access; CI runs it in test.yml's verify job.
diff --git a/scripts/ci-ubicloud.ts b/scripts/ci-ubicloud.ts
index c18c535e8e..653b143334 100755
--- a/scripts/ci-ubicloud.ts
+++ b/scripts/ci-ubicloud.ts
@@ -66,7 +66,7 @@ import {
} from "./ubicloud/schedule.ts";
import { runScript, type RunScriptOpts } from "./ubicloud/run-script.ts";
import { buildTypecheckState, portableBuildInfo, typecheckBuildInfo } from "./ubicloud/typecheck-state.ts";
-import { ARM_SHARD_BUDGET_MS, ARM_SHARDS, ARM_WEIGHTS, armShards, readArmsList } from "./postgres-unit-arms.ts";
+import { ARM_SHARDS, ARM_STEP_TIMEOUT_MS, ARM_WEIGHTS, armShards, readArmsList } from "./postgres-unit-arms.ts";
const ROOT = resolve(import.meta.dir, "..");
const RUNNER = join(ROOT, "scripts/ubicloud/ubi-runner.sh");
@@ -538,10 +538,10 @@ async function main() {
}))
: [];
if (armShardReport.length) {
- console.log(` pg-arms shards (unit-postgres-arms partition, ${ARM_SHARDS} shards, budget ${ARM_SHARD_BUDGET_MS / 1000}s each):`);
+ console.log(` pg-arms shards (unit-postgres-arms partition, ${ARM_SHARDS} shards, step timeout ${ARM_STEP_TIMEOUT_MS / 1000}s each):`);
for (const s of armShardReport) console.log(` ${s.shard}/${ARM_SHARDS}: ${Math.round(s.ms / 1000)}s across ${s.files} files`);
}
- const overBudget = armShardReport.filter((s) => s.ms > ARM_SHARD_BUDGET_MS);
+ const overBudget = armShardReport.filter((s) => s.ms > ARM_STEP_TIMEOUT_MS);
const timings: Record<string, number> = {};
for (const r of all) if (r.rc === 0 && r.file !== "-") timings[weightKey(r.lane as Lane, r.file)] = r.ms;
@@ -574,7 +574,7 @@ async function main() {
exitCode = 1;
}
if (overBudget.length) {
- console.log(`\npg-arms: ${overBudget.map((s) => `shard ${s.shard}/${ARM_SHARDS} measured ${Math.round(s.ms / 1000)}s`).join(", ")}, over the ${ARM_SHARD_BUDGET_MS / 1000}s step timeout of persistence-validation's unit-postgres-arms job, which would cut that shard off mid-list. Fix: raise ARM_SHARDS (and the workflow matrix) or speed up the heaviest files, then re-mine scripts/postgres-arm-weights.json. Docs: docs/TESTING.md#postgres-arm-lanes`);
+ console.log(`\npg-arms: ${overBudget.map((s) => `shard ${s.shard}/${ARM_SHARDS} measured ${Math.round(s.ms / 1000)}s`).join(", ")}, over the ${ARM_STEP_TIMEOUT_MS / 1000}s step timeout of persistence-validation's unit-postgres-arms job, which would cut that shard off mid-list. Fix: raise ARM_SHARDS (and the workflow matrix) or speed up the heaviest files, then re-mine scripts/postgres-arm-weights.json. Docs: docs/TESTING.md#postgres-arm-lanes`);
exitCode = 1;
}
const expected = totalItems;
diff --git a/scripts/postgres-unit-arms.ts b/scripts/postgres-unit-arms.ts
index 058ac76ea3..5a75fe67aa 100644
--- a/scripts/postgres-unit-arms.ts
+++ b/scripts/postgres-unit-arms.ts
@@ -10,11 +10,11 @@
*
* Weights are milliseconds per file (both arms, one Bun process) mined from
* the job's `::group::<file>` timestamps; a file without a weight gets the
- * p75 (scripts/sharding.ts). The job runs ARM_SHARDS shards inside a
- * ARM_SHARD_BUDGET_MS step; re-mine after adding heavy files.
+ * p75 (scripts/sharding.ts). The job runs ARM_SHARDS shards, each inside an
+ * ARM_STEP_TIMEOUT_MS step; re-mine after adding heavy files.
* test/scripts/postgres-unit-arms.test.ts fails when a shard's weighted sum
- * passes 80% of the budget, and ci:ubicloud's pg-arms lane fails when a
- * shard's measured sum passes it (scripts/ubicloud/README.md).
+ * passes ARM_SHARD_BUDGET_MS, and ci:ubicloud's pg-arms lane fails when a
+ * shard's measured sum passes the step timeout (scripts/ubicloud/README.md).
* Docs: docs/TESTING.md#postgres-arm-lanes.
*/
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
@@ -24,9 +24,14 @@ import { loadWeights, partition } from './sharding.ts';
export const ARMS_LIST = 'test/postgres-unit-arms.txt';
export const ARM_WEIGHTS = 'scripts/postgres-arm-weights.json';
/** persistence-validation's unit-postgres-arms matrix size; test/scripts/postgres-unit-arms.test.ts pins the workflow to it. */
-export const ARM_SHARDS = 8;
+export const ARM_SHARDS = 12;
/** The workflow step's `timeout-minutes: 20`: a shard whose files run longer is cut off mid-list. */
-export const ARM_SHARD_BUDGET_MS = 20 * 60 * 1000;
+export const ARM_STEP_TIMEOUT_MS = 20 * 60 * 1000;
+/**
+ * A shard's weighted sum may be at most this: on a runner twice as slow as the mined weights (Bun 1.4.0 runners
+ * measured 1.3-2x) it still ends a minute inside the step timeout.
+ */
+export const ARM_SHARD_BUDGET_MS = (ARM_STEP_TIMEOUT_MS - 60_000) / 2;
const DOCS = 'docs/TESTING.md#postgres-arm-lanes';
const PATH_RE = /^test\/[\w./-]+\.test\.ts$/;
diff --git a/scripts/ubicloud/README.md b/scripts/ubicloud/README.md
index 3e7a05cd0a..ace76d3bf9 100644
--- a/scripts/ubicloud/README.md
+++ b/scripts/ubicloud/README.md
@@ -110,8 +110,11 @@ runs every file in `test/postgres-unit-arms.txt` the way persistence-validation'
`unit-postgres-arms` step does (`bun --no-env-file test --timeout=120000`,
`GBRAIN_TEST_ALLOW_DATABASE_URL=1`, no timeout multiplier) against the slot's
own empty `gbrain_arms_test` database. The summary sums its measured durations over
-that job's `ARM_SHARDS` partition, and a shard over the step's 20-minute timeout
-fails the run, since GitHub would cut that shard off mid-list. Tests run natively as
+that job's `ARM_SHARDS` partition (12 shards), and a shard over the step's 20-minute timeout
+fails the run, since GitHub would cut that shard off mid-list. The committed
+weights must also fit each shard twice over with a minute to spare
+(`ARM_SHARD_BUDGET_MS`, 570 s), because a slow runner ran the files 1.3-2x
+their mined weights. Tests run natively as
a non-root user on Ubuntu 24.04, the same OS as the CI runners, instead of as
root in the `oven/bun` container.
diff --git a/test/scripts/postgres-unit-arms.test.ts b/test/scripts/postgres-unit-arms.test.ts
index cc6b517d8e..183baea5d7 100644
--- a/test/scripts/postgres-unit-arms.test.ts
+++ b/test/scripts/postgres-unit-arms.test.ts
@@ -8,7 +8,7 @@ import { describe, expect, test } from 'bun:test';
import { spawnSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
-import { ARM_SHARD_BUDGET_MS, ARM_SHARDS, ARM_WEIGHTS, mineArmWeights, parseArmsList, readArmsList } from '../../scripts/postgres-unit-arms.ts';
+import { ARM_SHARD_BUDGET_MS, ARM_SHARDS, ARM_STEP_TIMEOUT_MS, ARM_WEIGHTS, mineArmWeights, parseArmsList, readArmsList } from '../../scripts/postgres-unit-arms.ts';
import { computeQuantile, loadWeights, partition } from '../../scripts/sharding.ts';
const REPO = join(import.meta.dir, '..', '..');
@@ -29,22 +29,23 @@ describe('postgres-unit-arms list', () => {
expect(shards.every(s => s.length > 0)).toBe(true);
});
- test('the workflow runs ARM_SHARDS shards inside the ARM_SHARD_BUDGET_MS step timeout', () => {
+ test('the workflow runs ARM_SHARDS shards inside the ARM_STEP_TIMEOUT_MS step timeout', () => {
const workflow = readFileSync(join(REPO, '.github', 'workflows', 'persistence-validation.yml'), 'utf8');
const job = workflow.slice(workflow.indexOf(' unit-postgres-arms:'), workflow.indexOf('\n invariants:'));
const shards = Array.from({ length: ARM_SHARDS }, (_, i) => i + 1);
expect(job).toContain(`shard: [${shards.join(', ')}]`);
expect(job).toContain(`Unit-lane PostgreSQL arms \${{ matrix.shard }}/${ARM_SHARDS}`);
expect(job).toContain(`postgres-unit-arms.ts shard "$SHARD" ${ARM_SHARDS})`);
- expect(job).toMatch(new RegExp(`- name: Require PostgreSQL arms of unit-lane suites\\n\\s+timeout-minutes: ${ARM_SHARD_BUDGET_MS / 60_000}\\n`));
+ expect(job).toMatch(new RegExp(`- name: Require PostgreSQL arms of unit-lane suites\\n\\s+timeout-minutes: ${ARM_STEP_TIMEOUT_MS / 60_000}\\n`));
});
- test('every CI shard\'s measured weight leaves a fifth of the step budget as headroom', () => {
+ test('every CI shard\'s measured weight fits the step twice over, with a minute to spare', () => {
const files = readArmsList(REPO).files;
const weights = loadWeights(join(REPO, ARM_WEIGHTS));
const p75 = computeQuantile(files.filter(f => weights.has(f)).map(f => weights.get(f)!), 0.75);
const sums = partition(files, weights, ARM_SHARDS).map(shard => shard.reduce((ms, f) => ms + (weights.get(f) ?? p75), 0));
- expect(sums.filter(ms => ms > ARM_SHARD_BUDGET_MS * 0.8)).toEqual([]);
+ expect(2 * ARM_SHARD_BUDGET_MS + 60_000).toBe(ARM_STEP_TIMEOUT_MS);
+ expect(sums.filter(ms => ms > ARM_SHARD_BUDGET_MS)).toEqual([]);
});
test('ci:ubicloud\'s pg-arms lane runs each file with the workflow step\'s own command', () => {