@@ -1242,6 +1242,62 @@ describe("session history HTTP endpoints", () => {
12421242 } ) ;
12431243 } ) ;
12441244
1245+ test ( "keeps repeated assistant replies from separate hidden user turns in REST and SSE history" , async ( ) => {
1246+ const storePath = await createSessionStoreFile ( ) ;
1247+ const sessionId = "sess-hidden-turn-replies" ;
1248+ const sessionKey = "agent:main:main" ;
1249+ await writeSessionStore ( {
1250+ entries : { main : { sessionId, updatedAt : Date . now ( ) } } ,
1251+ storePath,
1252+ } ) ;
1253+ const assistantMessage = ( text : string , model : string ) =>
1254+ makeTranscriptAssistantMessage ( { text, provider : "openclaw" , model } ) ;
1255+ await replaceTranscriptEvents ( { agentId : AGENT_ID , sessionId, sessionKey, storePath } , [
1256+ { type : "session" , version : 1 , id : sessionId } ,
1257+ { message : assistantMessage ( "First reply." , "acp-runtime" ) } ,
1258+ { message : { role : "user" , content : "" } } ,
1259+ { message : assistantMessage ( "First reply." , "gateway-injected" ) } ,
1260+ { message : assistantMessage ( "Second reply." , "acp-runtime" ) } ,
1261+ { message : { role : "user" , content : HEARTBEAT_PROMPT } } ,
1262+ { message : assistantMessage ( "Second reply." , "gateway-injected" ) } ,
1263+ { message : assistantMessage ( "Third reply." , "acp-runtime" ) } ,
1264+ { message : { role : "user" , content : HEARTBEAT_PROMPT } } ,
1265+ { message : { role : "assistant" , content : "HEARTBEAT_OK" } } ,
1266+ { message : assistantMessage ( "Third reply." , "gateway-injected" ) } ,
1267+ ] ) ;
1268+
1269+ const expectedRows = [
1270+ "1:assistant:First reply." ,
1271+ "3:assistant:First reply." ,
1272+ "4:assistant:Second reply." ,
1273+ "6:assistant:Second reply." ,
1274+ "7:assistant:Third reply." ,
1275+ "10:assistant:Third reply." ,
1276+ ] ;
1277+ await withGatewayHarness ( async ( harness ) => {
1278+ const history = await readSessionHistoryBody ( harness . port , sessionKey ) ;
1279+ expect ( history . messages ?. map ( sessionHistoryRowIdentity ) ) . toEqual ( expectedRows ) ;
1280+ expect ( history . messages ?. map ( ( message ) => message [ "__openclaw" ] ?. turnBoundary ) ) . toEqual ( [
1281+ undefined ,
1282+ undefined ,
1283+ undefined ,
1284+ true ,
1285+ undefined ,
1286+ true ,
1287+ ] ) ;
1288+
1289+ const stream = await openSessionHistorySse ( harness . port , sessionKey ) ;
1290+ try {
1291+ const event = await readSseEvent ( stream . reader , stream . streamState ) ;
1292+ expect ( event . event ) . toBe ( "history" ) ;
1293+ const streamedHistory = event . data as SessionHistoryBody ;
1294+ expect ( streamedHistory . messages ?. map ( sessionHistoryRowIdentity ) ) . toEqual ( expectedRows ) ;
1295+ } finally {
1296+ await stream . reader . cancel ( ) ;
1297+ }
1298+ } ) ;
1299+ } ) ;
1300+
12451301 test . each ( [
12461302 { name : "all-silent tail" , heartbeatBoundary : false , silentMessages : 40 } ,
12471303 { name : "heartbeat context boundary" , heartbeatBoundary : true , silentMessages : 39 } ,
0 commit comments