Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: put_page's summary guard counts against the stored body, not overlapping chunks (/ship fix-check)
garrytaneb274fa6b603
diff --git a/scripts/page-body-readers-baseline.tsv b/scripts/page-body-readers-baseline.tsvindex c756cf2759..acf5beaf64 100644--- a/scripts/page-body-readers-baseline.tsv+++ b/scripts/page-body-readers-baseline.tsv@@ -465,6 +465,7 @@ src/core/persistence/page-edit.ts pageSegments field SEGWsrc/core/persistence/page-edit.ts prepareSegmentedEditMutation call:serializePageToMarkdown NONE serializes the frontmatter head with an empty body; the body streams from the segmentssrc/core/persistence/page-input.ts normalizeSubagentPageInput call:serializeMarkdown SEGWsrc/core/persistence/page-input.ts normalizeSubagentPageInput field SEGW+src/core/persistence/page-mutations.ts unquotedPutContent field SEGW counts the stored inline body's literal tool-call summaries through readStoredBody; a segmented page reads NULL, so a summarized remote round trip is refused and nothing is writtensrc/core/persistence/page-prepare.ts canonical field SEGW lane 1d file; segmented page: getter throws page_body_segmentedsrc/core/persistence/page-prepare.ts fileMatchesSnapshot field SEGW lane 1d file; segmented page: getter throws page_body_segmentedsrc/core/persistence/page-prepare.ts prepareInlineOrSegmentedMutation call:serializePageToMarkdown SEGW lane 1d filediff --git a/src/core/persistence/page-mutations.ts b/src/core/persistence/page-mutations.tsindex 229ac84c18..e8b48976b4 100644--- a/src/core/persistence/page-mutations.ts+++ b/src/core/persistence/page-mutations.ts@@ -44,7 +44,7 @@ import { liveSearchable } from './searchable.ts';import { cachedPreadmitBrain, dropPreadmitCache, preadmitReads, preadmitRecheckFailed } from './preadmit-cache.ts';import { pipelined } from '../page-state/transactions.ts';import { holdsSummarizedToolCalls, isQuotedPageType, quotesTier, unquoteTranscriptText } from '../search/transcript-quote.ts';-import { chunkVisibleFilter } from '../search/safe-chunks.ts';+import { readStoredBody } from '../facts/file-body-guard.ts';import { isMirrorOnlyPage, sourceMirrorReadOnly } from './mirror-read-only.ts';export async function requestPrincipalForContext(ctx: OperationContext): Promise<Principal> {@@ -265,14 +265,11 @@ async function unquotedPutContent(engine: BrainEngine, sourceId: string, slug: sconst unquoted = unquoteTranscriptText(content, slug);const summarized = /, arguments omitted\]/.test(unquoted);if (!summarized && (unquoted === content || isQuotedPageType(String(parseMarkdownHead(content).frontmatter.type ?? '')))) return unquoted;- const [stored] = await engine.executeRaw<{ id: number; type: string | null; trust_tier: string | null }>(- 'SELECT id, type, trust_tier FROM pages WHERE source_id = $1 AND slug = $2', [sourceId, slug]);- // The stored page's own literal summaries, read from its chunks; a summary split across two chunks is missed, so that write is refused,- // and one in the overlap of two chunks counts twice.- const storedSummaries = async (pageId: number) => (await engine.executeRaw<{ chunk_text: string }>(- `SELECT cc.chunk_text FROM content_chunks cc JOIN pages p ON p.id = cc.page_id- WHERE cc.page_id = $1 AND cc.chunk_text LIKE '%, arguments omitted]%' AND ${chunkVisibleFilter('p', 'cc')}`, [pageId])).map(r => r.chunk_text).join('\n');- if (summarized && stored && isQuotedPageType(stored.type) && holdsSummarizedToolCalls(await storedSummaries(Number(stored.id)), unquoted)) {+ const [stored] = await engine.executeRaw<{ type: string | null; trust_tier: string | null }>(+ 'SELECT type, trust_tier FROM pages WHERE source_id = $1 AND slug = $2', [sourceId, slug]);+ // The stored body's own literal summaries; a segmented page reads NULL inline columns, so its summarized round trip is refused.+ const storedText = async () => { const body = await readStoredBody(engine, sourceId, slug); return `${body?.compiled_truth ?? ''}\n${body?.timeline ?? ''}`; };+ if (summarized && stored && isQuotedPageType(stored.type) && holdsSummarizedToolCalls(await storedText(), unquoted)) {throw new OperationError('invalid_params', `put_page: this content has tool calls that a read of ${slug} summarized; writing it would replace the stored calls with their summaries.`,'Nothing was written. Read the page with get_page include_content: true (its content keeps the stored text) and write that back, or change the page with edit_page.');}diff --git a/test/search-transcript-quote-tiers.test.ts b/test/search-transcript-quote-tiers.test.tsindex 187da3a61f..c06a041174 100644--- a/test/search-transcript-quote-tiers.test.ts+++ b/test/search-transcript-quote-tiers.test.ts@@ -254,11 +254,12 @@ for (const backend of testBackends()) {const slug = 'conversations/probe-literal-summary';const literal = neutralizeToolCalls(TOOL_CALL);expect(literal).toMatch(/^\[tool call: search, arguments omitted\]$/);- await ok('put_page', { slug, content: `${pageContent('conversation')}\n\n**bob-example** (2026-10-01 9:06 AM): earlier result ${literal}` });+ const words = (n: number) => Array.from({ length: n }, (_, i) => `word${i}`).join(' ');+ await ok('put_page', { slug, content: `${pageContent('conversation')}\n\n**bob-example** (2026-10-01 9:06 AM): ${words(270)} earlier result ${literal} noted. ${words(500)}.` });const stored = (await engine.getPage(slug))!;- const chunks = await engine.executeRaw<{ n: number }>(- `SELECT count(*)::int AS n FROM content_chunks cc JOIN pages p ON p.id = cc.page_id WHERE p.slug = $1 AND cc.chunk_text LIKE '%, arguments omitted]%'`, [slug]);- expect(chunks[0]!.n).toBe(1);+ const chunks = await engine.executeRaw<{ chunk_text: string }>(+ 'SELECT cc.chunk_text FROM content_chunks cc JOIN pages p ON p.id = cc.page_id WHERE p.slug = $1', [slug]);+ expect(chunks.map(c => c.chunk_text.split(literal).length - 1).reduce((a, b) => a + b, 0)).toBe(2);const summarized = await ok('get_page', { slug });const read = String(summarized.compiled_truth).split('\n').slice(2, -1).join('\n');expect(read.split(literal).length - 1).toBe(2);