Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
refactor(doctor): generic 'Could not ...' sites go through checkError(); no human-only or source-tree fixes (E1)
garrytanf1ec98b2fbd2
diff --git a/src/commands/doctor/checks/calibration.ts b/src/commands/doctor/checks/calibration.tsindex e969d6f2d5..ef50520a3f 100644--- a/src/commands/doctor/checks/calibration.ts+++ b/src/commands/doctor/checks/calibration.ts@@ -21,6 +21,8 @@ import { resolveHardExcludes, DEFAULT_HARD_EXCLUDES } from '../../../core/searchimport { escapeLikePattern, buildVisibilityClause } from '../../../core/search/sql-ranking.ts';import { safeChunksFilter } from '../../../core/search/safe-chunks.ts';import type { Check } from '../../doctor.ts';+import { checkError, doctorVerify } from '../check-fix.ts';+import { pricingSetArgv } from '../../../core/budget/no-pricing.ts';// --- v0.36.1.0 calibration doctor checks (T12) ---@@ -128,11 +130,7 @@ export async function checkContextualRetrievalCoverage(details,};} catch (e) {- return {- name: 'contextual_retrieval_coverage',- status: 'warn',- message: `Could not check contextual retrieval coverage: ${e instanceof Error ? e.message : String(e)}`,- };+ return checkError('contextual_retrieval_coverage', 'check contextual retrieval coverage', e);}}@@ -218,11 +216,7 @@ export async function checkHiddenBySearchPolicy(engine: BrainEngine): Promise<Chdetails: { prefixes, counts },};} catch (e) {- return {- name,- status: 'warn',- message: `Could not check hidden-by-search-policy: ${e instanceof Error ? e.message : String(e)}`,- };+ return checkError(name, 'check hidden-by-search-policy', e);}}@@ -367,11 +361,7 @@ export async function checkAbandonedThreads(engine: BrainEngine): Promise<Check>message: `${count} high-conviction take(s) older than 12 months and never revisited — see \`gbrain calibration\` for details`,};} catch (e) {- return {- name: 'abandoned_threads',- status: 'warn',- message: `Could not check abandoned threads: ${e instanceof Error ? e.message : String(e)}`,- };+ return checkError('abandoned_threads', 'check abandoned threads', e);}}@@ -415,11 +405,7 @@ export async function checkCalibrationFreshness(engine: BrainEngine): Promise<Chmessage: `Calibration profile generated ${ageDays}d ago`,};} catch (e) {- return {- name: 'calibration_freshness',- status: 'warn',- message: `Could not check calibration freshness: ${e instanceof Error ? e.message : String(e)}`,- };+ return checkError('calibration_freshness', 'check calibration freshness', e);}}@@ -459,11 +445,7 @@ export async function checkGradeConfidenceDrift(engine: BrainEngine): Promise<Chmessage: `${applied} auto-applied verdicts; drift math arrives in v0.37+`,};} catch (e) {- return {- name: 'grade_confidence_drift',- status: 'warn',- message: `Could not check grade confidence drift: ${e instanceof Error ? e.message : String(e)}`,- };+ return checkError('grade_confidence_drift', 'check grade confidence drift', e);}}@@ -566,7 +548,8 @@ export async function checkVoiceGateHealth(engine: BrainEngine): Promise<Check>return {name: 'voice_gate_health',status: 'warn',- message: `Voice gate failed ${failures}/${total} (${Math.round(failRate * 100)}%) in last 7 days. Review src/core/calibration/voice-gate.ts rubric.`,+ message: `Voice gate failed ${failures}/${total} (${Math.round(failRate * 100)}%) in last 7 days: the calibration voice gate rejects most generated profiles. That is a gbrain quality issue, not something to change locally; report it with \`gbrain doctor --json\` output.`,+ fix_unavailable_reason: 'operator_judgement',};}return {@@ -575,11 +558,7 @@ export async function checkVoiceGateHealth(engine: BrainEngine): Promise<Check>message: `Voice gate ${failures}/${total} failed in last 7 days (${Math.round(failRate * 100)}%)`,};} catch (e) {- return {- name: 'voice_gate_health',- status: 'warn',- message: `Could not check voice gate health: ${e instanceof Error ? e.message : String(e)}`,- };+ return checkError('voice_gate_health', 'check voice gate health', e);}}@@ -690,7 +669,16 @@ export async function checkRerankerHealth(engine: BrainEngine, now: Date = new Dreturn {name: 'reranker_health',status: 'warn',- message: `${budgetFails.length} reranker budget/pricing failure(s) in last 7 days. Fix: add rerank pricing to src/core/embedding-pricing.ts or drop --max-cost.`,+ message: `${budgetFails.length} reranker budget/pricing failure(s) in last 7 days: ${model} has no registered price, so capped searches skip reranking. Register its per-token rate (look it up on the provider's pricing page) or drop --max-cost.`,+ fix: {+ argv: pricingSetArgv(model, 'rerank'), consent: [], actor: 'agent', requires_exclusive: false,+ why: `Registers ${model}'s price so spend caps can account for reranking.`,+ inputs: [+ { name: 'usd-per-1M-tokens', how: `Look up ${model}'s price per 1M tokens on the provider's pricing page (for example by web search).` },+ { name: 'pricing-page-url', how: 'The URL you read the price from.' },+ ],+ verify: doctorVerify('reranker_health'),+ },};}@@ -748,10 +736,6 @@ export async function checkRerankerHealth(engine: BrainEngine, now: Date = new D};} catch (e) {const msg = e instanceof Error ? e.message : String(e);- return {- name: 'reranker_health',- status: 'warn',- message: `Could not check reranker audit: ${msg}`,- };+ return checkError('reranker_health', 'check reranker audit', msg);}}diff --git a/src/commands/doctor/checks/consolidation-cycle.ts b/src/commands/doctor/checks/consolidation-cycle.tsindex 36da2b4e34..4ffbfc7fec 100644--- a/src/commands/doctor/checks/consolidation-cycle.ts+++ b/src/commands/doctor/checks/consolidation-cycle.ts@@ -60,11 +60,7 @@ export async function checkSyncConsolidation(engine: BrainEngine): Promise<Check'future sources auto-pick-up without a crontab edit.',};} catch (err) {- return {- name: 'sync_consolidation',- status: 'warn',- message: `Could not check sync consolidation: ${err instanceof Error ? err.message : String(err)}`,- };+ return checkError('sync_consolidation', 'check sync consolidation', err);}}diff --git a/src/commands/doctor/checks/content-quality.ts b/src/commands/doctor/checks/content-quality.tsindex ba5f1eab12..0878206d01 100644--- a/src/commands/doctor/checks/content-quality.ts+++ b/src/commands/doctor/checks/content-quality.ts@@ -12,6 +12,7 @@ import { startHeartbeat } from '../../../core/progress.ts';import { checkUnverifiedExtractions } from './extraction-sync.ts';import type { Check } from '../../doctor.ts';import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';+import { checkError } from '../check-fix.ts';async function runContentSanity(ctx: DoctorContext): Promise<Check[]> {const { args, progress } = ctx;@@ -409,11 +410,7 @@ async function runFrontmatter(ctx: DoctorContext): Promise<Check[]> {// OOM, disk full, etc.). Pre-v0.38.2.0 (PR #1287) had an unreachable// abort-classifier branch here; removed because timer-based aborts// in a sync walker can't surface as a thrown error anyway.- checks.push({- name: 'frontmatter_integrity',- status: 'warn',- message: `Could not scan frontmatter: ${e instanceof Error ? e.message : String(e)}`,- });+ checks.push(checkError('frontmatter_integrity', 'scan frontmatter', e));} finally {fmHb();}diff --git a/src/commands/doctor/checks/conversation-coverage.ts b/src/commands/doctor/checks/conversation-coverage.tsindex ef743a9d2d..7c91f0a400 100644--- a/src/commands/doctor/checks/conversation-coverage.ts+++ b/src/commands/doctor/checks/conversation-coverage.ts@@ -12,6 +12,7 @@import type { BrainEngine } from '../../../core/engine.ts';import { ALLOWED_TYPES, isConversationFactsEligiblePage, requireParseableConversationFlag } from '../../../core/facts/conversation-types.ts';import type { Check } from '../../doctor.ts';+import { checkError } from '../check-fix.ts';export async function computeConversationFormatCoverageCheck(engine: BrainEngine,@@ -80,10 +81,6 @@ export async function computeConversationFormatCoverageCheck(message: `${sample.length} pages: ${breakdown}`,};} catch (err) {- return {- name,- status: 'warn',- message: `Could not check conversation format coverage: ${(err as Error)?.message ?? String(err)}`,- };+ return checkError(name, 'check conversation format coverage', err);}}diff --git a/src/commands/doctor/checks/core-health.ts b/src/commands/doctor/checks/core-health.tsindex 0c913a82a9..39a6aed75c 100644--- a/src/commands/doctor/checks/core-health.ts+++ b/src/commands/doctor/checks/core-health.ts@@ -14,6 +14,7 @@ import { loadConfig } from '../../../core/config.ts';import type { ProgressReporter } from '../../../core/progress.ts';import type { Check } from '../../doctor.ts';import { PAGE_CHILD_FK_TARGETS, orphanPredicate } from '../../../core/repair/orphan-children.ts';+import { checkError } from '../check-fix.ts';/*** Doctor check: takes.weight grid integrity (v0.32 — EXP-2).@@ -124,11 +125,7 @@ export async function whoknowsHealthCheck(_engine: BrainEngine): Promise<Check>};} catch (e) {const msg = e instanceof Error ? e.message : String(e);- return {- name: 'whoknows_health',- status: 'warn',- message: `Could not check whoknows fixture: ${msg}`,- };+ return checkError('whoknows_health', 'check whoknows fixture', msg);}}@@ -150,7 +147,7 @@ export async function pgvectorCheck(engine: BrainEngine): Promise<Check> {}return { name: 'pgvector', status: 'fail', message: 'Extension not found. Run: CREATE EXTENSION vector;' };} catch {- return { name: 'pgvector', status: 'warn', message: 'Could not check pgvector extension' };+ return checkError('pgvector', 'check pgvector extension');}}@@ -188,7 +185,7 @@ export async function pagesUpsertArbiterCheck(engine: BrainEngine): Promise<Chec`Run \`gbrain apply-migrations --yes\` to heal it.`,};} catch {- return { name: 'pages_upsert_arbiter', status: 'warn', message: 'Could not check the pages upsert arbiter' };+ return checkError('pages_upsert_arbiter', 'check the pages upsert arbiter');}}@@ -231,7 +228,7 @@ export async function linkSourceCheckConstraintCheck(engine: BrainEngine): Promi: `links_link_source_check is NOT VALID — existing rows were never validated. ${heal}`,};} catch {- return { name, status: 'warn', message: 'Could not check the links_link_source_check constraint' };+ return checkError(name, 'check the links_link_source_check constraint');}}@@ -292,7 +289,7 @@ export async function jsonbIntegrityCheck(message: `${totalBad} row(s) double-encoded (${breakdown.join(', ')}). Fix: gbrain repair-jsonb`,};} catch {- return { name: 'jsonb_integrity', status: 'warn', message: 'Could not check JSONB integrity' };+ return checkError('jsonb_integrity', 'check JSONB integrity');}}@@ -448,11 +445,7 @@ export async function takesWeightGridCheck(engine: BrainEngine): Promise<Check>} catch (e) {const msg = e instanceof Error ? e.message : String(e);// takes table missing on a fresh pre-v37 brain — warn, don't fail.- return {- name: 'takes_weight_grid',- status: 'warn',- message: `Could not check takes weight grid: ${msg}`,- };+ return checkError('takes_weight_grid', 'check takes weight grid', msg);}}@@ -580,7 +573,7 @@ export async function rawProvenanceCheck(engine: BrainEngine): Promise<Check> {`raw_trace_exempt_reason in frontmatter. Warn-only (#1978).`,};} catch {- return { name: 'raw_provenance', status: 'warn', message: 'Could not check raw provenance (older schema?)' };+ return checkError('raw_provenance', 'check raw provenance (older schema?)');}}diff --git a/src/commands/doctor/checks/embedding-health.ts b/src/commands/doctor/checks/embedding-health.tsindex c292bb9232..ceb86f81a7 100644--- a/src/commands/doctor/checks/embedding-health.ts+++ b/src/commands/doctor/checks/embedding-health.ts@@ -16,7 +16,7 @@ import { credentialEnvName, keyShadowWarning } from '../../../core/ai/key-warninimport { getRecipe } from '../../../core/ai/recipes/index.ts';import type { Check } from '../../doctor.ts';import { embeddingsDisabled } from '../../../core/embedding-disabled.ts';-import { infoCheck, keylessEnablementFix } from '../check-fix.ts';+import { checkError, infoCheck, keylessEnablementFix } from '../check-fix.ts';import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';async function runEmbeddingProvider(ctx: DoctorContext): Promise<Check[]> {@@ -410,11 +410,7 @@ async function runEmbeddingColumnRegistry(ctx: DoctorContext): Promise<Check[]>} catch (err) {// Pre-config brains, registry-validation throws, etc. Surfaces the// error message but doesn't fail the doctor run.- checks.push({- name: 'embedding_column_registry',- status: 'warn',- message: `Could not check embedding column registry: ${(err as Error).message}`,- });+ checks.push(checkError('embedding_column_registry', 'check embedding column registry', err));}return checks;}diff --git a/src/commands/doctor/checks/extraction-sync.ts b/src/commands/doctor/checks/extraction-sync.tsindex 4732fab05a..bca0ce33bb 100644--- a/src/commands/doctor/checks/extraction-sync.ts+++ b/src/commands/doctor/checks/extraction-sync.ts@@ -31,6 +31,7 @@ import type { Check } from '../../doctor.ts';import { ownedContentFreshness } from '../../../core/shared-skills/content-freshness.ts';import { connectorAuthorities } from '../../../core/persistence/connector-authority.ts';import { parseSourceConfig } from '../../../core/sources-load.ts';+import { checkError } from '../check-fix.ts';/** Local aliases; the shared warn-once memo lives in core so it can't fork per module. */const _resolveEnvNumber = resolveEnvNumber;@@ -172,7 +173,7 @@ export async function checkLinksExtractionLag(if (isUndefinedColumnError(e, 'links_extracted_at')) {return { name, status: 'ok', message: 'links_extracted_at not present (pre-v112 brain)' };}- return { name, status: 'warn', message: `Could not check links_extraction_lag: ${(e as Error).message}` };+ return checkError(name, 'check links_extraction_lag', e);}}@@ -218,7 +219,7 @@ export async function checkUnverifiedExtractions(details: { count: n, days, source_id: sourceId ?? null },};} catch (e) {- return { name, status: 'warn', message: `Could not check unverified_extractions: ${(e as Error).message}` };+ return checkError(name, 'check unverified_extractions', e);}}@@ -302,7 +303,7 @@ export async function checkContentHashDuplicates(engine: BrainEngine): Promise<C},};} catch (e) {- return { name, status: 'warn', message: `Could not check content-hash duplicates: ${(e as Error).message}` };+ return checkError(name, 'check content-hash duplicates', e);}}@@ -344,7 +345,7 @@ export async function checkCodeChunkMetadata(engine: BrainEngine): Promise<Checkdetails: { chunks_missing_metadata: chunks, pages_affected: pages },};} catch (e) {- return { name, status: 'warn', message: `Could not check code chunk metadata: ${(e as Error).message}` };+ return checkError(name, 'check code chunk metadata', e);}}@@ -462,7 +463,7 @@ export async function checkUndeclaredDbOnlyPages(engine: BrainEngine): Promise<Cdetails: { total, per_source: perSource, sample_slugs: samples },};} catch (e) {- return { name, status: 'warn', message: `Could not check undeclared db-only pages: ${(e as Error).message}` };+ return checkError(name, 'check undeclared db-only pages', e);}}@@ -525,7 +526,7 @@ export async function checkDbOnlyCollectorCollision(details: { collisions: hits },};} catch (e) {- return { name, status: 'warn', message: `Could not check collector/db_only collisions: ${(e as Error).message}` };+ return checkError(name, 'check collector/db_only collisions', e);}}@@ -1482,10 +1483,6 @@ export async function checkSyncFreshness(details,};} catch (e) {- return {- name: 'sync_freshness',- status: 'warn',- message: `Could not check sync freshness: ${e instanceof Error ? e.message : String(e)}`,- };+ return checkError('sync_freshness', 'check sync freshness', e);}}diff --git a/src/commands/doctor/checks/graph-embedding.ts b/src/commands/doctor/checks/graph-embedding.tsindex 33a94ce362..46d80ba52d 100644--- a/src/commands/doctor/checks/graph-embedding.ts+++ b/src/commands/doctor/checks/graph-embedding.ts@@ -7,6 +7,7 @@import { loadConfigFileOnly } from '../../../core/config.ts';import type { BrainEngine } from '../../../core/engine.ts';import type { Check } from '../../doctor.ts';+import { checkError } from '../check-fix.ts';/*** v0.40.4 graph_signals_coverage doctor check.@@ -106,11 +107,7 @@ export async function checkGraphSignalsCoverage(engine: BrainEngine): Promise<Ch};} catch (e) {const msg = e instanceof Error ? e.message : String(e);- return {- name: 'graph_signals_coverage',- status: 'warn',- message: `Could not check graph_signals_coverage: ${msg}`,- };+ return checkError('graph_signals_coverage', 'check graph_signals_coverage', msg);}}@@ -297,11 +294,7 @@ export async function checkEmbeddingWidthConsistency(engine: BrainEngine): Promi};} catch (e) {const msg = e instanceof Error ? e.message : String(e);- return {- name: 'embedding_width_consistency',- status: 'warn',- message: `Could not check embedding width: ${msg}`,- };+ return checkError('embedding_width_consistency', 'check embedding width', msg);}}@@ -382,11 +375,7 @@ export async function checkFactsEmbeddingWidthConsistency(engine: BrainEngine):};} catch (e) {const msg = e instanceof Error ? e.message : String(e);- return {- name: 'facts_embedding_width_consistency',- status: 'warn',- message: `Could not check facts.embedding width: ${msg}`,- };+ return checkError('facts_embedding_width_consistency', 'check facts.embedding width', msg);}}@@ -499,10 +488,6 @@ export async function checkJunkEntityHubs(};} catch (e) {const msg = e instanceof Error ? e.message : String(e);- return {- name: 'junk_entity_hubs',- status: 'warn',- message: `Could not check for junk entity hubs: ${msg}`,- };+ return checkError('junk_entity_hubs', 'check for junk entity hubs', msg);}}diff --git a/src/commands/doctor/checks/graph-health.ts b/src/commands/doctor/checks/graph-health.tsindex bc89a8cd17..40f8ae44a0 100644--- a/src/commands/doctor/checks/graph-health.ts+++ b/src/commands/doctor/checks/graph-health.ts@@ -11,6 +11,7 @@ import { startHeartbeat } from '../../../core/progress.ts';import { quarantineFilterFragment } from '../../../core/quarantine.ts';import type { Check } from '../../doctor.ts';import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';+import { checkError } from '../check-fix.ts';async function runGraphCoverage(ctx: DoctorContext): Promise<Check[]> {const { progress } = ctx;@@ -115,7 +116,7 @@ async function runGraphCoverage(ctx: DoctorContext): Promise<Check[]> {checks.push({ name: 'brain_score', status: 'ok', message: `Brain score 100/100` });}} catch {- checks.push({ name: 'graph_coverage', status: 'warn', message: 'Could not check graph coverage' });+ checks.push(checkError('graph_coverage', 'check graph coverage'));}return checks;}@@ -202,7 +203,7 @@ async function runOrphanRatio(ctx: DoctorContext): Promise<Check[]> {}}} catch {- checks.push({ name: 'orphan_ratio', status: 'warn', message: 'Could not check orphan ratio' });+ checks.push(checkError('orphan_ratio', 'check orphan ratio'));}return checks;}diff --git a/src/commands/doctor/checks/knowledge-health.ts b/src/commands/doctor/checks/knowledge-health.tsindex daaf3d5a9f..c954f79126 100644--- a/src/commands/doctor/checks/knowledge-health.ts+++ b/src/commands/doctor/checks/knowledge-health.ts@@ -12,6 +12,7 @@ import { computeEffectiveDate } from '../../../core/effective-date.ts';import { zeroTotalContradictionsCheck } from '../../../core/eval-contradictions/run-health.ts';import type { Check } from '../../doctor.ts';import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';+import { checkError, doctorVerify } from '../check-fix.ts';async function runEvalCapture(ctx: DoctorContext): Promise<Check[]> {const { progress } = ctx;@@ -43,8 +44,13 @@ async function runEvalCapture(ctx: DoctorContext): Promise<Check[]> {name: 'eval_capture',status: 'warn',message: `${failures.length} capture failure(s) in the last 24h (${breakdown}). ` +- `If you care about replay fidelity, investigate. If not, set eval.capture: false ` +- `in ~/.gbrain/config.json to silence.`,+ 'Captured queries feed retrieval evals; if the user does not use them, capture can be turned off.',+ fix: {+ argv: ['gbrain', 'config', 'set', 'eval.capture', 'false'], consent: [], actor: 'user', requires_exclusive: false,+ why: 'Query capture only feeds retrieval evals (gbrain eval export/replay). Turning it off stops these failures; it is the user\'s preference, so ask first.',+ user_message: 'gbrain failed to record some queries for its retrieval evals. If you don\'t run gbrain evals, I can turn query capture off. Should I?',+ verify: doctorVerify('eval_capture'),+ },});}} catch (err) {@@ -62,11 +68,7 @@ async function runEvalCapture(ctx: DoctorContext): Promise<Check[]> {message: 'RLS denies SELECT on eval_capture_failures. Capture INSERTs are almost certainly failing too. Run as a role with BYPASSRLS or grant SELECT on this table.',});} else {- checks.push({- name: 'eval_capture',- status: 'warn',- message: `Could not read eval_capture_failures: ${(err as Error)?.message ?? String(err)}`,- });+ checks.push(checkError('eval_capture', 'read eval_capture_failures', err));}}return checks;@@ -153,11 +155,7 @@ async function runContradictions(ctx: DoctorContext): Promise<Check[]> {if (code === '42P01') {checks.push({ name: 'contradictions', status: 'ok', message: 'Skipped (eval_contradictions_runs table unavailable — apply migrations to enable)' });} else {- checks.push({- name: 'contradictions',- status: 'warn',- message: `Could not read contradictions trend: ${(err as Error)?.message ?? String(err)}`,- });+ checks.push(checkError('contradictions', 'read contradictions trend', err));}}return checks;@@ -294,11 +292,7 @@ async function runFactsExtraction(ctx: DoctorContext): Promise<Check[]> {message: 'RLS denies SELECT on ingest_log. The check can\'t see facts:absorb rows. Run as a BYPASSRLS role or grant SELECT on this table.',});} else {- checks.push({- name: 'facts_extraction_health',- status: 'warn',- message: `Could not read ingest_log for facts:absorb: ${(err as Error)?.message ?? String(err)}`,- });+ checks.push(checkError('facts_extraction_health', 'read ingest_log for facts:absorb', err));}}return checks;@@ -430,7 +424,7 @@ async function runEffectiveDate(ctx: DoctorContext): Promise<Check[]> {// column doesn't exist — pre-v0.29.1 brainchecks.push({ name: 'effective_date_health', status: 'ok', message: 'Skipped (effective_date column unavailable — run gbrain apply-migrations)' });} else {- checks.push({ name: 'effective_date_health', status: 'warn', message: `Could not read pages: ${(err as Error)?.message ?? String(err)}` });+ checks.push(checkError('effective_date_health', 'read pages', err));}}return checks;@@ -489,7 +483,7 @@ async function runSalience(ctx: DoctorContext): Promise<Check[]> {if (code === '42703' || code === '42P01') {checks.push({ name: 'salience_health', status: 'ok', message: 'Skipped (emotional_weight or takes table unavailable — pre-v0.29 brain)' });} else {- checks.push({ name: 'salience_health', status: 'warn', message: `Could not read pages: ${(err as Error)?.message ?? String(err)}` });+ checks.push(checkError('salience_health', 'read pages', err));}}return checks;diff --git a/src/commands/doctor/checks/local-runtime.ts b/src/commands/doctor/checks/local-runtime.tsindex 271ee2b2bd..2c0654ff91 100644--- a/src/commands/doctor/checks/local-runtime.ts+++ b/src/commands/doctor/checks/local-runtime.ts@@ -15,6 +15,7 @@ import { buildMemoryWritebackCheck } from './memory-writeback.ts';import { checkBunRuntime, checkSelfUpgradeHealth, checkUpgradeErrors } from './upgrade-health.ts';import type { Check } from '../../doctor.ts';import type { DoctorContext, DoctorEntry } from '../context.ts';+import { checkError } from '../check-fix.ts';async function runBootstrapChecks(ctx: DoctorContext): Promise<Check[]> {const { engine } = ctx;@@ -91,7 +92,7 @@ async function runConnectors(ctx: DoctorContext): Promise<Check[]> {const { dreamPaidLoopCheck } = await import('./dream-breaker.ts');checks.push(await dreamPaidLoopCheck(engine));} catch (e) {- checks.push({ name: 'dream_paid_loop', status: 'warn', message: `Could not count dead dream submissions: ${e instanceof Error ? e.message : String(e)}` });+ checks.push(checkError('dream_paid_loop', 'count dead dream submissions', e));}}return checks;diff --git a/src/commands/doctor/checks/postgres-cancellation.ts b/src/commands/doctor/checks/postgres-cancellation.tsindex cd498519bb..44dd37baef 100644--- a/src/commands/doctor/checks/postgres-cancellation.ts+++ b/src/commands/doctor/checks/postgres-cancellation.ts@@ -2,6 +2,7 @@ import type { BrainEngine } from '../../../core/engine.ts';import type { PostgresEngine } from '../../../core/postgres-engine.ts';import { hasPostgresCancellationCapability, postgresCancellationUnavailable, reserveWithCancellation } from '../../../core/postgres-engine/cancellation.ts';import type { Check } from '../../doctor.ts';+import { checkError } from '../check-fix.ts';export async function checkPostgresCancellationDriver(engine: BrainEngine,@@ -28,11 +29,7 @@ export async function checkPostgresCancellationDriver(message: 'Postgres driver supports safe query cancellation.',};} catch {- return {- name: 'postgres_cancellation_driver',- status: 'warn',- message: 'Could not inspect a reserved Postgres connection within the readiness budget. Check database connectivity and retry; a timeout does not prove a driver fault.',- };+ return checkError('postgres_cancellation_driver', 'inspect a reserved Postgres connection within the readiness budget. Check database connectivity and retry; a timeout does not prove a driver fault.');} finally {clearTimeout(timer);owner?.release();diff --git a/src/commands/doctor/checks/queue-jobs.ts b/src/commands/doctor/checks/queue-jobs.tsindex 1cd53d6cbd..b6fa60885b 100644--- a/src/commands/doctor/checks/queue-jobs.ts+++ b/src/commands/doctor/checks/queue-jobs.ts@@ -7,6 +7,7 @@import type { BrainEngine } from '../../../core/engine.ts';import { resolveEnvNumber } from '../../../core/env-number.ts';import type { Check } from '../../doctor.ts';+import { checkError } from '../check-fix.ts';/** Local alias; the shared warn-once memo lives in core so it can't fork per module. */const _resolveEnvNumber = resolveEnvNumber;@@ -806,10 +807,6 @@ export async function checkBatchRetryHealth(_engine: BrainEngine): Promise<Check};} catch (e) {const msg = e instanceof Error ? e.message : String(e);- return {- name: 'batch_retry_health',- status: 'warn',- message: `Could not check batch_retry audit: ${msg}`,- };+ return checkError('batch_retry_health', 'check batch_retry audit', msg);}}diff --git a/src/commands/doctor/checks/schema-health.ts b/src/commands/doctor/checks/schema-health.tsindex e71648ed60..f38c4f94ea 100644--- a/src/commands/doctor/checks/schema-health.ts+++ b/src/commands/doctor/checks/schema-health.ts@@ -21,7 +21,7 @@ import { checkProjectionReadiness } from './projection-readiness.ts';import type { Check } from '../../doctor.ts';import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';import { embeddingsDisabled } from '../../../core/embedding-disabled.ts';-import { infoCheck, keylessEnablementFix } from '../check-fix.ts';+import { checkError, infoCheck, keylessEnablementFix } from '../check-fix.ts';async function runPgvector(ctx: DoctorContext): Promise<Check[]> {const { progress } = ctx;@@ -170,7 +170,7 @@ async function runRls(ctx: DoctorContext): Promise<Check[]> {});}} catch {- checks.push({ name: 'rls', status: 'warn', message: 'Could not check RLS status' });+ checks.push(checkError('rls', 'check RLS status'));}}return checks;@@ -230,11 +230,11 @@ async function runSchemaVersion(ctx: DoctorContext): Promise<Check[]> {});}} catch {- checks.push({ name: 'schema_columns', status: 'warn', message: 'Could not verify live schema columns' });+ checks.push(checkError('schema_columns', 'verify live schema columns'));}}} catch {- checks.push({ name: 'schema_version', status: 'warn', message: 'Could not check schema version' });+ checks.push(checkError('schema_version', 'check schema version'));}ctx.schemaVersion = schemaVersion;return checks;@@ -307,11 +307,7 @@ async function runRlsEventTrigger(ctx: DoctorContext): Promise<Check[]> {});}} catch {- checks.push({- name: 'rls_event_trigger',- status: 'warn',- message: 'Could not check RLS event trigger',- });+ checks.push(checkError('rls_event_trigger', 'check RLS event trigger'));}}return checks;@@ -372,7 +368,7 @@ async function runEmbeddings(ctx: DoctorContext): Promise<Check[]> {checks.push({ name: 'embeddings', status: 'warn', message: `No embeddings yet${carveOut}. Backlog: ${backlog} chunk(s) without embeddings. ${fixText}`, details: backlogDetails });}} catch {- checks.push({ name: 'embeddings', status: 'warn', message: 'Could not check embedding health' });+ checks.push(checkError('embeddings', 'check embedding health'));}return checks;}diff --git a/src/commands/doctor/checks/search-eval.ts b/src/commands/doctor/checks/search-eval.tsindex c7110bd900..fe7f98e430 100644--- a/src/commands/doctor/checks/search-eval.ts+++ b/src/commands/doctor/checks/search-eval.ts@@ -10,6 +10,7 @@ import { loadConfig, type GBrainConfig } from '../../../core/config.ts';// Leaf module (no flag surface of its own) — see that file for why this// isn't imported from extract-conversation-facts.ts directly (#4135).import { ALLOWED_TYPES, conversationFactsEligibleSql, pageTypesForAllowed, isConversationFactsEligiblePage, requireParseableConversationFlag } from '../../../core/facts/conversation-types.ts';+import { checkError } from '../check-fix.ts';function hasNonEmptyChatFallbackChain(value: unknown): boolean {if (Array.isArray(value)) {@@ -392,11 +393,7 @@ export async function checkSubagentCapability(engine: BrainEngine): Promise<Chec: `Subagent tier resolves to default (claude-sonnet-4-6) — full tool-loop capability`,};} catch (e) {- return {- name: 'subagent_capability',- status: 'warn',- message: `Could not check subagent capability: ${e instanceof Error ? e.message : String(e)}`,- };+ return checkError('subagent_capability', 'check subagent capability', e);}}diff --git a/src/commands/doctor/checks/skill-group.ts b/src/commands/doctor/checks/skill-group.tsindex b14b7e1622..13d1d291b6 100644--- a/src/commands/doctor/checks/skill-group.ts+++ b/src/commands/doctor/checks/skill-group.ts@@ -20,6 +20,7 @@ import { checkVolunteerChannels } from './core-health.ts';import { buildRetrievalReflexCheck, buildMemoryVerbsCheck } from './verbs-reflex.ts';import type { Check } from '../../doctor.ts';import type { DoctorContext, DoctorEntry } from '../context.ts';+import { checkError } from '../check-fix.ts';async function runResolverHealth(ctx: DoctorContext): Promise<Check[]> {const { skillsDirResolution: detected, doFix, dryRun, jsonOutput, scope } = ctx;@@ -76,7 +77,7 @@ async function runResolverHealth(ctx: DoctorContext): Promise<Check[]> {checks.push(check);}} else if (scope === 'all') {- checks.push({ name: 'resolver_health', status: 'warn', message: 'Could not find skills directory' });+ checks.push(checkError('resolver_health', 'find skills directory'));}return checks;}diff --git a/src/commands/doctor/report-remote.ts b/src/commands/doctor/report-remote.tsindex 3beae69131..bcfa4c938b 100644--- a/src/commands/doctor/report-remote.ts+++ b/src/commands/doctor/report-remote.ts@@ -62,6 +62,7 @@ import {multiSourceDriftCheck,multiSourceDriftNotVerified,} from './schema-pack-checks.ts';+import { checkError } from './check-fix.ts';// Same alias the local doctor keeps for its own freshness checks; the alias// is a private one-liner in doctor.ts's check-fn library, so this module@@ -123,7 +124,7 @@ export async function doctorReportRemote(...schemaVersionHealth(version, LATEST_VERSION, { remote: true }),});} catch {- checks.push({ name: 'schema_version', status: 'warn', message: 'Could not check schema version' });+ checks.push(checkError('schema_version', 'check schema version'));}// 2b. #2038: idx_timeline_dedup shape. A renumbered-during-merge migration@@ -152,7 +153,7 @@ export async function doctorReportRemote(});}} catch {- checks.push({ name: 'timeline_dedup_index', status: 'warn', message: 'Could not check idx_timeline_dedup shape' });+ checks.push(checkError('timeline_dedup_index', 'check idx_timeline_dedup shape'));}// 2c. #550: pages(source_id, slug) upsert arbiter — same drift class as 2b.@@ -205,11 +206,7 @@ export async function doctorReportRemote(message: `Brain score ${score}/100`,});} catch (e) {- checks.push({- name: 'brain_score',- status: 'warn',- message: `Could not compute: ${e instanceof Error ? e.message : String(e)}`,- });+ checks.push(checkError('brain_score', 'compute', e));}// 3b. Migration wedge hint (v0.31.8 — D14 + D19). The brain server'sdiff --git a/src/commands/doctor/skill-checks.ts b/src/commands/doctor/skill-checks.tsindex 1dbcbf4f97..81c4797707 100644--- a/src/commands/doctor/skill-checks.ts+++ b/src/commands/doctor/skill-checks.ts@@ -29,7 +29,7 @@ import {appendAuditEventsForTransitions,} from '../../core/audit-skill-brain-first.ts';import type { Check } from '../doctor.ts';-import { infoCheck } from './check-fix.ts';+import { checkError, infoCheck } from './check-fix.ts';/** Quick skill conformance check — frontmatter + required sections */export function skillConformanceCheck(skillsDir: string): Check {@@ -67,7 +67,7 @@ export function skillConformanceCheck(skillsDir: string): Check {message: `${passing}/${skills.length} pass. Failing: ${failing.join(', ')}`,};} catch {- return { name: 'skill_conformance', status: 'warn', message: 'Could not load or derive skills manifest' };+ return checkError('skill_conformance', 'load or derive skills manifest');}}