Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(embed): dry-run announced one page of progress for any stale count (#3955)

Masa7c65bcee9bc1
diff --git a/src/commands/embed.ts b/src/commands/embed.ts
index cb017aa437..bcf6cc516e 100644
--- a/src/commands/embed.ts
+++ b/src/commands/embed.ts
@@ -1057,7 +1057,11 @@ async function embedAllStale(
if (dryRun) {
result.would_embed += staleCount;
result.total_chunks += staleCount;
- if (onProgress) onProgress(1, 1, 0);
+ // No progress event: a dry run reads a count and processes zero pages, so
+ // there is no page total to report. The previous synthetic onProgress(1,1,0)
+ // made `embed.pages` claim total:1 next to a summary naming a much larger
+ // stale count. docs/progress-events.md allows omitting `total` when it is
+ // not known up front; it does not allow asserting a wrong one.
if (!staleOpts?.quiet) slog(`[dry-run] Would embed ${staleCount} stale chunks`);
return;
}
diff --git a/test/embed.serial.test.ts b/test/embed.serial.test.ts
index b27700a8e4..9846c892f0 100644
--- a/test/embed.serial.test.ts
+++ b/test/embed.serial.test.ts
@@ -280,6 +280,38 @@ describe('runEmbedCore --dry-run never calls the embedding model', () => {
expect(result.pages_processed).toBe(0);
});
+ test('dry-run --stale emits no page progress, since it processes no pages', async () => {
+ const { runEmbedCore } = await import('../src/commands/embed.ts');
+ const stale = [
+ { slug: 'a', chunk_index: 0, chunk_text: 'a', chunk_source: 'compiled_truth' as const, model: null, token_count: 1, source_id: 'default', page_id: 1 },
+ { slug: 'b', chunk_index: 0, chunk_text: 'b', chunk_source: 'compiled_truth' as const, model: null, token_count: 1, source_id: 'default', page_id: 2 },
+ { slug: 'c', chunk_index: 0, chunk_text: 'c', chunk_source: 'compiled_truth' as const, model: null, token_count: 1, source_id: 'default', page_id: 3 },
+ ];
+ const engine = mockEngine({
+ countStaleChunks: async () => stale.length,
+ listStaleChunks: async () => stale,
+ listPages: async () => [{ slug: 'a' }, { slug: 'b' }, { slug: 'c' }],
+ getChunks: async () => [],
+ });
+
+ const calls: Array<[number, number]> = [];
+ const result = await runEmbedCore(engine, {
+ stale: true,
+ dryRun: true,
+ onProgress: (done, total) => { calls.push([done, total]); },
+ });
+
+ // The CLI latches its `embed.pages` total from the first callback, so a
+ // synthetic (1, 1) here made the progress stream announce one page while
+ // the summary named every stale chunk. Consistent with pages_processed
+ // above: a dry run enumerates no pages, so it reports no page progress.
+ // docs/progress-events.md permits omitting a total that is not known up
+ // front; it does not permit asserting a wrong one.
+ expect(calls).toEqual([]);
+ expect(result.pages_processed).toBe(0);
+ expect(result.would_embed).toBe(3);
+ });
+
test('dry-run --stale correctly identifies stale chunks (SQL-side path)', async () => {
const { runEmbedCore } = await import('../src/commands/embed.ts');
// SQL-side stale: only the 3 chunks where embedding IS NULL come back,