Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
#6712 PR 1 lane B: a bulk group stops before a prescreened entry so the kernel passes it
garrytan9aa5bcce6ef9
diff --git a/src/core/persistence/sync-run.ts b/src/core/persistence/sync-run.tsindex 5c8291f098..10e2c48e73 100644--- a/src/core/persistence/sync-run.ts+++ b/src/core/persistence/sync-run.ts@@ -1005,7 +1005,7 @@ async function waiveRun(engine: BrainEngine, cursor: Cursor, head: Pending, key:* #6712 PR 1 (L1): the consecutive prescreened entries at the head (sync-prescreen.ts), passed by the guarded kernel's* bounded checks in one transaction (`waivePrescreenedRun`) without freezing or preparing them. Null when the head is* not a prescreened entry or the kernel passed none; `missed` then remembers the head, so the ordinary path freezes,- * screens and imports it (the prescreen fails toward importing).+ * screens and imports it (the prescreen fails toward importing). A bulk group stops before a prescreened entry (`freezeAt`).*/async function prescreenRun(engine: BrainEngine, cursor: Cursor, key: string, run: { missed: Set<number>; limit: number; embeddingRequested: boolean;drainStartedAt: number; assertActive: () => void; signal?: AbortSignal; onProgress: SyncOpts['onProgress'] }): Promise<Cursor | null> {@@ -1618,7 +1618,7 @@ async function runManagedSync(engine: BrainEngine, opts: SyncOpts, slice: { maxPif (slice && (cursor.index - sliceFirstIndex >= slice.maxPages || performance.now() - sliceStarted >= slice.maxMs)) return result(cursor, 'partial', 'writer_yield');continue;}- const freezeAt: FreezeAt = base => async index => { const frozen = await freezeEntry(engine, { ...base, index }, key, assertActive, frozenRun); return 'hold' in frozen ? null : frozen; };+ const freezeAt: FreezeAt = base => async index => { if (base.entries[index]?.prescreened && !prescreen.missed.has(index)) return null; const frozen = await freezeEntry(engine, { ...base, index }, key, assertActive, frozenRun); return 'hold' in frozen ? null : frozen; };if (bulk.settings.enabled && (bulk.foregroundFirst || !foregroundQueued) && !prior && !cursor.group && !pending.rebound && !pending.knockOn && groupableIntent(pending.intent)) cursor = await formGroup(engine, cursor, pending, key, bulk, config, freezeAt, assertActive);if (cursor.group?.[0]?.requestId === pending.requestId && cursor.pending?.requestId === pending.requestId) {const step = await groupStep(engine, cursor, key, bulk, config, opts.drainStartedAt ? { waitMs: 30_000, signal } : { waitMs: 5000 }, drainStartedAt, opts.onProgress,diff --git a/test/sync-prescreen-drift-6712.test.ts b/test/sync-prescreen-drift-6712.test.tsindex 94a18b689f..e8ee132679 100644--- a/test/sync-prescreen-drift-6712.test.ts+++ b/test/sync-prescreen-drift-6712.test.ts@@ -25,7 +25,7 @@import { describe, expect, test } from 'bun:test';import { execFileSync } from 'node:child_process';import { randomUUID } from 'node:crypto';-import { mkdirSync, writeFileSync } from 'node:fs';+import { chmodSync, mkdirSync, writeFileSync } from 'node:fs';import { join } from 'node:path';import type { BrainEngine } from '../src/core/engine.ts';import type { OperationContext } from '../src/core/ops/contract.ts';@@ -34,6 +34,7 @@ import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';import { readGitHold, readSyncImportProvenance, SYNC_IMPORT_PARSER_VERSION, SYNC_IMPORT_PROVENANCE_OP } from '../src/core/persistence/sync-holds.ts';import { readDriftSkips } from '../src/core/persistence/drift-conflicts.ts';import { SYNC_READ_BOUND } from '../src/core/persistence/sync-blobs.ts';+import { resolveBulkSettings } from '../src/core/persistence/sync-group.ts';import { managedBrain } from './helpers/managed-brain.ts';import { waitFor } from './helpers/wait-for.ts';@@ -111,6 +112,18 @@ for (const databaseUrl of process.env.DATABASE_URL ? [undefined, process.env.DATexpect(full).toMatchObject({ prescreened: 0, waived: { imports: SLUGS.length } });}, { databaseUrl, setup }), 180_000);+ test('in a bulk drain a prescreened entry between changed files ends the group and is passed by the kernel', () => managedBrain(async ({ engine, root }) => {+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');+ const bulk = await resolveBulkSettings(engine, false);+ expect(bulk.enabled).toBe(engine.kind === 'postgres'); // bulk groups are Postgres-only+ // a, c, e change; b, d, f change only their mode (same blob): one Git delta interleaves them.+ for (const slug of ['notes/a', 'notes/c', 'notes/e']) writeFileSync(join(root, `${slug}.md`), note(slug, `A changed body of ${slug}.`));+ for (const slug of ['notes/b', 'notes/d', 'notes/f']) chmodSync(join(root, `${slug}.md`), 0o755);+ commit(root, 'interleave');+ const delta = await performManagedSync(engine, { ...OPTS, bulk });+ expect(delta).toMatchObject({ status: 'synced', prescreened: 3, modified: 3 });+ }, { databaseUrl, setup }), 180_000);+test('a fingerprint that changes after discovery froze the prescreen falls through to the ordinary path', () => managedBrain(async ({ engine, root }) => {expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');rewriteHistory(root);