Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(dream): a classic same-day synthesize rerun that writes nothing keeps the summary (#6935)

time-attack08d77fc07d63
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index cc2f0f5bfc..4345af98bc 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -904,6 +904,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.299.0', text: 'Managed sync of a Markdown file over 24 MiB whose origin another page records (a page renamed with its file) now imports it into that page, as for a smaller file, instead of failing it `revision_conflict` ("A different page already owns this file identity") and stopping the source\'s sync at it.' },
{ since: '0.60.299.0', text: '`gbrain repair stuck-recovery` now resolves a page recovery whose file is over 24 MiB, which used to be listed as refused (`recovery_large_file_unsupported`) with no exit while it stopped every write on its source\'s worktree. The preview lists it with both fingerprints and the state of the staged copy of the prior file, backs up both versions, and writes a summary instead of a full diff (both hashes and sizes, the first byte where they differ, and a window of at most 1 KiB); `--apply --expect <hash> --keep prior|disk --yes` resolves it as it does a small file. Every read, hash and copy of the large file is done in pieces of at most a segment. When the staged copy of the prior file is missing or damaged, `--keep prior` refuses with `recovery_prior_stage_unavailable`, whose fix is the `--keep disk` apply, which keeps a damaged copy in the backup directory and removes it from the checkout.' },
{ since: '0.60.307.0', text: 'The remote doctor (`run_doctor`, `gbrain remote doctor`) now confines every check to the sources the caller may read. A source-scoped token no longer sees other sources\' ids, names, lag, embed coverage or failed jobs in `federation_health` and `sync_freshness`, or brain-wide counts in `sync_consolidation`, `links_extraction_lag` (each granted source is graded on its own and the worst is reported), `schema_pack_source_drift`, `graph_signals_coverage`, `hidden_by_search_policy`, `link_resolution_opportunity`, `embedding_migration_state`, the synopsis-failure line of `contextual_retrieval_coverage`, `brainstorm_health`, `abandoned_threads`, `calibration_freshness`, `grade_confidence_drift` and `voice_gate_health`. `federation_health` grades a scoped caller\'s sources even when it is granted only one. The local doctor and unscoped callers are unchanged.' },
+ // Fix wave 20 lane 2 (dream, transcripts, extraction, autopilot).
+ { since: '0.60.307.0', text: 'A same-day `dream` synthesize rerun that writes no pages now keeps that day\'s existing `dream-cycle-summaries/<date>` page (database row and file) on every brain, as managed brains already did, instead of replacing it with an empty summary. The first run of a day still writes its summary even when it wrote nothing.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/cycle/synthesize.ts b/src/core/cycle/synthesize.ts
index 8033aecb0b..cdbf286f17 100644
--- a/src/core/cycle/synthesize.ts
+++ b/src/core/cycle/synthesize.ts
@@ -1179,7 +1179,7 @@ async function runPhaseSynthesizeInner(
const summarySlug = buildDreamSummarySlug(config.outputRoot, summaryDate);
const writtenSlugs = writtenRefs.map(r => r.slug);
if (SUMMARY_SLUG_RE.test(summarySlug) && !publishPending) {
- const preserveSummary = maintenance && !writtenRefs.length && await engine.readPageSnapshot(summarySlug, { sourceId: cycleSourceId });
+ const preserveSummary = !writtenRefs.length && await engine.readPageSnapshot(summarySlug, { sourceId: cycleSourceId });
if (!preserveSummary) await writeSummaryPage(engine, opts.brainDir, summarySlug, summaryDate, finalizedRefs.map(r => r.slug), childOutcomes, cycleSourceId, opts.signal, maintenance)
.then(held => held && fileHolds.push(held), (e: unknown) => { deferPublishOrThrow(e, summarySlug); publishPending++; });
}
diff --git a/test/e2e/dream-synthesize-pglite.test.ts b/test/e2e/dream-synthesize-pglite.test.ts
index 2192045669..6247df1a3a 100644
--- a/test/e2e/dream-synthesize-pglite.test.ts
+++ b/test/e2e/dream-synthesize-pglite.test.ts
@@ -1397,4 +1397,63 @@ describe('E2E synthesize — oneshot mode (#4216, DEFAULT)', () => {
await rig.cleanup();
}
}, 60_000);
+
+ test('a same-day rerun that writes zero pages keeps the existing summary (DB row and file)', async () => {
+ const rig = await setupRig();
+ const savedKey = process.env.ANTHROPIC_API_KEY;
+ process.env.ANTHROPIC_API_KEY = 'sk-test-summary-preserve';
+ try {
+ await rig.engine.setConfig('dream.synthesize.enabled', 'true');
+ await rig.engine.setConfig('dream.synthesize.session_corpus_dir', rig.corpusDir);
+ await rig.engine.setConfig('agent.use_gateway_loop', 'true');
+
+ // The earlier run of the day already published its summary.
+ const date = '2026-08-16';
+ const summarySlug = `dream-cycle-summaries/${date}`;
+ const summaryPath = join(rig.brainDir, `${summarySlug}.md`);
+ await synthTesting.writeSummaryPage(rig.engine, rig.brainDir, summarySlug, date,
+ ['wiki/originals/ideas/earlier-page'], [{ jobId: 1, status: 'completed' }], 'default');
+ const bytes = readFileSync(summaryPath, 'utf8');
+ const before = await rig.engine.readPageSnapshot(summarySlug, { sourceId: 'default' });
+ expect(before).not.toBeNull();
+
+ const content = 'User: the doomed transcript whose writes all fail\n'.repeat(120);
+ const file = join(rig.corpusDir, `${date}-doomed.txt`);
+ writeFileSync(file, content);
+ await seedVerdictFor(rig, file, content);
+
+ // Same doomed shape as the mixed-outcome test: the only child dies.
+ let turns = 0;
+ __setChatTransportForTests(async () => {
+ const mk = (text: string, blocks: unknown[], stop: string) => ({
+ text, blocks, stopReason: stop,
+ usage: { input_tokens: 100, output_tokens: 20, cache_read_tokens: 0, cache_creation_tokens: 0 },
+ model: 'anthropic:claude-sonnet-4-6',
+ providerId: 'anthropic',
+ }) as any;
+ turns++;
+ if (turns === 1) return mk('here you go! pages!', [{ type: 'text', text: 'here you go! pages!' }], 'end');
+ if (turns === 2) {
+ return mk('', [{
+ type: 'tool-call', toolCallId: 'tc1', toolName: 'brain_put_page',
+ input: { slug: 'notallowed/sneaky-page', content: 'nope' },
+ }], 'tool_calls');
+ }
+ return mk('done', [{ type: 'text', text: 'done' }], 'end');
+ });
+
+ const result = await runPhaseSynthesize(rig.engine, { brainDir: rig.brainDir, dryRun: false, date });
+ expect(result.status).toBe('fail');
+ expect(result.error?.code).toBe('SYNTH_ALL_CHILDREN_DEAD');
+
+ expect(readFileSync(summaryPath, 'utf8')).toBe(bytes);
+ expect(await rig.engine.readPageSnapshot(summarySlug, { sourceId: 'default' })).toEqual(before);
+ } finally {
+ if (savedKey === undefined) delete process.env.ANTHROPIC_API_KEY;
+ else process.env.ANTHROPIC_API_KEY = savedKey;
+ __setChatTransportForTests(null);
+ resetGateway();
+ await rig.cleanup();
+ }
+ }, 60_000);
});