Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(persistence): drop the put_page/capture contact-row dedupe; no gbrain path writes contact rows (#8109)
garrytaned88688ff6a4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e1b595c7b4..e9cca96a54 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,8 +20,7 @@ identifiers and attribution are available in the pre-removal Git revision|---|---|---|| A person page's file differs from the database only in frontmatter (for example one contact row's `last_used` moved forward), and an agent saves a fact | `remember` refused `source_changed` (`file_database_drift`) until someone reconciled the page | the fact lands; the file keeps its own frontmatter with the new body, and the frontmatter drift stays for reconcile. Body, timeline, title, type, tag and policy or privacy key drift still refuse, and so does a write that changes frontmatter || `gbrain sources reconcile <source> <slug> --preview --auto-additive` on a contact row whose only change is a later `last_used` | `review` (`list_entries_changed_or_reordered`) | `auto` (rule `contacts_activity_advance`); a removed, reordered or otherwise changed row, or a date moved backward or into the future, still needs review. Unquoted YAML dates compare as dates |-| A `put_page` or `capture` whose frontmatter `contacts:` list repeats a `(type, value)` row | stored every copy | keeps one row per `(type, value)` with the newest `last_used`; rows that differ in another field and every distinct value stay |-| Pages that already hold repeated contact rows | no repair | `gbrain repair contact-rows [--source <id>] [--slug <slug>]...` previews (writes nothing), then `--apply --expect <hash> --yes` rewrites exactly the previewed pages through revision-bound `put_page`: the file through the coordinated writer on sources with a checkout, the database on repo-less brains. Drifted pages are listed `needs_reconcile` with the reconcile command |+| Pages whose frontmatter `contacts:` list repeats a `(type, value)` row | no repair | `gbrain repair contact-rows [--source <id>] [--slug <slug>]...` keeps one row per `(type, value)` with the newest `last_used` (rows that differ in another field and every distinct value stay). It previews (writes nothing), then `--apply --expect <hash> --yes` rewrites exactly the previewed pages through revision-bound `put_page`: the file through the coordinated writer on sources with a checkout, the database on repo-less brains. Drifted pages are listed `needs_reconcile` with the reconcile command |Nothing runs on upgrade.diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex 41a87db38c..c25264f872 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -1160,9 +1160,8 @@ nothing, and a timeline-only rewrite queues no facts extraction.A writer that appended a `{type, value, last_used}` row to a page'sfrontmatter `contacts:` list on every touch, instead of updating the existing-row, left the same value many times (#8109). `put_page` and `capture` now keep-one row per (type, value); this explicit-only, preview-bound kind collapses the-rows already stored. It never runs from `--all`, doctor's remediation plan, the+row, left the same value many times (#8109). This explicit-only, preview-bound+kind collapses the rows already stored, whichever writer left them. It never runs from `--all`, doctor's remediation plan, themaintenance cycle or an upgrade.**Say to your agent:** *"Preview which pages repeat contact rows, show me thediff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex cfd2510ec4..5da51ec951 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1378,7 +1378,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.525.0', id: 'oversize_hold_unread_8072', text: 'A Markdown file over 24 MiB that sync had to read whole to refuse (segmented storage on, held `file_too_large`, for example for a facts fence) is no longer read again by every sync: it stays held, unread, until it changes, gbrain is upgraded, or `gbrain sources retry-held <source>` schedules it. After changing a setting the hold message names, run `gbrain sources retry-held <source>`. A file held from its size alone still re-checks on every sync.' },{ since: '0.60.528.0', id: 'frontmatter_drift_write_8109', text: 'A write that leaves a page\'s frontmatter unchanged (`remember`, a fact or timeline write, a `put_page` of the stored frontmatter) is no longer refused `source_changed` (`file_database_drift`) when the page\'s canonical file differs from the database only in ordinary frontmatter keys (for example a contact row\'s `last_used` moved forward in the file): the write lands in the database and the file keeps its own frontmatter with the new body, so the frontmatter drift stays for `gbrain sources reconcile <source> <slug> --preview --auto-additive`. Drift in the body, timeline, title, type, tags or a policy or privacy key (`access`, `visibility`, `aliases`, ...) refuses as before, and so does a write that changes frontmatter (#8109).' },{ since: '0.60.528.0', id: 'contacts_activity_advance_8109', text: '`gbrain sources reconcile --auto-additive` now decides a `contacts` row whose only change is an activity date (`last_used`, `last_*`, `*_last_used`, `updated`) moving forward as structurally additive (rule `contacts_activity_advance`) instead of `review` (`list_entries_changed_or_reordered`); a row that changed in any other way, moved, was removed or moved a date backward or into the future still needs review. Unquoted YAML dates compare as the instants they are instead of `date_not_text` (#8109).' },- { since: '0.60.528.0', id: 'contact_rows_dedupe_8109', text: '`put_page` and `capture` keep one frontmatter `contacts` row per (type, value), in first-seen order with the newest `last_used`, in the file and the database alike; a row that differs in another field and every distinct value are kept. New explicit repair `gbrain repair contact-rows [--source <id>] [--slug <slug>]...` collapses rows already duplicated: the preview writes nothing and prints a hash, `--apply --expect <hash> --yes` rewrites exactly the previewed pages through revision-bound `put_page` (the canonical file on sources with a checkout, the database on repo-less ones), and a page whose file drifted is listed `needs_reconcile`. Nothing runs on upgrade (#8109).' },+ { since: '0.60.528.0', id: 'contact_rows_dedupe_8109', text: 'New explicit repair `gbrain repair contact-rows [--source <id>] [--slug <slug>]...` collapses duplicated frontmatter `contacts` rows: one row per (type, value), in first-seen order with the newest `last_used`; a row that differs in another field and every distinct value are kept. the preview writes nothing and prints a hash, `--apply --expect <hash> --yes` rewrites exactly the previewed pages through revision-bound `put_page` (the canonical file on sources with a checkout, the database on repo-less ones), and a page whose file drifted is listed `needs_reconcile`. Nothing runs on upgrade (#8109).' },{ since: '0.60.525.0', id: 'refresh_sync_budget_8072', text: 'The member syncs of one `gbrain sources refresh` run stop starting work after `sources.refresh_sync_budget_ms` (default 5 minutes; `GBRAIN_REFRESH_SYNC_BUDGET_MS`). Each member gets an equal share of what is left. A run past it reports `sync_deferred` with the members it left `deferred` and still completes the refresh, so writes to the checkout are admitted again and the next `gbrain sources refresh <source>` continues them; a member that committed nothing in its share is reported `refresh_sync_timeout` in `sync_blocked`. A stalled sync no longer holds the refresh lock across scheduled runs or starves the other members.' },];diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex c696df3cc3..ef40007058 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -90,7 +90,6 @@ import { parseFenceRepairReceipt } from '../fence-repair/receipt.ts';import { fenceRepairCommit } from './effect-model.ts';import { withoutSafetyAssessments } from './reconcile-safety.ts';import { POLICY_KEYS } from './reconcile-additive.ts';-import { dedupeFrontmatterContacts } from '../contact-rows.ts';import { protectedReconcileKey } from './reconcile-merge.ts';import { preparePagePurge, purgePageInTransaction, type PreparedPagePurge } from './page-purge.ts';import { withTrustKeep } from './context.ts';@@ -131,12 +130,6 @@ function canonical(page: Pick<Page, 'type' | 'title' | 'compiled_truth' | 'timelfrontmatter: comparableFrontmatter(page.frontmatter), tags: [...new Set(tags)].sort() };}interface CanonicalProvenance { source_kind: string; ingested_via: string; ingested_at: string; }-/** #8109: a caller-authored page (put_page, capture) keeps one contact row per (type, value), the newest last_used kept; file and database alike. */-function callerContactsDeduped(row: Pick<WriteRequest, 'operation'>, page: ParsedPage): ParsedPage {- const contacts = row.operation === 'put_page' || row.operation === 'capture' ? dedupeFrontmatterContacts(page.frontmatter) : null;- if (contacts) page.frontmatter = contacts.frontmatter;- return page;-}/*** 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.@@ -963,7 +956,7 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wri...(gateTrust ? { writeGate: gateInput(gateTrust, row.id) } : {}),// Provenance compares the caller's page with the stored one, so it runs before the server's trust marker is stamped.prepareFrontmatter: page => {- provenance = putProvenance(row, snapshot, callerContactsDeduped(row, page));+ provenance = putProvenance(row, snapshot, page);suppliedTrustMarker = page.frontmatter.trust_tier;stampPageTrustMarker(row, page.frontmatter, trust, storedTier, snapshot?.page.frontmatter);if (privateRequest) assertPrivateRequestKept(row, page.frontmatter);diff --git a/test/repair-contact-rows.test.ts b/test/repair-contact-rows.test.tsindex 34611d99a4..db937da061 100644--- a/test/repair-contact-rows.test.ts+++ b/test/repair-contact-rows.test.ts@@ -3,7 +3,6 @@* canonical file is published through the coordinated writer) and a database-only (repo-less) source share one run.* The preview writes nothing, a moved preview refuses, the apply collapses exactly the planned pages without dropping a* distinct value, a page whose file drifted is listed needs_reconcile and left alone, and a second preview finds nothing.- * put_page itself keeps one row per (type, value).*/import { describe, expect, test } from 'bun:test';import { randomUUID } from 'node:crypto';@@ -114,15 +113,5 @@ for (const backend of testBackends()) {expect(await contacts(engine, 'source-a', 'people/alice-example')).toHaveLength(5);}, { databaseUrl, setup: seeded([['source-a', 'people/alice-example', doc('Alice Example', TRIPLED)], ['source-a', 'people/carol-example', doc('Carol Example', TRIPLED)]]) }), 180_000);- test('put_page keeps one contact row per (type, value), in the file and the database', () => managedBrain(async ({ engine, ctx, root }) => {- for (const sourceId of ['default', 'source-a']) {- await submitPageMutation({ ...ctx, sourceId } as OperationContext, { operation: 'put_page', params: { slug: 'people/alice-example', source_id: sourceId,- request_id: randomUUID(), content: doc('Alice Example', TRIPLED) } });- expect(await contacts(engine, sourceId, 'people/alice-example')).toEqual([{ type: 'phone', value: '+15550100', last_used: '2026-10-03' },- { type: 'email', value: '[email protected]', last_used: '2026-09-01' }, { type: 'phone', value: '+1 555 0100', last_used: '2026-08-01' }]);- }- expect(parseMarkdown(readFileSync(join(root, 'people/alice-example.md'), 'utf8'), 'people/alice-example.md').frontmatter.contacts)- .toEqual(await contacts(engine, 'default', 'people/alice-example'));- }, { databaseUrl, setup: gitRoot }), 180_000);});}