Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(pinned-reads): unwind the timed-out arm instead of reassigning PATH
garrytan72ff16046ba8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7eba07e847..9d6e099d5b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,7 +21,7 @@ Three gaps the hang exposed are fixed too. A managed sync no longer mistakes a t- **Bun 1.4.3 everywhere CI pins one version:** every `bun-version:` in `.github/workflows/`, the `['1.4.0', '1.4.3']` floor-plus-primary matrices (the 1.4.0 cells stay, since 1.4.0 is the supported floor), `docker-compose.ci.yml` (`bun run ci:local`), `scripts/ubicloud/setup-ci-vm.sh` and `scripts/ci-ubicloud.ts` (`bun run ci:ubicloud`), `tests/docker/`, and `scripts/setup-in-agent.sh`'s runtime pin for new in-agent installs (repairs keep the version their receipt records). `test/scripts/ci-pr-scope.test.ts` still requires every single-version pin to equal the primary. The release compiler (`release.yml`) now builds the published binaries on 1.4.3, so a compiled `gbrain` no longer carries the defect.- **`isConnectionDrop` (`src/core/persistence/sync-drain.ts`):** a child-process error is no longer a dropped database connection. That covers Node's `syscall: 'spawnSync git'` and any message of the form `spawn(Sync) <cmd> E…`. Before, the drain's git reads coming back `spawnSync git ETIMEDOUT` printed "database connection dropped", reconnected the database, and counted a strike toward `connection_lost`, which pointed the operator at the wrong component. Now the error takes the drain's ordinary transient retry, with no reconnect and no connection line. The test throws a real `spawnSync` timeout and a synthetic `spawnSync git ETIMEDOUT` through `runDrain`. It fails on the old code, where the first is classified as a drop.- **`scripts/capture-test-log.ts`:** two live notes, each printed once to stderr and appended to the job's step summary as soon as its evidence arrives. The first, `bun_spawnsync_poisoned?`, fires on the first `spawnSync <cmd> ETIMEDOUT` line and names its file. The second is the existing `bun_spawnsync_poisoned` verdict, the moment it holds. Before, the classifier ran only when the test process exited, so the cancelled #6578 job never named the signature. The tests replay that job's log shape and check a still-running capture's summary. Both fail on the old script.-- **`test/managed-sync-pinned-reads.test.ts`:** `afterEach` aborts the running arm's sync (`performSync` now gets the arm's signal), puts PATH back, and prints the arm's Git calls: how long each took and which never finished. Before, a timed-out test left PATH on its counting `git` shim. It also kept spawning Git behind the next test and threw `ENOENT` into the temp home that `afterAll` had already removed. The shim now records a start and end line per call (`calls()` counts are unchanged). Forced probe: with the test deadline cut to 4 s and a `git` that sleeps 200 ms, a trailing test that checks PATH and the arm's Git log fails on the old file and passes on the new one.+- **`test/managed-sync-pinned-reads.test.ts`:** `afterEach` aborts the running arm's sync (`performSync` now gets the arm's signal), waits up to 20 s for the arm to unwind so its PATH override is gone, and prints the arm's Git calls: how long each took and which never finished. Each counter wraps the Git and PATH the file loaded with, never another arm's shim. Before, a timed-out test left PATH on its counting `git` shim. It also kept spawning Git behind the next test and threw `ENOENT` into the temp home that `afterAll` had already removed. The shim now records a start and end line per call (`calls()` counts are unchanged). Forced probe: with the test deadline cut to 4 s and a `git` that sleeps 200 ms, a trailing test that checks PATH and the arm's Git log fails on the old file and passes on the new one.- `TODOS.md`: the P2 "Bump Bun when a release carries 13a98b0" item is done. `docs/TESTING.md`, `docs/RELEASING.md`, `docs/guides/authorization-upgrade.md` and `native/locks/README.md` name 1.4.3 as the CI and build runtime.## [0.60.192.0] - 2026-10-13diff --git a/test/managed-sync-pinned-reads.test.ts b/test/managed-sync-pinned-reads.test.tsindex d9a26e2f35..bb00a1b087 100644--- a/test/managed-sync-pinned-reads.test.ts+++ b/test/managed-sync-pinned-reads.test.ts@@ -12,9 +12,11 @@* as they are. Runs on PGLite, and on Postgres when DATABASE_URL is set.** #6586: a test that hits its deadline does not keep running behind the next- * one. `afterEach` aborts the running arm's sync, puts PATH back and prints- * the arm's Git calls (how long each took, which never finished), so a hang- * says whether Git was slow or the runtime missed a finished child.+ * one. `afterEach` aborts the running arm's sync, waits for it to unwind (so+ * its PATH override is gone) and prints the arm's Git calls (how long each+ * took, which never finished), so a hang says whether Git was slow or the+ * runtime missed a finished child. Each counter wraps the Git and PATH this+ * file loaded with, never another arm's shim.*/import { afterAll, afterEach, beforeAll, expect, test } from 'bun:test';import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';@@ -146,19 +148,21 @@ async function dump(e: BrainEngine, root: string): Promise<Record<string, string};}+const PATH_AT_LOAD = process.env.PATH;+let REAL_GIT: string | undefined;type GitCounter = { path: string; real: string; calls: () => string[]; timings: () => string };/** A `git` on PATH that logs each invocation with its start and end, so an arm's Git process count and timing are known. */function gitCounter(dir: string): GitCounter {const log = join(dir, 'git.log'), bin = join(dir, 'bin');mkdirSync(bin, { recursive: true });- const real = execFileSync('sh', ['-c', 'command -v git'], { encoding: 'utf8', timeout: 10_000 }).trim();+ const real = REAL_GIT ??= execFileSync('sh', ['-c', 'command -v git'], { encoding: 'utf8', timeout: 10_000, env: { ...process.env, PATH: PATH_AT_LOAD } }).trim();writeFileSync(join(bin, 'git'), `#!/bin/sh\nprintf 'S %s %s %s\\n' "$$" "$(date +%s%N)" "$*" >> '${log}'\n'${real}' "$@"\ncode=$?\n`+ `printf 'E %s %s %s\\n' "$$" "$(date +%s%N)" "$code" >> '${log}'\nexit $code\n`);chmodSync(join(bin, 'git'), 0o755);const lines = () => existsSync(log) ? readFileSync(log, 'utf8').split('\n').filter(Boolean) : [];const ns = (value: string) => Number(value.replace(/N$/, '000000000'));return {- path: `${bin}${delimiter}${process.env.PATH ?? ''}`, real,+ path: `${bin}${delimiter}${PATH_AT_LOAD ?? ''}`, real,calls: () => lines().filter(line => line.startsWith('S ')).map(line => line.split(' ').slice(3).join(' ')),timings: () => {const open = new Map<string, { at: number; args: string }>(), done: Array<{ ms: number; args: string; code: string }> = [];@@ -175,16 +179,15 @@ function gitCounter(dir: string): GitCounter {}/** The arm or test in flight, so `afterEach` can stop it and say where it was when its test hit the deadline. */-let active: { label: string; stop: AbortController; counter: GitCounter | null } | null = null;-const PATH_AT_LOAD = process.env.PATH;-afterEach(() => {- if (active) {- console.error(`[pinned-reads] ${active.label} was still running at the test deadline; stopping it.\n${active.counter?.timings() ?? 'no Git counter on this platform'}`);- active.stop.abort(new Error(`${active.label}: test deadline`));- active = null;- }- process.env.PATH = PATH_AT_LOAD;-});+let active: { label: string; stop: AbortController; counter: GitCounter | null; done: Promise<void> } | null = null;+afterEach(async () => {+ const run = active;+ if (!run) return;+ active = null;+ console.error(`[pinned-reads] ${run.label} was still running at the test deadline; stopping it.\n${run.counter?.timings() ?? 'no Git counter on this platform'}`);+ run.stop.abort(new Error(`${run.label}: test deadline`));+ await Promise.race([run.done, new Promise(resolve => setTimeout(resolve, 20_000))]);+}, 30_000);type Arm = { name: string; window: number | null };const ARMS: Arm[] = [{ name: 'per-entry', window: 0 }, { name: 'window', window: null }, { name: 'window-3', window: 3 }];@@ -197,7 +200,8 @@ async function runArm(backend: string, arm: Arm, open: () => Promise<{ engine: Bconst { engine, close } = await open();const counter = process.platform === 'win32' ? null : gitCounter(dir);const restore = __setPinnedWindowForTests(arm.window);- const run = active = { label: `${backend} arm ${arm.name}`, stop: new AbortController(), counter };+ let settle = () => {};+ const run = active = { label: `${backend} arm ${arm.name}`, stop: new AbortController(), counter, done: new Promise<void>(resolve => { settle = resolve; }) };const signal = run.stop.signal;try {return await withEnv({ GBRAIN_HOME: join(dir, 'home'), ...(counter ? { PATH: counter.path } : {}) }, async () => {@@ -223,7 +227,7 @@ async function runArm(backend: string, arm: Arm, open: () => Promise<{ engine: Bthrow error;} finally {if (active === run) active = null;- restore(); await close();+ restore(); await close(); settle();}}