@@ -2066,6 +2066,124 @@ const multiSelectQuestion = {
20662066 multiSelect : true ,
20672067} as const ;
20682068
2069+ describe ( "subagent continued by a later turn" , ( ) => {
2070+ // Stored shape from #15891: resuming a subagent moves its item to the
2071+ // resuming run, but the item keeps the ordinal from the turn that started it.
2072+ const run2 = RunId . make ( "run-2" ) ;
2073+ const at = ( second : number ) => `2026-10-09T10:00:${ String ( second ) . padStart ( 2 , "0" ) } .000Z` ;
2074+ const item = ( id : string , itemRunId : RunId , ordinal : number , second : number ) => ( {
2075+ ...base ( id , at ( second ) , ordinal ) ,
2076+ runId : itemRunId ,
2077+ } ) ;
2078+ const user = ( id : string , itemRunId : RunId , ordinal : number , second : number ) => ( {
2079+ ...item ( id , itemRunId , ordinal , second ) ,
2080+ type : "user_message" as const ,
2081+ messageId : MessageId . make ( id ) ,
2082+ createdBy : "user" as const ,
2083+ creationSource : "mobile" as const ,
2084+ inputIntent : "turn_start" as const ,
2085+ text : `Prompt ${ id } ` ,
2086+ attachments : [ ] ,
2087+ } ) ;
2088+ const assistant = ( id : string , itemRunId : RunId , ordinal : number , second : number ) => ( {
2089+ ...item ( id , itemRunId , ordinal , second ) ,
2090+ type : "assistant_message" as const ,
2091+ messageId : MessageId . make ( id ) ,
2092+ text : `Answer ${ id } ` ,
2093+ streaming : false ,
2094+ } ) ;
2095+ const reasoning = ( id : string , itemRunId : RunId , ordinal : number , second : number ) => ( {
2096+ ...item ( id , itemRunId , ordinal , second ) ,
2097+ type : "reasoning" as const ,
2098+ text : "Thinking" ,
2099+ streaming : false ,
2100+ } ) ;
2101+ const items : OrchestrationV2TurnItem [ ] = [
2102+ user ( "prompt-1" , runId , 1_000_001 , 0 ) ,
2103+ reasoning ( "reasoning-1" , runId , 1_000_002 , 1 ) ,
2104+ {
2105+ ...item ( "subagent" , run2 , 1_000_003 , 2 ) ,
2106+ type : "subagent" ,
2107+ subagentId : NodeId . make ( "subagent" ) ,
2108+ origin : "provider_native" ,
2109+ driver : ProviderDriverKind . make ( "claudeAgent" ) ,
2110+ providerInstanceId : ProviderInstanceId . make ( "claudeAgent" ) ,
2111+ childThreadId : null ,
2112+ prompt : "Research the bug" ,
2113+ result : "Found it" ,
2114+ } ,
2115+ assistant ( "answer-1" , runId , 1_000_004 , 3 ) ,
2116+ user ( "prompt-2" , run2 , 2_000_001 , 30 ) ,
2117+ reasoning ( "reasoning-2" , run2 , 2_000_002 , 31 ) ,
2118+ assistant ( "answer-2" , run2 , 2_000_003 , 32 ) ,
2119+ {
2120+ ...item ( "send-message" , run2 , 2_000_004 , 33 ) ,
2121+ type : "dynamic_tool" ,
2122+ toolName : "SendMessage" ,
2123+ input : { to : "subagent" } ,
2124+ output : "Sent" ,
2125+ } ,
2126+ assistant ( "closing-2" , run2 , 2_000_005 , 41 ) ,
2127+ ] ;
2128+
2129+ it ( "keeps each turn's fold between its own prompt and answer" , ( ) => {
2130+ const presented = deriveThreadFeedPresentation (
2131+ buildThreadFeed ( items . map ( ( entry , index ) => projected ( entry , index ) ) ) ,
2132+ { runId : run2 , status : "completed" , startedAt : at ( 30 ) , completedAt : at ( 41 ) } ,
2133+ new Set ( ) ,
2134+ ) ;
2135+ expect ( presented . map ( ( entry ) => entry . id ) ) . toEqual ( [
2136+ "prompt-1" ,
2137+ `run-fold:${ runId } ` ,
2138+ "answer-1" ,
2139+ "prompt-2" ,
2140+ `run-fold:${ run2 } ` ,
2141+ "answer-2" ,
2142+ "closing-2" ,
2143+ ] ) ;
2144+ } ) ;
2145+
2146+ it ( "keeps a wake run's work open when the user steers it" , ( ) => {
2147+ const wakeRun = RunId . make ( "wake-run" ) ;
2148+ const wakeItems : OrchestrationV2TurnItem [ ] = [
2149+ user ( "prompt-1" , runId , 1_000_001 , 0 ) ,
2150+ reasoning ( "reasoning-1" , runId , 1_000_002 , 1 ) ,
2151+ assistant ( "answer-1" , runId , 1_000_003 , 3 ) ,
2152+ {
2153+ ...item ( "wake" , wakeRun , 2_000_001 , 30 ) ,
2154+ type : "notification" ,
2155+ source : { kind : "background_task" } ,
2156+ outcome : "completed" ,
2157+ summary : "Background task finished" ,
2158+ } ,
2159+ {
2160+ ...item ( "wake-command" , wakeRun , 2_000_002 , 31 ) ,
2161+ type : "command_execution" ,
2162+ input : "vp test" ,
2163+ output : "ok" ,
2164+ exitCode : 0 ,
2165+ } ,
2166+ { ...user ( "steer" , wakeRun , 2_000_003 , 32 ) , inputIntent : "steer" } ,
2167+ ] ;
2168+ const presented = deriveThreadFeedPresentation (
2169+ buildThreadFeed ( wakeItems . map ( ( entry , index ) => projected ( entry , index ) ) ) ,
2170+ { runId : wakeRun , status : "running" , startedAt : at ( 30 ) , completedAt : null } ,
2171+ new Set ( ) ,
2172+ new Set ( ) ,
2173+ at ( 30 ) ,
2174+ ) ;
2175+ expect ( presented . map ( ( entry ) => entry . id ) ) . toEqual ( [
2176+ "prompt-1" ,
2177+ `run-fold:${ runId } ` ,
2178+ "answer-1" ,
2179+ "local:thread-1:wake" ,
2180+ "work-toggle:work-group:local:thread-1:wake-command" ,
2181+ "steer" ,
2182+ "live-activity-row" ,
2183+ ] ) ;
2184+ } ) ;
2185+ } ) ;
2186+
20692187describe ( "pending user input answers" , ( ) => {
20702188 it ( "preserves exact editor text, including a deliberately cleared answer" , ( ) => {
20712189 const question = { ...singleSelectQuestion , initialAnswer : " Proposed message\n" } ;
0 commit comments