@@ -926,12 +926,12 @@ describe("session.compaction.process", () => {
926926 )
927927
928928 itCompaction . instance (
929- "persists tail_start_id for retained recent turns" ,
929+ "does not persist tail_start_id for serialized recent turns" ,
930930 Effect . gen ( function * ( ) {
931931 const ssn = yield * SessionNs . Service
932932 const session = yield * ssn . create ( { } )
933933 yield * createUserMessage ( session . id , "first" )
934- const keep = yield * createUserMessage ( session . id , "second" )
934+ yield * createUserMessage ( session . id , "second" )
935935 yield * createUserMessage ( session . id , "third" )
936936 yield * createSummaryCompaction ( session . id )
937937
@@ -947,18 +947,18 @@ describe("session.compaction.process", () => {
947947
948948 const part = yield * readCompactionPart ( session . id )
949949 expect ( part ?. type ) . toBe ( "compaction" )
950- expect ( part ?. tail_start_id ) . toBe ( keep . id )
950+ expect ( part ?. tail_start_id ) . toBeUndefined ( )
951951 } ) . pipe ( withCompaction ( { config : cfg ( { tail_turns : 2 , preserve_recent_tokens : 10_000 } ) } ) ) ,
952952 )
953953
954954 itCompaction . instance (
955- "shrinks retained tail to fit preserve token budget " ,
955+ "does not persist tail_start_id when shrinking serialized tail " ,
956956 Effect . gen ( function * ( ) {
957957 const ssn = yield * SessionNs . Service
958958 const session = yield * ssn . create ( { } )
959959 yield * createUserMessage ( session . id , "first" )
960960 yield * createUserMessage ( session . id , "x" . repeat ( 2_000 ) )
961- const keep = yield * createUserMessage ( session . id , "tiny" )
961+ yield * createUserMessage ( session . id , "tiny" )
962962 yield * createSummaryCompaction ( session . id )
963963
964964 const msgs = yield * ssn . messages ( { sessionID : session . id } )
@@ -973,7 +973,7 @@ describe("session.compaction.process", () => {
973973
974974 const part = yield * readCompactionPart ( session . id )
975975 expect ( part ?. type ) . toBe ( "compaction" )
976- expect ( part ?. tail_start_id ) . toBe ( keep . id )
976+ expect ( part ?. tail_start_id ) . toBeUndefined ( )
977977 } ) . pipe ( withCompaction ( { config : cfg ( { tail_turns : 2 , preserve_recent_tokens : 100 } ) } ) ) ,
978978 )
979979
@@ -1005,7 +1005,7 @@ describe("session.compaction.process", () => {
10051005 )
10061006
10071007 itCompaction . instance (
1008- "falls back to full summary when retained tail media exceeds preserve token budget " ,
1008+ "serializes retained tail media as text in the summary input " ,
10091009 ( ) => {
10101010 const stub = llm ( )
10111011 let captured = ""
@@ -1078,15 +1078,16 @@ describe("session.compaction.process", () => {
10781078
10791079 const part = yield * readCompactionPart ( session . id )
10801080 expect ( part ?. type ) . toBe ( "compaction" )
1081- expect ( part ?. tail_start_id ) . toBe ( keep . id )
1081+ expect ( part ?. tail_start_id ) . toBeUndefined ( )
10821082 expect ( captured ) . toContain ( "zzzz" )
1083- expect ( captured ) . not . toContain ( "keep tail" )
1083+ expect ( captured ) . toContain ( "keep tail" )
10841084
10851085 const filtered = MessageV2 . filterCompacted ( MessageV2 . stream ( session . id ) )
1086- expect ( filtered . map ( ( msg ) => msg . info . id ) . slice ( 0 , 3 ) ) . toEqual ( [ parent ! , expect . any ( String ) , keep . id ] )
1086+ expect ( filtered . map ( ( msg ) => msg . info . id ) ) . toEqual ( [ parent ! , expect . any ( String ) ] )
10871087 expect ( filtered [ 1 ] ?. info . role ) . toBe ( "assistant" )
10881088 expect ( filtered [ 1 ] ?. info . role === "assistant" ? filtered [ 1 ] . info . summary : false ) . toBe ( true )
10891089 expect ( filtered . map ( ( msg ) => msg . info . id ) ) . not . toContain ( large . id )
1090+ expect ( filtered . map ( ( msg ) => msg . info . id ) ) . not . toContain ( keep . id )
10901091 } ) . pipe ( withCompaction ( { llm : stub . layer , config : cfg ( { tail_turns : 1 , preserve_recent_tokens : 100 } ) } ) )
10911092 } ,
10921093 { git : true } ,
@@ -1353,13 +1354,13 @@ describe("session.compaction.process", () => {
13531354 )
13541355
13551356 itCompaction . instance (
1356- "summarizes only the head while keeping recent tail out of summary input" ,
1357+ "summarizes the head while serializing recent tail into summary input" ,
13571358 ( ) => {
13581359 const stub = llm ( )
1359- let captured = ""
1360+ let captured : LLM . StreamInput [ "messages" ] = [ ]
13601361 stub . push (
13611362 reply ( "summary" , ( input ) => {
1362- captured = JSON . stringify ( input . messages )
1363+ captured = input . messages
13631364 } ) ,
13641365 )
13651366 return Effect . gen ( function * ( ) {
@@ -1380,10 +1381,15 @@ describe("session.compaction.process", () => {
13801381 auto : false ,
13811382 } )
13821383
1383- expect ( captured ) . toContain ( "older context" )
1384- expect ( captured ) . not . toContain ( "keep this turn" )
1385- expect ( captured ) . not . toContain ( "and this one too" )
1386- expect ( captured ) . not . toContain ( "What did we do so far?" )
1384+ const head = JSON . stringify ( captured . slice ( 0 , - 1 ) )
1385+ const prompt = JSON . stringify ( captured . at ( - 1 ) )
1386+ expect ( head ) . toContain ( "older context" )
1387+ expect ( head ) . not . toContain ( "keep this turn" )
1388+ expect ( head ) . not . toContain ( "and this one too" )
1389+ expect ( prompt ) . toContain ( "keep this turn" )
1390+ expect ( prompt ) . toContain ( "and this one too" )
1391+ expect ( prompt ) . toContain ( "recent-conversation-tail" )
1392+ expect ( prompt ) . not . toContain ( "What did we do so far?" )
13871393 } ) . pipe ( withCompaction ( { llm : stub . layer } ) )
13881394 } ,
13891395 { git : true } ,
@@ -1431,7 +1437,7 @@ describe("session.compaction.process", () => {
14311437 { git : true } ,
14321438 )
14331439
1434- itCompaction . instance ( "keeps recent pre-compaction turns across repeated compactions" , ( ) => {
1440+ itCompaction . instance ( "does not replay recent pre-compaction turns across repeated compactions" , ( ) => {
14351441 const stub = llm ( )
14361442 stub . push ( reply ( "summary one" ) )
14371443 stub . push ( reply ( "summary two" ) )
@@ -1462,8 +1468,8 @@ describe("session.compaction.process", () => {
14621468
14631469 expect ( ids ) . not . toContain ( u1 . id )
14641470 expect ( ids ) . not . toContain ( u2 . id )
1465- expect ( ids ) . toContain ( u3 . id )
1466- expect ( ids ) . toContain ( u4 . id )
1471+ expect ( ids ) . not . toContain ( u3 . id )
1472+ expect ( ids ) . not . toContain ( u4 . id )
14671473 expect ( filtered . some ( ( msg ) => msg . info . role === "assistant" && msg . info . summary ) ) . toBe ( true )
14681474 expect (
14691475 filtered . some ( ( msg ) => msg . info . role === "user" && msg . parts . some ( ( part ) => part . type === "compaction" ) ) ,
@@ -1472,7 +1478,7 @@ describe("session.compaction.process", () => {
14721478 } )
14731479
14741480 itCompaction . instance (
1475- "ignores previous summaries when sizing the retained tail" ,
1481+ "ignores previous summaries when sizing the serialized tail" ,
14761482 Effect . gen ( function * ( ) {
14771483 const ssn = yield * SessionNs . Service
14781484 const test = yield * TestInstance
@@ -1511,7 +1517,7 @@ describe("session.compaction.process", () => {
15111517
15121518 const part = yield * readCompactionPart ( session . id )
15131519 expect ( part ?. type ) . toBe ( "compaction" )
1514- expect ( part ?. tail_start_id ) . toBe ( keep . id )
1520+ expect ( part ?. tail_start_id ) . toBeUndefined ( )
15151521 } ) . pipe ( withCompaction ( { config : cfg ( { tail_turns : 2 , preserve_recent_tokens : 500 } ) } ) ) ,
15161522 )
15171523} )
0 commit comments