Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: rows-behind primes only metafile blobs no larger than the head it keeps, so a batch never loads large blobs whole
garrytanffcd596009d5
diff --git a/src/core/persistence/rows-behind.ts b/src/core/persistence/rows-behind.tsindex f586aaa5df..f524a0ee33 100644--- a/src/core/persistence/rows-behind.ts+++ b/src/core/persistence/rows-behind.ts@@ -39,6 +39,7 @@ import { prepareRepairPublication, repairScreenConfig } from './file-repair.ts';import { SYNC_READ_BOUND } from './sync-blobs.ts';import { heldGitPaths, readSyncImportProvenances } from './sync-holds.ts';import { loadSyncEligibility } from './sync-discovery.ts';+import { METAFILE_HEAD_BYTES } from '../sync.ts';import { isSourceDbOnlySlug } from './source-storage.ts';export const ROWS_BEHIND_BATCH = 256;@@ -156,7 +157,7 @@ export async function scanRowsBehind(engine: BrainEngine, sourceId: string,if (blob.mode !== '100644' && blob.mode !== '100755') { skip(key.id, 'not_regular_file'); continue; }listed.push({ key, rel, blob });}- metafileHeads.prime(listed.map(row => ({ path: gitPath(row.rel), oid: row.blob.oid, size: row.blob.size })));+ metafileHeads.prime(listed.filter(row => row.blob.size <= METAFILE_HEAD_BYTES).map(row => ({ path: gitPath(row.rel), oid: row.blob.oid, size: row.blob.size })));const rows = listed.filter(row => {if (eligible(gitPath(row.rel))) return true;skip(row.key.id, 'not_eligible');diff --git a/test/rows-behind-checkpoint-8071.test.ts b/test/rows-behind-checkpoint-8071.test.tsindex 0dceca697f..9a965da5c7 100644--- a/test/rows-behind-checkpoint-8071.test.ts+++ b/test/rows-behind-checkpoint-8071.test.ts@@ -301,16 +301,19 @@ for (const backend of testBackends()) describe(`[${backend}] #8071: rows behindexpect(await doctor(engine)).toMatchObject({ name: CHECK, status: 'ok', readiness_state: 'unknown' });}, { databaseUrl, setup }), 240_000);- test('nested typed index pages are screened with one batched head read per batch, not a Git read per page', () => managedBrain(async ({ engine, root }) => {+ test('nested typed index pages are screened with one batched head read per batch, not a Git read per page; a large one is read alone', () => managedBrain(async ({ engine, root }) => {for (const dir of ['notes/s1', 'notes/s2', 'notes/s3']) { mkdirSync(join(root, dir), { recursive: true }); writeFileSync(join(root, dir, 'index.md'), note(dir, `The index of ${dir}.`)); }+ mkdirSync(join(root, 'notes/big'), { recursive: true });+ writeFileSync(join(root, 'notes/big/index.md'), note('notes/big', 'A long index line.\n'.repeat(5_000)));commit(root, 'indexes');expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');const trace = join(tmpdir(), `gbrain-rows-behind-trace-${randomUUID()}.log`);try {const scan = await withEnv({ GIT_TRACE: trace }, () => scanRowsBehind(engine, 'default'));- expect(scan).toMatchObject({ status: 'known', complete: true, behind: [], pages: 8 });- // The eligibility screen reads the index pages' heads from the batch's checkpoint blobs, never one lookup per page.- expect(readFileSync(trace, 'utf8').split('\n').filter(line => line.includes('cat-file') && line.includes('--batch-check'))).toEqual([]);+ expect(scan).toMatchObject({ status: 'known', complete: true, behind: [], pages: 9 });+ // The small index pages' heads come from one batched read of their checkpoint blobs, never a lookup per page. A blob+ // larger than the head kept is not loaded into the batch's read; its head is read on its own (one lookup).+ expect(readFileSync(trace, 'utf8').split('\n').filter(line => line.includes('cat-file') && line.includes('--batch-check'))).toHaveLength(1);} finally { rmSync(trace, { force: true }); }}, { databaseUrl, setup }), 240_000);