Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(persistence): PR-budget Postgres robot skips the publication seams and pooler fault that wait out a claim lease

garrytan3c3beea3c1e1
diff --git a/.github/workflows/persistence-validation.yml b/.github/workflows/persistence-validation.yml
index 85f4777ece..5b8f4d7352 100644
--- a/.github/workflows/persistence-validation.yml
+++ b/.github/workflows/persistence-validation.yml
@@ -212,8 +212,9 @@ jobs:
# 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.
+ # Pull requests run a 150 s budget (Postgres skips the seams and the pooler
+ # disconnect fault that can wait out a dead owner's claim lease, listed in the
+ # manifest); 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
diff --git a/docs/architecture/key-files/tooling-and-tests.md b/docs/architecture/key-files/tooling-and-tests.md
index 38145ddeb6..fcbc3cbcab 100644
--- a/docs/architecture/key-files/tooling-and-tests.md
+++ b/docs/architecture/key-files/tooling-and-tests.md
@@ -62,7 +62,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `scripts/persistence/{harness,schedules,worker,validate,failure-diagnostics}.ts` — executable concurrency gate using real journal/coordinator APIs: 1,000 seeded schedules per engine, eight actual process-kill publication boundaries, and 10,000 writes from four producer processes. Each phase owns a temporary disk PGLite datastore or a fresh test Postgres database. Independent accounting queries verify conservation; every soak receipt is compared to its canonical snapshot and file. JSON manifests separate actual counts and latency measurements from the configured Linux/Bun CI matrix. Failed runs preserve private fixtures and collect bounded, allowlisted request/queue/owner diagnostics without changing deadlines or hiding the original error. Cleanup commands read the existing test URL from the environment. The PGLite loopback endpoint is a fixture transport, not production authentication coverage. Contract and commands: `scripts/persistence/README.md`; smoke entries: `test/persistence-chaos.slow.test.ts`, `test/e2e/persistence-chaos.test.ts`; diagnostic/retention contracts: `test/persistence-failure-diagnostics.test.ts`.
-- `scripts/persistence/{ops,generator,model,crash-robot,robot-driver,shrink,lock-order,history-fixture,would-have-caught}.ts` — the crash robot, a phase of `validate.ts` (`--robot-seconds`, default 300; CI runs it as its own `persistence-validation.yml` job). `ops.ts` is the JSON op-descriptor protocol between driver and workers: each descriptor names an op kind (put/edit/delete/restore page, remember/forget, takes add/supersede, timeline add, sync, connector publish, revoke access), an actor (the local CLI principal or a remote agent whose bearer token the production `verifyAccessToken` resolves), a source, a fixed request id and arguments whose `{ $ref }` values come from earlier observations; workers run every op through its registered operation handler. `generator.ts` builds seeded schedules: the fixed cross-boundary sequences (withdrawal then stale republication, overlapping slugs across two sources, competing writers, caller-bound replay, authority revoked with effects pending, sync and connector publish racing direct writes) plus random sequences with concurrent groups. `model.ts` is the temporal oracle: receipts and revisions at the observation point, legal later transitions, late receipts against page history, withdrawal permanence on recall/get_page/facts, source isolation, caller-bound replay, takes/facts fence projections, attribution, orphans, drain and wedge bounds; `EFFECT_SEAMS` maps every `EffectKind` to its trigger op and seam (typecheck-exhaustive). `crash-robot.ts` runs a schedule in-process or as a worker role (`count`, `run` frozen at a `fault-points.ts` seam and SIGKILLed by the driver, `recover`), plus process faults (stale `index.lock`, a hung git commit holding `index.lock`, Postgres session drops, the owner killed after a `facts-absorb` job's extraction commits and the job re-run). `robot-driver.ts` crashes every seam the fixed sequences reach, then fills the budget with random sequences; Postgres connects through `GBRAIN_PGBOUNCER_URL` when set and, under a budget below 300 s, skips seams that wait out a dead owner's claim lease. `shrink.ts` is dependency-preserving ddmin accepted on 3/3 reproduction; `--replay`/`--shrink` re-run a manifest's failing runs. `lock-order.ts` traces each transaction's row locks (worktrees before sources, sources by id, no exclusive brain lock in a publication). `history-fixture.ts` exports `buildHistoryFixture(engine, { pages, seed, sources, worktrees })` (a managed brain with real persistence history up to 10k pages, used by engine graduation and attribution backfill) and `prepareTopology`. `would-have-caught.ts` reverts each fix in `would-have-caught.json` in a scratch worktree and runs the pre-robot gate and the robot against it. Tests: `test/persistence-crash-robot.test.ts`, `test/persistence-crash-robot.slow.test.ts` (shrunk regressions in `test/fixtures/crash-robot/`), `test/persistence-history-fixture.test.ts`.
+- `scripts/persistence/{ops,generator,model,crash-robot,robot-driver,shrink,lock-order,history-fixture,would-have-caught}.ts` — the crash robot, a phase of `validate.ts` (`--robot-seconds`, default 300; CI runs it as its own `persistence-validation.yml` job). `ops.ts` is the JSON op-descriptor protocol between driver and workers: each descriptor names an op kind (put/edit/delete/restore page, remember/forget, takes add/supersede, timeline add, sync, connector publish, revoke access), an actor (the local CLI principal or a remote agent whose bearer token the production `verifyAccessToken` resolves), a source, a fixed request id and arguments whose `{ $ref }` values come from earlier observations; workers run every op through its registered operation handler. `generator.ts` builds seeded schedules: the fixed cross-boundary sequences (withdrawal then stale republication, overlapping slugs across two sources, competing writers, caller-bound replay, authority revoked with effects pending, sync and connector publish racing direct writes) plus random sequences with concurrent groups. `model.ts` is the temporal oracle: receipts and revisions at the observation point, legal later transitions, late receipts against page history, withdrawal permanence on recall/get_page/facts, source isolation, caller-bound replay, takes/facts fence projections, attribution, orphans, drain and wedge bounds; `EFFECT_SEAMS` maps every `EffectKind` to its trigger op and seam (typecheck-exhaustive). `crash-robot.ts` runs a schedule in-process or as a worker role (`count`, `run` frozen at a `fault-points.ts` seam and SIGKILLed by the driver, `recover`), plus process faults (stale `index.lock`, a hung git commit holding `index.lock`, Postgres session drops, the owner killed after a `facts-absorb` job's extraction commits and the job re-run). `robot-driver.ts` crashes every seam the fixed sequences reach, then fills the budget with random sequences; Postgres connects through `GBRAIN_PGBOUNCER_URL` when set and, under a budget below 300 s, skips the seams and the pooler disconnect fault that can wait out a dead owner's claim lease (`effect:*`, `consumer:prepared`, three publication seams), listed in the manifest as `lease_bound_seams_skipped` and `lease_bound_faults_skipped`. `shrink.ts` is dependency-preserving ddmin accepted on 3/3 reproduction; `--replay`/`--shrink` re-run a manifest's failing runs. `lock-order.ts` traces each transaction's row locks (worktrees before sources, sources by id, no exclusive brain lock in a publication). `history-fixture.ts` exports `buildHistoryFixture(engine, { pages, seed, sources, worktrees })` (a managed brain with real persistence history up to 10k pages, used by engine graduation and attribution backfill) and `prepareTopology`. `would-have-caught.ts` reverts each fix in `would-have-caught.json` in a scratch worktree and runs the pre-robot gate and the robot against it. Tests: `test/persistence-crash-robot.test.ts`, `test/persistence-crash-robot.slow.test.ts` (shrunk regressions in `test/fixtures/crash-robot/`), `test/persistence-history-fixture.test.ts`.
- `scripts/persistence/{matrix,matrix-cases}.ts` — required real Postgres/PgBouncer deployment matrix: 24 combinations of RLS policy enforcement, ordinary pool sizes 1/2/3 and shared/separate direct capacity. Production bulk reservations must leave short claims, renewals and reads usable; size-one publication stays queued. Fresh fixtures also verify successor manifests, stale owners, retained native lock exclusion during root replacement and source deletion/recreation. `test/e2e/persistence-runtime-matrix.test.ts` runs it when configured and refuses missing required pooler fixtures. Supplied URLs pass the test-database guard before its CREATE/DROP control connection uses the maintenance database; fresh case databases isolate it from other E2E shards.
- `scripts/persistence/{performance,read-workload,read-metrics,read-admission,read-diagnostics}.ts` — required median-of-three read-workload validity check with advisory CI latency around the existing heavy query corpus (500 pages, 200 reads, four writers, writesPerWriter 25, four-connection PostgreSQL pool). Both engines use public page mutation handlers; every read/write or drained sampler error invalidates the sample, actual in-flight mutation intervals must cover at least 90% of reads, and CI reports the 50% loaded-versus-idle p99 threshold without blocking on that ratio. CI uses `--informational`, which never suppresses invalid-workload failures; the default CLI and explicit strict heavy runs still enforce the threshold. Isolated children retain runtime/source hashes, queue/admission/commit/RSS/recovery/pool metrics and bounded diagnostic records with total/dropped counts, including failed partial observations. Numeric query/corpus/write indices and monotonic timestamps correlate reads, admissions, terminal receipts and pool samples without retaining SQL, parameters, identifiers, content or raw errors. Fixed failure stages retain only allowlisted error properties; raw stacks are omitted. The root postgres.js begin observer covers lexical readers and writers, preserves the original promise/receiver/arguments, and excludes nested savepoints. Dispatch-to-callback includes BEGIN and client scheduling, not pure checkout wait; PGLite has no transaction-entry timing. Identical 20ms timers record event-loop lateness in both phases. Observers run during seed/warmup before measurement; context setup and read retention sit outside query timing where possible, but transaction/timer callbacks add unquantified overhead. No SQL or server sampling is added, and sparse pool samples cannot establish lock causes. The original `tests/heavy/read_latency_under_sync.sh` invokes this runner. The stable admission proxy requires one resolved top-level queued journal transaction per committed UUID. `test/persistence-performance.test.ts` guards validity, strict threshold semantics and advisory CLI exit behavior; `test/persistence-admission-observer.test.ts` proves rollback/publication boundaries; `test/persistence-read-diagnostics{,.serial}.test.ts` covers bounds, transparency, nested transactions, safe failure retention, tiny manifests and late sampler rejection.
diff --git a/docs/fix-wave-notes/capy-foundations-2.md b/docs/fix-wave-notes/capy-foundations-2.md
index 83a295015a..b442defab1 100644
--- a/docs/fix-wave-notes/capy-foundations-2.md
+++ b/docs/fix-wave-notes/capy-foundations-2.md
@@ -58,6 +58,16 @@ Every P0 item shipped. Nothing was cut.
PGLite `releaseAbandonedClaims` with Lane F's refresh-fence predicate in the
idle probe; released claims are still fenced when they are claimed again.
+- PR-budget coverage cut: the 150 s pull-request robot run on Postgres skips
+ the seams and the fault that can wait out a dead owner's 2-minute claim
+ lease (`effect:*`, `consumer:prepared`, `publication:prepared`,
+ `publication:before_publication`, `publication:after_publication`, and the
+ pooler disconnect fault). Before the cut that run took 669 s locally (three
+ publication seams at about 128 s each, the pooler disconnect at 125 s). The
+ manifest lists the cut as `lease_bound_seams_skipped` and
+ `lease_bound_faults_skipped`; 600 s runs on pushes, schedules and manual
+ dispatch still crash every seam and run every fault.
+
## Gates
- `bun run verify` (69 checks) and `bun run typecheck`.
diff --git a/scripts/persistence/README.md b/scripts/persistence/README.md
index 08b00d3ca6..9af921418a 100644
--- a/scripts/persistence/README.md
+++ b/scripts/persistence/README.md
@@ -122,11 +122,14 @@ transaction's row locks: worktrees before sources, sources in id order, and
no exclusive brain-row lock inside a publication.
Postgres runs connect through `GBRAIN_PGBOUNCER_URL` when it is set, with
-prepared statements off. A Postgres run with a budget under 300 s skips the
-seams whose recovery waits out a dead owner's claim lease; full runs crash
-every seam. The manifest's `robot` key lists every run (schedule, seed,
-seam and occurrence or process fault), `sequences_x_crash_points`,
-`lease_bound_seams_skipped` and violations with the observed trace;
+prepared statements off. A Postgres run with a budget under 300 s (the
+pull-request run) skips what can wait out a dead owner's claim lease: the
+`effect:*` seams, `consumer:prepared`, the publication seams `prepared`,
+`before_publication` and `after_publication`, and the pooler disconnect
+fault. Full runs crash every seam and run every fault. The manifest's `robot`
+key lists every run (schedule, seed, seam and occurrence or process fault),
+`sequences_x_crash_points`, `lease_bound_seams_skipped`,
+`lease_bound_faults_skipped` and violations with the observed trace;
`robot_full_gate` is true for a full-budget run with no violations.
A failing run prints two commands. `--replay=<manifest>` re-runs exactly the
diff --git a/scripts/persistence/robot-driver.ts b/scripts/persistence/robot-driver.ts
index 23e24e9db8..fbf2463332 100644
--- a/scripts/persistence/robot-driver.ts
+++ b/scripts/persistence/robot-driver.ts
@@ -25,12 +25,20 @@ export const PROCESS_FAULTS: ProcessFault[] = ['stale_index_lock', 'hung_git', '
/** 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.
+ * Seams and process faults whose recovery on Postgres can wait out a dead
+ * owner's claim lease (requests 30 s, effects 2 minutes): a publication seam
+ * does when the dead owner also held an effect claim, and the pooler
+ * disconnect fault holds its run for about two minutes. A Postgres run with a
+ * budget under FULL_ROBOT_SECONDS skips them and lists them in the manifest
+ * (`lease_bound_seams_skipped`, `lease_bound_faults_skipped`); full runs
+ * (master, nightly, manual) crash every seam and run every fault.
*/
export const FULL_ROBOT_SECONDS = 300;
-export function leaseBoundSeam(point: FaultPoint): boolean { return point.startsWith('effect:') || point === 'consumer:prepared'; }
+const LEASE_BOUND_PUBLICATION_SEAMS: readonly FaultPoint[] = ['publication:prepared', 'publication:before_publication', 'publication:after_publication'];
+export function leaseBoundSeam(point: FaultPoint): boolean {
+ return point.startsWith('effect:') || point === 'consumer:prepared' || LEASE_BOUND_PUBLICATION_SEAMS.includes(point);
+}
+export const LEASE_BOUND_FAULTS: readonly ProcessFault[] = ['pooler_disconnect'];
export interface RobotRun {
schedule: string; seed: number; length: number; fault?: { point: FaultPoint; nth: number }; process?: ProcessFault;
@@ -146,8 +154,10 @@ export async function runRobotPhase(o: RobotOptions) {
if (!mandatory && over()) break;
record(await execute(item.schedule, 'run', { fault: { point: item.point, nth: 1 + Math.floor(rand() * item.count) } }));
}
+ const skippedFaults = new Set<ProcessFault>();
for (const fault of PROCESS_FAULTS) {
if (fault === 'pooler_disconnect' && !o.admin) continue;
+ if (skipLease && LEASE_BOUND_FAULTS.includes(fault)) { skippedFaults.add(fault); continue; }
record(await execute(fixed[1], 'run', { process: fault }));
}
// serve killed right after the facts-absorb job's extraction commits; the job then runs again.
@@ -162,7 +172,7 @@ export async function runRobotPhase(o: RobotOptions) {
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), lease_bound_seams_skipped: [...skipped].sort() };
+ return { ...summarize(runs, started, o), lease_bound_seams_skipped: [...skipped].sort(), lease_bound_faults_skipped: [...skippedFaults].sort() };
}
function summarize(runs: RobotRun[], started: number, o: RobotOptions) {
diff --git a/scripts/persistence/validate.ts b/scripts/persistence/validate.ts
index 2dd3d18584..de376e06b2 100644
--- a/scripts/persistence/validate.ts
+++ b/scripts/persistence/validate.ts
@@ -196,7 +196,7 @@ export async function runValidation(options: ValidationOptions) {
const executedBoundaries = manifest.crash_cases.map((entry: { boundary: string }) => entry.boundary);
if (options.crashes !== false) assert.deepEqual(executedBoundaries, [...CRASH_BOUNDARIES]);
if (manifest.robot) manifest.robot_full_gate = (options.robotSeconds ?? 0) >= FULL_ROBOT_SECONDS && manifest.robot.violations.length === 0
- && (manifest.robot.lease_bound_seams_skipped ?? []).length === 0;
+ && (manifest.robot.lease_bound_seams_skipped ?? []).length === 0 && (manifest.robot.lease_bound_faults_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)