Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(persistence): a remote timeline entry, link or tag keeps the page's provenance
garrytan1c34931cb476
diff --git a/src/core/persistence/page-mutations.ts b/src/core/persistence/page-mutations.tsindex 1ec79103d5..3d7eeb116f 100644--- a/src/core/persistence/page-mutations.ts+++ b/src/core/persistence/page-mutations.ts@@ -42,7 +42,7 @@ import { decideUnboundWrite, isUnboundSourcePage } from './unbound-source.ts';import { assertRestoreOrigin } from './detached-pages.ts';import { isSourceDbOnlySlug } from './source-storage.ts';import { colonSlugWindowsRefusal, isWindowsColonTarget } from './native-file-target.ts';-import { publishesDatabaseOnly } from './page-prepare.ts';+import { CALLER_CONTENT_OPERATIONS, publishesDatabaseOnly } from './page-prepare.ts';import { isSegmentedPage } from '../page-body/page-shape.ts';import { liveSearchable } from './searchable.ts';import { cachedPreadmitBrain, dropPreadmitCache, preadmitReads, preadmitRecheckFailed } from './preadmit-cache.ts';@@ -477,7 +477,11 @@ export async function preparePageAdmission(ctx: OperationContext,// terminal replay depend on a page that may have since been purged.if (input.operation === 'add_timeline_entry') await requireWritablePage({ ...ctx, sourceId }, slug, input.operation, 'page');intent.slug = slug;- if (ctx.remote !== false) Object.assign(intent, { source_kind: `mcp:${input.operation}`, source_uri: null, ingested_via: `mcp:${input.operation}` });+ // #8667: only a remote write that supplies page text is an ingestion; any other keeps the page's provenance.+ if (ctx.remote !== false) {+ const via = CALLER_CONTENT_OPERATIONS.includes(input.operation) ? `mcp:${input.operation}` : null;+ Object.assign(intent, { source_kind: via, source_uri: null, ingested_via: via });+ }const [authority, , snapshot, boundAtStart, writeThroughSetting, repoPath] = await pipelined(ctx.engine, [() => submissionAuthority(ctx, input.operation, sourceId, source.incarnation, slug),() => assertKnowledgePublicationAllowed(ctx.engine, { source_id: sourceId, source_incarnation: source.incarnation, slug, operation: input.operation,diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex b9b67a1939..3a951a1a2c 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -136,7 +136,7 @@ interface CanonicalProvenance { source_kind: string; ingested_via: string; inges* Writes whose caller supplies the page text, and so could supply provenance stamps in its frontmatter. Unlike* trust/page-write.ts CONTENT_OPERATIONS, revert_version and restore_page are absent: they replay a stored version.*/-const CALLER_CONTENT_OPERATIONS = ['put_page', 'edit_page', 'append_page', 'capture'];+export const CALLER_CONTENT_OPERATIONS = ['put_page', 'edit_page', 'append_page', 'capture'];/*** Canonical stamps belong to the first write, never to a later preparation attempt. #7873: they are server-owned on* every caller-content write a remote caller makes, with or without a repository: the caller's values are dropped anddiff --git a/test/put-page-provenance.test.ts b/test/put-page-provenance.test.tsindex 0267ac836b..2615ecd52c 100644--- a/test/put-page-provenance.test.ts+++ b/test/put-page-provenance.test.ts@@ -290,6 +290,23 @@ describe('put_page provenance — CV12 COALESCE-preserve UPDATE', () => {const prov = await readProvenance('wiki/p3a-local-then-remote');expect(prov.source_kind).toBe('mcp:put_page');});++ test('a remote timeline entry, tag or link keeps the page provenance and ignores supplied stamps (#8667)', async () => {+ const run = (name: string, ctx: OperationContext, p: Record<string, unknown>) =>+ withEnv({ GBRAIN_HOME: home }, () => operations.find((o) => o.name === name)!.handler(ctx, p));+ const slug = 'wiki/p3a-local-then-remote-meta';+ await putPageOp.handler(makeCtx({ remote: false }), {+ slug, content: '---\ntype: note\ntitle: V1\n---\n\nbody', source_kind: 'capture-cli', source_uri: 'file:///tmp/v1.md', ingested_via: 'put_page',+ });+ const before = await readProvenance(slug);+ expect(before.source_kind).toBe('capture-cli');+ await new Promise((resolve) => setTimeout(resolve, 20));+ await run('add_timeline_entry', makeCtx({ remote: true }), { slug, date: '2026-11-01', summary: 'Kickoff with acme-example' });+ await run('add_tag', makeCtx({ remote: true }), { slug, tag: 'follow-up', source_kind: 'spoofed', ingested_via: 'spoofed' });+ await putPageOp.handler(makeCtx({ remote: false }), { slug: 'wiki/p3a-link-target', content: '---\ntype: note\ntitle: Target\n---\n\nbody' });+ await run('add_link', makeCtx({ remote: true }), { from: slug, to: 'wiki/p3a-link-target', link_type: 'mentions' });+ expect(await readProvenance(slug)).toEqual(before);+ });});describe('put_page provenance — T2 subagent namespace regression', () => {