@@ -3787,6 +3787,117 @@ describe("v2 run and attempt history", () => {
37873787 run2 ,
37883788 ] ) ;
37893789 } ) ;
3790+ it ( "keeps a failed run's continued sub-agent visible inside an earlier fold" , ( ) => {
3791+ const run1 = RunId . make ( "run-1" ) ;
3792+ const run2 = RunId . make ( "run-2" ) ;
3793+ // Same shape as the test above, but run 2 failed. Failed runs stay
3794+ // unfolded, so the continued sub-agent — which folds with turn 1 —
3795+ // must not disappear inside turn 1's collapsed fold.
3796+ const timelineEntries = [
3797+ {
3798+ id : "prompt-1" ,
3799+ kind : "message" as const ,
3800+ createdAt : "2026-01-01T00:00:00Z" ,
3801+ message : {
3802+ id : MessageId . make ( "prompt-1" ) ,
3803+ role : "user" as const ,
3804+ text : "Spawn a subagent" ,
3805+ runId : run1 ,
3806+ createdAt : "2026-01-01T00:00:00Z" ,
3807+ updatedAt : "2026-01-01T00:00:00Z" ,
3808+ streaming : false ,
3809+ } ,
3810+ } ,
3811+ {
3812+ id : "continued-subagent" ,
3813+ kind : "event" as const ,
3814+ createdAt : "2026-01-01T00:00:03Z" ,
3815+ projectedItem : {
3816+ item : {
3817+ type : "subagent" ,
3818+ runId : run2 ,
3819+ } ,
3820+ } ,
3821+ } as never ,
3822+ {
3823+ id : "answer-1" ,
3824+ kind : "message" as const ,
3825+ createdAt : "2026-01-01T00:00:20Z" ,
3826+ message : {
3827+ id : MessageId . make ( "answer-1" ) ,
3828+ role : "assistant" as const ,
3829+ text : "Subagent started." ,
3830+ runId : run1 ,
3831+ createdAt : "2026-01-01T00:00:20Z" ,
3832+ updatedAt : "2026-01-01T00:00:22Z" ,
3833+ streaming : false ,
3834+ } ,
3835+ } ,
3836+ {
3837+ id : "prompt-2" ,
3838+ kind : "message" as const ,
3839+ createdAt : "2026-01-01T00:01:00Z" ,
3840+ message : {
3841+ id : MessageId . make ( "prompt-2" ) ,
3842+ role : "user" as const ,
3843+ text : "Continue the subagent" ,
3844+ runId : run2 ,
3845+ createdAt : "2026-01-01T00:01:00Z" ,
3846+ updatedAt : "2026-01-01T00:01:00Z" ,
3847+ streaming : false ,
3848+ } ,
3849+ } ,
3850+ {
3851+ id : "work-2" ,
3852+ kind : "work" as const ,
3853+ createdAt : "2026-01-01T00:01:05Z" ,
3854+ entry : {
3855+ id : "work-2" ,
3856+ runId : run2 ,
3857+ createdAt : "2026-01-01T00:01:05Z" ,
3858+ label : "Running command" ,
3859+ tone : "tool" as const ,
3860+ toolLifecycleStatus : "completed" as const ,
3861+ } ,
3862+ } ,
3863+ {
3864+ id : "answer-2" ,
3865+ kind : "message" as const ,
3866+ createdAt : "2026-01-01T00:01:20Z" ,
3867+ message : {
3868+ id : MessageId . make ( "answer-2" ) ,
3869+ role : "assistant" as const ,
3870+ text : "Done." ,
3871+ runId : run2 ,
3872+ createdAt : "2026-01-01T00:01:20Z" ,
3873+ updatedAt : "2026-01-01T00:01:22Z" ,
3874+ streaming : false ,
3875+ } ,
3876+ } ,
3877+ ] ;
3878+
3879+ const rows = deriveMessagesTimelineRows ( {
3880+ timelineEntries,
3881+ latestRun : {
3882+ runId : run2 ,
3883+ status : "failed" as const ,
3884+ startedAt : "2026-01-01T00:01:00Z" ,
3885+ completedAt : "2026-01-01T00:01:30Z" ,
3886+ } ,
3887+ isWorking : false ,
3888+ turnDiffSummaries : [ ] ,
3889+ supportsConversationRollback : false ,
3890+ } ) ;
3891+
3892+ expect ( rows . map ( ( row ) => row . id ) ) . toEqual ( [
3893+ "prompt-1" ,
3894+ "continued-subagent" ,
3895+ "answer-1" ,
3896+ "prompt-2" ,
3897+ "work-2" ,
3898+ "answer-2" ,
3899+ ] ) ;
3900+ } ) ;
37903901 it ( "does not move the fold of an ordinary single-run turn" , ( ) => {
37913902 const run1 = RunId . make ( "run-1" ) ;
37923903 const timelineEntries = [
0 commit comments