Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(dream): date transcript-derived atoms by the transcript, not the run (#7268)

garrytanff637d487236
diff --git a/src/core/cycle/atom-source-date.ts b/src/core/cycle/atom-source-date.ts
index 3cfb0a5c89..bcc48e5d96 100644
--- a/src/core/cycle/atom-source-date.ts
+++ b/src/core/cycle/atom-source-date.ts
@@ -6,11 +6,12 @@
* (including a retained-output retry) store the same `effective_date`
* instead of the extraction run time. The stored projection wins; a legacy
* page without one is dated by the same precedence chain import uses.
- * Transcript-derived atoms have no source page and get no date.
+ * Transcript-derived atoms have no source page: transcriptAtomSourceDate.
*/
import type { BrainEngine } from '../engine.ts';
import type { Page } from '../types.ts';
import { computeEffectiveDate } from '../effective-date.ts';
+import { transcriptFrontmatter } from './transcript-discovery.ts';
export async function atomSourceDate(engine: Pick<BrainEngine, 'getConfig'>, page: Page | null): Promise<string | null> {
if (!page) return null;
@@ -22,3 +23,19 @@ export async function atomSourceDate(engine: Pick<BrainEngine, 'getConfig'>, pag
});
return date ? date.toISOString() : null;
}
+
+/**
+ * #7268: the content date a transcript-derived atom inherits, by the same
+ * precedence chain: the transcript's frontmatter date keys, else `pathDate`
+ * (the date in its path that names its atoms/<date>/ folder). Null when it
+ * carries neither; the extraction run never stands in for it. A failed
+ * timezone read keeps the phase fail-soft and reads the date as UTC.
+ */
+export async function transcriptAtomSourceDate(engine: Pick<BrainEngine, 'getConfig'>, content: string, pathDate: string): Promise<string | null> {
+ const { date } = computeEffectiveDate({
+ slug: '', frontmatter: transcriptFrontmatter(content), filename: pathDate,
+ createdAt: new Date(NaN), updatedAt: new Date(NaN),
+ timeZone: (await engine.getConfig('brain.timezone').catch(() => null)) ?? undefined,
+ });
+ return date ? date.toISOString() : null;
+}
diff --git a/src/core/cycle/extract-atoms.ts b/src/core/cycle/extract-atoms.ts
index f5fc349b6e..1c221bc06f 100644
--- a/src/core/cycle/extract-atoms.ts
+++ b/src/core/cycle/extract-atoms.ts
@@ -85,7 +85,7 @@ import { slugifySegment } from '../sync.ts';
import { resolveAlias, resolveTierDefault } from '../model-config.ts';
import { isMissingSchemaObject, warnOncePerProcess } from '../utils.ts';
import { utcDate } from './cycle-date.ts';
-import { atomSourceDate } from './atom-source-date.ts';
+import { atomSourceDate, transcriptAtomSourceDate } from './atom-source-date.ts';
import { normalizeForGrounding } from './synthesize-verify.ts';
import type { TranscriptPageIndex } from '../transcripts/discover.ts';
import { atomOriginPin, atomWriteFailure, type AtomWriteFailure, managedAtomSession, readAtomOrigin, resumeManagedAtoms, publishManagedAtoms, publishManagedAtomGeneration, resumeManagedGenerationMembers,
@@ -1108,7 +1108,7 @@ export async function runPhaseExtractAtoms(
try {
origin = managed ? { ...await readAtomOrigin(engine, managed, item), ...(truncated ? { partialInputChars: maxInputChars } : {}) } : null;
const sourcePage = item.kind === 'page' ? await engine.getPage(item.slug, { sourceId }) : null;
- const contentDate = await atomSourceDate(engine, sourcePage); // #6720: captured with the input, before inference
+ const contentDate = await (item.kind === 'page' ? atomSourceDate(engine, sourcePage) : transcriptAtomSourceDate(engine, item.content, sourceDate(item.filePath, ''))); // #6720, #7268: captured with the input, before inference
const visibility = origin?.visibility ?? effectiveVisibility(item.kind === 'transcript' ? { kind: 'transcript' } // #5525
: { kind: 'page', page: sourcePage && { ...sourcePage, folder_restricted: await folderRestricted(engine, sourceId, item.slug) } });
throwIfAborted(opts.signal, 'extract_atoms');
diff --git a/src/core/cycle/transcript-discovery.ts b/src/core/cycle/transcript-discovery.ts
index ae1f65bbd8..6ffa911c34 100644
--- a/src/core/cycle/transcript-discovery.ts
+++ b/src/core/cycle/transcript-discovery.ts
@@ -80,7 +80,7 @@ const DATE_RE = /^(\d{4}-\d{2}-\d{2})/;
const WORD_BOUNDARY_HEURISTIC = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
/** A transcript's frontmatter; none, or unreadable, is `{}` (a plain-text header is not an error). */
-function transcriptFrontmatter(content: string): Record<string, unknown> {
+export function transcriptFrontmatter(content: string): Record<string, unknown> {
try {
return parseDataFrontmatter(content).data;
} catch {
diff --git a/test/extract-atoms-source-date.test.ts b/test/extract-atoms-source-date.test.ts
index a6726c16eb..c93e4f430d 100644
--- a/test/extract-atoms-source-date.test.ts
+++ b/test/extract-atoms-source-date.test.ts
@@ -7,8 +7,12 @@
* with the extraction input, before the model call, and serialized into the
* atom's frontmatter `date`, so classic import and managed publication
* (test/helpers/managed-atoms-contract.ts) store the same date.
- * Regression: dropping the stamp, reading the date after inference, or
- * borrowing a date for a transcript-derived atom (no source page).
+ * #7268: a transcript-derived atom has no source page; it takes the
+ * transcript's own frontmatter date, else the date in its path (the one that
+ * names its atoms/<date>/ folder), and an undated transcript borrows none.
+ * Regression: dropping the stamp, reading the date after inference, dating
+ * a transcript atom by the extraction run, or borrowing a date for an
+ * undated transcript.
* Model calls go through the `_chat` seam; persistence is real PGLite.
*/
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
@@ -70,16 +74,29 @@ describe('#6720 atom content dates', () => {
}, 60_000);
}
- test('a transcript-derived atom has no source page and borrows no date', async () => {
- const sourceId = 'atom-date-transcript';
- await engine.executeRaw('INSERT INTO sources(id,name) VALUES($1,$1)', [sourceId]);
- const result = await runPhaseExtractAtoms(engine, {
- sourceId, _pages: [], _transcripts: [{ filePath: '/fake/2026-07-09-call.txt', content: body, contentHash: 'ab'.repeat(32) }],
- _chat: async () => reply(),
- });
- expect(result.details?.atoms_extracted).toBe(1);
- const atom = await onlyAtom(sourceId);
- expect(atom.frontmatter.date).toBeUndefined();
- expect(atom.effective_date_source).not.toBe('date');
- }, 60_000);
+ for (const fx of [
+ { id: 'path-filename', filePath: '/fake/2026-07-09-call.txt', head: '', date: '2026-07-09T00:00:00.000Z' },
+ { id: 'path-folder', filePath: '/fake/2026-07-09/call.txt', head: '', date: '2026-07-09T00:00:00.000Z' },
+ { id: 'frontmatter', filePath: '/fake/2026-07-09-call.md', head: '---\ndate: 2026-05-04\n---\n', date: '2026-05-04T00:00:00.000Z' },
+ { id: 'plain-header', filePath: '/fake/2026-07-09-call.txt', head: '--- BEGIN TRANSCRIPT\n', date: '2026-07-09T00:00:00.000Z' },
+ { id: 'undated', filePath: '/fake/call.txt', head: '', date: undefined },
+ ]) {
+ test(`a transcript-derived atom carries the transcript's ${fx.id} date, never the run's`, async () => {
+ const sourceId = `atom-date-transcript-${fx.id}`;
+ await engine.executeRaw('INSERT INTO sources(id,name) VALUES($1,$1)', [sourceId]);
+ const result = await runPhaseExtractAtoms(engine, {
+ sourceId, _pages: [], _transcripts: [{ filePath: fx.filePath, content: fx.head + body, contentHash: 'ab'.repeat(32) }],
+ _chat: async () => reply(),
+ });
+ expect(result.details?.atoms_extracted).toBe(1);
+ const atom = await onlyAtom(sourceId);
+ expect(atom.frontmatter.date).toBe(fx.date);
+ if (fx.date === undefined) {
+ expect(atom.effective_date_source).toBe('fallback');
+ return;
+ }
+ expect(new Date(atom.effective_date!).toISOString()).toBe(fx.date);
+ expect(atom.effective_date_source).toBe('date');
+ }, 60_000);
+ }
});
diff --git a/test/helpers/managed-atoms-contract.ts b/test/helpers/managed-atoms-contract.ts
index a4a28a117d..8933eba234 100644
--- a/test/helpers/managed-atoms-contract.ts
+++ b/test/helpers/managed-atoms-contract.ts
@@ -39,7 +39,7 @@ export async function exerciseManagedAtoms(engine: BrainEngine, scenario: Case):
await disposePersistenceConsumer(engine);
await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
await engine.executeRaw('INSERT INTO sources(id,name) VALUES($1,$1)', [sourceId]);
- const contentDate = '2026-07-09T15:45:00.000Z'; // #6720: page-derived atoms inherit it, transcript-derived ones never do
+ const contentDate = '2026-07-09T15:45:00.000Z'; // #6720: page-derived atoms inherit it; this undated transcript gives its atoms none (#7268)
await engine.putPage('notes/example', { type: 'source', title: 'Example', compiled_truth: 'A private project record. '.repeat(40),
frontmatter: { visibility: 'private', date: contentDate }, effective_date: new Date(contentDate), effective_date_source: 'date' }, { sourceId });
const page = (await engine.getPage('notes/example', { sourceId }))!;