Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

revert(backup): drop the Windows cold-start PowerShell retry; the windows-11-arm controls bound each failing launch to one attempt

garrytanb46196046048
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01cc5a8730..bf40f4c335 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,16 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [0.60.110.0] - 2026-10-08
+
+**Reverts the Windows backup cold-start retry from v0.60.109.0, which turned master red.**
+
+The retry launched PowerShell a second time after any 15-second timeout. The Windows ARM backup controls deliberately run a PowerShell program that hangs, and they require every failing launch to be bounded to one attempt; with the retry each took two launches (30 s). A first Windows backup on a cold machine whose PowerShell start passes 15 s fails again, as before v0.60.109.0. The order hunt, the contract drain fix and the shard weights from v0.60.109.0 stay.
+
+## To take advantage of v0.60.110.0
+
+`gbrain upgrade` installs the binary. There are no schema migrations.
+
## [0.60.109.0] - 2026-10-08
**A Windows backup no longer fails on a cold machine's first PowerShell start, and a new nightly job catches tests that leak state into the next one.**
diff --git a/src/core/backup/private-path.ts b/src/core/backup/private-path.ts
index 43e0e76160..e0f2b078d4 100644
--- a/src/core/backup/private-path.ts
+++ b/src/core/backup/private-path.ts
@@ -42,54 +42,24 @@ foreach ($rule in $rules) {
[Console]::Write('private')
`;
-type ProtectRunner = (path: string, kind: 'directory' | 'file') => Promise<string>;
-
-const runPowerShellProtect: ProtectRunner = (path, kind) => new Promise<string>((resolve, reject) => {
- let inputFailed = false;
- const child = execFile(join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'),
- ['-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(protect, 'utf16le').toString('base64')], {
- env: { ...process.env, GBRAIN_BACKUP_PRIVATE_PATH: path, GBRAIN_BACKUP_PRIVATE_KIND: kind },
- encoding: 'utf8', timeout: 15_000, maxBuffer: 64 * 1024, windowsHide: true,
- }, (error, stdout) => inputFailed ? reject(new Error('Private path input failed')) : error ? reject(error) : resolve(stdout));
- const inputFailure = () => { inputFailed = true; child.kill(); };
- if (!child.stdin) { inputFailure(); return; }
- child.stdin.once('error', inputFailure);
- try { child.stdin.end(); } catch { inputFailure(); }
-});
-
-let protectRunner: ProtectRunner = runPowerShellProtect;
-/** Test seam: replace the PowerShell invocation (undefined restores it). */
-export function __setPrivatePathRunnerForTests(runner?: ProtectRunner): void {
- protectRunner = runner ?? runPowerShellProtect;
-}
-
-/**
- * PowerShell's first start on a cold Windows machine can take longer than the
- * 15 s bound (measured 3.3-27.7 s on fresh CI runners; later starts take
- * 0.2-1.5 s), which failed a user's first backup. A run killed by that bound is
- * retried once; any other failure (an output overflow included), or a second
- * timeout, is final. The script
- * only sets and verifies the ACL of the same new empty path, so a rerun is safe.
- */
-export async function withColdStartRetry<T>(run: () => Promise<T>): Promise<T> {
- try {
- return await run();
- } catch (error) {
- // execFile kills the child for the timeout and for an output overflow; only
- // the timeout leaves `code` unset (the overflow is ERR_CHILD_PROCESS_STDIO_MAXBUFFER).
- const killed = error as { killed?: boolean; code?: unknown } | null;
- if (killed?.killed !== true || typeof killed.code === 'string') throw error;
- return await run();
- }
-}
-
export async function protectNewBackupPath(path: string, kind: 'directory' | 'file'): Promise<void> {
if (process.platform !== 'win32') return;
try {
assertNoSymlinks(path);
const before = lstatSync(path, { bigint: true });
if (!before.ino || (kind === 'directory' ? !before.isDirectory() || readdirSync(path).length !== 0 : !before.isFile() || before.size !== 0n || before.nlink !== 1n)) throw new Error('Expected a new empty path with stable identity');
- const result = await withColdStartRetry(() => protectRunner(path, kind));
+ const result = await new Promise<string>((resolve, reject) => {
+ let inputFailed = false;
+ const child = execFile(join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'),
+ ['-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(protect, 'utf16le').toString('base64')], {
+ env: { ...process.env, GBRAIN_BACKUP_PRIVATE_PATH: path, GBRAIN_BACKUP_PRIVATE_KIND: kind },
+ encoding: 'utf8', timeout: 15_000, maxBuffer: 64 * 1024, windowsHide: true,
+ }, (error, stdout) => error || inputFailed ? reject(error ?? new Error('Private path input failed')) : resolve(stdout));
+ const inputFailure = () => { inputFailed = true; child.kill(); };
+ if (!child.stdin) { inputFailure(); return; }
+ child.stdin.once('error', inputFailure);
+ try { child.stdin.end(); } catch { inputFailure(); }
+ });
assertNoSymlinks(path);
const after = lstatSync(path, { bigint: true });
if (result !== 'private' || before.dev !== after.dev || before.ino !== after.ino
diff --git a/test/backup-fsync.serial.test.ts b/test/backup-fsync.serial.test.ts
index c42ef8d03e..e15a94da42 100644
--- a/test/backup-fsync.serial.test.ts
+++ b/test/backup-fsync.serial.test.ts
@@ -177,8 +177,7 @@ process.stdin.on('end', () => {
expect(callback).toBe(false);
if (mode === 'success') await pending;
else await expect(pending).rejects.toMatchObject({ code: 'private_backup_path_unavailable' });
- // A timeout is PowerShell's cold start: launched once more, then final (withColdStartRetry).
- expect(calls).toBe(mode === 'timeout' ? 2 : 1);
+ expect(calls).toBe(1);
expect(callback).toBe(true);
expect(child).toBeDefined();
expect(child!.exitCode !== null || child!.signalCode !== null).toBe(true);
@@ -186,8 +185,8 @@ process.stdin.on('end', () => {
if (mode === 'nonzero') expect(child!.exitCode).toBe(7);
if (!mode.startsWith('input-')) expect(child?.stdin?.writableEnded).toBe(true);
if (mode === 'timeout') {
- expect(performance.now() - started).toBeGreaterThanOrEqual(28_000);
- expect(performance.now() - started).toBeLessThan(38_000);
+ expect(performance.now() - started).toBeGreaterThanOrEqual(14_000);
+ expect(performance.now() - started).toBeLessThan(19_000);
expect(child?.killed).toBe(true);
expect(processError).not.toBeNull();
}
@@ -205,5 +204,5 @@ process.stdin.on('end', () => {
}
fs.rmSync(tmp, { recursive: true, force: true });
}
- }, mode === 'timeout' ? 45_000 : 25_000);
+ }, 25_000);
}
diff --git a/test/backup-private-path-retry.test.ts b/test/backup-private-path-retry.test.ts
deleted file mode 100644
index f4cf8c941f..0000000000
--- a/test/backup-private-path-retry.test.ts
+++ /dev/null
@@ -1,82 +0,0 @@
-import { afterEach, describe, expect, test } from 'bun:test';
-import { mkdtempSync, rmSync } from 'node:fs';
-import { tmpdir } from 'node:os';
-import { join } from 'node:path';
-import { __setPrivatePathRunnerForTests, protectNewBackupPath, withColdStartRetry } from '../src/core/backup/private-path.ts';
-
-// A PowerShell cold start can outrun the 15 s bound on a fresh Windows machine
-// (protectNewBackupPath). These cases pin the retry policy on every platform;
-// the Windows ACL path itself runs in backup-portability-native.serial.test.ts.
-const timedOut = () => Object.assign(new Error('Command failed: powershell.exe'), { killed: true, signal: 'SIGTERM' });
-
-describe('withColdStartRetry', () => {
- test('a run killed by the timeout is retried once and its second result returned', async () => {
- let calls = 0;
- const result = await withColdStartRetry(async () => { calls++; if (calls === 1) throw timedOut(); return 'private'; });
- expect(result).toBe('private');
- expect(calls).toBe(2);
- });
-
- test('a second timeout is final', async () => {
- let calls = 0;
- await expect(withColdStartRetry(async () => { calls++; throw timedOut(); })).rejects.toMatchObject({ killed: true });
- expect(calls).toBe(2);
- });
-
- test('any other failure is not retried', async () => {
- for (const failure of [new Error('Access rule mismatch'), new Error('Private path input failed'), Object.assign(new Error('exit 1'), { killed: false, code: 1 }),
- Object.assign(new Error('stdout maxBuffer length exceeded'), { killed: true, code: 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER' })]) {
- let calls = 0;
- await expect(withColdStartRetry(async () => { calls++; throw failure; })).rejects.toBe(failure);
- expect(calls).toBe(1);
- }
- });
-
- test('a first success runs once', async () => {
- let calls = 0;
- expect(await withColdStartRetry(async () => { calls++; return 'private'; })).toBe('private');
- expect(calls).toBe(1);
- });
-});
-
-// Forced probe through protectNewBackupPath itself: the platform reads as
-// win32 and the PowerShell runner is replaced, so the first launch is killed
-// by the 15 s bound (as a cold start is) and the second answers.
-describe('protectNewBackupPath on a cold Windows start', () => {
- const realPlatform = process.platform;
- const dirs: string[] = [];
- const asWindows = () => Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });
- afterEach(() => {
- Object.defineProperty(process, 'platform', { value: realPlatform, configurable: true });
- __setPrivatePathRunnerForTests();
- while (dirs.length) rmSync(dirs.pop()!, { recursive: true, force: true });
- });
- const emptyDir = () => { const d = mkdtempSync(join(tmpdir(), 'gbrain-private-path-')); dirs.push(d); return d; };
-
- test('a first launch killed by the timeout is retried and the path is protected', async () => {
- const dir = emptyDir();
- let launches = 0;
- __setPrivatePathRunnerForTests(async () => { launches++; if (launches === 1) throw timedOut(); return 'private'; });
- asWindows();
- await protectNewBackupPath(dir, 'directory');
- expect(launches).toBe(2);
- });
-
- test('two timeouts still refuse with private_backup_path_unavailable', async () => {
- const dir = emptyDir();
- let launches = 0;
- __setPrivatePathRunnerForTests(async () => { launches++; throw timedOut(); });
- asWindows();
- await expect(protectNewBackupPath(dir, 'directory')).rejects.toMatchObject({ code: 'private_backup_path_unavailable' });
- expect(launches).toBe(2);
- });
-
- test('a failed ACL check is not retried', async () => {
- const dir = emptyDir();
- let launches = 0;
- __setPrivatePathRunnerForTests(async () => { launches++; throw new Error('Access rule mismatch'); });
- asWindows();
- await expect(protectNewBackupPath(dir, 'directory')).rejects.toMatchObject({ code: 'private_backup_path_unavailable' });
- expect(launches).toBe(1);
- });
-});