Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(backup): an output overflow is not a cold start; the subprocess contract test pins two bounded launches on a timeout

garrytand53f3d32c69f
diff --git a/src/core/backup/private-path.ts b/src/core/backup/private-path.ts
index dc96d16550..43e0e76160 100644
--- a/src/core/backup/private-path.ts
+++ b/src/core/backup/private-path.ts
@@ -67,14 +67,18 @@ export function __setPrivatePathRunnerForTests(runner?: ProtectRunner): void {
* 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, or a second timeout, is final. The script
+ * 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) {
- if ((error as { killed?: boolean } | null)?.killed !== true) throw 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();
}
}
diff --git a/test/backup-fsync.serial.test.ts b/test/backup-fsync.serial.test.ts
index e15a94da42..c42ef8d03e 100644
--- a/test/backup-fsync.serial.test.ts
+++ b/test/backup-fsync.serial.test.ts
@@ -177,7 +177,8 @@ process.stdin.on('end', () => {
expect(callback).toBe(false);
if (mode === 'success') await pending;
else await expect(pending).rejects.toMatchObject({ code: 'private_backup_path_unavailable' });
- expect(calls).toBe(1);
+ // A timeout is PowerShell's cold start: launched once more, then final (withColdStartRetry).
+ expect(calls).toBe(mode === 'timeout' ? 2 : 1);
expect(callback).toBe(true);
expect(child).toBeDefined();
expect(child!.exitCode !== null || child!.signalCode !== null).toBe(true);
@@ -185,8 +186,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(14_000);
- expect(performance.now() - started).toBeLessThan(19_000);
+ expect(performance.now() - started).toBeGreaterThanOrEqual(28_000);
+ expect(performance.now() - started).toBeLessThan(38_000);
expect(child?.killed).toBe(true);
expect(processError).not.toBeNull();
}
@@ -204,5 +205,5 @@ process.stdin.on('end', () => {
}
fs.rmSync(tmp, { recursive: true, force: true });
}
- }, 25_000);
+ }, mode === 'timeout' ? 45_000 : 25_000);
}
diff --git a/test/backup-private-path-retry.test.ts b/test/backup-private-path-retry.test.ts
index 16d920b512..f4cf8c941f 100644
--- a/test/backup-private-path-retry.test.ts
+++ b/test/backup-private-path-retry.test.ts
@@ -24,7 +24,8 @@ describe('withColdStartRetry', () => {
});
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 })]) {
+ 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);