Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(unindexed): name a committed symlink instead of screening its target as content (#7149)

garrytanc94b88e21f3a
diff --git a/src/core/persistence/unindexed-files.ts b/src/core/persistence/unindexed-files.ts
index 687cb86acc..4c93869b31 100644
--- a/src/core/persistence/unindexed-files.ts
+++ b/src/core/persistence/unindexed-files.ts
@@ -75,6 +75,7 @@ export const UNINDEXED_REVISIT_CAP = 5_000;
/** A stored result older than this is stale. */
export const UNINDEXED_STALE_MS = 7 * 24 * 3_600_000;
const BATCH = 1_000;
+const SYMLINK_MODE = '120000';
/** Blob bytes one screening slice holds in memory at most (a single larger blob is read alone); each slice is released before the next. */
const SCREEN_SLICE_BYTES = 32 * 1024 ** 2;
@@ -144,7 +145,7 @@ export interface UnindexedRecord extends Omit<UnindexedScan, 'files' | 'schedule
source_prefix: string;
}
-interface TreeEntry { path: string; oid: string; size: number }
+interface TreeEntry { path: string; oid: string; size: number; mode: string }
/** Reads `entries` in slices of at most `SCREEN_SLICE_BYTES` and visits each with its text (undefined when too large to read); stops before a slice once `stop()` is true. */
function visitBlobSlices<T extends TreeBlob>(gitRoot: string, entries: T[], visit: (entry: T, content: string | undefined) => void, stop: () => boolean): void {
@@ -172,10 +173,10 @@ async function* treeBatches(gitRoot: string, target: string, scope: string, afte
const row = pending.subarray(0, nul).toString('utf8');
pending = pending.subarray(nul + 1);
const tab = row.indexOf('\t');
- const [, kind, oid, bytes] = row.slice(0, tab).split(/\s+/);
+ const [mode, kind, oid, bytes] = row.slice(0, tab).split(/\s+/);
const path = row.slice(tab + 1);
if (kind !== 'blob' || floor && Buffer.compare(Buffer.from(path, 'utf8'), floor) <= 0 && !revisit?.has(path)) continue;
- batch.push({ path, oid: oid!, size: Number(bytes) });
+ batch.push({ path, oid: oid!, size: Number(bytes), mode: mode! });
if (batch.length >= size) { yield batch; batch = []; }
}
}
@@ -244,9 +245,10 @@ export async function findUnindexedFiles(engine: BrainEngine, sourceId: string,
'SELECT slug FROM pages WHERE source_id=$1 AND deleted_at IS NULL AND slug = ANY($2::text[])', [sourceId, slugs])).map(page => page.slug) : []);
const deleted = new Set(fresh.length ? (await engine.executeRaw<{ source_path: string }>(
'SELECT source_path FROM pages WHERE source_id=$1 AND deleted_at IS NOT NULL AND source_path = ANY($2::text[])', [sourceId, fresh.map(row => row.origin)])).map(page => page.source_path) : []);
- const toScreen = fresh.slice(0, Math.max(0, screenLimit - screened));
+ // #7149: a committed symlink's blob is its target path, not page content; it is named as one instead of screened.
+ const codes = new Map<string, string>(fresh.filter(row => row.mode === SYMLINK_MODE).map(row => [row.root, 'symlink']));
+ const toScreen = fresh.filter(row => row.mode !== SYMLINK_MODE).slice(0, Math.max(0, screenLimit - screened));
screened += toScreen.length;
- const codes = new Map<string, string>();
visitBlobSlices(gitRoot, toScreen, (row, content) => {
if (content === undefined) { codes.set(row.root, 'file_too_large'); return; }
const result = screenImportContent({ content, path: row.origin, byteLength: row.size, expectedSlug: resolveSlugForPath(row.origin) || null });
diff --git a/test/unindexed-files-convergence-7149.test.ts b/test/unindexed-files-convergence-7149.test.ts
index 84fd776917..ab8ca25870 100644
--- a/test/unindexed-files-convergence-7149.test.ts
+++ b/test/unindexed-files-convergence-7149.test.ts
@@ -13,7 +13,7 @@
import { afterAll, beforeAll, expect, test } from 'bun:test';
import { execFileSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
-import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import type { BrainEngine } from '../src/core/engine.ts';
@@ -25,7 +25,7 @@ import { claimWorktree } from '../src/core/persistence/ownership.ts';
import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { performManagedSync } from '../src/core/persistence/sync-run.ts';
import { installFaultHook } from '../src/core/persistence/fault-points.ts';
-import { readGitHoldRetryPaths, requestGitHoldRetry } from '../src/core/persistence/sync-holds.ts';
+import { readGitHoldRetryPaths, readGitSourceHolds, requestGitHoldRetry } from '../src/core/persistence/sync-holds.ts';
import { readUnindexedFiles, refreshUnindexedFiles, unindexedBudgetForPages } from '../src/core/persistence/unindexed-files.ts';
import { unindexedFilesEntry } from '../src/commands/doctor/checks/unindexed-files.ts';
import { runUnindexedFilesPhase } from '../src/core/cycle/unindexed-files.ts';
@@ -149,6 +149,19 @@ test('the maintenance phase serves the least recently scanned source first, so a
expect((await readUnindexedFiles(engine, [b.id])).get(b.id)).toMatchObject({ unindexed: 1, pending: ['notes/legacy-b.md'] });
}), 240_000);
+test('a committed symlink with no page is named symlink, not screened as page content; the next sync holds it, so it ends in a terminal state', () => each(async engine => {
+ const s = await source(engine, 'unidx7149-link', files('notes', 2));
+ await s.sync();
+ symlinkSync('/nonexistent/elsewhere/target.md', join(s.root, 'notes/link.md'));
+ await s.legacy({});
+ const found = await refreshUnindexedFiles(engine, s.id);
+ expect(found.scan).toMatchObject({ complete: true, unindexed: 1, by_code: { symlink: 1 } });
+ expect(found.scheduled).toEqual(['notes/link.md']);
+ await s.sync();
+ expect(((await readGitSourceHolds(engine, { sourceIds: [s.id] }))[0]?.holds ?? []).map(hold => hold.path)).toEqual(['notes/link.md']);
+ expect((await s.doctor()).details).toMatchObject({ sources: [{ source_id: s.id, state: 'ok', still_unindexed: 0, waiting: 0 }] });
+}), 240_000);
+
test('a source gets one minute of scan budget per started 100k live pages, at most five', () => {
expect([0, 1, 100_000, 100_001, 245_000, 311_000, 2_000_000].map(unindexedBudgetForPages)).toEqual([60_000, 60_000, 60_000, 120_000, 180_000, 240_000, 300_000]);
});