@@ -3841,9 +3841,15 @@ it("keeps the working header in place across worktree setup handoff", () => {
38413841} ) ;
38423842
38433843describe ( "failed turn transcript" , ( ) => {
3844- it . each ( [ "provider_error" , "usage_limit" ] as const ) (
3845- "keeps historical %s failures and preceding work visible without disclosures" ,
3846- ( failureClass ) => {
3844+ it . each ( [
3845+ { position : "historical" , failureClass : "provider_error" } ,
3846+ { position : "historical" , failureClass : "usage_limit" } ,
3847+ { position : "latest" , failureClass : "usage_limit" } ,
3848+ ] as const ) (
3849+ "keeps $position $failureClass failures visible with preceding work grouped appropriately" ,
3850+ ( { position, failureClass } ) => {
3851+ const isLatest = position === "latest" ;
3852+ const commands = isLatest ? [ "pwd" , "ls" , "false" ] : [ "pwd" ] ;
38473853 const runId = RunId . make ( "failed-run" ) ;
38483854 const threadId = ThreadId . make ( "failed-thread" ) ;
38493855 const at = DateTime . makeUnsafe ( "2026-09-20T12:00:00Z" ) ;
@@ -3880,23 +3886,24 @@ describe("failed turn transcript", () => {
38803886 attachments : [ ] ,
38813887 } ,
38823888 } ,
3883- {
3884- position : 1 ,
3889+ ... commands . map ( ( input , index ) : OrchestrationV2ProjectedTurnItem => ( {
3890+ position : index + 1 ,
38853891 visibility : "local" ,
38863892 sourceThreadId : threadId ,
3887- sourceItemId : TurnItemId . make ( "command" ) ,
3893+ sourceItemId : TurnItemId . make ( index === 0 ? "command" : `command- ${ index } ` ) ,
38883894 item : {
38893895 ...base ,
3890- id : TurnItemId . make ( "command" ) ,
3896+ id : TurnItemId . make ( index === 0 ? "command" : `command-${ index } ` ) ,
3897+ ordinal : index + 1 ,
38913898 type : "command_execution" ,
38923899 status : "completed" ,
3893- input : "pwd" ,
3900+ input,
38943901 output : "" ,
38953902 exitCode : 0 ,
38963903 } ,
3897- } ,
3904+ } ) ) ,
38983905 {
3899- position : 2 ,
3906+ position : commands . length + 1 ,
39003907 visibility : "local" ,
39013908 sourceThreadId : threadId ,
39023909 sourceItemId : TurnItemId . make ( "failure" ) ,
@@ -3918,37 +3925,44 @@ describe("failed turn transcript", () => {
39183925 timelineEntries : deriveTimelineEntriesFromVisibleTurnItems ( {
39193926 visibleTurnItems : items ,
39203927 optimisticMessages : [ ] ,
3921- } ) . map ( ( entry ) => ( {
3922- ...entry ,
3923- attempt : {
3924- id : RunAttemptId . make ( "superseded-attempt" ) ,
3925- runId,
3926- attemptOrdinal : 1 ,
3927- rootNodeId : NodeId . make ( "superseded-root" ) ,
3928- status : "superseded" as const ,
3929- completedAt : null ,
3930- } ,
3931- } ) ) ,
3928+ } ) . map ( ( entry ) =>
3929+ isLatest
3930+ ? entry
3931+ : {
3932+ ...entry ,
3933+ attempt : {
3934+ id : RunAttemptId . make ( "superseded-attempt" ) ,
3935+ runId,
3936+ attemptOrdinal : 1 ,
3937+ rootNodeId : NodeId . make ( "superseded-root" ) ,
3938+ status : "superseded" as const ,
3939+ completedAt : null ,
3940+ } ,
3941+ } ,
3942+ ) ,
39323943 latestRun : {
3933- runId : RunId . make ( "newer-run" ) ,
3934- status : "completed" ,
3944+ runId : isLatest ? runId : RunId . make ( "newer-run" ) ,
3945+ status : isLatest ? "failed" : "completed" ,
39353946 startedAt : DateTime . formatIso ( at ) ,
39363947 completedAt : DateTime . formatIso ( at ) ,
39373948 } ,
39383949 isWorking : false ,
39393950 turnDiffSummaries : [ ] ,
39403951 supportsConversationRollback : false ,
39413952 } ) ;
3942- expect (
3943- rows . some (
3944- ( row ) =>
3945- row . kind === "turn-fold" || row . kind === "attempt-fold" || row . kind === "work-toggle" ,
3946- ) ,
3947- ) . toBe ( false ) ;
3953+ expect ( rows . some ( ( row ) => row . kind === "turn-fold" || row . kind === "attempt-fold" ) ) . toBe (
3954+ false ,
3955+ ) ;
39483956 const work = rows . flatMap ( ( row ) => ( row . kind === "work" ? row . groupedEntries : [ ] ) ) ;
3949- expect ( work . map ( ( entry ) => entry . id ) ) . toEqual ( [ "command" , "failure" ] ) ;
3957+ expect ( rows . find ( ( row ) => row . kind === "work-toggle" ) ) . toEqual (
3958+ isLatest ? expect . objectContaining ( { hiddenCount : 3 , expanded : false } ) : undefined ,
3959+ ) ;
3960+ expect ( work . map ( ( entry ) => entry . id ) ) . toEqual (
3961+ isLatest ? [ "failure" ] : [ "command" , "failure" ] ,
3962+ ) ;
39503963 expect ( work . at ( - 1 ) ?. detail ) . toBe ( "The provider stopped this turn.\nRetry later." ) ;
39513964 expect ( work . at ( - 1 ) ?. createdAt ) . toBe ( "2026-09-20T12:00:00.000Z" ) ;
3965+ if ( isLatest ) return ;
39523966 const entriesWithoutTools = deriveTimelineEntriesFromVisibleTurnItems ( {
39533967 visibleTurnItems : items . filter ( ( row ) => row . item . type !== "command_execution" ) ,
39543968 optimisticMessages : [ ] ,
@@ -3987,74 +4001,6 @@ describe("failed turn transcript", () => {
39874001 } ) ;
39884002 } ,
39894003 ) ;
3990-
3991- it ( "keeps tool groups collapsed when the latest run stops on a usage limit" , ( ) => {
3992- const runId = RunId . make ( "limited-run" ) ;
3993- const threadId = ThreadId . make ( "limited-thread" ) ;
3994- const at = DateTime . makeUnsafe ( "2026-10-25T09:00:00Z" ) ;
3995- const base = {
3996- threadId,
3997- runId,
3998- nodeId : null ,
3999- providerThreadId : null ,
4000- providerTurnId : null ,
4001- nativeItemRef : null ,
4002- parentItemId : null ,
4003- title : null ,
4004- startedAt : at ,
4005- completedAt : at ,
4006- updatedAt : at ,
4007- } ;
4008- const items : OrchestrationV2TurnItem [ ] = [
4009- ...[ "pwd" , "ls" , "false" ] . map ( ( input , index ) : OrchestrationV2TurnItem => ( {
4010- ...base ,
4011- id : TurnItemId . make ( input ) ,
4012- ordinal : index ,
4013- type : "command_execution" ,
4014- status : "completed" ,
4015- input,
4016- output : "" ,
4017- exitCode : 0 ,
4018- } ) ) ,
4019- {
4020- ...base ,
4021- id : TurnItemId . make ( "limit" ) ,
4022- ordinal : 3 ,
4023- type : "error" ,
4024- status : "failed" ,
4025- failure : { class : "usage_limit" , message : "Limit hit" , code : null , retryable : true } ,
4026- } ,
4027- ] ;
4028- const rows = deriveMessagesTimelineRows ( {
4029- timelineEntries : deriveTimelineEntriesFromVisibleTurnItems ( {
4030- visibleTurnItems : items . map ( ( item ) => ( {
4031- position : item . ordinal ,
4032- visibility : "local" ,
4033- sourceThreadId : threadId ,
4034- sourceItemId : item . id ,
4035- item,
4036- } ) ) ,
4037- optimisticMessages : [ ] ,
4038- } ) ,
4039- latestRun : {
4040- runId,
4041- status : "failed" ,
4042- startedAt : DateTime . formatIso ( at ) ,
4043- completedAt : DateTime . formatIso ( at ) ,
4044- } ,
4045- isWorking : false ,
4046- turnDiffSummaries : [ ] ,
4047- supportsConversationRollback : false ,
4048- } ) ;
4049-
4050- expect ( rows . find ( ( row ) => row . kind === "work-toggle" ) ) . toMatchObject ( {
4051- hiddenCount : 3 ,
4052- expanded : false ,
4053- } ) ;
4054- expect (
4055- rows . flatMap ( ( row ) => ( row . kind === "work" ? row . groupedEntries . map ( ( e ) => e . id ) : [ ] ) ) ,
4056- ) . toEqual ( [ "limit" ] ) ;
4057- } ) ;
40584004} ) ;
40594005
40604006describe ( "live subagents after their parent turn settles" , ( ) => {
0 commit comments