Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(persistence): crash robot job beside the soak, Postgres through PgBouncer

garrytan7b9feab78996
diff --git a/.github/workflows/persistence-validation.yml b/.github/workflows/persistence-validation.yml
index 4623f21cc2..85f4777ece 100644
--- a/.github/workflows/persistence-validation.yml
+++ b/.github/workflows/persistence-validation.yml
@@ -199,7 +199,7 @@ jobs:
SOAK_OPERATIONS: ${{ github.event_name == 'pull_request' && '2500' || '10000' }}
run: >-
bun --no-env-file scripts/persistence/validate.ts --engine=${{ matrix.engine }}
- --operations="$SOAK_OPERATIONS"
+ --operations="$SOAK_OPERATIONS" --robot-seconds=0
--manifest=.context/persistence-manifest.json
- name: Upload executed-case and latency manifest
if: always()
@@ -209,6 +209,84 @@ jobs:
path: .context/persistence-manifest.json
if-no-files-found: error
+ # The crash robot runs beside the soak: generated sequences of real operations,
+ # SIGKILL at every crash seam they reach, and process faults, checked by the
+ # reference model. Postgres connects through a transaction-mode PgBouncer.
+ # Pull requests run a 150 s budget (Postgres skips the seams that wait out a
+ # dead owner's claim lease); pushes, schedules and manual runs crash every seam.
+ crash-robot:
+ name: Crash robot / ${{ matrix.engine }} / Bun ${{ matrix.bun }}
+ runs-on: ubicloud-standard-4-ubuntu-2404
+ timeout-minutes: 60
+ strategy:
+ fail-fast: false
+ matrix:
+ engine: [pglite, postgres]
+ bun: ['1.4.0', '1.4.2']
+ # Pull requests run the primary Bun version; pushes, schedules and
+ # manual runs keep every supported version.
+ exclude: ${{ fromJSON(github.event_name == 'pull_request' && '[{"bun":"1.4.0"}]' || '[]') }}
+ services:
+ postgres:
+ image: pgvector/pgvector:pg16
+ env:
+ POSTGRES_USER: gbrain_test
+ POSTGRES_PASSWORD: gbrain_test
+ POSTGRES_DB: gbrain_test
+ ports: ['5432:5432']
+ options: >-
+ --health-cmd "pg_isready -U gbrain_test -d gbrain_test"
+ --health-interval 5s --health-timeout 5s --health-retries 20
+ pgbouncer:
+ image: edoburu/pgbouncer:latest
+ env:
+ DB_HOST: postgres
+ DB_PORT: '5432'
+ DB_USER: gbrain_test
+ DB_PASSWORD: gbrain_test
+ POOL_MODE: transaction
+ AUTH_TYPE: plain
+ MAX_CLIENT_CONN: '200'
+ DEFAULT_POOL_SIZE: '10'
+ IGNORE_STARTUP_PARAMETERS: extra_float_digits,statement_timeout,idle_in_transaction_session_timeout,search_path
+ ports: ['55433:5432']
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6
+ with:
+ bun-version: ${{ matrix.bun }}
+ - run: bun install --frozen-lockfile --ignore-scripts
+ # The service password reaches every client through PGPASSWORD, so the URLs carry none.
+ - name: Crash every reachable seam of the generated sequences
+ env:
+ PGPASSWORD: gbrain_test
+ DATABASE_URL: postgres://[email protected]:5432/gbrain_test
+ GBRAIN_PGBOUNCER_URL: postgres://[email protected]:55433/gbrain_test
+ ROBOT_SECONDS: ${{ github.event_name == 'pull_request' && '150' || '600' }}
+ run: >-
+ bun --no-env-file scripts/persistence/validate.ts --engine=${{ matrix.engine }}
+ --schedules=0 --operations=0 --no-crashes --robot-seconds="$ROBOT_SECONDS"
+ --manifest=.context/persistence-robot.json
+ - name: Replay every shrunk crash-robot failure and the history fixture
+ timeout-minutes: 10
+ env:
+ PGPASSWORD: gbrain_test
+ DATABASE_URL: postgres://[email protected]:5432/gbrain_test
+ GBRAIN_TEST_ALLOW_DATABASE_URL: '1'
+ run: |
+ if [ '${{ matrix.engine }}' = 'postgres' ]; then
+ GBRAIN_TEST_BACKEND=postgres bun --no-env-file test --timeout=300000 test/persistence-history-fixture.test.ts
+ else
+ env -u DATABASE_URL -u GBRAIN_DATABASE_URL bun --no-env-file test --timeout=300000 test/persistence-crash-robot.slow.test.ts test/persistence-history-fixture.test.ts
+ fi
+ - name: Upload the crash-robot manifest
+ if: always()
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
+ with:
+ name: persistence-robot-${{ matrix.engine }}-bun-${{ matrix.bun }}
+ path: .context/persistence-robot.json
+ if-no-files-found: error
+
# The reconciliation crash suites run beside the soak instead of after it, so
# neither holds the other's runner: each is about four minutes on PGLite.
reconciliation:
diff --git a/scripts/persistence/robot-driver.ts b/scripts/persistence/robot-driver.ts
index 8bf4b3cf48..5f0b7eafc7 100644
--- a/scripts/persistence/robot-driver.ts
+++ b/scripts/persistence/robot-driver.ts
@@ -24,6 +24,14 @@ export const ROBOT_TOPOLOGY: GeneratorTopology = { sources: ['robot-0', 'robot-1
export const PROCESS_FAULTS: ProcessFault[] = ['stale_index_lock', 'hung_git', 'pooler_disconnect'];
/** One executed run, enough to replay it exactly: `--replay` re-injects this entry. */
+/**
+ * Seams whose recovery on Postgres waits out a dead owner's claim lease
+ * (requests 30 s, effects 2 minutes). A Postgres run with a budget under
+ * FULL_ROBOT_SECONDS skips them; full runs (master, nightly) crash every seam.
+ */
+export const FULL_ROBOT_SECONDS = 300;
+export function leaseBoundSeam(point: FaultPoint): boolean { return point.startsWith('effect:') || point === 'consumer:prepared'; }
+
export interface RobotRun {
schedule: string; seed: number; length: number; fault?: { point: FaultPoint; nth: number }; process?: ProcessFault;
ops?: string[]; crashed: boolean; violations: RobotOutcome['violations']; duration_ms: number; trace?: string[];
@@ -118,9 +126,14 @@ export async function runRobotPhase(o: RobotOptions) {
// seams first covered across sequences (a seam no run has crashed yet goes first).
const fixed = crossBoundarySequences(ROBOT_TOPOLOGY, o.seed);
const plan: { schedule: Schedule; point: FaultPoint; count: number }[] = [];
+ const skipLease = o.engine === 'postgres' && o.seconds < FULL_ROBOT_SECONDS;
+ const skipped = new Set<string>();
for (const schedule of fixed) {
const counted = await execute(schedule, 'count'); record(counted);
- for (const [point, count] of Object.entries(counted.counts ?? {}) as [FaultPoint, number][]) plan.push({ schedule, point, count });
+ for (const [point, count] of Object.entries(counted.counts ?? {}) as [FaultPoint, number][]) {
+ if (skipLease && leaseBoundSeam(point)) { skipped.add(point); continue; }
+ plan.push({ schedule, point, count });
+ }
}
// The seed rotates which sequence covers each seam first.
const turn = (x: (typeof plan)[number]) => (fixed.indexOf(x.schedule) + o.seed) % fixed.length;
@@ -140,12 +153,12 @@ export async function runRobotPhase(o: RobotOptions) {
for (let i = 0; !over(); i++) {
const schedule = randomSchedule(ROBOT_TOPOLOGY, (o.seed + 1 + i) >>> 0, 24);
const counted = await execute(schedule, 'count'); record(counted);
- const points = Object.entries(counted.counts ?? {}) as [FaultPoint, number][];
+ const points = (Object.entries(counted.counts ?? {}) as [FaultPoint, number][]).filter(([point]) => !(skipLease && leaseBoundSeam(point)));
if (!points.length || over()) continue;
const [point, count] = points[Math.floor(rand() * points.length)];
record(await execute(schedule, 'run', { fault: { point, nth: 1 + Math.floor(rand() * count) } }));
}
- return summarize(runs, started, o);
+ return { ...summarize(runs, started, o), lease_bound_seams_skipped: [...skipped].sort() };
}
function summarize(runs: RobotRun[], started: number, o: RobotOptions) {
diff --git a/scripts/persistence/validate.ts b/scripts/persistence/validate.ts
index 576a7b1cc6..8b1c3f3294 100644
--- a/scripts/persistence/validate.ts
+++ b/scripts/persistence/validate.ts
@@ -8,7 +8,7 @@ import { assertSafeE2eDatabaseUrl } from '../../test/helpers/db-guard.ts';
import { distribution, type HarnessConfig } from './harness.ts';
import { keylessBrainEnv } from '../../test/helpers/provider-env.ts';
import { boundedDiagnostic, diagnosticError, retentionMetadata } from './failure-diagnostics.ts';
-import { replayEntries, runDigest, runRobotPhase, type RobotRun } from './robot-driver.ts';
+import { FULL_ROBOT_SECONDS, replayEntries, runDigest, runRobotPhase, type RobotRun } from './robot-driver.ts';
import { shrinkRun } from './shrink.ts';
export interface ValidationOptions {
@@ -195,7 +195,9 @@ export async function runValidation(options: ValidationOptions) {
manifest.status = 'passed';
const executedBoundaries = manifest.crash_cases.map((entry: { boundary: string }) => entry.boundary);
if (options.crashes !== false) assert.deepEqual(executedBoundaries, [...CRASH_BOUNDARIES]);
- manifest.full_gate = counts.schedules >= 1000 && counts.operations >= 10_000 && manifest.robot?.violations.length === 0
+ if (manifest.robot) manifest.robot_full_gate = (options.robotSeconds ?? 300) >= FULL_ROBOT_SECONDS && manifest.robot.violations.length === 0
+ && (manifest.robot.lease_bound_seams_skipped ?? []).length === 0;
+ manifest.full_gate = counts.schedules >= 1000 && counts.operations >= 10_000
&& executedBoundaries.length === CRASH_BOUNDARIES.length && CRASH_BOUNDARIES.every((boundary, index) => executedBoundaries[index] === boundary)
&& manifest.crash_cases.every((entry: { staging_cleanup_verified?: boolean }) => entry.staging_cleanup_verified === true)
&& manifest.crash_cases.find((entry: { boundary: string }) => entry.boundary === 'staging_flushed')?.flushed_before_rename_verified === true
diff --git a/scripts/persistence/would-have-caught.ts b/scripts/persistence/would-have-caught.ts
index 705da59122..bf396b3750 100644
--- a/scripts/persistence/would-have-caught.ts
+++ b/scripts/persistence/would-have-caught.ts
@@ -79,8 +79,14 @@ async function measure(fix: Fix | null): Promise<FixResult> {
}
}
-const queue: (Fix | null)[] = [null, ...fixes];
-const results: FixResult[] = [];
+// The control runs alone first: a gate that fails without any revert measures nothing.
+const control = await measure(null);
+if (control.current?.caught || control.robot?.caught) {
+ process.stderr.write(`[would-have-caught] control failed on HEAD; fix the gate or its environment first: ${control.current?.first_failure ?? control.robot?.first_failure}\n`);
+ process.exit(2);
+}
+const queue: Fix[] = [...fixes];
+const results: FixResult[] = [control];
await Promise.all(Array.from({ length: Math.max(1, jobs) }, async () => {
for (;;) { const next = queue.shift(); if (next === undefined) return; results.push(await measure(next)); }
}));
diff --git a/test/scripts/ci-pr-scope.test.ts b/test/scripts/ci-pr-scope.test.ts
index 517736df07..d7675e373c 100644
--- a/test/scripts/ci-pr-scope.test.ts
+++ b/test/scripts/ci-pr-scope.test.ts
@@ -158,7 +158,7 @@ describe('pull-request CI scope', () => {
expect(/GBRAIN_E2E_BUN_IMAGE:-oven\/bun:([^}]+)\}/.exec(read('tests/docker/bootstrap-e2e.sh'))?.[1]).toBe(primary);
const matrices = [load('test.yml').jobs['security-regressions'], ...Object.values(load('persistence-validation.yml').jobs)]
.map(job => job.strategy?.matrix.bun).filter(Boolean);
- expect(matrices).toHaveLength(5);
+ expect(matrices).toHaveLength(6);
for (const bun of matrices) expect(bun).toEqual([MINIMUM_BUN_VERSION, primary]);
for (const job of ['native', 'musl', 'windows-backup-console', 'windows-backup-dotnet']) {
expect(native[job].strategy!.matrix.bun).toEqual([MINIMUM_BUN_VERSION, primary]);
diff --git a/test/scripts/data-safety-native-workflow.test.ts b/test/scripts/data-safety-native-workflow.test.ts
index 0ec5e7e335..e598f7a448 100644
--- a/test/scripts/data-safety-native-workflow.test.ts
+++ b/test/scripts/data-safety-native-workflow.test.ts
@@ -226,8 +226,25 @@ describe('data-safety native CI coverage', () => {
expect(result.exitCode).toBe(0);
expect(result.stdout.toString().trim().split('\n')).toEqual([
'--no-env-file', 'scripts/persistence/validate.ts', '--engine=pglite',
- `--operations=${operations}`, '--manifest=.context/persistence-manifest.json',
+ `--operations=${operations}`, '--robot-seconds=0', '--manifest=.context/persistence-manifest.json',
]);
}
});
+
+ test('the crash robot runs beside the soak: 150 s on pull requests, 600 s elsewhere, Postgres through PgBouncer', () => {
+ const persistence = safeLoad(readFileSync(join(import.meta.dir, '../../.github/workflows/persistence-validation.yml'), 'utf8')) as {
+ jobs: { 'crash-robot': { steps: Step[]; services: Record<string, { env?: Record<string, string> }> } };
+ };
+ const job = persistence.jobs['crash-robot'];
+ expect(job.services.pgbouncer?.env?.POOL_MODE).toBe('transaction');
+ const step = job.steps.find(entry => entry.run?.includes('scripts/persistence/validate.ts'));
+ expect(step?.env?.ROBOT_SECONDS).toBe("${{ github.event_name == 'pull_request' && '150' || '600' }}");
+ expect(step?.env?.GBRAIN_PGBOUNCER_URL).toContain(':55433/');
+ const result = Bun.spawnSync(['bash', '-e', '-o', 'pipefail', '-c', `
+ bun() { printf '%s\\n' "$@"; }
+ ${step!.run!.replaceAll('${{ matrix.engine }}', 'postgres')}
+ `], { env: { PATH: process.env.PATH ?? '', ROBOT_SECONDS: '150' } });
+ expect(result.stdout.toString().trim().split('\n')).toEqual(['--no-env-file', 'scripts/persistence/validate.ts', '--engine=postgres',
+ '--schedules=0', '--operations=0', '--no-crashes', '--robot-seconds=150', '--manifest=.context/persistence-robot.json']);
+ });
});