@@ -87,3 +87,42 @@ test("checkSession resets message id aliases after native compaction", async ()
8787 assert . equal ( state . messageIds . byRef . get ( "m0002" ) , "msg-user-follow-up" )
8888 assert . equal ( state . messageIds . nextRef , 3 )
8989} )
90+
91+ test ( "assignMessageRefs stops cleanly when alias capacity is exhausted" , ( ) => {
92+ const sessionID = `ses_message_ids_exhausted_${ Date . now ( ) } `
93+ const state = createSessionState ( )
94+ state . messageIds . nextRef = 10000
95+
96+ const messages : WithParts [ ] = [
97+ {
98+ info : {
99+ id : "msg-a" ,
100+ role : "assistant" ,
101+ sessionID,
102+ agent : "assistant" ,
103+ time : { created : 1 } ,
104+ } as WithParts [ "info" ] ,
105+ parts : [ textPart ( "msg-a" , sessionID , "msg-a-part" , "A" ) ] ,
106+ } ,
107+ {
108+ info : {
109+ id : "msg-b" ,
110+ role : "assistant" ,
111+ sessionID,
112+ agent : "assistant" ,
113+ time : { created : 2 } ,
114+ } as WithParts [ "info" ] ,
115+ parts : [ textPart ( "msg-b" , sessionID , "msg-b-part" , "B" ) ] ,
116+ } ,
117+ ]
118+
119+ const firstAssigned = assignMessageRefs ( state , messages )
120+ const secondAssigned = assignMessageRefs ( state , messages )
121+
122+ assert . equal ( firstAssigned , 0 )
123+ assert . equal ( secondAssigned , 0 )
124+ assert . equal ( state . messageIds . byRawId . size , 0 )
125+ assert . equal ( state . messageIds . byRef . size , 0 )
126+ assert . equal ( state . messageIds . byRawId . get ( "msg-a" ) , undefined )
127+ assert . equal ( state . messageIds . byRawId . get ( "msg-b" ) , undefined )
128+ } )
0 commit comments