@@ -2,10 +2,14 @@ import { ThreadId, type WorktreeSetupSnapshot } from "@t3tools/contracts";
22import {
33 CheckpointRef ,
44 NodeId ,
5+ ProviderDriverKind ,
6+ ProviderInstanceId ,
7+ ProviderTurnId ,
58 RunAttemptId ,
69 TurnItemId ,
710 RuntimeRequestId ,
811 type OrchestrationV2ProjectedTurnItem ,
12+ type OrchestrationV2TurnItem ,
913} from "@t3tools/contracts" ;
1014import * as DateTime from "effect/DateTime" ;
1115import {
@@ -4889,3 +4893,172 @@ describe("failed turn transcript", () => {
48894893 } ,
48904894 ) ;
48914895} ) ;
4896+
4897+ describe ( "live subagents after their parent turn settles" , ( ) => {
4898+ const runId = RunId . make ( "parent-run" ) ;
4899+ const threadId = ThreadId . make ( "parent-thread" ) ;
4900+ const providerTurnId = ProviderTurnId . make ( "parent-provider-turn" ) ;
4901+ const at = ( second : number ) =>
4902+ DateTime . makeUnsafe ( `2026-10-06T10:00:${ String ( second ) . padStart ( 2 , "0" ) } Z` ) ;
4903+ const base = ( id : string , second : number ) => ( {
4904+ id : TurnItemId . make ( id ) ,
4905+ threadId,
4906+ runId,
4907+ nodeId : null ,
4908+ providerThreadId : null ,
4909+ providerTurnId,
4910+ nativeItemRef : null ,
4911+ parentItemId : null ,
4912+ ordinal : second ,
4913+ title : null ,
4914+ startedAt : at ( second ) ,
4915+ completedAt : at ( second ) ,
4916+ updatedAt : at ( second ) ,
4917+ } ) ;
4918+ const projected = ( item : OrchestrationV2TurnItem ) : OrchestrationV2ProjectedTurnItem => ( {
4919+ position : item . ordinal ,
4920+ visibility : "local" ,
4921+ sourceThreadId : threadId ,
4922+ sourceItemId : item . id ,
4923+ item,
4924+ } ) ;
4925+ const child = (
4926+ id : string ,
4927+ second : number ,
4928+ status : OrchestrationV2TurnItem [ "status" ] ,
4929+ origin : "app_owned" | "provider_native" = "app_owned" ,
4930+ ) : OrchestrationV2TurnItem => ( {
4931+ ...base ( id , second ) ,
4932+ status,
4933+ completedAt : status === "running" ? null : at ( second ) ,
4934+ type : "subagent" ,
4935+ subagentId : NodeId . make ( id ) ,
4936+ origin,
4937+ driver : ProviderDriverKind . make ( "codex" ) ,
4938+ providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
4939+ childThreadId : origin === "app_owned" ? ThreadId . make ( `${ id } -thread` ) : null ,
4940+ prompt : `Inspect ${ id } ` ,
4941+ result : null ,
4942+ } ) ;
4943+ const rowsFor = ( children : ReadonlyArray < OrchestrationV2TurnItem > ) =>
4944+ deriveMessagesTimelineRows ( {
4945+ timelineEntries : deriveTimelineEntriesFromVisibleTurnItems ( {
4946+ visibleTurnItems : (
4947+ [
4948+ {
4949+ ...base ( "user" , 0 ) ,
4950+ status : "completed" ,
4951+ type : "user_message" ,
4952+ messageId : MessageId . make ( "user" ) ,
4953+ createdBy : "user" ,
4954+ creationSource : "web" ,
4955+ inputIntent : "turn_start" ,
4956+ text : "Delegate the review" ,
4957+ attachments : [ ] ,
4958+ } ,
4959+ {
4960+ ...base ( "reasoning" , 1 ) ,
4961+ status : "completed" ,
4962+ type : "reasoning" ,
4963+ text : "Two children can split this." ,
4964+ streaming : false ,
4965+ } ,
4966+ {
4967+ ...base ( "command" , 2 ) ,
4968+ status : "completed" ,
4969+ type : "command_execution" ,
4970+ input : "pwd" ,
4971+ output : "/repo" ,
4972+ exitCode : 0 ,
4973+ } ,
4974+ ...children ,
4975+ {
4976+ ...base ( "assistant" , 8 ) ,
4977+ status : "completed" ,
4978+ type : "assistant_message" ,
4979+ messageId : MessageId . make ( "assistant" ) ,
4980+ text : "Both children are running." ,
4981+ streaming : false ,
4982+ } ,
4983+ ] satisfies OrchestrationV2TurnItem [ ]
4984+ ) . map ( projected ) ,
4985+ optimisticMessages : [ ] ,
4986+ } ) ,
4987+ latestRun : {
4988+ runId,
4989+ status : "completed" ,
4990+ startedAt : DateTime . formatIso ( at ( 0 ) ) ,
4991+ completedAt : DateTime . formatIso ( at ( 8 ) ) ,
4992+ } ,
4993+ isWorking : false ,
4994+ turnDiffSummaries : [ ] ,
4995+ supportsConversationRollback : false ,
4996+ } ) ;
4997+
4998+ it . each ( [ "app_owned" , "provider_native" ] as const ) (
4999+ "keeps a running %s child visible while the rest of the settled turn folds" ,
5000+ ( origin ) => {
5001+ const rows = rowsFor ( [ child ( "child" , 3 , "running" , origin ) ] ) ;
5002+ // The reasoning and command still fold; only the live card stays out.
5003+ expect ( rows . map ( ( row ) => row . id ) ) . toEqual ( [
5004+ "user" ,
5005+ `turn-fold:${ runId } ` ,
5006+ "child" ,
5007+ "assistant" ,
5008+ ] ) ;
5009+ } ,
5010+ ) ;
5011+
5012+ it . each ( [ "completed" , "failed" ] as const ) ( "folds a %s child with its settled turn" , ( status ) => {
5013+ const rows = rowsFor ( [ child ( "child" , 3 , status ) ] ) ;
5014+ expect ( rows . some ( ( row ) => row . id === "child" ) ) . toBe ( false ) ;
5015+ expect ( rows . some ( ( row ) => row . kind === "turn-fold" ) ) . toBe ( true ) ;
5016+ } ) ;
5017+
5018+ it ( "keeps a launch batch visible while any member is still running" , ( ) => {
5019+ const rows = rowsFor ( [ child ( "done" , 3 , "completed" ) , child ( "live" , 4 , "running" ) ] ) ;
5020+ expect ( rows . map ( ( row ) => row . id ) ) . toEqual ( [ "user" , `turn-fold:${ runId } ` , "done" , "assistant" ] ) ;
5021+ expect ( rows . find ( ( row ) => row . id === "done" ) ) . toMatchObject ( {
5022+ subagents : [ { item : { id : "done" } } , { item : { id : "live" } } ] ,
5023+ } ) ;
5024+ } ) ;
5025+
5026+ it ( "keeps a running child visible when a steer supersedes its attempt" , ( ) => {
5027+ const attempt = {
5028+ id : RunAttemptId . make ( "superseded-attempt" ) ,
5029+ runId,
5030+ attemptOrdinal : 1 ,
5031+ rootNodeId : NodeId . make ( "superseded-root" ) ,
5032+ status : "superseded" as const ,
5033+ } ;
5034+ const entries = deriveTimelineEntriesFromVisibleTurnItems ( {
5035+ visibleTurnItems : (
5036+ [
5037+ {
5038+ ...base ( "command" , 2 ) ,
5039+ status : "completed" ,
5040+ type : "command_execution" ,
5041+ input : "pwd" ,
5042+ output : "/repo" ,
5043+ exitCode : 0 ,
5044+ } ,
5045+ child ( "child" , 3 , "running" ) ,
5046+ ] satisfies OrchestrationV2TurnItem [ ]
5047+ ) . map ( projected ) ,
5048+ optimisticMessages : [ ] ,
5049+ } ) . map ( ( entry ) => ( { ...entry , attempt } ) ) ;
5050+ const rows = deriveMessagesTimelineRows ( {
5051+ timelineEntries : entries ,
5052+ latestRun : {
5053+ runId,
5054+ status : "running" ,
5055+ startedAt : DateTime . formatIso ( at ( 0 ) ) ,
5056+ completedAt : null ,
5057+ } ,
5058+ isWorking : false ,
5059+ turnDiffSummaries : [ ] ,
5060+ supportsConversationRollback : false ,
5061+ } ) ;
5062+ expect ( rows . map ( ( row ) => row . id ) ) . toEqual ( [ `attempt-fold:${ attempt . id } ` , "child" ] ) ;
5063+ } ) ;
5064+ } ) ;
0 commit comments