@@ -1041,7 +1041,13 @@ describe("memory-core dreaming phases", () => {
10411041 setDreamingTestEnv ( path . join ( workspaceDir , ".state" ) ) ;
10421042 const sessionsDir = resolveSessionTranscriptsDirForAgent ( "main" ) ;
10431043 await fs . mkdir ( sessionsDir , { recursive : true } ) ;
1044- const transcriptPath = path . join ( sessionsDir , "dreaming-main.jsonl" ) ;
1044+ const transcriptName = `dreaming-${ "x" . repeat ( 48 ) } .jsonl` ;
1045+ const transcriptPath = path . join ( sessionsDir , transcriptName ) ;
1046+ const snippetTranscriptName = "snippet-boundary.jsonl" ;
1047+ const snippetTranscriptPath = path . join ( sessionsDir , snippetTranscriptName ) ;
1048+ const renderedSource = `[main/sessions/main/${ transcriptName } #L4] ` ;
1049+ const renderedPadding = "r" . repeat ( 343 - renderedSource . length - "User: " . length ) ;
1050+ const snippetPadding = "s" . repeat ( 273 ) ;
10451051 await fs . writeFile (
10461052 transcriptPath ,
10471053 [
@@ -1066,9 +1072,29 @@ describe("memory-core dreaming phases", () => {
10661072 content : [ { type : "text" , text : "Set retention to 365 days." } ] ,
10671073 } ,
10681074 } ) ,
1075+ JSON . stringify ( {
1076+ type : "message" ,
1077+ message : {
1078+ role : "user" ,
1079+ timestamp : "2026-04-05T18:03:00.000Z" ,
1080+ content : [ { type : "text" , text : `${ renderedPadding } 🎉 omitted tail` } ] ,
1081+ } ,
1082+ } ) ,
10691083 ] . join ( "\n" ) + "\n" ,
10701084 "utf-8" ,
10711085 ) ;
1086+ await fs . writeFile (
1087+ snippetTranscriptPath ,
1088+ JSON . stringify ( {
1089+ type : "message" ,
1090+ message : {
1091+ role : "user" ,
1092+ timestamp : "2026-04-05T18:04:00.000Z" ,
1093+ content : [ { type : "text" , text : `${ snippetPadding } 🌍 omitted tail` } ] ,
1094+ } ,
1095+ } ) + "\n" ,
1096+ "utf-8" ,
1097+ ) ;
10721098
10731099 const { beforeAgentReply } = createHarness (
10741100 {
@@ -1118,7 +1144,7 @@ describe("memory-core dreaming phases", () => {
11181144 expect ( transcriptReadCount ) . toBeLessThanOrEqual ( 1 ) ;
11191145
11201146 const sessionIngestion = await testing . readSessionIngestionState ( workspaceDir ) ;
1121- expect ( Object . keys ( sessionIngestion . files ) ) . toContain ( " main:sessions/main/dreaming-main.jsonl" ) ;
1147+ expect ( Object . keys ( sessionIngestion . files ) ) . toContain ( ` main:sessions/main/${ transcriptName } ` ) ;
11221148 const corpusPath = path . join (
11231149 workspaceDir ,
11241150 "memory" ,
@@ -1129,6 +1155,12 @@ describe("memory-core dreaming phases", () => {
11291155 const corpus = await fs . readFile ( corpusPath , "utf-8" ) ;
11301156 expect ( corpus ) . toContain ( "Move backups to S3 Glacier." ) ;
11311157 expect ( corpus ) . toContain ( "Set retention to 365 days." ) ;
1158+ expect ( corpus ) . toContain ( `${ renderedSource } User: ${ renderedPadding } \n` ) ;
1159+ expect ( corpus ) . toContain (
1160+ `[main/sessions/main/${ snippetTranscriptName } #L1] User: ${ snippetPadding } \n` ,
1161+ ) ;
1162+ expect ( corpus ) . not . toContain ( "🎉" ) ;
1163+ expect ( corpus ) . not . toContain ( "🌍" ) ;
11321164
11331165 const ranked = await rankShortTermPromotionCandidates ( {
11341166 workspaceDir,
@@ -2515,6 +2547,41 @@ describe("memory-core dreaming phases", () => {
25152547 expect ( after [ 0 ] ?. snippet ) . toContain ( "messages short and low-pressure" ) ;
25162548 } ) ;
25172549
2550+ it ( "keeps daily ingestion snippets valid at surrogate-pair boundaries" , async ( ) => {
2551+ const workspaceDir = await createDreamingWorkspace ( ) ;
2552+ const memoryDir = path . join ( workspaceDir , "memory" ) ;
2553+ const headingPrefix = "h" . repeat ( 279 ) ;
2554+ const itemPrefix = "i" . repeat ( 279 ) ;
2555+ const chunkPrefix = "c" . repeat ( 272 ) ;
2556+ await Promise . all ( [
2557+ fs . writeFile (
2558+ path . join ( memoryDir , "2026-04-05-heading.md" ) ,
2559+ [ `# ${ headingPrefix } 🎉` , "" , "- Durable heading context item." ] . join ( "\n" ) ,
2560+ "utf-8" ,
2561+ ) ,
2562+ fs . writeFile (
2563+ path . join ( memoryDir , "2026-04-05-item.md" ) ,
2564+ [ "# 2026-04-05" , "" , `- ${ itemPrefix } 🎉` ] . join ( "\n" ) ,
2565+ "utf-8" ,
2566+ ) ,
2567+ fs . writeFile (
2568+ path . join ( memoryDir , "2026-04-05-chunk.md" ) ,
2569+ [ "# 2026-04-05" , "" , "## Topic" , `- ${ chunkPrefix } 🎉` ] . join ( "\n" ) ,
2570+ "utf-8" ,
2571+ ) ,
2572+ ] ) ;
2573+
2574+ const { beforeAgentReply } = createLightDreamingHarness ( workspaceDir ) ;
2575+ await withDreamingTestClock ( async ( ) => {
2576+ await triggerLightDreaming ( beforeAgentReply , workspaceDir , 5 ) ;
2577+ } ) ;
2578+
2579+ const snippets = await readCandidateSnippets ( workspaceDir , "2026-04-05T10:05:00.000Z" ) ;
2580+ expect ( snippets ) . toEqual (
2581+ expect . arrayContaining ( [ `${ headingPrefix } :` , itemPrefix , `Topic: ${ chunkPrefix } ` ] ) ,
2582+ ) ;
2583+ } ) ;
2584+
25182585 it ( "drops generic day headings but keeps meaningful section labels" , async ( ) => {
25192586 const workspaceDir = await createDreamingWorkspace ( ) ;
25202587 await fs . writeFile (
0 commit comments