Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Fix four flaky tests at their cause, split a slow E2E file and run docs-repo-paths on every pull request (GST-2548)
garrytan3c92ba500faa
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 927b2836bc..d2074fc819 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,19 @@ 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).+## [Unreleased]++### Flaky and slow tests fixed at their cause++**Four tests that failed at random in CI now pass reliably, one E2E file is back under its time limit, and one of the fixes is a real bug: a cycle could re-read pages it had already handled.** Each fix was proven with a forced probe that reproduces the CI failure before the fix and passes after it. No assertion, timeout or retry limit was loosened.++- `src/core/cycle/source-window.ts`: the cycle's page-listing cursor steps back to before the oldest transaction still open on another connection, so a page written by that transaction can't be missed. That count included Postgres autovacuum workers, which never write pages. An autovacuum pass open while the cycle listed pages made the next cycle read the pages written since that pass began a second time. Autovacuum workers no longer move the cursor (`test/sync-disabled-cycle-window.test.ts`).+- `test/facts-entity-moved-7602.test.ts`: the test created and killed the page write's facts-absorb job before the write's own background effect had queued it. When the effect ran later, it found a dead job under its key and queued a fresh one, so the preview reported a waiting job. The test now waits for the effect to finish before it touches the job.+- `test/persistence-index-lock-reclaim-6932.test.ts`: cleanup killed a helper shell whose `rm -rf` kept running after the shell died (dash forks a script's last command instead of replacing itself with it), and then ran `chmod -R` over the tree that `rm` was still deleting. Cleanup now waits for each helper to exit.+- `test/e2e/worktree-refresh-postgres.test.ts` ran six refresh suites in one file and took 139 to 156 s on CI against the 180 s per-file limit. Its crash-recovery, orphan and diverged-publish suites moved to `test/e2e/worktree-refresh-recovery-postgres.test.ts`; all 95 cases still run, and each file takes about 100 s on a 4-vCPU machine.+- `scripts/postgres-arm-weights.json`: the two PostgreSQL arm weights that were estimates now hold measured medians.+- `test/docs-repo-paths.test.ts` (the scripts/ and test/ paths named in docs must exist) runs in `bun run verify` as `check:docs-repo-paths`. Before, it ran only in the full suite and in `scripts/ci-doc-checks.sh`, so a pull request's own checks never ran it, and a doc edit could name a missing path and pass.+## [0.60.699.0] - 2026-11-12### The Ubicloud gate VMs run a current gitdiff --git a/package.json b/package.jsonindex 07a0d9fa11..a49316f391 100644--- a/package.json+++ b/package.json@@ -83,6 +83,7 @@"check:gateway-routed": "bash scripts/check-gateway-routed-no-direct-anthropic.sh","check:worker-pool-atomicity": "bash scripts/check-worker-pool-atomicity.sh","check:doc-history": "bash scripts/check-key-files-current-state.sh",+ "check:docs-repo-paths": "bun test --timeout 60000 test/docs-repo-paths.test.ts","check:resolver": "bun src/cli.ts check-resolvable --strict --skills-dir skills/","check:skill-brain-first": "bash scripts/check-skill-brain-first.sh","check:skill-publication": "bun scripts/check-skill-publication.ts",diff --git a/scripts/ci-doc-checks.sh b/scripts/ci-doc-checks.shindex 63b378c449..949acf4d5c 100755--- a/scripts/ci-doc-checks.sh+++ b/scripts/ci-doc-checks.sh@@ -28,7 +28,7 @@ check() {check "llms.txt + llms-full.txt are fresh" "bun run build:llms" bun test --timeout 60000 test/build-llms.test.tscheck "KEY_FILES and TESTING.md byte caps / current-state voice" "follow the check's message, then rerun bun run check:doc-history" bun run check:doc-history-check "documented scripts/ and test/ paths exist" "fix or delete the reference the test names" bun test --timeout 60000 test/docs-repo-paths.test.ts+check "documented scripts/ and test/ paths exist" "fix or delete the reference the test names" bun run check:docs-repo-pathscheck "skill references resolve" "follow the check's message, then rerun bun run check:skill-refs" bun run check:skill-refscheck "privacy guard" "replace real names with placeholders (alice-example, acme-example), then rerun bun run check:privacy" bun run check:privacycheck "fixture privacy guard" "replace real names with placeholders, then rerun bun run check:fixture-privacy" bun run check:fixture-privacydiff --git a/scripts/e2e-weights.json b/scripts/e2e-weights.jsonindex 1563155743..30ff504998 100644--- a/scripts/e2e-weights.json+++ b/scripts/e2e-weights.json@@ -864,7 +864,8 @@"test/e2e/worker-readiness-cli.test.ts": 3350,"test/e2e/worker-shutdown-error-matrix-postgres.test.ts": 3050,"test/e2e/workspace-generic-compat.test.ts": 222,- "test/e2e/worktree-refresh-postgres.test.ts": 91160,+ "test/e2e/worktree-refresh-postgres.test.ts": 97650,+ "test/e2e/worktree-refresh-recovery-postgres.test.ts": 103360,"test/e2e/worktree-refresh-settle-matrix-postgres.test.ts": 20820,"test/e2e/worktree-refresh-unmoved-matrix-postgres.test.ts": 22180,"test/e2e/write-attribution-postgres.test.ts": 41960,diff --git a/scripts/postgres-arm-weights.json b/scripts/postgres-arm-weights.jsonindex a6abbfd3f8..e32a45d51a 100644--- a/scripts/postgres-arm-weights.json+++ b/scripts/postgres-arm-weights.json@@ -321,7 +321,7 @@"test/migration-persistence-request-id-index.test.ts": 10916,"test/migration-persistence-request-slug-index.test.ts": 13917,"test/notifier-passed-freshness-marker-7941.test.ts": 31038,- "test/notifier-retry-unwatched-gst2515.test.ts": 7000,+ "test/notifier-retry-unwatched-gst2515.test.ts": 6875,"test/on-commit-embedding.serial.test.ts": 13575,"test/oneshot-consumer-direct-route.test.ts": 6699,"test/oneshot-housekeeping-cli.test.ts": 15812,@@ -648,7 +648,7 @@"test/sync-status-failure-detail-6513.test.ts": 7065,"test/sync-status-truthful-7243.test.ts": 14660,"test/sync-storage-invalid-8007.test.ts": 45745,- "test/sync-strict-skip-gst2520.test.ts": 19500,+ "test/sync-strict-skip-gst2520.test.ts": 18114,"test/sync-strict-unmanaged-gst2492.test.ts": 16305,"test/sync-tree-reuse-gbra133.test.ts": 16696,"test/sync-unblock-repair-error-gbra130.test.ts": 9641,diff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.shindex 2adab261d4..71241da449 100755--- a/scripts/run-verify-parallel.sh+++ b/scripts/run-verify-parallel.sh@@ -145,6 +145,9 @@ CHECKS=("check:gateway-routed""check:worker-pool-atomicity""check:doc-history"+ # GST-2548: documented scripts/ and test/ paths exist. The unit and census+ # lanes skip a doc-only pull request; verify does not.+ "check:docs-repo-paths""check:fixture-privacy""check:source-scope-onboard""check:getpage-scope"diff --git a/src/core/cycle/source-window.ts b/src/core/cycle/source-window.tsindex 615087d9d7..a47be06d7e 100644--- a/src/core/cycle/source-window.ts+++ b/src/core/cycle/source-window.ts@@ -34,10 +34,13 @@ export interface SourceCycleWindow {* The listing instant, moved back to just before the oldest transaction still* open on another connection the cycle's role can see (at most 10 minutes* back): `pages.updated_at` is its writer's transaction start, so a page that- * commits after the listing still lands after the cursor.+ * commits after the listing still lands after the cursor. An autovacuum+ * worker never writes a page, so its transaction does not move the instant;+ * one open across the listing made the next cycle walk the pages written+ * since it started again.*/const LISTING_INSTANT_SQL = `SELECT to_char(GREATEST(LEAST(clock_timestamp(),- (SELECT min(xact_start) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid()) - interval '1 millisecond'),+ (SELECT min(xact_start) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid() AND backend_type <> 'autovacuum worker') - interval '1 millisecond'),clock_timestamp() - interval '10 minutes') AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"') AS at`;/**diff --git a/test/e2e/worktree-refresh-postgres.test.ts b/test/e2e/worktree-refresh-postgres.test.tsindex c37ab8b18b..39b5edd0ad 100644--- a/test/e2e/worktree-refresh-postgres.test.ts+++ b/test/e2e/worktree-refresh-postgres.test.ts@@ -1,12 +1,9 @@import { registerPostgresTests } from '../helpers/test-backends.ts';// F0 `gbrain sources refresh` on Postgres: the same state machine, admission-// fence, claim predicates and crash recovery as the PGLite unit files.+// fence and claim predicates as the PGLite unit files. Crash recovery, orphans+// and the diverged publish run in worktree-refresh-recovery-postgres.test.ts.await registerPostgresTests(() => import('../persistence-worktree-refresh.test.ts'),- () => import('../persistence-worktree-refresh-restart.test.ts'),- () => import('../worktree-refresh-orphan-7679.test.ts'),- () => import('../refresh-publish-diverged-7686.test.ts'),() => import('../refresh-source-changed-retry-8617.test.ts'),- () => import('../refresh-recovery-followups-gst1465.test.ts'),);diff --git a/test/e2e/worktree-refresh-recovery-postgres.test.ts b/test/e2e/worktree-refresh-recovery-postgres.test.tsnew file mode 100644index 0000000000..fff2c0c51f--- /dev/null+++ b/test/e2e/worktree-refresh-recovery-postgres.test.ts@@ -0,0 +1,10 @@+import { registerPostgresTests } from '../helpers/test-backends.ts';++// F0 `gbrain sources refresh` on Postgres: crash recovery, orphaned refreshes and+// the diverged publish, split from worktree-refresh-postgres.test.ts (GST-2548).+await registerPostgresTests(+ () => import('../persistence-worktree-refresh-restart.test.ts'),+ () => import('../worktree-refresh-orphan-7679.test.ts'),+ () => import('../refresh-publish-diverged-7686.test.ts'),+ () => import('../refresh-recovery-followups-gst1465.test.ts'),+);diff --git a/test/facts-entity-moved-7602.test.ts b/test/facts-entity-moved-7602.test.tsindex 07ad3cbb7d..10783bfa3a 100644--- a/test/facts-entity-moved-7602.test.ts+++ b/test/facts-entity-moved-7602.test.ts@@ -29,7 +29,9 @@ import { jobRefusal } from '../src/core/minions/refusal.ts';import { MinionQueue } from '../src/core/minions/queue.ts';import type { MinionJobContext } from '../src/core/minions/types.ts';import { prepareManagedFactsSession, publishManagedFacts, resumeManagedFacts } from '../src/core/persistence/facts-maintenance.ts';+import { runPersistenceEffects } from '../src/core/persistence/effects.ts';import { installFaultHook } from '../src/core/persistence/fault-points.ts';+import { localHostId } from '../src/core/persistence/identity.ts';import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';import { maintenancePreflight, submitDatabaseMaintenanceIntent } from '../src/core/persistence/prepared-maintenance.ts';import { declarePersistenceProtocol } from '../src/core/persistence/protocol.ts';@@ -40,6 +42,7 @@ import { repairRunner } from '../src/core/repair/registry.ts';import type { ManagedBrain } from './helpers/managed-brain.ts';import { managedBrain } from './helpers/managed-brain.ts';import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';+import { testWaitMs } from './helpers/wait-for.ts';const TARGET = 'people/alice-example';const CLAIM_B = 'Alice-example owns the synthetic onboarding checklist.';@@ -107,11 +110,20 @@ const claimB = (engine: ManagedBrain['engine']) => engine.executeRaw<{ fact: str'SELECT fact, source_markdown_slug FROM facts WHERE fact=$1', [CLAIM_B]);/**- * The page write's facts-absorb job, by its idempotency key. The facts-backstop effect queues it asynchronously, so a test- * that reads or sets its status adds it first (an add with the same key returns the job the effect queued, if any).+ * The page write's facts-absorb job, by its idempotency key. The facts-backstop effect queues it asynchronously, and its add+ * releases the key of a job that is already dead and queues a fresh one (queue.ts coalesceOnIdempotencyKey), so the effect+ * is settled first; the add then returns the job the effect queued, or queues it when the effect skipped.*/async function factsAbsorbJob(engine: ManagedBrain['engine'], loser: Awaited<ReturnType<typeof extraction>>, status?: string) {const key = `facts-absorb:write:${loser.write}`;+ const deadline = performance.now() + testWaitMs(30_000);+ for (;;) {+ await runPersistenceEffects(engine, { engine: engine.kind }, { hostId: localHostId(), limit: 10 });+ const [effect] = await engine.executeRaw<{ state: string }>("SELECT state FROM persistence_effects WHERE request_id=$1::uuid AND kind='facts-backstop'", [loser.write]);+ if (!effect || effect.state === 'committed' || effect.state === 'failed') break;+ if (performance.now() > deadline) throw new Error(`the facts-backstop effect of ${loser.write} is still ${effect.state} after the wait`);+ await Bun.sleep(50);+ }const job = await new MinionQueue(engine).add('facts-absorb', { slug: loser.slug, sourceId: 'default', source: 'mcp:put_page', persistence_request_id: loser.write,page_id: loser.snapshot.page.id, revision: loser.snapshot.revision }, { queue: 'default', idempotency_key: key });if (status) expect(await engine.executeRaw('UPDATE minion_jobs SET status=$2 WHERE id=$1 RETURNING id', [job.id, status])).toHaveLength(1);diff --git a/test/persistence-index-lock-reclaim-6932.test.ts b/test/persistence-index-lock-reclaim-6932.test.tsindex eb15e8a096..83dcb5700a 100644--- a/test/persistence-index-lock-reclaim-6932.test.ts+++ b/test/persistence-index-lock-reclaim-6932.test.ts@@ -367,7 +367,9 @@ test('probe: the writer recovers on its own: a Git effect parked by a held lock*/const fixtureProcRunnable = !blind && process.getuid?.() !== 0;const procFixtures: string[] = [];-afterEach(() => {+const mutators: ChildProcess[] = [];+afterEach(async () => {+ await Promise.all(mutators.splice(0).map(child => child.exitCode !== null || child.signalCode !== null ? undefined : new Promise(done => child.once('exit', done))));for (const proc of procFixtures.splice(0)) {execFileSync('chmod', ['-R', 'u+rwx', proc]);rmSync(proc, { recursive: true, force: true });@@ -388,8 +390,12 @@ function fixtureProc(pids: Record<string, { uid: number; state?: string; fds?: R}return proc;}-/** Change a fixture process after `ms` from another process, while the synchronous proof runs. */-const later = (ms: number, script: string) => { const child = spawn('sh', ['-c', `sleep ${ms / 1000}; ${script}`], { stdio: 'ignore' }); children.push(child); };+/**+ * Change a fixture process after `ms` from another process, while the synchronous proof runs. The proof can+ * return before the script ends, so the fixture cleanup waits for it: killing the shell would leave its `rm`+ * running against the tree the cleanup walks.+ */+const later = (ms: number, script: string) => { mutators.push(spawn('sh', ['-c', `sleep ${ms / 1000}; ${script}`], { stdio: 'ignore' })); };const staleEmptyLock = () => { const r = repo(); writeFileSync(r.lock, ''); age(r.lock, RECLAIM_MIN_AGE_MS + 1_000); return r; };test.skipIf(!fixtureProcRunnable)('this user\'s git that denies its open files while it exits is re-checked, and the proof follows once it is gone', () => {