Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
trust: held-removal accept reads a segmented page from its segments; a held strike-through or kind change applies instead of removing the take
garrytan6e56216fef3f
diff --git a/scripts/page-body-readers-baseline.tsv b/scripts/page-body-readers-baseline.tsvindex d300b51f40..0307a68e2e 100644--- a/scripts/page-body-readers-baseline.tsv+++ b/scripts/page-body-readers-baseline.tsv@@ -518,8 +518,8 @@ src/core/timeline-write-through.ts writeTimelineEntryThrough sql SEGW assertInlisrc/core/transcripts/recover.ts userlessCodexSessions sql STREAMsrc/core/transcripts/secret-audit.ts auditTranscriptSecrets field STREAMsrc/core/transcripts/secret-audit.ts auditTranscriptSecrets sql STREAM-src/core/trust/held-removals.ts heldRow sql SEGW loads the body for acceptHeldRemoval, which refuses a segmented page (assertInlineBody) before using it-src/core/trust/held-removals.ts acceptHeldRemoval field SEGW assertInlineBody: refuses a segmented page (page_body_segmented) and the proposal stays pending+src/core/trust/held-removals.ts heldRow sql SEGW inline body only; acceptHeldRemoval reads a segmented page within the single-string ceiling with materializeSegmentedBody+src/core/trust/held-removals.ts acceptHeldRemoval field SEGW materializeSegmentedBody within the single-string ceiling; over it assertInlineBody refuses (no fences there) and the proposal stays pendingsrc/core/trust/page-handlers.ts markdownWithoutMarker call:serializeMarkdown SEGWsrc/core/trust/page-handlers.ts markdownWithoutMarker field SEGWsrc/core/trust/page-handlers.ts versionMarkdown call:serializePageToMarkdown SEGWdiff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 13e777b583..db349dc23d 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -648,6 +648,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }// W1 trust prerequisites (#6783 §12 (a) and (b)).{ since: '0.60.253.0', text: 'A write less trusted than a take or timeline row no longer deletes, replaces or deactivates it. A page publish (`put_page`, sync, a maintenance republish) that drops or rewrites such a row, `takes_remove`, the takes reconcile (`gbrain extract takes`) and the timeline orphan prune now keep the row as it is and file a `forget` proposal (`gbrain trust review`): `gbrain trust confirm tp<id>` applies the change, `gbrain trust drop tp<id>` keeps the row. A refused `takes_remove` returns `forget_requires_owner` with the proposal ref. The page text keeps what the writer published, and the put_page response lists the proposals under `contested`.' },{ since: '0.60.253.0', text: 'Lowering a row\'s trust tier now lowers what was derived from it: facts, takes, pages and timeline rows reached through their recorded derivation inputs drop to the least trusted of their current inputs (an agent edit that lowers a page, an owner tier change, the `gbrain trust claim-sources` relower repair, a derived republish, a fence field rewrite). Raising a tier never promotes a derivative, and recorded history keeps its tiers. A lowered row\'s `write_origin.input_lowered` names the tier it had; on a managed brain a dependent in another source is marked `needs_rederive` instead.' },+ // Held-removal accept follow-up. `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.+ { since: '0.60.253.0', text: 'Accepting a held take change (`gbrain trust confirm tp<id>`) that struck the take through or changed its kind now applies exactly that change; before, the accept removed the take from the page and the index. Accepting a held take or timeline change on a page stored in segments now applies it as on any page instead of refusing with `page_body_segmented`.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/trust/held-removals.ts b/src/core/trust/held-removals.tsindex c3a886420e..1a0bce624c 100644--- a/src/core/trust/held-removals.ts+++ b/src/core/trust/held-removals.ts@@ -4,16 +4,17 @@* A lower-tier write never deletes, replaces or deactivates a take or timeline* row more trusted than it (trust/fence-guard.ts): the row stays and a `forget`* proposal targets it. Accepting applies what the write asked for:- * - a take the page's fence still carries with the same claim (a refused- * `takes_remove`) is removed by an owner `takes_remove` bound to the+ * - a refused `takes_remove` whose take the page's fence still carries with+ * the same claim is removed by an owner `takes_remove` bound to the* proposal by a one-time nonce, so the fence and the index change together;- * - otherwise the page's current text rules that row: the fence row at its+ * - otherwise (a page publish removed, rewrote, re-kinded or struck through+ * the row) the page's current text rules that row: the fence row at its* number (or the timeline entry with its date, source and summary) replaces* it at the writer's tier, and when the page no longer carries one the row* is deleted.- * Dismissing keeps the row (the default reject). A segmented page has no body- * string to rule the row, so its accept refuses (`page_body_segmented`) and the- * proposal stays pending.+ * A segmented page within the single-string ceiling is read back from its+ * segments; one over it holds no fences and refuses (`page_body_segmented`),+ * leaving the proposal pending. Dismissing keeps the row (the default reject).*/import type { BrainEngine } from '../engine.ts';import { parseTakesFence } from '../takes-fence.ts';@@ -26,12 +27,14 @@ import { reprojectTimelineRow } from '../persistence/canonical-projections.ts';import { decisionResult, getTrustProposal, transitionTrustProposal, type TrustDecisionContext, type TrustDecisionResult, type TrustProposalRow } from './proposals.ts';import { storedTrustTier } from './tier.ts';import { assertInlineBody } from '../page-body/page-shape.ts';+import { materializeSegmentedBody } from '../page-body/ingest.ts';+import { segmentedOverCeiling } from '../persistence/segmented-apply.ts';-interface HeldPageRow { id: number; page_id: number; source_id: string; slug: string; body_storage: 'inline' | 'segmented' | null; compiled_truth: string; timeline: string | null }+interface HeldPageRow { id: number; page_id: number; source_id: string; slug: string; body_storage: 'inline' | 'segmented' | null; body_bytes: number | null; compiled_truth: string | null; timeline: string | null }async function heldRow(engine: BrainEngine, table: string, id: number): Promise<(HeldPageRow & Record<string, unknown>) | undefined> {const columns = table === 'takes' ? 'x.row_num, x.claim' : 'x.date::text AS date, x.source, x.summary';- const [row] = await engine.executeRaw<HeldPageRow & Record<string, unknown>>(`SELECT x.id, x.page_id, ${columns}, p.source_id, p.slug, p.body_storage, p.compiled_truth, p.timeline+ const [row] = await engine.executeRaw<HeldPageRow & Record<string, unknown>>(`SELECT x.id, x.page_id, ${columns}, p.source_id, p.slug, p.body_storage, p.body_bytes, p.compiled_truth, p.timelineFROM ${table === 'takes' ? 'takes' : 'timeline_entries'} x JOIN pages p ON p.id = x.page_id WHERE x.id = $1`, [id]);return row;}@@ -53,10 +56,11 @@ export async function acceptHeldRemoval(engine: BrainEngine, proposal: TrustPropawait transitionTrustProposal(engine, proposal.id, 'pending', 'superseded', { decidedBy: ctx.decidedBy });return decisionResult(proposal, 'accept', 'superseded', { reason: 'row_missing' });}- assertInlineBody(row, 'trust confirm (held removal)');- const body = { compiled_truth: row.compiled_truth, timeline: row.timeline ?? '' };- const fenceRow = table === 'takes' ? parseTakesFence(`${row.compiled_truth}\n${row.timeline ?? ''}`).takes.find(t => t.rowNum === Number(row.row_num)) : undefined;- if (fenceRow && fenceRow.claim === row.claim) {+ if (segmentedOverCeiling(row)) assertInlineBody(row, 'trust confirm (held removal)');+ const body = row.body_storage === 'segmented' ? await materializeSegmentedBody(engine, Number(row.page_id), row.source_id)+ : { compiled_truth: row.compiled_truth ?? '', timeline: row.timeline ?? '' };+ const fenceRow = table === 'takes' ? parseTakesFence(`${body.compiled_truth}\n${body.timeline}`).takes.find(t => t.rowNum === Number(row.row_num)) : undefined;+ if (proposal.proposer === 'takes_remove' && fenceRow && fenceRow.claim === row.claim) {const nonce = crypto.randomUUID();await engine.executeRaw(`UPDATE trust_proposals SET after_state = after_state || jsonb_build_object('accept_nonce', $2::text) WHERE id = $1 AND status = 'pending'`, [proposal.id, nonce]);const { submitPageMutation } = await import('../persistence/page-mutations.ts');diff --git a/test/trust-held-removals.test.ts b/test/trust-held-removals.test.tsindex 696a8bc8e7..dadc9cfffe 100644--- a/test/trust-held-removals.test.ts+++ b/test/trust-held-removals.test.ts@@ -32,6 +32,7 @@ import { decideTrustProposal } from '../src/core/trust/decide.ts';import { recordDerivationInputs } from '../src/core/facts/derivation-inputs.ts';import { setRowTier } from '../src/core/trust/page-handlers.ts';import { extractTakesFromDb } from '../src/core/cycle/extract-takes.ts';+import { materializeSegmentedBody } from '../src/core/page-body/ingest.ts';import { LEGACY_EMBEDDING_CONFIG } from './helpers/legacy-embedding-config.ts';import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';import { withEnv } from './helpers/with-env.ts';@@ -181,6 +182,87 @@ describe('held removals (W1 #6783 §12 (a))', () => {}}), 120_000);+ test('the owner accept of a held strike-through (or kind change) applies it to the take; it does not remove the take', async () => withEnv({ GBRAIN_HOME: home }, async () => {+ for (const engine of engines) {+ const b = await brain(engine);+ const slug = 'people/lena-example';+ await run(b.local, 'put_page', { slug, content: page('Lena', 'Lena.') });+ for (const claim of ['Lena will move to Lima', 'Lena prefers tea']) await run(b.local, 'takes_add', { slug, claim, kind: 'bet', holder: 'world', weight: 0.6 });+ const before = await takesOf(b, slug);+ for (const take of before) await confirm(b, 'takes', take.id);+ const current = await localContent(b, slug);+ const edited = String(current.content).replace('Lena will move to Lima', '~~Lena will move to Lima~~').replace(/(\| Lena prefers tea \| )bet/, '$1take');+ expect(edited).not.toBe(String(current.content));+ const put = await run(b.local, 'put_page', { slug, content: edited, expected_revision: current.revision });+ expect(put.contested?.proposal_refs).toHaveLength(2);+ const struck = (await proposalsFor(b, 'takes', before[0]!.id))[0]!;+ const rekinded = (await proposalsFor(b, 'takes', before[1]!.id))[0]!;+ expect(struck.before_state).toMatchObject({ change: 'deactivated' });+ expect(rekinded.before_state).toMatchObject({ change: 'replaced' });+ expect((await decideTrustProposal(engine, struck.id, 'accept', owner)).status).toBe('accepted');+ expect((await decideTrustProposal(engine, rekinded.id, 'accept', owner)).status).toBe('accepted');+ const after = await engine.executeRaw<{ row_num: number; claim: string; kind: string; active: boolean }>(+ 'SELECT row_num, claim, kind, active FROM takes WHERE page_id=$1 ORDER BY row_num', [await pageId(b, slug)]);+ expect(after).toEqual([+ { row_num: before[0]!.row_num, claim: 'Lena will move to Lima', kind: 'bet', active: false },+ { row_num: before[1]!.row_num, claim: 'Lena prefers tea', kind: 'take', active: true },+ ]);+ const text = String((await localContent(b, slug)).content);+ expect(text).toContain('~~Lena will move to Lima~~');+ expect(text).toContain('Lena prefers tea');+ }+ }), 120_000);++ test('on a segmented page, the owner accept of held take and timeline changes applies them; the page and its rows agree', async () => withEnv({ GBRAIN_HOME: home }, async () => {+ for (const engine of engines) {+ const b = await brain(engine);+ await engine.setConfig('pages.segmented_storage', 'on');+ try {+ const slug = 'people/kai-example';+ const filler = Array.from({ length: 20_000 }, (_, i) => `Kai note line ${i} about the acme-example offsite and its agenda.`).join('\n');+ // takes_* verbs refuse a segmented page, so the takes are added while the page is inline and a publish over 1 MiB promotes it.+ await run(b.local, 'put_page', { slug, content: page('Kai', 'Kai.\n\n## Timeline\n\n- **2026-01-05** | note — Kai joined acme-example\n- **2026-02-07** | note — Kai moved to Seoul') });+ for (const claim of ['Kai will lead the offsite', 'Kai ships the agenda']) await run(b.local, 'takes_add', { slug, claim, kind: 'bet', holder: 'world', weight: 0.6 });+ const storage = async () => (await engine.executeRaw<{ body_storage: string }>('SELECT body_storage FROM pages WHERE id=$1', [await pageId(b, slug)]))[0]!.body_storage;+ const small = await localContent(b, slug);+ const big = String(small.content).replace('Kai.\n', `Kai.\n\n${filler}\n`);+ await run(b.local, 'put_page', { slug, content: big, expected_revision: small.revision });+ expect(await storage()).toBe('segmented');+ const takes = await takesOf(b, slug);+ const timeline = await engine.executeRaw<{ id: number; summary: string }>('SELECT id::int AS id, summary FROM timeline_entries WHERE page_id=$1 ORDER BY date', [await pageId(b, slug)]);+ expect(takes).toHaveLength(2);+ expect(timeline).toHaveLength(2);+ for (const take of takes) await confirm(b, 'takes', take.id);+ await confirm(b, 'timeline_entries', timeline[0]!.id);+ // A local agent publish drops take 1, rewrites take 2 and drops the confirmed timeline row.+ // A whole-body get_page refuses a segmented page (body: 'none' reads the revision), so the agent edits the text it published.+ const current = await operationsByName.get_page.handler(b.local, { slug, body: 'none' }) as Record<string, any>;+ const edited = big.split('\n').filter(line => !line.includes('Kai will lead the offsite') && !line.includes('Kai joined acme-example')).join('\n')+ .replace('Kai ships the agenda', 'Kai ships the budget');+ const put = await run(b.local, 'put_page', { slug, content: edited, expected_revision: current.revision });+ expect(put.contested?.proposal_refs).toHaveLength(3);+ expect(await storage()).toBe('segmented');+ // takes_remove refuses a segmented page for every writer before any guard, so it files nothing.+ const refused = await run(b.remote, 'takes_remove', { slug, row_num: takes[1]!.row_num }).then(() => null, (error: unknown) => error) as any;+ expect(refused?.code).toBe('page_body_segmented');+ const pending = (await listTrustProposals(engine, { sourceId: b.sourceId })).filter(p => p.status === 'pending');+ expect(pending.map(p => `${p.target_table}:${p.target_id}`).sort()).toEqual([`takes:${takes[0]!.id}`, `takes:${takes[1]!.id}`, `timeline_entries:${timeline[0]!.id}`].sort());+ for (const proposal of pending) expect((await decideTrustProposal(engine, proposal.id, 'accept', owner)).status).toBe('accepted');+ expect((await takesOf(b, slug)).map(t => [t.row_num, t.claim, t.active])).toEqual([[takes[1]!.row_num, 'Kai ships the budget', true]]);+ expect((await engine.executeRaw<{ summary: string }>('SELECT summary FROM timeline_entries WHERE page_id=$1', [await pageId(b, slug)])).map(r => r.summary)).toEqual(['Kai moved to Seoul']);+ expect(await storage()).toBe('segmented');+ const stored = await materializeSegmentedBody(engine, await pageId(b, slug), b.sourceId);+ const text = `${stored.compiled_truth}\n${stored.timeline}`;+ for (const gone of ['Kai will lead the offsite', 'Kai ships the agenda', 'Kai joined acme-example']) expect(text).not.toContain(gone);+ expect(text).toContain('Kai ships the budget');+ expect(text).toContain('Kai moved to Seoul');+ expect(text).toContain('Kai note line 19999');+ } finally {+ await engine.setConfig('pages.segmented_storage', 'off');+ }+ }+ }), 240_000);+test('the takes reconcile never prunes or overwrites a held take', async () => withEnv({ GBRAIN_HOME: home }, async () => {for (const engine of engines) {const b = await brain(engine);