Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(doctor): extraction_input_truncated counts only derivation receipts with a kind; synopsis tier receipts are not input truncation

garrytan0347b80c8e8a
diff --git a/src/commands/doctor/checks/extraction-input.ts b/src/commands/doctor/checks/extraction-input.ts
index fce2b657bc..a3cf02ceec 100644
--- a/src/commands/doctor/checks/extraction-input.ts
+++ b/src/commands/doctor/checks/extraction-input.ts
@@ -14,7 +14,9 @@
* derivations keep their receipt per occurrence on page_segment_derivations
* (`unread_windows`: the run stopped before every window was read, at the
* per-page spend cap or a window limit; the next run resumes there). Both tables
- * are read; a page counts once per pipeline and receipt kind.
+ * are read; a page counts once per pipeline and receipt kind. A derivation receipt
+ * without a `kind` (the synopsis pass's tier fallback or refused reservation) is
+ * not an input-truncation receipt and is not counted.
*/
import type { Check } from '../../doctor.ts';
import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';
@@ -46,7 +48,7 @@ async function runExtractionInputTruncatedCheck(ctx: DoctorContext): Promise<Che
FROM page_extraction_state s WHERE s.input_truncated IS NOT NULL
UNION ALL
SELECT d.page_id, d.pipeline, COALESCE(d.receipt->>'kind', 'unknown') AS kind, max(d.updated_at) AS updated_at
- FROM page_segment_derivations d WHERE d.receipt IS NOT NULL GROUP BY 1, 2, 3)
+ FROM page_segment_derivations d WHERE d.receipt->>'kind' IS NOT NULL GROUP BY 1, 2, 3)
SELECT r.pipeline, r.kind, count(DISTINCT r.page_id)::int AS pages,
(array_agg(p.source_id || ':' || p.slug ORDER BY r.updated_at DESC))[1:3] AS samples
FROM receipts r JOIN pages p ON p.id = r.page_id AND p.deleted_at IS NULL
diff --git a/test/helpers/synopsis-segment-hash-cases.ts b/test/helpers/synopsis-segment-hash-cases.ts
index be029de4a3..03bd72ea55 100644
--- a/test/helpers/synopsis-segment-hash-cases.ts
+++ b/test/helpers/synopsis-segment-hash-cases.ts
@@ -33,6 +33,9 @@ import { installSegmentedVectors, readSegmentedEmbedPage } from '../../src/core/
import type { AppendBrain } from './append-brain.ts';
import { needlePage, needlePageBody, sealAtOldChunker } from './rechunk-segmented-cases.ts';
import { runSegmentedRechunk } from '../../src/core/page-body/rechunk.ts';
+import { extractionInputTruncatedEntry } from '../../src/commands/doctor/checks/extraction-input.ts';
+import type { DoctorContext } from '../../src/commands/doctor/context.ts';
+import type { Check } from '../../src/commands/doctor.ts';
const WORDS = ['launch', 'pricing', 'roadmap', 'hiring', 'metrics', 'retention', 'design', 'latency', 'budget', 'customer'];
const paragraph = (d: number, k: number) =>
@@ -351,6 +354,36 @@ export function defineSynopsisSegmentHashCases(opts: { getBrain: () => AppendBra
expect((await synopsisRows(id)).every(r => r.state === 'done')).toBe(true);
}, 300_000);
+ test('doctor: synopsis receipts (a title-tier fallback, a refused reservation) are not extraction truncation and raise no extraction_input_truncated warning', async () => {
+ const brain = opts.getBrain();
+ await roomyCap();
+ const fallbackSlug = 'notes/synopsis-doctor-fallback';
+ await brain.seed(fallbackSlug, page(days(1_300_000).body + '\nDoctor fallback fixture.\n'));
+ refuse = args => args.chunkIndex === 0;
+ try {
+ expect(await run(fallbackSlug)).toMatchObject({ kind: 'page_fallback', fallback_kind: 'refusal' });
+ } finally {
+ refuse = null;
+ }
+ const cappedSlug = 'notes/synopsis-doctor-capped';
+ await brain.seed(cappedSlug, page(days(1_300_000).body + '\nDoctor cap fixture.\n'));
+ await brain.engine.setConfig(PAGE_EMBED_CAP_KEY, '0.000001');
+ try {
+ reset();
+ expect(await run(cappedSlug)).toEqual({ kind: 'skipped', reason: 'budget_limited' });
+ expect(calls.length).toBe(0);
+ } finally {
+ await roomyCap();
+ }
+ const receipts = [...await synopsisRows((await pageRow(fallbackSlug)).id), ...await synopsisRows((await pageRow(cappedSlug)).id)].map(r => r.receipt);
+ expect(receipts).toContainEqual({ fallback_kind: 'refusal' });
+ expect(receipts.some(r => (r as { reason?: string } | null)?.reason === 'budget_limited')).toBe(true);
+ const check = (await extractionInputTruncatedEntry.run({ engine: brain.engine } as unknown as DoctorContext) as Check[]).find(c => c.name === 'extraction_input_truncated')!;
+ const groups = (check.details as { groups: Array<{ pipeline: string; kind: string }> }).groups;
+ expect(groups.filter(g => g.pipeline === 'synopsis')).toEqual([]);
+ expect(check.status).not.toBe('warn');
+ }, 300_000);
+
test('an inline page keeps the synopsisBodyHash input', async () => {
const brain = opts.getBrain();
const slug = 'notes/synopsis-inline';