Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

wip(large-pages): evidence delivery windows large pages, span-only anchoring above 1 MiB, identity capability

garrytan7846512ce4b3
diff --git a/src/core/engine-sql/chunks.ts b/src/core/engine-sql/chunks.ts
index 536120afe3..de789c1749 100644
--- a/src/core/engine-sql/chunks.ts
+++ b/src/core/engine-sql/chunks.ts
@@ -750,7 +750,7 @@ export async function getChunkWindows(exec: ScopedRead, requests: ChunkWindowReq
AND p.deleted_at IS NULL AND ${trustedSql(currentTextProjectionFilter('p'))} AND NOT s.archived
AND ${trustedSql(QUARANTINE_FILTER_FRAGMENT)} ${privateSql} ${safeSql}
), chunk_rows AS (
- SELECT cc.page_id, cc.id AS chunk_id, cc.chunk_index, cc.chunk_text, cc.chunk_source, a.prio
+ SELECT cc.page_id, cc.id AS chunk_id, cc.chunk_index, cc.chunk_text, cc.chunk_source, cc.projected_byte_start, cc.projected_byte_end, a.prio
FROM auth a
JOIN content_chunks cc ON cc.page_id = a.id
WHERE a.sealed
@@ -763,11 +763,12 @@ export async function getChunkWindows(exec: ScopedRead, requests: ChunkWindowReq
SELECT 'page' AS kind, a.id AS page_id, a.slug, a.source_id, a.type, a.revision, a.sealed, a.prio,
(SELECT MAX(c2.chunk_index) FROM content_chunks c2 WHERE c2.page_id = a.id) AS max_chunk_index,
a.compiled_truth, a.timeline,
- NULL::int AS chunk_id, NULL::int AS chunk_index, NULL::text AS chunk_text, NULL::text AS chunk_source
+ NULL::int AS chunk_id, NULL::int AS chunk_index, NULL::text AS chunk_text, NULL::text AS chunk_source,
+ NULL::bigint AS projected_byte_start, NULL::bigint AS projected_byte_end
FROM auth a
UNION ALL
SELECT 'chunk' AS kind, c.page_id, NULL, NULL, NULL, NULL, NULL, c.prio,
- NULL, NULL, NULL, c.chunk_id, c.chunk_index, c.chunk_text, c.chunk_source
+ NULL, NULL, NULL, c.chunk_id, c.chunk_index, c.chunk_text, c.chunk_source, c.projected_byte_start, c.projected_byte_end
FROM chunk_rows c
`);
return mapChunkWindowRows(rows, maxRows);
diff --git a/src/core/ops/admin.ts b/src/core/ops/admin.ts
index 4ab493f970..a72e3d8661 100644
--- a/src/core/ops/admin.ts
+++ b/src/core/ops/admin.ts
@@ -18,6 +18,7 @@ import { enforceClientSlugFence, sourceScopeOpts } from './context.ts';
import { VERSION } from '../../version.ts';
import { resolveActiveEmbeddingColumnFromEngine } from '../search/embedding-column.ts';
import { memoizedHealth } from '../health-memo.ts';
+import { LARGE_PAGES_CAPABILITY } from './get-page-body.ts';
// --- Admin ---
@@ -107,7 +108,7 @@ const get_brain_identity: Operation = {
mutating: false,
idempotent: true,
outputRedaction: 'no_stored_text',
- description: 'Brain identity + counters for thin-client banner — remote callers see counters confined to their source grant. Returns version, engine kind, and page/chunk counts. Read-scope.',
+ description: 'Brain identity + counters for thin-client banner — remote callers see counters confined to their source grant. Returns version, engine kind, page/chunk counts and capabilities (large_pages_v1: windowed get_page). Read-scope.',
params: {},
handler: async (ctx) => {
// #4592: read-scope + unscoped counters made this op the quiet third
@@ -138,6 +139,7 @@ const get_brain_identity: Operation = {
last_sync_iso: null as string | null,
update_available,
latest_version,
+ capabilities: [LARGE_PAGES_CAPABILITY],
};
},
scope: 'read',
diff --git a/src/core/ops/get-page-body.ts b/src/core/ops/get-page-body.ts
index 8aadc42e75..c9874d7a45 100644
--- a/src/core/ops/get-page-body.ts
+++ b/src/core/ops/get-page-body.ts
@@ -34,7 +34,7 @@ import { opError } from './contract.ts';
import { invalidParam, readFix } from './op-fix.ts';
import { serializePageToMarkdown } from '../markdown.ts';
import { encodedFrameBytes, EGRESS_CAP_CONFIG_KEYS, egressTransport, FRAME_RESERVE_BYTES, resultByteCap } from '../egress-budget.ts';
-import { chunkDocumentSpan, readPageDocument, spanHoldsChunk, type PageDocument } from '../page-window/document.ts';
+import { DEFAULT_INLINE_BODY_BYTES, chunkDocumentSpan, readPageDocument, spanHoldsChunk, type PageDocument } from '../page-window/document.ts';
import {
DEFAULT_CONTEXT_LINES, DEFAULT_OUTLINE_LIMIT, DEFAULT_WINDOW_BYTES, MAX_CONTEXT_LINES, MAX_OUTLINE_LIMIT, MAX_WINDOW_BYTES,
decodeCursor, encodeCursor, pageOutline, sha256Hex, totalLines, windowAround, windowForBytes, windowForLines, windowFrom,
@@ -47,12 +47,15 @@ export const BODY_MODES = ['auto', 'full', 'none', 'outline', 'window'] as const
export type BodyMode = typeof BODY_MODES[number];
export const INLINE_BODY_BYTES_KEY = 'mcp.inline_body_bytes';
/** `auto` returns the whole body up to this many bytes of compiled truth plus timeline. */
-export const DEFAULT_INLINE_BODY_BYTES = 256 * 1024;
+export { DEFAULT_INLINE_BODY_BYTES };
/** Room a partial response keeps for its metadata, notices and escaping inside the egress cap. */
const ENVELOPE_RESERVE_BYTES = 64 * 1024;
/** The first window `auto` returns next to the outline. */
const AUTO_WINDOW_BYTES = 16_000;
+/** Advertised in get_brain_identity.capabilities: this host speaks the windowed get_page contract (body modes, cursors, view markdown + sha256). */
+export const LARGE_PAGES_CAPABILITY = 'large_pages_v1';
+
export const GET_PAGE_BODY_PARAMS: Record<string, ParamDef> = {
body: { type: 'string', enum: [...BODY_MODES], description: "auto (default: whole body up to 256 KB, else outline + first window), full, none (revision + size only), outline, window." },
lines: { type: 'object', description: 'Window selector: 1-based lines.', properties: { from: { type: 'number', required: true }, count: { type: 'number', required: true } } },
diff --git a/src/core/page-window/document.ts b/src/core/page-window/document.ts
index a9cbf9e4c6..716579b64a 100644
--- a/src/core/page-window/document.ts
+++ b/src/core/page-window/document.ts
@@ -30,6 +30,9 @@ import { loadFenceChunkOverlay, markFenceChunk, splitFenceOverlay, type FenceChu
/** Separator serializeMarkdown writes between compiled truth and timeline. */
export const TIMELINE_SEPARATOR = '\n\n<!-- timeline -->\n\n';
+/** Pages whose read body is over this many bytes are read in windows by default (mcp.inline_body_bytes moves it for get_page). */
+export const DEFAULT_INLINE_BODY_BYTES = 256 * 1024;
+
/** Raw prefix a bounded-prefix reader sanitizes (64 KiB of the overlaid body). */
export const BOUNDED_PREFIX_BYTES = 64 * 1024;
diff --git a/src/core/search/chunk-windows.ts b/src/core/search/chunk-windows.ts
index a582543aee..b8bc2d502b 100644
--- a/src/core/search/chunk-windows.ts
+++ b/src/core/search/chunk-windows.ts
@@ -28,6 +28,9 @@ export interface ChunkWindowChunk {
chunk_index: number;
chunk_text: string;
chunk_source: string;
+ /** Large pages: the chunk's UTF-8 byte span in its source's read projection, when recorded. */
+ projected_byte_start?: number | null;
+ projected_byte_end?: number | null;
}
export interface ChunkWindowPage {
@@ -64,7 +67,8 @@ export function mapChunkWindowRows(rows: Record<string, unknown>[], maxRows: num
const pages = new Map<number, ChunkWindowPage & { prio: number }>();
const chunkRows = rows
.filter(r => r.kind === 'chunk')
- .map(r => ({ page_id: Number(r.page_id), id: Number(r.chunk_id), chunk_index: Number(r.chunk_index), chunk_text: String(r.chunk_text ?? ''), chunk_source: String(r.chunk_source), prio: Number(r.prio) }))
+ .map(r => ({ page_id: Number(r.page_id), id: Number(r.chunk_id), chunk_index: Number(r.chunk_index), chunk_text: String(r.chunk_text ?? ''), chunk_source: String(r.chunk_source), prio: Number(r.prio),
+ projected_byte_start: r.projected_byte_start == null ? null : Number(r.projected_byte_start), projected_byte_end: r.projected_byte_end == null ? null : Number(r.projected_byte_end) }))
.sort((a, b) => a.prio - b.prio || a.page_id - b.page_id || a.chunk_index - b.chunk_index);
for (const r of rows) {
if (r.kind !== 'page') continue;
@@ -85,7 +89,8 @@ export function mapChunkWindowRows(rows: Record<string, unknown>[], maxRows: num
}
const limited = chunkRows.length > maxRows;
const kept = limited ? chunkRows.slice(0, maxRows) : chunkRows;
- for (const c of kept) pages.get(c.page_id)?.chunks.push({ id: c.id, chunk_index: c.chunk_index, chunk_text: c.chunk_text, chunk_source: c.chunk_source });
+ for (const c of kept) pages.get(c.page_id)?.chunks.push({ id: c.id, chunk_index: c.chunk_index, chunk_text: c.chunk_text, chunk_source: c.chunk_source,
+ ...(c.projected_byte_start != null && c.projected_byte_end != null ? { projected_byte_start: c.projected_byte_start, projected_byte_end: c.projected_byte_end } : {}) });
if (limited) {
const cutoff = chunkRows[maxRows];
for (const p of pages.values()) {
diff --git a/src/core/search/evidence-delivery.ts b/src/core/search/evidence-delivery.ts
index 16aafa801b..2830174b95 100644
--- a/src/core/search/evidence-delivery.ts
+++ b/src/core/search/evidence-delivery.ts
@@ -31,7 +31,7 @@ import { currentTextProjectionFilter, safeChunksFilter, requiresSafeChunks } fro
import { resolveExcludePrivatePages } from './private-visibility.ts';
import { safeSplitIndex } from '../text-safe.ts';
import { loadFenceChunkOverlay, type FenceChunkOverlay } from '../eligibility/fence-overlay.ts';
-import { projectPageText, TIMELINE_SEPARATOR } from '../page-window/document.ts';
+import { chunkDocumentSpan, DEFAULT_INLINE_BODY_BYTES, projectPageText, spanHoldsChunk, TIMELINE_SEPARATOR } from '../page-window/document.ts';
import { stripChunkHeader } from '../chunkers/code.ts';
import { OperationError } from '../ops/contract.ts';
import { blockDateHeaders, evidenceDateHeaderEnabled } from './evidence-date.ts';
@@ -414,7 +414,7 @@ function squeeze(text: string): { s: string; map: number[] } {
* match ignores whitespace differences; consecutive chunks overlap, so each
* search starts just after the previous chunk's start. Unlocated chunks are absent.
*/
-export function locateChunks(text: string, chunks: Array<{ id: number; chunk_index: number; chunk_text: string }>): Array<{ id: number; chunk_index: number; start: number; end: number }> {
+export function locateChunks(text: string, chunks: Array<{ id: number; chunk_index: number; chunk_text: string }>, fold = true): Array<{ id: number; chunk_index: number; start: number; end: number }> {
let body: ReturnType<typeof squeeze> | null = null;
const out: Array<{ id: number; chunk_index: number; start: number; end: number }> = [];
let from = 0;
@@ -428,6 +428,7 @@ export function locateChunks(text: string, chunks: Array<{ id: number; chunk_ind
from = at + 1;
continue;
}
+ if (!fold) continue;
body ??= squeeze(text);
const needle = squeeze(exact).s;
let lo = 0;
@@ -584,12 +585,12 @@ export function pageEvidenceText(page: { compiled_truth: string; timeline: strin
return projectPageText(page, includeTimeline);
}
-function locateAnchor(doc: Doc, hit: SearchResult): Anchor {
+function locateAnchor(doc: Doc, hit: SearchResult, fold: boolean): Anchor {
const byId = hit.chunk_id > 0 ? doc.spans.find(x => x.id === hit.chunk_id) : undefined;
if (byId) return { chunk_id: hit.chunk_id, mapped: true, pieces: piecesOverlapping(doc, byId.start, byId.end), start: byId.start, end: byId.end, chunkIndex: byId.chunk_index };
const text = hitPageText(hit).trim();
if (text.length >= 16) {
- const found = locateChunks(doc.text, [{ id: hit.chunk_id, chunk_index: hit.chunk_index, chunk_text: text }])[0];
+ const found = locateChunks(doc.text, [{ id: hit.chunk_id, chunk_index: hit.chunk_index, chunk_text: text }], fold)[0];
if (found) {
// A fenced_code chunk_index follows every prose chunk, so it says nothing
// about position: the window grows from the prose chunk holding the fence,
@@ -647,19 +648,50 @@ function sectionCandidates(doc: Doc, anchors: Anchor[], conversation: boolean):
return set.size === 0 ? null : [...set].sort((x, y) => x - y);
}
+/** Large pages: above this size hits are located by their stored spans only (no whole-text whitespace folding). */
+const SPAN_ONLY_LOCATE_BYTES = 1024 * 1024;
+/** fallback_reason when a 'page' (or auto) unit was cut to a window because the page is over the inline read size. */
+export const PAGE_OVER_INLINE_BYTES = 'page_over_inline_bytes';
+
+/**
+ * Locate chunks by their recorded projected byte spans, verified against the
+ * text; one forward pass converts byte offsets to the string's UTF-16
+ * offsets. Chunks without a span (or with a stale one) stay unlocated.
+ */
+function locateByStoredSpans(text: string, timelineAt: number, chunks: ChunkWindowPage['chunks']): Array<{ id: number; chunk_index: number; start: number; end: number }> {
+ const doc = { bytes: Buffer.from(text, 'utf8'), timelineByte: timelineAt < 0 ? -1 : Buffer.byteLength(text.slice(0, timelineAt), 'utf8') };
+ const found: Array<{ id: number; chunk_index: number; start: number; end: number }> = [];
+ for (const c of chunks) {
+ const span = chunkDocumentSpan(doc, c);
+ if (span && spanHoldsChunk(doc, span, c.chunk_text)) found.push({ id: c.id, chunk_index: c.chunk_index, start: span.start, end: span.end });
+ }
+ const positions = [...new Set(found.flatMap(f => [f.start, f.end]))].sort((a, b) => a - b);
+ const toChar = new Map<number, number>();
+ let byte = 0;
+ let char = 0;
+ for (const pos of positions) {
+ char += doc.bytes.subarray(byte, pos).toString('utf8').length;
+ byte = pos;
+ toChar.set(pos, char);
+ }
+ return found.map(f => ({ ...f, start: toChar.get(f.start)!, end: toChar.get(f.end)! })).sort((a, b) => a.chunk_index - b.chunk_index);
+}
+
function planBlock(page: ChunkWindowPage, hits: SearchResult[], plan: EvidencePlan, includeTimeline: boolean): PlannedBlock {
const best = hits[0];
if (!page.sealed) return fallbackBlock(best, hits, 'unsealed_page');
if (page.chunks.length === 0 && page.row_limited) return fallbackBlock(best, hits, 'row_limit');
const { text, timelineAt } = pageEvidenceText(page, includeTimeline);
+ const textBytes = Buffer.byteLength(text, 'utf8');
const truthChunks = page.chunks.filter(c => c.chunk_source === 'compiled_truth');
const timelineChunks = page.chunks.filter(c => c.chunk_source === 'timeline');
- const spans = [
+ // Large pages: above 1 MiB the text is never whitespace-folded whole; hits are anchored by their stored spans only.
+ const spans = textBytes > SPAN_ONLY_LOCATE_BYTES ? locateByStoredSpans(text, timelineAt, page.chunks) : [
...locateChunks(timelineAt < 0 ? text : text.slice(0, timelineAt - TIMELINE_SEPARATOR.length), truthChunks),
...(timelineAt < 0 ? [] : locateChunks(text.slice(timelineAt), timelineChunks).map(sp => ({ ...sp, start: sp.start + timelineAt, end: sp.end + timelineAt }))),
];
const doc = buildDoc(text, spans);
- const anchors = hits.map(h => locateAnchor(doc, h));
+ const anchors = hits.map(h => locateAnchor(doc, h, textBytes <= SPAN_ONLY_LOCATE_BYTES));
if (anchors.every(a => a.pieces.length === 0)) {
return fallbackBlock(best, hits, page.row_limited ? 'row_limit' : page.chunks.length === 0 ? 'no_text_chunks' : 'anchor_not_located');
}
@@ -669,6 +701,8 @@ function planBlock(page: ChunkWindowPage, hits: SearchResult[], plan: EvidencePl
let unit: DeliveredUnit = plan.unit === 'auto' ? 'page' : plan.unit;
let fallbackReason: string | undefined;
let candidates: number[];
+ // Large pages (T18): a page over the inline read size is never delivered whole; it becomes the window around its hits.
+ if (unit === 'page' && textBytes > DEFAULT_INLINE_BODY_BYTES) { unit = 'window'; fallbackReason = PAGE_OVER_INLINE_BYTES; }
if (unit === 'page') {
candidates = doc.pieces.map((_, i) => i);
} else if (unit === 'section') {
@@ -1153,7 +1187,7 @@ export async function deliverEvidence(
truncated,
...(b.revision ? { revision: b.revision } : {}),
...(out.unmapped.length > 0 ? { unmapped_chunk_ids: out.unmapped } : {}),
- ...(b.fallbackReason && b.unit === 'chunk' ? { fallback_reason: b.fallbackReason } : {}),
+ ...(b.fallbackReason && (b.unit === 'chunk' || b.fallbackReason === PAGE_OVER_INLINE_BYTES) ? { fallback_reason: b.fallbackReason } : {}),
...(b.reason ? { reason: b.reason } : {}),
};
return { ...b.hit, title: b.title, chunk_text: text, delivered };
diff --git a/test/evidence-large-page.test.ts b/test/evidence-large-page.test.ts
new file mode 100644
index 0000000000..7a028e4524
--- /dev/null
+++ b/test/evidence-large-page.test.ts
@@ -0,0 +1,91 @@
+/**
+ * Large pages (Wave A, T18): evidence delivery never assembles a page over the
+ * inline read size whole. A 'page' unit (assemble_evidence's default, query
+ * return_unit: 'page') becomes the window around the hits, and `delivered`
+ * names the downgrade. Above 1 MiB hits are anchored by their stored spans,
+ * with no whole-text whitespace folding. Hermetic in-memory PGLite.
+ */
+import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { operations, type OperationContext } from '../src/core/operations.ts';
+import { importFromContent } from '../src/core/import-file.ts';
+import { serializeMarkdown } from '../src/core/markdown.ts';
+import { pageDocument } from '../src/core/page-window/document.ts';
+import { PAGE_OVER_INLINE_BYTES } from '../src/core/search/evidence-delivery.ts';
+import { SAFE_FENCE_CHUNKER_VERSION } from '../src/core/search/safe-chunks.ts';
+
+let engine: PGLiteEngine;
+const assemble = operations.find(o => o.name === 'assemble_evidence')!;
+const ctx = (): OperationContext => ({ engine, config: {}, logger: { info() {}, warn() {}, error() {} }, dryRun: false, remote: false, sourceId: 'default',
+ emitResponseMeta: () => {} } as unknown as OperationContext);
+
+function conversation(lines: number): string {
+ return ['# Session log', '', ...Array.from({ length: lines }, (_, i) => i % 2 === 0
+ ? `**user:** 2026-04-${String(1 + (i % 28)).padStart(2, '0')} question ${i} about the acme-example widget rollout`
+ : `**assistant:** answer ${i}: the widget rollout step ${i} is scheduled`)].join('\n');
+}
+
+async function put(slug: string, body: string) {
+ const r = await importFromContent(engine, slug, serializeMarkdown({}, body, '', { type: 'conversation', title: slug, tags: [] }), { sourceId: 'default', noEmbed: true, forceRechunk: true });
+ expect(r.status).toBe('imported');
+}
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+}, 120_000);
+afterAll(async () => { await engine.disconnect(); }, 60_000);
+
+describe('assemble_evidence on large pages', () => {
+ test("a 'page' unit over the inline size is delivered as a window and says so", async () => {
+ await put('chat/mid-example', conversation(5000));
+ const chunks = await engine.getChunks('chat/mid-example', { sourceId: 'default' } as any);
+ const target = chunks[chunks.length - 3];
+ const out = await assemble.handler(ctx(), { hits: [{ source_id: 'default', slug: 'chat/mid-example', chunk_id: target.id }], return_unit: 'page', token_budget: 20_000 }) as { results: any[] };
+ const r = out.results[0];
+ expect(r.delivered.unit).toBe('window');
+ expect(r.delivered.fallback_reason).toBe(PAGE_OVER_INLINE_BYTES);
+ expect(r.chunk_text.replace(/\s+/g, ' ')).toContain(target.chunk_text.replace(/\s+/g, ' ').slice(0, 120));
+ expect(r.chunk_text.length).toBeLessThan(200_000);
+ }, 60_000);
+
+ test('a small page keeps its whole-page unit', async () => {
+ await put('chat/small-example', conversation(40));
+ const [c] = await engine.getChunks('chat/small-example', { sourceId: 'default' } as any);
+ const out = await assemble.handler(ctx(), { hits: [{ source_id: 'default', slug: 'chat/small-example', chunk_id: c.id }], return_unit: 'page' }) as { results: any[] };
+ expect(out.results[0].delivered.unit).toBe('page');
+ expect(out.results[0].delivered.fallback_reason).toBeUndefined();
+ }, 60_000);
+
+ test('above 1 MiB hits are anchored by stored spans only: a duplicate line by its span, a span-less chunk not at all', async () => {
+ const repeated = 'the same rollout message, sent again and again in this session. '.repeat(20);
+ await put('chat/huge-example', Array.from({ length: 1200 }, (_, i) => `**user:** ${i % 2 ? repeated : `turn ${i}: ${repeated}`}`).join('\n\n'));
+ const snap = await engine.readPageSnapshot('chat/huge-example', { sourceId: 'default' });
+ const doc = pageDocument({ compiled_truth: snap!.page.compiled_truth, timeline: snap!.page.timeline });
+ expect(doc.bytes.length).toBeGreaterThan(1024 * 1024);
+ // Ingest leaves an oversized page chunkless in Wave A; write three chunks with spans the way the chunker records them.
+ const text = doc.bytes.toString('utf8');
+ // Odd turns are byte-identical lines: only the stored span can tell which one a chunk is.
+ const identical = [...text.matchAll(/^\*\*user:\*\* the same/gm)].map(m => m.index!);
+ const pick = [identical[1], identical[150], identical[295]];
+ const rows = pick.map((at, i) => {
+ const end = text.indexOf('\n', at);
+ const chunk = text.slice(at, end === -1 ? text.length : end);
+ const start = Buffer.byteLength(text.slice(0, at));
+ return { chunk_index: i, chunk_text: chunk, chunk_source: 'compiled_truth' as const, projected_byte_start: start, projected_byte_end: start + Buffer.byteLength(chunk) };
+ });
+ // A fourth chunk with no recorded span whose whitespace differs from the page: only whole-text folding could place it.
+ const unique = text.slice(text.indexOf('**user:** turn 800:'), text.indexOf('\n', text.indexOf('**user:** turn 800:'))).replace(/\. /g, '. ');
+ await engine.upsertChunks('chat/huge-example', [...rows, { chunk_index: 3, chunk_text: unique, chunk_source: 'compiled_truth' as const }],
+ { sourceId: 'default', sealChunkerVersion: SAFE_FENCE_CHUNKER_VERSION });
+ const chunks = await engine.getChunks('chat/huge-example', { sourceId: 'default' } as any);
+ expect(chunks[0].chunk_text).toBe(chunks[2].chunk_text);
+ const located = await assemble.handler(ctx(), { hits: [{ source_id: 'default', slug: 'chat/huge-example', chunk_id: chunks[2].id }], return_unit: 'window', token_budget: 4000 }) as { results: any[] };
+ expect(located.results[0].delivered.unit).toBe('window');
+ expect(located.results[0].delivered.match_spans.length).toBeGreaterThan(0);
+ const unplaced = await assemble.handler(ctx(), { hits: [{ source_id: 'default', slug: 'chat/huge-example', chunk_id: chunks[3].id }], return_unit: 'window', token_budget: 4000 }) as { results: any[] };
+ expect(unplaced.results[0].delivered.unmapped_chunk_ids).toContain(chunks[3].id);
+ expect(located.results[0].delivered.unmapped_chunk_ids).toBeUndefined();
+ }, 120_000);
+});
diff --git a/test/get-brain-identity.test.ts b/test/get-brain-identity.test.ts
index 1faca82961..33f21716fa 100644
--- a/test/get-brain-identity.test.ts
+++ b/test/get-brain-identity.test.ts
@@ -106,6 +106,7 @@ describe('get_brain_identity op', () => {
const result = (await op.handler(buildCtx(), {})) as Record<string, unknown>;
const keys = Object.keys(result).sort();
expect(keys).toEqual([
+ 'capabilities',
'chunk_count',
'engine',
'last_sync_iso',
@@ -114,6 +115,7 @@ describe('get_brain_identity op', () => {
'update_available',
'version',
]);
+ expect(result.capabilities).toEqual(['large_pages_v1']);
});
test('last_sync_iso is null in v0.31.1 (deferred to v0.31.x — see plan)', async () => {