Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Keep the sweep links pass under the function-size limit; page-body reader baseline follows cutBlocked
garrytan258b51e55233
diff --git a/scripts/page-body-readers-baseline.tsv b/scripts/page-body-readers-baseline.tsvindex 1d09ef9617..02497dca10 100644--- a/scripts/page-body-readers-baseline.tsv+++ b/scripts/page-body-readers-baseline.tsv@@ -541,6 +541,6 @@ src/eval/brainbench/metrics/trust-reads.ts canaryPersisted sql STREAMsrc/eval/chronicle/harness.ts seedChronicleEvalCorpus call:putPage SEGWsrc/eval/longmemeval/call-plan.ts planPages call:prepareMarkdownChunks INLINEsrc/eval/longmemeval/call-plan.ts planPages field INLINE-src/core/page-body/segmenter.ts Segmenter.blocked field NONE not the page body: st.timeline is the segmenter's timeline-run parser state+src/core/page-body/segmenter.ts cutBlocked field NONE not the page body: st.timeline is the segmenter's timeline-run parser statesrc/core/page-body/segmenter.ts Segmenter.line field NONE not the page body: st.timeline is the segmenter's timeline-run parser statesrc/core/page-body/segmenter.ts Segmenter.piece field NONE not the page body: st.timeline is the segmenter's timeline-run parser statediff --git a/src/core/persistence/canonical-projections.ts b/src/core/persistence/canonical-projections.tsindex 1fdf2f7aee..cff488043c 100644--- a/src/core/persistence/canonical-projections.ts+++ b/src/core/persistence/canonical-projections.ts@@ -188,19 +188,19 @@ async function segmentedPriorView(engine: BrainEngine, page: { id: number; slug:keys.forEach((key, i) => { const at = index.get(key); if (at) at.push(i); else index.set(key, [i]); });const flags = new Uint8Array(keys.length);const mark = (key: string, bit: number) => { for (const i of index.get(key) ?? []) flags[i]! |= bit; };- const takes: Record<BodyRegion, TakesFenceScan> = { truth: new TakesFenceScan(page), timeline: new TakesFenceScan(page) };+ const takes = new Map<BodyRegion, TakesFenceScan>((['truth', 'timeline'] as const).map(region => [region, new TakesFenceScan(page)]));let region: BodyRegion | null = null;let regionAt = 0;for await (const block of bodyBlocks(engine, page)) {if (block.region && block.region !== region) { region = block.region; regionAt = block.at; }- if (block.region) takes[block.region].push({ text: block.text, at: block.at - regionAt });+ if (block.region) takes.get(block.region)!.push({ text: block.text, at: block.at - regionAt });const safe = sanitizeRemoteBody(block.text, { keepMaterializedMarkers: true });for (const t of extractTimelineFromContent(safe, slug)) mark(timelineKey(t), PRIOR_ENTRY);for (const t of parseTimelineEntries(safe)) mark(timelineKey({ ...t, source: t.source ?? 'markdown' }), PRIOR_ENTRY);for (const key of markedTimeline(safe, slug)) mark(key, PRIOR_MARKED);for (const t of supersededCitationTimeline(safe)) mark(timelineKey(t), PRIOR_SUPERSEDED);}- const fields = [takes.truth.result(), takes.timeline.result()];+ const fields = [...takes.values()].map(scan => scan.result());const view: PriorView = {rows: { entry: i => (flags[i]! & PRIOR_ENTRY) !== 0, marked: i => (flags[i]! & PRIOR_MARKED) !== 0, superseded: i => (flags[i]! & PRIOR_SUPERSEDED) !== 0 },takeRows: new Set(fields.flatMap(field => field.parsed.takes.map(t => t.rowNum))), takesWarn: fields.some(field => field.parsed.warnings.length > 0),diff --git a/src/core/sweep.ts b/src/core/sweep.tsindex 37907df5cb..311354106c 100644--- a/src/core/sweep.ts+++ b/src/core/sweep.ts@@ -388,7 +388,7 @@ async function runLinksTimelinePass(type Extracted = Awaited<ReturnType<typeof extractPageLinks>>;type Snapshot = NonNullable<Awaited<ReturnType<BrainEngine['readPageSnapshot']>>>;const { extractSegmentedPageLinks, segmentedRoleText } = await import('./page-body/segment-links.ts');- const { bodyBlocks, BodyReadStopped, detachedValue } = await import('./page-body/segment-blocks.ts');+ const { bodyBlocks, detachedValue } = await import('./page-body/segment-blocks.ts');/*** One batch through every phase. A segmented page's reads ask `stop` before each segment, so one that does not fit@@ -617,10 +617,22 @@ async function runLinksTimelinePass(}};- // #C5: a segmented page is read several times per pass and can outlast any budget, so it never shares a batch: the- // inline pages run first as one batch, then each segmented page alone, smallest first, while budget remains. One- // that does not fit stops at a segment bound and is deferred (left unstamped) until its page changes, so it cannot- // take the budget of the rest of this sweep, or of later sweeps in this process.+ await runLinksTimelineBatches(recent, ctx, runBatch);+}++/**+ * #C5: a segmented page is read several times per pass and can outlast any budget, so it never shares a batch: the+ * inline pages run first as one batch, then each segmented page alone, smallest first, while budget remains. One+ * that does not fit stops at a segment bound (BodyReadStopped) and is deferred (left unstamped) until its page+ * changes, so it cannot take the budget of the rest of this sweep, or of later sweeps in this process.+ */+async function runLinksTimelineBatches(+ recent: Array<{ slug: string; updated_at_iso: string; body_storage: string | null; body_bytes: number | null }>,+ ctx: Pick<PassCtx, 'sourceId' | 'overBudget' | 'skip'> & { log: (msg: string) => void },+ runBatch: (recent: Array<{ slug: string; updated_at_iso: string }>, stop?: () => boolean) => Promise<void>,+): Promise<void> {+ const { sourceId, overBudget, skip, log } = ctx;+ const { BodyReadStopped } = await import('./page-body/segment-blocks.ts');const pending = recent.filter(row => {if (deferredSegmentedPages.get(`${sourceId}\0${row.slug}`) !== row.updated_at_iso) return true;skip('segmented_page_deferred');