Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
GBRA-161 PR 4: an unchanged synthesis re-run admits no activation (#7065)
garrytan33d8fe76362c
diff --git a/src/core/cycle/synthesize-generations.ts b/src/core/cycle/synthesize-generations.tsindex 368266b39d..67d48d4c94 100644--- a/src/core/cycle/synthesize-generations.ts+++ b/src/core/cycle/synthesize-generations.ts@@ -111,13 +111,13 @@ export async function activateSynthesisGenerations(engine: BrainEngine, input: Sif (maintenance) {const plan = await planManagedGeneration(engine, synthesisAdapter, request, { locator: t.filePath });if (plan.kind === 'held') { details.held.push({ owner_key: key.ownerKey, reason: plan.outcome.reason }); continue; }- if (plan.kind === 'publish') {- await admitInPlaceGeneration(engine, maintenance, plan);- retired = plan.members.filter(member => member.action === 'retire').map(member => member.slug);- }+ if (plan.kind === 'unchanged') continue;+ await admitInPlaceGeneration(engine, maintenance, plan);+ retired = plan.members.filter(member => member.action === 'retire').map(member => member.slug);} else {const outcome = await publishGeneration(engine, synthesisAdapter, request);if (outcome.state === 'held') { details.held.push({ owner_key: key.ownerKey, reason: outcome.reason }); continue; }+ if (outcome.state === 'unchanged') continue;retired = outcome.retired;for (const slug of retired) {const file = await removeDreamPageFile(engine, input.brainDir, slug, sourceId, sourceId);diff --git a/src/core/generations/managed.ts b/src/core/generations/managed.tsindex e4be494584..26de087b5c 100644--- a/src/core/generations/managed.ts+++ b/src/core/generations/managed.ts@@ -102,7 +102,7 @@ export async function planManagedGeneration<C>(engine: BrainEngine, adapter: Genconst outcome = await engine.transaction(tx => recordHeld(tx, request.key, config, planned as PublishRequest<unknown>, setHash, plan.reason, plan.context));return { kind: 'held', outcome: outcome as Extract<PublishOutcome, { state: 'held' }> };}- if (plan.kind === 'unchanged' && !request.items.length) return { kind: 'unchanged' };+ if (plan.kind === 'unchanged' && (!request.items.length || adapter.publishesInPlace)) return { kind: 'unchanged' };const retires = plan.kind === 'publish' ? plan.retires : [];// A kind whose producer already wrote its items (publishesInPlace) keeps each one live at its identity without a member.const inPlace = adapter.publishesInPlace === true ? request.items.filter(item => { const row = rows.get(item.key); return row?.live && row.identityHash === item.identityHash; }) : [];diff --git a/test/generations-synthesis-coverage.test.ts b/test/generations-synthesis-coverage.test.tsnew file mode 100644index 0000000000..12cdb2fc43--- /dev/null+++ b/test/generations-synthesis-coverage.test.ts@@ -0,0 +1,51 @@+/**+ * GBRA-161 PR 4 (#7065): the pure predecessor match (generations/synthesis-coverage.ts). An earlier synthesis output may+ * retire only as an exact duplicate, or on the same subject with every claim unit, quote and citation covered.+ */+import { describe, expect, test } from 'bun:test';+import { citations, claimUnits, matchPredecessor, quotes, subjectStem, titleTokens } from '../src/core/generations/synthesis-coverage.ts';++const earlier = { slug: 'wiki/personal/reflections/2026-10-01-storage-plan-0b4ba2', title: 'Storage plan',+ body: 'The storage plan moved to object storage. Costs are reviewed weekly.\n\n> we charge for durability\n\nDecided with [[people/alice-example]].' };+const page = (slug: string, title: string, body: string) => ({ slug, title, body });++describe('synthesis predecessor match (#7065)', () => {+ test('the subject stem drops the hash suffix, the chunk suffix and the date prefix; title tokens are a sorted lowercase set', () => {+ expect(subjectStem('wiki/personal/reflections/2026-10-01-storage-plan-0b4ba2')).toBe('wiki/personal/reflections/storage-plan');+ expect(subjectStem('wiki/personal/reflections/storage-plan-70251c-c1')).toBe('wiki/personal/reflections/storage-plan');+ expect(titleTokens('Plan: Storage, plan!')).toBe('plan storage');+ });++ test('claim units skip quote blocks and headings; quotes are > blocks and quoted spans of three or more words; citations are link targets', () => {+ const body = '# Heading\nFirst claim. Second claim!\n> a quoted block\nShe said "only two" and "this one counts here".\nSee [[people/alice-example|Alice]] and [doc](https://example.com/a).';+ expect(claimUnits(body)).toEqual(['first claim', 'second claim', 'she said "only two" and "this one counts here"', 'see alice and doc']);+ expect(quotes(body)).toEqual(['a quoted block', 'this one counts here']);+ expect(citations(body)).toEqual(['https://example.com/a', 'people/alice-example']);+ });++ test('an exact duplicate matches whatever its slug', () => {+ expect(matchPredecessor(earlier, [page('wiki/personal/originals/other-1a2b3c', 'Other', earlier.body)])).toMatchObject({ matched: true, why: 'duplicate' });+ });++ test('a successor on the same subject that covers every claim, quote and citation matches', () => {+ const successor = page('wiki/personal/reflections/2026-10-02-storage-plan-70251c', 'Storage plan', earlier.body + '\n\nA new claim from the grown transcript.');+ expect(matchPredecessor(earlier, [successor])).toEqual({ matched: true, why: 'covered', successor: successor.slug });+ });++ test('one unquoted claim the successor lacks keeps the earlier page live, with the count', () => {+ const successor = page('wiki/personal/reflections/storage-plan-70251c', 'Storage plan', earlier.body.replace(' Costs are reviewed weekly.', ''));+ expect(matchPredecessor(earlier, [successor])).toEqual({ matched: false, why: 'uncovered', missing: { claims: 1, quotes: 0, citations: 0 } });+ });++ test('a missing quote or citation keeps it live', () => {+ const noQuote = page('wiki/personal/reflections/storage-plan-70251c', 'Storage plan', earlier.body.replace('> we charge for durability', 'We charge for it.'));+ expect(matchPredecessor(earlier, [noQuote])).toMatchObject({ matched: false, missing: { quotes: 1 } });+ const noCite = page('wiki/personal/reflections/storage-plan-70251c', 'Storage plan', earlier.body.replace('[[people/alice-example]]', 'Alice-example'));+ expect(matchPredecessor(earlier, [noCite])).toMatchObject({ matched: false, missing: { citations: 1 } });+ });++ test('full coverage under another subject is not a match', () => {+ const renamed = page('wiki/personal/reflections/storage-strategy-70251c', 'Storage strategy', earlier.body + ' More.');+ expect(matchPredecessor(earlier, [renamed])).toMatchObject({ matched: false, why: 'no_subject', missing: { claims: 0, quotes: 0, citations: 0 } });+ });+});