@@ -518,4 +518,56 @@ describe("Rewind After Condense - Issue #8295", () => {
518518 } )
519519 } )
520520 } )
521+
522+ describe ( "Resume after condense preserves summary" , ( ) => {
523+ it ( "should keep condensed messages filtered when a new user message is added after summary" , ( ) => {
524+ const condenseId = "summary-resume-test"
525+
526+ // Simulate post-condensation state: all old messages tagged, summary at end,
527+ // then a new user message added after resume (the fix preserves summary)
528+ const historyAfterResume : ApiMessage [ ] = [
529+ { role : "user" , content : "Original task" , ts : 100 , condenseParent : condenseId } ,
530+ { role : "assistant" , content : "Response 1" , ts : 200 , condenseParent : condenseId } ,
531+ { role : "user" , content : "Follow-up" , ts : 300 , condenseParent : condenseId } ,
532+ { role : "assistant" , content : "Response 2" , ts : 400 , condenseParent : condenseId } ,
533+ {
534+ role : "user" ,
535+ content : [ { type : "text" , text : "## Conversation Summary\nSummary of work done" } ] ,
536+ ts : 401 ,
537+ isSummary : true ,
538+ condenseId,
539+ } ,
540+ // New user message added after resume (no isSummary, no condenseId)
541+ { role : "user" , content : [ { type : "text" , text : "Please continue with the next step" } ] , ts : 500 } ,
542+ ]
543+
544+ const effective = getEffectiveApiHistory ( historyAfterResume )
545+
546+ // Should only include summary + new message (fresh start model)
547+ expect ( effective ) . toHaveLength ( 2 )
548+ expect ( effective [ 0 ] . isSummary ) . toBe ( true )
549+ expect ( effective [ 1 ] . ts ) . toBe ( 500 )
550+ } )
551+
552+ it ( "should restore ALL messages if summary is missing (the bug scenario before fix)" , ( ) => {
553+ const condenseId = "summary-bug-demo"
554+
555+ // Simulate the bug: summary was stripped during resume, replaced with regular message.
556+ // condenseParent tags still exist but point to a non-existent summary.
557+ const historyWithoutSummary : ApiMessage [ ] = [
558+ { role : "user" , content : "Original task" , ts : 100 , condenseParent : condenseId } ,
559+ { role : "assistant" , content : "Response 1" , ts : 200 , condenseParent : condenseId } ,
560+ { role : "user" , content : "Follow-up" , ts : 300 , condenseParent : condenseId } ,
561+ { role : "assistant" , content : "Response 2" , ts : 400 , condenseParent : condenseId } ,
562+ // Summary was REMOVED and replaced with a regular user message (no isSummary)
563+ { role : "user" , content : [ { type : "text" , text : "Summary content merged with new input" } ] , ts : 500 } ,
564+ ]
565+
566+ const effective = getEffectiveApiHistory ( historyWithoutSummary )
567+
568+ // Without the summary, ALL messages are restored (orphaned condenseParent)
569+ // This demonstrates the bug: condensation is effectively undone
570+ expect ( effective ) . toHaveLength ( 5 )
571+ } )
572+ } )
521573} )
0 commit comments