Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

doctor timeline_history: a pre-flag pass state at the cap is a lower bound

garrytan1c8f2dd16e2c
diff --git a/src/commands/doctor/checks/timeline-history.ts b/src/commands/doctor/checks/timeline-history.ts
index 90b519cc2a..0ea913f007 100644
--- a/src/commands/doctor/checks/timeline-history.ts
+++ b/src/commands/doctor/checks/timeline-history.ts
@@ -33,7 +33,8 @@ interface ScanState extends PassTotals {
cursor: number;
/** Pages earlier runs of this pass found with rows to report (capped). */
found?: number[];
- /** `found` dropped pages past FOUND_CAP, so this pass's recount is a lower bound. */
+ /** `found` dropped pages past FOUND_CAP, so this pass's recount is a lower bound. A state saved
+ * before this flag existed has none; its `found` at the cap may have dropped pages. */
found_clipped?: boolean;
/** Highest timeline row id when the pass started; rows above it may be unscanned. */
started_max_entry: number;
@@ -76,7 +77,7 @@ export async function timelineHistoryCheck(engine: BrainEngine, sourceId?: strin
inspected: state.inspected + scan.inspected,
runs: state.runs + 1,
};
- const clipped = state.found_clipped === true || state.affected > (state.found?.length ?? 0);
+ const clipped = state.found_clipped ?? (state.found?.length ?? 0) >= foundCap;
const multiRun = pass.runs > 1;
const segmented = await segmentedTimelinePages(engine, sources);
const segmentedDetails = segmented.pages ? { segmented_pages: segmented.pages, segmented_rows: segmented.rows, segmented_sample: segmented.sample } : {};
diff --git a/test/doctor-timeline-history-clipped-8468.test.ts b/test/doctor-timeline-history-clipped-8468.test.ts
index a9f73db815..2744539456 100644
--- a/test/doctor-timeline-history-clipped-8468.test.ts
+++ b/test/doctor-timeline-history-clipped-8468.test.ts
@@ -5,6 +5,8 @@
* as exact and could record a clean pass while the dropped pages still held
* database-only rows. A clipped pass is now a lower bound and never clean.
* `foundCap` lowers the cap the way `pageCap` lowers the per-run budget.
+ * A pass state saved before the clipped flag existed records no flag; one
+ * whose kept list is at the cap may have dropped pages and is a lower bound.
*/
import { afterAll, beforeAll, beforeEach, expect, test } from 'bun:test';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
@@ -69,3 +71,17 @@ test('a clipped pass whose kept pages were repaired keeps warning and is not tru
expect(next.status).toBe('warn');
expect(next.details).not.toHaveProperty('last_full_pass');
});
+
+test('a saved pass from before the clipped flag, with its list at the cap, is a lower bound (no cap seam)', async () => {
+ const [{ max_entry }] = await engine.executeRaw<{ max_entry: number | string }>('SELECT COALESCE(max(id), 0) AS max_entry FROM timeline_entries');
+ const legacy = { materializable: 0, unrenderable: 0, affected: 0, inspected: PAGES, runs: 1, cursor: 2 ** 31 - 1,
+ found: Array.from({ length: 10_000 }, (_, i) => 1_000_000 + i), started_max_entry: Number(max_entry) };
+ await engine.setConfig('doctor.timeline_history.scan:default', JSON.stringify(legacy));
+ const end = await timelineHistoryCheck(engine, 'default');
+ expect(end.status).toBe('warn');
+ expect(end.details).toMatchObject({ count: 'lower_bound', truncated: false });
+ expect(end.message).toContain('gbrain repair timeline');
+ const fresh = await timelineHistoryCheck(engine, 'default');
+ expect(fresh.status).toBe('warn');
+ expect(fresh.details).toMatchObject({ count: 'exact', materializable_rows: 2 });
+});