@@ -1068,6 +1068,52 @@ describe("session history HTTP endpoints", () => {
10681068 } ) ;
10691069 } ) ;
10701070
1071+ test ( "keeps older SQLite history reachable past an all-silent bounded tail" , async ( ) => {
1072+ const storePath = await createSessionStoreFile ( ) ;
1073+ const sessionId = "sess-silent-tail" ;
1074+ const sessionKey = "agent:main:main" ;
1075+ await writeSessionStore ( {
1076+ entries : { main : { sessionId, updatedAt : Date . now ( ) } } ,
1077+ storePath,
1078+ } ) ;
1079+ await replaceTranscriptEvents ( { agentId : AGENT_ID , sessionId, sessionKey, storePath } , [
1080+ { type : "session" , version : 1 , id : sessionId } ,
1081+ { message : { role : "assistant" , content : "reachable older history" } } ,
1082+ ...Array . from ( { length : 40 } , ( ) => ( {
1083+ message : { role : "assistant" , content : "NO_REPLY" } ,
1084+ } ) ) ,
1085+ ] ) ;
1086+
1087+ await withGatewayHarness ( async ( harness ) => {
1088+ const firstPage = await readSessionHistoryBody ( harness . port , sessionKey , {
1089+ query : "?limit=1" ,
1090+ } ) ;
1091+ expect ( firstPage . messages ) . toEqual ( [ ] ) ;
1092+ expect ( firstPage . hasMore ) . toBe ( true ) ;
1093+ expect ( firstPage . nextCursor ) . toBe ( "2" ) ;
1094+
1095+ const stream = await openSessionHistorySse ( harness . port , sessionKey , {
1096+ query : "?limit=1" ,
1097+ } ) ;
1098+ try {
1099+ const event = await readSseEvent ( stream . reader , stream . streamState ) ;
1100+ expect ( event . event ) . toBe ( "history" ) ;
1101+ expect ( event . data ) . toMatchObject ( { messages : [ ] , hasMore : true , nextCursor : "2" } ) ;
1102+ } finally {
1103+ await stream . reader . cancel ( ) ;
1104+ }
1105+
1106+ const olderPage = await readSessionHistoryBody ( harness . port , sessionKey , {
1107+ query : "?limit=1&cursor=2" ,
1108+ } ) ;
1109+ expect ( olderPage . messages ?. map ( ( message ) => message . content ) ) . toEqual ( [
1110+ "reachable older history" ,
1111+ ] ) ;
1112+ expect ( olderPage . hasMore ) . toBe ( false ) ;
1113+ expect ( olderPage . nextCursor ) . toBeUndefined ( ) ;
1114+ } ) ;
1115+ } ) ;
1116+
10711117 test ( "caps all-digit direct REST history limits that exceed safe integer range" , async ( ) => {
10721118 const { storePath } = await seedSession ( { text : "first message" } ) ;
10731119 await appendVisibleAssistantMessage ( {
0 commit comments