Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
doctor oversized_pages honors the DB-plane content_sanity.bytes_block (#6526)
garrytan20247153d64f
diff --git a/src/commands/doctor/checks/content-quality.ts b/src/commands/doctor/checks/content-quality.tsindex f0f2a4c7b1..14c833edb8 100644--- a/src/commands/doctor/checks/content-quality.ts+++ b/src/commands/doctor/checks/content-quality.ts@@ -50,15 +50,9 @@ async function runContentSanity(ctx: DoctorContext): Promise<Check[]> {const fullContentAudit = args.includes('--content-audit');progress.heartbeat('oversized_pages');try {- // Read effective bytes_block from the cached effectiveCfg loaded- // earlier in this doctor run if available; otherwise default.- // (We re-read here per-check to avoid threading config through- // every check — bytes_block is read once per doctor run via- // loadConfig which caches in module-level config layer.)- const { loadConfig: _loadCfg } = await import('../../../core/config.ts');- const _cfg = _loadCfg();- const { DEFAULT_BYTES_BLOCK } = await import('../../../core/content-sanity.ts');- const bytesBlock = _cfg?.content_sanity?.bytes_block ?? DEFAULT_BYTES_BLOCK;+ // #6526: the write gate's bytes_block (the DB config plane over file and env),+ // so a `gbrain config set content_sanity.bytes_block N` reaches this check too.+ const bytesBlock = await (await import('../../../core/import-screen.ts')).effectiveBytesBlock(engine);// #1871: engine.executeRaw, not the dead-on-PGLite postgres singleton.const rows = await engine.executeRaw<{ slug: string; source_id: string; bytes: number }>(`SELECT p.slug, p.source_id,diff --git a/src/core/import-screen.ts b/src/core/import-screen.tsindex 2bb85d9adf..346661ea07 100644--- a/src/core/import-screen.ts+++ b/src/core/import-screen.ts@@ -11,7 +11,7 @@import type { BrainEngine } from './engine.ts';import { loadConfig, loadConfigWithEngine } from './config.ts';import { loadConfigSnapshot } from './config-snapshot.ts';-import { assessContentSanity, ContentSanityBlockError, type ContentSanityResult } from './content-sanity.ts';+import { assessContentSanity, ContentSanityBlockError, DEFAULT_BYTES_BLOCK, type ContentSanityResult } from './content-sanity.ts';import { carryStoredQuarantineOverride, dropClassifierMarkers, hasCurrentQuarantineOverride, QUARANTINE_OVERRIDE_KEY, withQuarantineOverride } from './quarantine-override.ts';import { logContentSanityAssessment } from './audit/content-sanity-audit.ts';import { buildEmbedSkipMarker, EMBED_SKIP_KEY } from './embed-skip.ts';@@ -92,6 +92,18 @@ export async function loadImportSanityConfig(engine: BrainEngine): Promise<Impor};}+/**+ * The bytes_block every size check applies: the write gate's resolution (DB+ * config plane over file and env, #6526), capped at the page ceiling, and the+ * ceiling itself when content sanity is disabled. Doctor's oversized_pages and+ * the oversized-page backfill read it, so they agree with the gate.+ */+export async function effectiveBytesBlock(engine: BrainEngine): Promise<number> {+ const sanity = await loadImportSanityConfig(engine);+ const block = sanity.disabled ? PAGE_MAX_BYTES : (sanity.cs.bytes_block ?? DEFAULT_BYTES_BLOCK);+ return Math.min(block, PAGE_MAX_BYTES);+}+export interface ContentDispositionContext {slug: string;sourceId?: string;diff --git a/src/core/oversized-backfill.ts b/src/core/oversized-backfill.tsindex f45c5dd6f3..7bfd588589 100644--- a/src/core/oversized-backfill.ts+++ b/src/core/oversized-backfill.ts@@ -35,8 +35,7 @@ import type { OperationContext } from './ops/contract.ts';import { managedPersistenceEnabled } from './persistence/ownership.ts';import { submitPageMutation } from './persistence/page-mutations.ts';import { resolveCliWriteWaitMs } from './persistence/write-wait.ts';-import { loadImportSanityConfig } from './import-screen.ts';-import { DEFAULT_BYTES_BLOCK } from './content-sanity.ts';+import { effectiveBytesBlock } from './import-screen.ts';import { PAGE_MAX_BYTES, isLargePageBytes } from './page-size-policy.ts';import { estimatePageEmbedUsd, holdPageEmbedding } from './page-embedding-budget.ts';import { currentEmbeddingSignature } from './embedding.ts';@@ -70,12 +69,6 @@ export interface OversizedBackfillReceipt {commands: { finish: string[]; approve: string[]; preview: string[] };}-async function effectiveBlockBytes(engine: BrainEngine): Promise<number> {- const sanity = await loadImportSanityConfig(engine);- const block = sanity.disabled ? PAGE_MAX_BYTES : (sanity.cs.bytes_block ?? DEFAULT_BYTES_BLOCK);- return Math.min(block, PAGE_MAX_BYTES);-}-interface Candidate { id: number; slug: string; source_id: string; bytes: number }async function listCandidates(engine: BrainEngine, block: number, opts: { sourceId?: string; afterId: number; limit: number }): Promise<Candidate[]> {@@ -124,7 +117,7 @@ export async function runOversizedBackfill(engine: BrainEngine, opts: {} = {}): Promise<OversizedBackfillReceipt> {const now = opts.now ?? Date.now;const started = now();- const block = await effectiveBlockBytes(engine);+ const block = await effectiveBytesBlock(engine);const before = await countMarked(engine, block, opts.sourceId);const embeddingEnabled = loadConfig()?.embedding_disabled !== true;const scope = opts.sourceId ? ['--source', opts.sourceId] : [];@@ -198,7 +191,7 @@ export function formatOversizedBackfillReceipt(r: OversizedBackfillReceipt): str*/export async function printOversizedBackfillUpgradeNotice(engine: BrainEngine): Promise<void> {try {- const block = await effectiveBlockBytes(engine);+ const block = await effectiveBytesBlock(engine);if ((await countMarked(engine, block, undefined)).under === 0) return;const receipt = await runOversizedBackfill(engine, { deadlineMs: 120_000 });const lines = ['', ...formatOversizedBackfillReceipt(receipt)];diff --git a/test/doctor-behavioral.test.ts b/test/doctor-behavioral.test.tsindex 5746cbbeaf..a6edb86ca8 100644--- a/test/doctor-behavioral.test.ts+++ b/test/doctor-behavioral.test.ts@@ -301,6 +301,34 @@ describe('buildChecks — orchestrator against PGLite', () => {expect(oversized!.message).toContain('oversized-embed-skip-absent-probe');});+ test('#6526: oversized_pages honors a DB-plane content_sanity.bytes_block override', async () => {+ // The check read bytes_block from the file and env planes only (loadConfig), so a+ // `gbrain config set content_sanity.bytes_block N` that the write gate honors never+ // reached it. It now uses the gate's resolution (import-screen.ts effectiveBytesBlock).+ // The page sits between the operator's 500_000 and the 24 MiB default, with no+ // embed_skip marker, so the DB-plane value alone decides the warn.+ const lowered = 500_000;+ await engine.setConfig('content_sanity.bytes_block', String(lowered));+ try {+ const big = 'oversized page body prose for the db-plane override probe. '.repeat(11_000); // ~650KB+ await engine.putPage('wiki/oversized-db-plane-probe', {+ type: 'note',+ title: 'Oversized DB-Plane Probe',+ compiled_truth: big,+ timeline: '',+ });++ const checks = await buildChecks(engine, []);+ const oversized = checks.find(c => c.name === 'oversized_pages');+ expect(oversized).toBeDefined();+ expect(oversized!.status).toBe('warn');+ expect(oversized!.message).toContain('oversized-db-plane-probe');+ expect(oversized!.message).toContain(`${lowered}`);+ } finally {+ await engine.unsetConfig('content_sanity.bytes_block');+ }+ });+test('mixed-outcome render path: synthesized checks aggregate as expected', () => {// The orchestrator's render path (outputResults in the wrapper) reads// the same DoctorReport.status enum we compute here. Pin the