Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(sources): a 20,000-file checkout registers through gbrain sources add

garrytan6e0c6169c86a
diff --git a/src/core/persistence/source-lifecycle.ts b/src/core/persistence/source-lifecycle.ts
index 710f374d3f..f2053014a5 100644
--- a/src/core/persistence/source-lifecycle.ts
+++ b/src/core/persistence/source-lifecycle.ts
@@ -129,7 +129,6 @@ export async function runManagedSourceLifecycle(engine:BrainEngine,input:SourceL
throw missingCheckoutError(input.sourceId,path);
}
const manifest=worktreeManifest(path,{progress:humanManifestProgress()});
- if(Buffer.byteLength(JSON.stringify(manifest))>1_048_576) throw new OperationError('request_too_large','The verified source manifest exceeds the 1 MiB administration metadata bound.');
manifests.set(path,manifest);
}
return topologyTransaction(engine,async tx=>{
diff --git a/src/core/persistence/topology-clone.ts b/src/core/persistence/topology-clone.ts
index 2777f2511a..4600c6e17d 100644
--- a/src/core/persistence/topology-clone.ts
+++ b/src/core/persistence/topology-clone.ts
@@ -89,7 +89,6 @@ export async function runManagedSourceClone(engine:BrainEngine,input:SourceLifec
const manifest=before?{...before,canonical_stamp:canonicalStamp}:owner?.manifest?compactStoredManifest(owner.manifest):null;
if(input.operation==='reclone'&&(!manifest||manifest.canonical_stamp!==canonicalStamp))
throw new OperationError('recovery_required','The missing checkout has no current verified canonical manifest. Recover it from a verified checkpoint before recloning.');
- if(manifest&&Buffer.byteLength(JSON.stringify(manifest))>1_048_576)throw new OperationError('request_too_large','The canonical manifest exceeds the 1 MiB recovery metadata bound.');
const recovery:TopologyCloneRecovery={version:1,kind:'clone',phase:'reserved',operation:input.operation as 'add'|'reclone',sourceId:input.sourceId,
incarnation,worktreeId,ownerHostId:localHostId(),ownerEpoch:String(currentBinding?.owner_epoch??preparedOwner?.owner_epoch??1),target,stage,aside,
beforeHash:before?.digest??null,afterHash:null,manifest,canonicalStamp,checkpoint:source?.last_commit??null,sourceRemoteUrl:source?.config.remote_url as string??null,input,cloneBudget:0};
@@ -126,7 +125,6 @@ export async function runManagedSourceClone(engine:BrainEngine,input:SourceLifec
await (hooks.clone??cloneTopologyCheckout)(url,recovery.stage,recovery.cloneBudget);
const stageBytes=await topologyDirectoryBytes(recovery.stage,recovery.cloneBudget);
const candidate=worktreeManifest(recovery.stage,{progress:humanManifestProgress()});
- if(Buffer.byteLength(JSON.stringify(candidate))>1_048_576)throw new OperationError('request_too_large','The cloned canonical manifest exceeds its 1 MiB recovery metadata bound.');
if(recovery.manifest&&candidate.digest!==recovery.manifest.digest)throw new OperationError('writer_manifest_mismatch','The cloned checkout differs from the verified canonical manifest, including deletions.');
flushTopologyTree(recovery.stage);flushTopologyDirectory(dirname(recovery.stage));
recovery.afterHash=candidate.digest;recovery.phase='prepared';recovery.manifest={...candidate,canonical_stamp:recovery.canonicalStamp};
diff --git a/test/large-brain-ceilings.serial.test.ts b/test/large-brain-ceilings.serial.test.ts
index 0a036f9696..226577158b 100644
--- a/test/large-brain-ceilings.serial.test.ts
+++ b/test/large-brain-ceilings.serial.test.ts
@@ -6,10 +6,14 @@
* - `gbrain sync` under a non-TTY caller: the default and env deadlines no
* longer kill a run that is still importing. A sync whose work outlasts
* its deadline window completes and imports every file.
+ * - `gbrain sources add` registers a checkout far above the ~8k-file point
+ * where the old per-file manifest crossed its 1 MiB metadata bound.
* Fails when: the sync watchdog goes back to a plain wall-clock kill (the
- * child exits 143 after the 1 s deadline with files missing).
+ * child exits 143 after the 1 s deadline with files missing), or the managed
+ * manifest grows with the file count again (`request_too_large`).
* Why new: test/process-watchdog.serial.test.ts drives the watchdog through a
- * harness; it does not run the real CLI command the operator runs.
+ * harness and test/persistence-large-manifest.test.ts calls the lifecycle
+ * function directly; neither runs the real CLI commands the operator runs.
* Seam: none. Deadlines are shortened through the documented env knob, not by
* waiting an hour.
*/
@@ -59,4 +63,14 @@ describe('large-brain ceilings (CLI)', () => {
expect(sync.exitCode).toBe(0);
expect(sync.stdout).toContain('150 file(s) imported');
}, 300_000);
+
+ test('sources add registers a 20,000-file checkout', async () => {
+ const home = await freshBrain('add');
+ const repo = join(dir, 'add', 'repo');
+ commitWorktree(repo, 20_000);
+ const add = await runCli(['sources', 'add', 'big', '--path', repo], { home, env: KEYS, timeoutMs: 180_000 });
+ expect(add.stderr).not.toContain('request_too_large');
+ expect(add.exitCode).toBe(0);
+ expect(JSON.parse(add.stdout.slice(add.stdout.indexOf('{')))).toMatchObject({ source_id: 'big', state: 'committed' });
+ }, 300_000);
});