Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(doctor): connectors reads the newest connector receipt; link_resolution_opportunity names its sample and its time bound (#7145)
garrytan8f5d6c762201
diff --git a/src/commands/doctor/checks/calibration.ts b/src/commands/doctor/checks/calibration.tsindex 09b0eb561f..6f1ce29522 100644--- a/src/commands/doctor/checks/calibration.ts+++ b/src/commands/doctor/checks/calibration.ts@@ -22,6 +22,7 @@ import { escapeLikePattern, buildVisibilityClause } from '../../../core/search/simport { safeChunksFilter } from '../../../core/search/safe-chunks.ts';import type { Check } from '../../doctor.ts';import { checkError, doctorVerify, withSkippedSegmented } from '../check-fix.ts';+import { boundUnknownDetails } from '../bounded-unknown.ts';import { pricingSetArgv } from '../../../core/budget/no-pricing.ts';// --- v0.36.1.0 calibration doctor checks (T12) ---@@ -290,11 +291,14 @@ export async function checkLinkResolutionOpportunity(const sampledNote = totalPages > SAMPLE_LIMIT? ` (scanned the ${SAMPLE_LIMIT} most-recent of ${totalPages} pages)`: '';+ // #7145: a sample is not the brain: every verdict below names it and carries exact: false.+ const sampleDetails = totalPages > SAMPLE_LIMIT ? { exact: false, bound: 'sample', limit: SAMPLE_LIMIT, sampled: sampled.length, total_pages: totalPages } : undefined;const deadline = Date.now() + 60_000;+ let stoppedAtDeadline = false;const hb = progress ? startHeartbeat(progress, `scanning ${sampled.length} pages for bare wikilinks…`) : null;try {for (const row of sampled) {- if (Date.now() > deadline) break; // backstop; in-memory scan rarely hits it+ if (Date.now() > deadline) { stoppedAtDeadline = true; break; } // backstop; in-memory scan rarely hits itconst content = (row.compiled_truth ?? '') + '\n' + (row.timeline ?? '');for (const e of extractEntityRefs(content)) {if (!e.needsResolution) continue;@@ -313,14 +317,19 @@ export async function checkLinkResolutionOpportunity(hb?.();}+ if (stoppedAtDeadline) {+ return result({ name, status: 'warn', details: { ...boundUnknownDetails('time'), limit: 60_000, bare_wikilinks_so_far: bareCount },+ message: `Link resolution opportunity unknown: the scan stopped at its 60 s limit before reading every sampled page${sampledNote}; ${bareCount} bare wikilink(s) seen so far.` });+ }if (bareCount === 0) {- return result({ name, status: 'ok', message: 'No bare wikilinks found' });+ return result({ name, status: 'ok', message: `No bare wikilinks found${sampledNote}`, ...(sampleDetails ? { details: sampleDetails } : {}) });}if (wouldResolveCount === 0) {return result({name,status: 'ok',- message: `${bareCount} bare wikilink(s) found, but none have basename matches in the brain.`,+ message: `${bareCount} bare wikilink(s) found${sampledNote}, but none have basename matches in the brain.`,+ ...(sampleDetails ? { details: sampleDetails } : {}),});}const ratio = wouldResolveCount / bareCount;@@ -333,6 +342,7 @@ export async function checkLinkResolutionOpportunity(`${wouldResolveCount} of ${bareCount} bare wikilinks (${pct}%) would resolve to ` +`${distinctTargets.size} distinct page(s) under global_basename mode${sampledNote}. ` +`Enable with: gbrain config set link_resolution.global_basename true`,+ ...(sampleDetails ? { details: sampleDetails } : {}),});}const pct = Math.round(ratio * 100);@@ -340,6 +350,7 @@ export async function checkLinkResolutionOpportunity(name,status: 'ok',message: `${wouldResolveCount}/${bareCount} bare wikilinks (${pct}%) would resolve — below the 20% / 5-link threshold for surfacing a hint${sampledNote}.`,+ ...(sampleDetails ? { details: sampleDetails } : {}),});} catch (e) {return {diff --git a/src/commands/doctor/checks/connectors.ts b/src/commands/doctor/checks/connectors.tsindex f34bfd4adb..366fa43219 100644--- a/src/commands/doctor/checks/connectors.ts+++ b/src/commands/doctor/checks/connectors.ts@@ -97,8 +97,8 @@ export async function connectorsHealthCheck(engine: BrainEngine): Promise<Check>// Drift: latest connector receipt reports skipped conversations.try {- const log = await engine.getIngestLog({ limit: 20 });- const latest = log.find((e) => e.source_type === 'connector');+ // #7145: the newest connector receipt itself, not whichever falls inside the newest rows of every source type.+ const [latest] = await engine.executeRaw<{ summary: string }>("SELECT summary FROM ingest_log WHERE source_type = 'connector' ORDER BY created_at DESC, id DESC LIMIT 1");if (latest && /DRIFT/.test(latest.summary)) {problems.push('last connector sync reported format drift — the provider API shape may have changed');}diff --git a/test/doctor-bound-unknown-7145.test.ts b/test/doctor-bound-unknown-7145.test.tsindex 5d71ad66e6..6c3141f289 100644--- a/test/doctor-bound-unknown-7145.test.ts+++ b/test/doctor-bound-unknown-7145.test.ts@@ -16,6 +16,10 @@ import { __setMissingFilesScanLimitForTests } from '../src/core/persistence/detaimport { CONVERSATION_EXTRACTOR_VERSION, TERMINAL_AUDIT_SOURCE } from '../src/core/facts/audit-sources.ts';import type { DoctorContext } from '../src/commands/doctor/context.ts';import type { Check } from '../src/commands/doctor.ts';+import { connectorsHealthCheck } from '../src/commands/doctor/checks/connectors.ts';+import { saveCredential } from '../src/core/connectors/credentials.ts';+import { withEnv } from './helpers/with-env.ts';+import { checkLinkResolutionOpportunity } from '../src/commands/doctor/checks/calibration.ts';const dirs: string[] = [];const tmp = (label: string) => {@@ -116,3 +120,41 @@ describe('conversation_outcomes_stale and missing_recorded_files stopped at theiexpect(found.message).toStartWith('At least 1 live page(s)');}, 60_000);});++describe('connectors drift is read from the newest connector receipt, not a 20-row window', () => {+ test('a drift receipt behind more than 20 newer ingest rows of other types still warns', async () => {+ const home = tmp('connectors-home');+ const engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+ try {+ await engine.executeRaw("INSERT INTO ingest_log(source_type, source_ref, summary, created_at) VALUES('connector', 'chatgpt', 'synced 3; DRIFT: 2 conversations skipped', now() - interval '1 hour')");+ await engine.executeRaw("INSERT INTO ingest_log(source_type, source_ref, summary) SELECT 'facts:absorb', 'synthetic-' || g, 'ok' FROM generate_series(1, 25) g");+ const check = await withEnv({ GBRAIN_HOME: home, GBRAIN_CONNECTOR_CHATGPT_COOKIE: undefined }, async () => {+ saveCredential({ provider: 'chatgpt', strategy: 'browser-session', cookie: 'x', savedAt: '2026-08-25T00:00:00.000Z' });+ return connectorsHealthCheck(engine);+ });+ expect(check.status).toBe('warn');+ expect(check.message).toContain('format drift');+ } finally {+ await engine.disconnect();+ }+ }, 60_000);+});++describe('link_resolution_opportunity names its sample on every verdict', () => {+ test('a brain larger than the sample: the clean verdict says it read a sample and carries exact: false', async () => {+ const engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+ try {+ await engine.executeRaw("INSERT INTO pages(source_id, slug, type, title, compiled_truth, timeline, frontmatter) SELECT 'default', 'notes/n-' || g, 'note', 'n', 'plain text', '', '{}'::jsonb FROM generate_series(1, 1001) g");+ const check = await checkLinkResolutionOpportunity(engine);+ expect(check.status).toBe('ok');+ expect(check.message).toBe('No bare wikilinks found (scanned the 1000 most-recent of 1001 pages)');+ expect(check.details).toMatchObject({ exact: false, bound: 'sample', limit: 1000, total_pages: 1001 });+ } finally {+ await engine.disconnect();+ }+ }, 120_000);+});