Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(backup): a timed-out local git probe keeps an established failing verdict

garrytan53adcc649041
diff --git a/src/core/backup/repository.ts b/src/core/backup/repository.ts
index b1b54be363..7b6817c6aa 100644
--- a/src/core/backup/repository.ts
+++ b/src/core/backup/repository.ts
@@ -72,8 +72,9 @@ export async function assessBackupRepository(
previous?: BackupAssetVerdict,
): Promise<BackupAssetVerdict> {
const asset: BackupAssetVerdict = { kind, id, state: 'unknown', fix_argv: null, verification: { state: 'not_checked' } };
+ let failedPush = false;
try {
- const failedPush = readPushStatusForRoot(root)?.ok === false;
+ failedPush = readPushStatusForRoot(root)?.ok === false;
// #6083: a managed canonical worktree is committed and pushed by its persistence owner; `sources push` refuses there.
const managed = managedFilesystemRootFor(root);
const managedFix = managed ? ['gbrain', 'sources', 'writer', 'status', ...(managed.sourceId ? [managed.sourceId] : []), '--probe', '--json'] : null;
@@ -165,6 +166,10 @@ export async function assessBackupRepository(
}
return asset;
} catch {
+ // A later local probe that failed (a 2 s git timeout on a loaded host) cannot undo a finding already
+ // established: a recorded failed push, or commits/edits a completed probe saw. It never certifies `ok`.
+ if (failedPush) return { ...asset, state: 'failing', detail: 'last_push_failed', verification: { state: 'unavailable' } };
+ if (asset.state === 'unpushed' || asset.state === 'dirty') return { ...asset, verification: { state: 'unavailable' } };
return { ...asset, state: 'unknown', detail: 'probe_failed', verification: { state: 'unavailable' } };
}
}
diff --git a/test/backup-verification.serial.test.ts b/test/backup-verification.serial.test.ts
index 6d6564e791..6c2a468094 100644
--- a/test/backup-verification.serial.test.ts
+++ b/test/backup-verification.serial.test.ts
@@ -386,3 +386,38 @@ test('assessBackupRepository with less than a full slot left starts no git proce
expect(killed.verification).toMatchObject({ state: 'unavailable', cause: 'timeout' });
} finally { probe.mockRestore(); }
}, 15_000);
+
+/** The error execFileSync throws when its `timeout` kills a slow git (what a loaded runner produced). */
+function timeOutLocalGit(match: (args: string[]) => boolean) {
+ const real = childProcess.execFileSync;
+ return spyOn(childProcess, 'execFileSync').mockImplementation(((file: string, args: string[], options: unknown) => {
+ if (file === 'git' && match(args)) throw Object.assign(new Error('spawnSync git ETIMEDOUT'), { code: 'ETIMEDOUT', signal: 'SIGTERM', status: null });
+ return real(file, args, options as Parameters<typeof real>[2]);
+ }) as unknown as typeof childProcess.execFileSync);
+}
+
+test('a local git probe that times out keeps an established bad verdict and never certifies a repository', async () => {
+ const { root } = await repository('slow-local');
+ git(root, 'commit', '--allow-empty', '-m', 'unpushed after a failed push');
+ const statusPath = pushStatusPathForRoot(root);
+ mkdirSync(join(statusPath, '..'), { recursive: true });
+ writeFileSync(statusPath, JSON.stringify({ schema_version: 'gbrain-push-status-v1', root, ok: false, reason: 'offline', timestamp: now.toISOString() }));
+ let slow = timeOutLocalGit(args => args.includes('status'));
+ try {
+ const failed = await assessBackupRepository(root, 'source_repo', 'source-id', now);
+ expect(failed).toMatchObject({ state: 'failing', detail: 'last_push_failed' });
+ const result = await computeBackupCoverage(engine([root]), verified);
+ expect(result.totals.failing).toBe(1);
+ expect(result.totals.recoverable_repos).toBe(0);
+ } finally { slow.mockRestore(); }
+ rmSync(statusPath);
+ slow = timeOutLocalGit(args => args.includes('--absolute-git-dir'));
+ try {
+ expect(await assessBackupRepository(root, 'source_repo', 'source-id', now)).toMatchObject({ state: 'unpushed', ahead: 1 });
+ } finally { slow.mockRestore(); }
+ git(root, 'push');
+ slow = timeOutLocalGit(args => args.includes('--absolute-git-dir'));
+ try {
+ expect(await assessBackupRepository(root, 'source_repo', 'source-id', now)).toMatchObject({ state: 'unknown', detail: 'probe_failed' });
+ } finally { slow.mockRestore(); }
+});