Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

doctor ghost_pages: a scan stopped at its bound before any ghost is health unknown (#7145)

garrytan7cd538afceb5
diff --git a/src/commands/doctor/checks/ghost-pages.ts b/src/commands/doctor/checks/ghost-pages.ts
index 56da0aa480..a51590b1f4 100644
--- a/src/commands/doctor/checks/ghost-pages.ts
+++ b/src/commands/doctor/checks/ghost-pages.ts
@@ -21,7 +21,8 @@
import type { Check } from '../../doctor.ts';
import { agentFix, checkError } from '../check-fix.ts';
import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';
-import { readGhostPages } from '../../../core/ghost-pages.ts';
+import { GHOST_CHECK_LIMIT, GHOST_SCAN_LIMIT, readGhostPages } from '../../../core/ghost-pages.ts';
+import { boundUnknownDetails } from '../bounded-unknown.ts';
import { SKILL_PACK_MEMBER_CODE, skillPathDetail } from '../../../core/repair/ghost-pages.ts';
const DOCS = 'docs/guides/repair.md#ghost-pages';
@@ -65,8 +66,15 @@ async function runGhostPages(ctx: DoctorContext): Promise<Check[]> {
: 'Not applicable: no source has a canonical checkout, so no page owns a file that could be missing.' });
return checks;
}
+ // #7145: a scan stopped at its page or candidate bound is not clear past it.
+ if (summary.truncated) {
+ checks.push({ name: 'ghost_pages', status: 'warn', details: { ...details, ...boundUnknownDetails('rows'), limit: GHOST_SCAN_LIMIT, candidate_limit: GHOST_CHECK_LIMIT },
+ message: `Ghost pages unknown: the scan stopped at its bound (${GHOST_SCAN_LIMIT} live pages or ${GHOST_CHECK_LIMIT} unconfirmed candidates per source; no setting) after ${summary.inspected} page(s), `
+ + `so pages past it were not checked; none of those inspected is missing its canonical file.${skillNote}` });
+ return checks;
+ }
checks.push({ name: 'ghost_pages', status: 'ok', details,
- message: `No live page is missing its canonical file (${summary.inspected} page(s) inspected${summary.truncated ? '; bounded, more not checked' : ''}).${skillNote}` });
+ message: `No live page is missing its canonical file (${summary.inspected} page(s) inspected).${skillNote}` });
} catch (error) {
checks.push(checkError('ghost_pages', 'check live pages for a missing canonical file', error, { details: { count: 'unknown', health: 'unknown', docs: DOCS } }));
}
diff --git a/src/core/ghost-pages.ts b/src/core/ghost-pages.ts
index 5024f0b4fa..6561dd4e10 100644
--- a/src/core/ghost-pages.ts
+++ b/src/core/ghost-pages.ts
@@ -94,6 +94,9 @@ export const GHOST_SAMPLE_LIMIT = 5;
export const GHOST_CHECK_LIMIT = 200;
/** Live pages the pre-filter reads per source. */
export const GHOST_SCAN_LIMIT = 250_000;
+let scanLimit = GHOST_SCAN_LIMIT;
+/** Tests only: a smaller per-source pre-filter limit (null restores the default). */
+export function __setGhostScanLimitForTests(limit: number | null): void { scanLimit = limit ?? GHOST_SCAN_LIMIT; }
const BATCH = 10_000;
interface PageRow { id: number; slug: string; source_path: string | null; source_uri: string | null }
@@ -185,7 +188,7 @@ export async function scanGhostSource(engine: BrainEngine, sourceId: string, opt
const rows = await engine.executeRaw<PageRow>(`SELECT id, slug, source_path, source_uri FROM pages
WHERE source_id=$1 AND deleted_at IS NULL AND id > $2 ORDER BY id LIMIT ${BATCH}`, [sourceId, after]);
for (const row of rows) {
- if (scan.inspected >= GHOST_SCAN_LIMIT) { scan.truncated = true; break; }
+ if (scan.inspected >= scanLimit) { scan.truncated = true; break; }
scan.inspected++;
const verdict = prefilter(context, row);
if (verdict.kind === 'present') { scan.file_backed++; continue; }
@@ -198,7 +201,7 @@ export async function scanGhostSource(engine: BrainEngine, sourceId: string, opt
if (result.kind === 'ghost') (await sharedPackMemberGhost(engine, context.owner, result.ghost) ? scan.skill_paths : scan.ghosts).push(result.ghost);
else if (result.reason === 'agrees' || result.reason === 'file_database_drift') scan.file_backed++;
}
- if (rows.length < BATCH || scan.inspected >= GHOST_SCAN_LIMIT) break;
+ if (rows.length < BATCH || scan.inspected >= scanLimit) break;
after = Number(rows[rows.length - 1]!.id);
}
scan.file_backed += scan.ghosts.length + scan.skill_paths.length + unchecked;
diff --git a/test/ghost-pages-6696.test.ts b/test/ghost-pages-6696.test.ts
index c39577309c..187aa366ad 100644
--- a/test/ghost-pages-6696.test.ts
+++ b/test/ghost-pages-6696.test.ts
@@ -25,7 +25,7 @@ import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { installFaultHook } from '../src/core/persistence/fault-points.ts';
import { liveFileDrift } from '../src/core/persistence/drift-conflicts.ts';
import { classifyTerminal } from '../src/core/persistence/terminal-classify.ts';
-import { readGhostPages, ghostPageNow } from '../src/core/ghost-pages.ts';
+import { readGhostPages, ghostPageNow, __setGhostScanLimitForTests } from '../src/core/ghost-pages.ts';
import { resolveRepairScope } from '../src/core/repair/core.ts';
import { AUTO_REPAIR_REGISTRY, EXPLICIT_REPAIR_REGISTRY, repairForCheck, repairRunner, repairSpec } from '../src/core/repair/registry.ts';
import { runRepairCommand } from '../src/commands/repair.ts';
@@ -145,6 +145,18 @@ for (const backend of testBackends()) describe(`#6696 B5 ghost pages (${backend}
expect(repairForCheck('ghost_pages')?.kind).toBe('ghost-pages');
}));
+ test('#7145: doctor ghost_pages stopped at its page bound before any ghost is health unknown, not clear', () => fixture(async f => {
+ await seed(f);
+ __setGhostScanLimitForTests(2);
+ try {
+ const [check] = await ghostPagesEntry.run({ engine } as never) as Array<Record<string, any>>;
+ expect(check).toMatchObject({ name: 'ghost_pages', status: 'warn', details: { count: 0, truncated: true, health: 'unknown', reason: 'bound', bound: 'rows', exact: false } });
+ expect(check.message).toContain('Ghost pages unknown: the scan stopped at its bound');
+ } finally {
+ __setGhostScanLimitForTests(null);
+ }
+ }));
+
test('off the owner host doctor is ok/info, pages ghosts and the repair refuse not_owner_host', () => fixture(async f => {
await seed(f);
const hash = (await repair(f.sourceId)).preview_hash!;