Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(extract): timeline walk refreshes planner stats on batch boundaries

garrytan8bd4e81f9661
diff --git a/src/commands/extract-timeline-db.ts b/src/commands/extract-timeline-db.ts
index edebc81bc7..574fe5a277 100644
--- a/src/commands/extract-timeline-db.ts
+++ b/src/commands/extract-timeline-db.ts
@@ -136,10 +136,11 @@ export async function extractTimelineFromDB(engine: BrainEngine, opts: TimelineD
}
for (const { slug, source_id } of refs) {
- if (analyzeEvery > 0 && ++walked % analyzeEvery === 0) {
+ if (analyzeEvery > 0 && walked > 0 && walked % analyzeEvery === 0) {
await flush();
await maybeRefreshPlannerStats(engine, 'extract', { throttle: false }).catch(() => undefined);
}
+ walked++;
if (managed) {
try {
const outcome = await publishPageTimeline(engine, await authorityFor(source_id), slug, source_id, opts);
diff --git a/test/extract-timeline-db-planner-stats.test.ts b/test/extract-timeline-db-planner-stats.test.ts
index 24e2acd229..8a6b365972 100644
--- a/test/extract-timeline-db-planner-stats.test.ts
+++ b/test/extract-timeline-db-planner-stats.test.ts
@@ -18,7 +18,7 @@ import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { extractTimelineFromDB } from '../src/commands/extract-timeline-db.ts';
import { __testing } from '../src/core/planner-stats.ts';
-const PAGES = 300;
+const PAGES = 301;
let engine: PGLiteEngine;
beforeAll(async () => {
@@ -51,7 +51,7 @@ describe('database timeline walk keeps PGLite planner statistics fresh', () => {
const result = await extractTimelineFromDB(engine, { dryRun: false, jsonMode: true, quiet: true });
expect(result.created).toBe(PAGES * 2);
- // The check before page 300 sees 299 pages' rows (598), the first count over the max(500, 10%) threshold.
+ // The check after page 300 sees 300 pages' rows (600), the first count over the max(500, 10%) threshold.
expect(analyzed.filter(a => a.table === 'timeline_entries').map(a => a.rows)).toEqual([(PAGES - 1) * 2]);
const [{ n }] = await engine.executeRaw<{ n: number }>(
"SELECT count(*)::int AS n FROM pg_stats WHERE schemaname = 'public' AND tablename = 'timeline_entries'");