Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

refactor: keep discoverManagedSync and runSyncPass within the function-size limit (GST-2331)

garrytan3478bcbbd1b1
diff --git a/src/core/persistence/sync-discovery.ts b/src/core/persistence/sync-discovery.ts
index 804d966332..3d406bbe02 100644
--- a/src/core/persistence/sync-discovery.ts
+++ b/src/core/persistence/sync-discovery.ts
@@ -526,9 +526,7 @@ export async function discoverManagedSync(engine: BrainEngine, opts: SyncOpts, c
for (const path of delta.manifest.deleted) put(path, 'delete');
for (const rename of delta.manifest.renamed) putRename(rename);
} else {
- let tree: string;
- try { tree = syncGit(gitRoot, ['ls-tree', '-r', '--name-only', '-z', target]); } catch (error) { throw partialCloneTreeRefusal(gitRoot, sourceId, target) ?? error; }
- const listed = tree.split('\0')
+ const listed = ((): string => { try { return syncGit(gitRoot, ['ls-tree', '-r', '--name-only', '-z', target]); } catch (error) { throw partialCloneTreeRefusal(gitRoot, sourceId, target) ?? error; } })().split('\0')
.filter(path => path && (!scope || path.startsWith(`${scope}/`)));
const paths = listed.filter(path => !refuse(path));
assertDistinctSyncOrigins(paths);
diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.ts
index f688ceba5c..8111ed7a79 100644
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@ -1013,11 +1013,7 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
await save('resumable', 'timeout', false, true, true).catch(() => undefined); return result('partial', 'timeout');
}
// A Git listing that did not finish cleanly classifies nothing (design v3.2 §9): the pass stops blocked, having written nothing for that round.
- if (error instanceof SyncTreeReadIncomplete) {
- await save('blocked', 'reconcile_read_incomplete').catch(() => undefined);
- const refusal = partialCloneTreeRefusal(context.gitRoot, sourceId, head); if (refusal) throw refusal;
- return result('blocked_by_failures', 'reconcile_read_incomplete');
- }
+ if (error instanceof SyncTreeReadIncomplete) { await save('blocked', 'reconcile_read_incomplete').catch(() => undefined); const refusal = partialCloneTreeRefusal(context.gitRoot, sourceId, head); if (refusal) throw refusal; return result('blocked_by_failures', 'reconcile_read_incomplete'); }
const stop = resumableRowStop(error); if (stop) await save('resumable', stop, false, stop !== 'lease_lost', true).catch(() => undefined); throw error;
} finally {
unregisterPassCost(passId);