Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

synthesize_concepts: leave the model out of a T3 concept's member hash (#7269)

garrytandd90204c1eb7
diff --git a/src/core/cycle/synthesize-concepts.ts b/src/core/cycle/synthesize-concepts.ts
index 1cdb6ba513..1008bcf1e8 100644
--- a/src/core/cycle/synthesize-concepts.ts
+++ b/src/core/cycle/synthesize-concepts.ts
@@ -365,20 +365,30 @@ export async function runPhaseSynthesizeConcepts(
.digest('hex').slice(0, 16);
const narrativeBodies = group.atomBodies.map(stripFenceSections);
const hashFor = (model: string): string => hashOf(model, narrativeBodies);
- const memberHash = hashFor(synthModel);
+ // #7269: a T3 narrative is the deterministic template, which never calls the model, so its hash leaves the model out.
+ const hashModel = group.tier === 'T1' || group.tier === 'T2' ? synthModel : '';
+ const memberHash = hashFor(hashModel);
const priorMode = existing?.frontmatter?.synthesis_mode;
const realNarrative = priorMode === 'llm' || priorMode === 'deterministic_tier';
if (existing?.frontmatter?.member_hash === memberHash && realNarrative) {
skippedUnchanged.push(conceptSlug);
continue;
}
+ // #7269: rewriting a deterministic page to the template it already holds, at a visibility it already has, would
+ // publish nothing new (a page hashed with the model before the fix keeps its body and is not rewritten).
+ const priorVisibility: Visibility = existing?.frontmatter?.visibility === 'private' ? 'private' : 'world';
+ if (hashModel === '' && priorMode === 'deterministic_tier' && strictestVisibility([group.visibility, priorVisibility]) === priorVisibility
+ && stripFenceSections(existing!.compiled_truth).trim() === deterministicNarrative(group).trim()) {
+ skippedUnchanged.push(conceptSlug);
+ continue;
+ }
// #6643 (B1): a drifted concept would only add a conflict receipt per publication; checked live before any spend.
if (await driftSkips.skip(conceptSlug, existingSnapshot)) continue;
const held = existing && conceptPublicationHold(existing); // checked before any spend
if (held) { publicationHeld.push({ concept: group.conceptSlug, reason: held }); continue; }
// A page hashed by the pre-D-N3 formula (full atom bodies) whose inputs are
// provably unchanged keeps its narrative: only the hash is rewritten, no spend.
- const grandfathered = realNarrative && existing?.frontmatter?.member_hash === hashOf(synthModel, group.atomBodies);
+ const grandfathered = realNarrative && existing?.frontmatter?.member_hash === hashOf(hashModel, group.atomBodies);
if (!grandfathered) tierCounts[group.tier]++;
let narrative: string;
let synthesisMode: ConceptSynthesisMode, unverifiedClaims: UnverifiedClaim[] = [];
diff --git a/test/e2e/g4-concept-t3-model-hash-7269-postgres.test.ts b/test/e2e/g4-concept-t3-model-hash-7269-postgres.test.ts
new file mode 100644
index 0000000000..113986699d
--- /dev/null
+++ b/test/e2e/g4-concept-t3-model-hash-7269-postgres.test.ts
@@ -0,0 +1,3 @@
+import { registerPostgresTests } from '../helpers/test-backends.ts';
+
+await registerPostgresTests(() => import('../pathological/g4-concept-t3-model-hash-7269.test.ts'));
diff --git a/test/pathological/g4-concept-t3-model-hash-7269.test.ts b/test/pathological/g4-concept-t3-model-hash-7269.test.ts
new file mode 100644
index 0000000000..ab11d00eb7
--- /dev/null
+++ b/test/pathological/g4-concept-t3-model-hash-7269.test.ts
@@ -0,0 +1,79 @@
+/**
+ * #7269 (reported by @p3ob7o): a T3 concept's narrative is the deterministic template (`deterministicNarrative` never
+ * calls the model), so its member hash must not include the synthesis model. Changing `models.dream.synthesize`
+ * rewrote every T3 page; after the fix none is rewritten, while T1 and T2 pages (model narratives) still are. A
+ * rewrite that would leave a deterministic page as it is publishes nothing. PGLite; Postgres when DATABASE_URL is set.
+ */
+import { describe, expect, test } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import type { BrainEngine } from '../../src/core/engine.ts';
+import type { ChatResult } from '../../src/core/ai/gateway.ts';
+import { runPhaseSynthesizeConcepts } from '../../src/core/cycle/synthesize-concepts.ts';
+import { _resetWriteThroughCacheForTest } from '../../src/core/write-through.ts';
+import { isolatedSharedSkillsEngine } from '../helpers/shared-skills-engine.ts';
+import { withEnv } from '../helpers/with-env.ts';
+import { pathologicalArms } from './harness.ts';
+
+const MODEL_A = 'anthropic:claude-sonnet-4-6';
+const MODEL_B = 'openai:gpt-5.5';
+const SIZES: Record<string, number> = { t1: 10, t2: 5, t3a: 2, t3b: 4 };
+
+const atoms = Object.entries(SIZES).flatMap(([concept, n]) => Array.from({ length: n }, (_, i) => ({
+ slug: `atoms/${concept}-${i}`, concept_refs: [`concepts/${concept}`], body: `Atom ${i} about ${concept}.`, title: `${concept} atom ${i}`,
+})));
+
+const chat = (model: string) => async (): Promise<ChatResult> => {
+ const text = 'A complete narrative about this concept.';
+ return { text, blocks: [{ type: 'text', text }], stopReason: 'end',
+ usage: { input_tokens: 10, output_tokens: 10, cache_read_tokens: 0, cache_creation_tokens: 0 }, model, providerId: model.split(':')[0]! };
+};
+
+async function revisions(engine: BrainEngine): Promise<Record<string, string>> {
+ const out: Record<string, string> = {};
+ for (const concept of Object.keys(SIZES)) out[concept] = (await engine.readPageSnapshot(`concepts/${concept}`, { sourceId: 'default' }))!.revision;
+ return out;
+}
+
+async function world(databaseUrl: string | undefined, run: (engine: BrainEngine) => Promise<void>): Promise<void> {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-7269-'));
+ try {
+ await withEnv({ GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () => {
+ _resetWriteThroughCacheForTest();
+ const { engine, close } = await isolatedSharedSkillsEngine(databaseUrl);
+ try { await run(engine); } finally { await close(); }
+ });
+ } finally { rmSync(home, { recursive: true, force: true }); }
+}
+
+for (const { backend, databaseUrl } of pathologicalArms()) {
+ describe(`#7269 T3 concept member hash (${backend})`, () => {
+ test('changing the synthesis model rewrites T1 and T2 concepts and leaves every T3 concept as it was', async () => {
+ await world(databaseUrl, async engine => {
+ await engine.setConfig('models.dream.synthesize', MODEL_A);
+ await runPhaseSynthesizeConcepts(engine, { _atoms: atoms, _chat: chat(MODEL_A) });
+ const tiers = Object.fromEntries(await Promise.all(Object.keys(SIZES).map(async c => [c, (await engine.getPage(`concepts/${c}`, { sourceId: 'default' }))!.frontmatter.tier])));
+ expect(tiers).toEqual({ t1: 'T1', t2: 'T2', t3a: 'T3', t3b: 'T3' });
+ const before = await revisions(engine);
+ await engine.setConfig('models.dream.synthesize', MODEL_B);
+ await runPhaseSynthesizeConcepts(engine, { _atoms: atoms, _chat: chat(MODEL_B) });
+ const after = await revisions(engine);
+ expect(Object.fromEntries(Object.keys(SIZES).map(c => [c, after[c] !== before[c]]))).toEqual({ t1: true, t2: true, t3a: false, t3b: false });
+ });
+ }, 240_000);
+
+ test('a T3 concept written before the fix (hash with the model) is not rewritten when the model changes', async () => {
+ await world(databaseUrl, async engine => {
+ await engine.setConfig('models.dream.synthesize', MODEL_A);
+ await runPhaseSynthesizeConcepts(engine, { _atoms: atoms, _chat: chat(MODEL_A) });
+ await engine.executeRaw(`UPDATE pages SET frontmatter = frontmatter || '{"member_hash":"0123456789abcdef"}'::jsonb WHERE slug IN ('concepts/t3a','concepts/t3b')`);
+ const before = await revisions(engine);
+ await engine.setConfig('models.dream.synthesize', MODEL_B);
+ await runPhaseSynthesizeConcepts(engine, { _atoms: atoms, _chat: chat(MODEL_B) });
+ const after = await revisions(engine);
+ expect([after.t3a === before.t3a, after.t3b === before.t3b]).toEqual([true, true]);
+ });
+ }, 240_000);
+ });
+}