Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: put_page keeps an owner page's fence only when its stored body holds one, so a read from before a claim stores the body (/ship Step 11)
garrytancb7b0239a17e
diff --git a/src/core/persistence/page-mutations.ts b/src/core/persistence/page-mutations.tsindex 6859a873d0..2ea411e2f5 100644--- a/src/core/persistence/page-mutations.ts+++ b/src/core/persistence/page-mutations.ts@@ -257,7 +257,8 @@ export async function submitPageMutation(ctx: OperationContext,* #8042: a remote put_page (put_pages too) of a quoted page's get_page content writes the page body, not the fences* get_page added (search/transcript-quote.ts). A fence naming the page is removed when its stored type or the type the* new content declares is one get_page quotes (either, so a retype keeps the body), or (GST-687) when the stored page is- * below the owner's tier, which get_page quotes too; an owner note's own fence-like text is kept.+ * below the owner's tier, which get_page quotes too; an owner-tier note keeps a fence naming it only when its stored body+ * already holds one, so a fence read before a claim raised the page's tier is never stored.* GST-687: content carrying a tool-call summary that only the neutralized read of the stored chat page holds (get_page's* reading shape, fetch) is refused, so a read-then-write never replaces a stored tool call with its summary.*/@@ -277,7 +278,13 @@ async function unquotedPutContent(engine: BrainEngine, sourceId: string, slug: s'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.');}if (unquoted === content || isQuotedPageType(String(parseMarkdownHead(content).frontmatter.type ?? ''))) return unquoted;- return stored && (isQuotedPageType(stored.type) || quotesTier(stored.trust_tier)) ? unquoted : content;+ if (!stored) return content;+ if (isQuotedPageType(stored.type) || quotesTier(stored.trust_tier)) return unquoted;+ // An owner-tier page keeps a fence naming it only when its stored body already holds one: a fence read while the page sat+ // below the owner's tier (before a claim or backfill raised it, or from a quoted version) is a read's, not the page's.+ const body = await readStoredBody(engine, sourceId, slug);+ const storedText = `${body?.compiled_truth ?? ''}\n${body?.timeline ?? ''}`;+ return body?.compiled_truth != null && unquoteTranscriptText(storedText, slug) === storedText ? unquoted : content;}/**diff --git a/test/search-transcript-quote-legacy-claim.test.ts b/test/search-transcript-quote-legacy-claim.test.tsindex ce03845d55..15e630ee1b 100644--- a/test/search-transcript-quote-legacy-claim.test.ts+++ b/test/search-transcript-quote-legacy-claim.test.ts@@ -54,7 +54,12 @@ for (const backend of testBackends()) {}, 180_000);afterAll(async () => { await close?.(); });+ let readBeforeClaim: { content: string; revision: string };+test('before the claim: both legacy pages are unverified and quoted for a remote reader; doctor names the pages and the fix', async () => {+ const res = await dispatchToolCall(engine, 'get_page', { slug: OWNER.slug, include_content: true }, remote);+ readBeforeClaim = JSON.parse(res.content[0]!.text);+ expect(readBeforeClaim.content).toContain(MARKER(OWNER.slug) + '\n```text\n');for (const p of [OWNER, AGENT]) {const read = await page(p.slug);expect([p.slug, read.trust_tier, read.quoted]).toEqual([p.slug, 'unknown', 'transcript']);@@ -83,5 +88,12 @@ for (const backend of testBackends()) {expect(tiers.message).not.toContain('Remote MCP readers see');expect((await trustSourcesUnclaimedEntry.run({ engine } as unknown as DoctorContext) as Check[])[0]!.status).toBe('ok');}, 120_000);++ test('a remote read from before the claim, written back after it, stores the body without the read\'s fence', async () => {+ const content = readBeforeClaim.content.replace('Legacy owner reference', 'Legacy owner reference (kept)');+ const res = await dispatchToolCall(engine, 'put_page', { slug: OWNER.slug, content, expected_revision: readBeforeClaim.revision }, remote);+ expect(res.isError, res.content[0]?.text).not.toBe(true);+ expect((await engine.getPage(OWNER.slug))!.compiled_truth).toBe(OWNER.body.replace('Legacy owner reference', 'Legacy owner reference (kept)'));+ }, 120_000);});}