@@ -229,11 +229,11 @@ it.effect("Stop reaches background work an earlier provider thread still runs",
229229 const codexProviderThread = ( yield * orchestrator . getThreadProjection ( threadId ) )
230230 . providerThreads [ 0 ] ! ;
231231 // A settled run with its root node, attempt, provider turn and,
232- // optionally, a command it left running.
232+ // optionally, a command or native subagent it left running.
233233 const settledRun = ( input : {
234234 readonly ordinal : number ;
235235 readonly providerThreadId : ProviderThreadId ;
236- readonly runningCommandId ?: TurnItemId ;
236+ readonly runningItem ?: { readonly id : TurnItemId ; readonly kind : "command" | "subagent" } ;
237237 } ) => {
238238 const runId = RunId . make ( `run:${ input . ordinal } ` ) ;
239239 const attemptId = RunAttemptId . make ( `attempt:${ input . ordinal } ` ) ;
@@ -324,49 +324,73 @@ it.effect("Stop reaches background work an earlier provider thread still runs",
324324 } ,
325325 } ,
326326 ] ;
327- if ( input . runningCommandId !== undefined ) {
327+ const item = input . runningItem ;
328+ if ( item !== undefined ) {
329+ const base = {
330+ id : item . id ,
331+ threadId,
332+ runId,
333+ nodeId,
334+ providerThreadId : input . providerThreadId ,
335+ providerTurnId,
336+ nativeItemRef : null ,
337+ parentItemId : null ,
338+ ordinal : input . ordinal * 100 ,
339+ status : "running" ,
340+ title : null ,
341+ startedAt : now ,
342+ completedAt : null ,
343+ updatedAt : now ,
344+ } as const ;
328345 events . push ( {
329- id : EventId . make ( `command :${ input . ordinal } ` ) ,
346+ id : EventId . make ( `item :${ input . ordinal } ` ) ,
330347 type : "turn-item.updated" ,
331348 threadId,
332349 runId,
333350 occurredAt : now ,
334- payload : {
335- id : input . runningCommandId ,
336- threadId,
337- runId,
338- nodeId,
339- providerThreadId : input . providerThreadId ,
340- providerTurnId,
341- nativeItemRef : null ,
342- parentItemId : null ,
343- ordinal : input . ordinal * 100 ,
344- status : "running" ,
345- title : null ,
346- startedAt : now ,
347- completedAt : null ,
348- updatedAt : now ,
349- type : "command_execution" ,
350- input : "vp run test --watch" ,
351- } ,
351+ payload :
352+ item . kind === "command"
353+ ? { ...base , type : "command_execution" , input : "vp run test --watch" }
354+ : {
355+ ...base ,
356+ // A native subagent item names its own provider thread
357+ // but its parent's provider turn.
358+ providerThreadId : ProviderThreadId . make ( "provider-thread:codex-subagent" ) ,
359+ type : "subagent" ,
360+ subagentId : NodeId . make ( `subagent:${ input . ordinal } ` ) ,
361+ origin : "provider_native" ,
362+ driver,
363+ providerInstanceId : instanceId ,
364+ childThreadId : null ,
365+ prompt : "Review the change" ,
366+ result : null ,
367+ } ,
352368 } ) ;
353369 }
354370 return { runId, providerTurnId, events } ;
355371 } ;
356372
357- // Codex leaves a second command in a later run. Then the thread moves
358- // on to another provider thread, which also has a live session.
373+ // Later Codex runs leave a second command and a native subagent. Then
374+ // the thread moves on to another provider thread, which also has a
375+ // live session.
359376 const watcherId = TurnItemId . make ( "turn-item:watcher" ) ;
360- const laterCodexRun = settledRun ( {
377+ const watcherRun = settledRun ( {
361378 ordinal : 2 ,
362379 providerThreadId : codexProviderThread . id ,
363- runningCommandId : watcherId ,
380+ runningItem : { id : watcherId , kind : "command" } ,
381+ } ) ;
382+ const reviewerId = TurnItemId . make ( "turn-item:reviewer" ) ;
383+ const reviewerRun = settledRun ( {
384+ ordinal : 3 ,
385+ providerThreadId : codexProviderThread . id ,
386+ runningItem : { id : reviewerId , kind : "subagent" } ,
364387 } ) ;
365388 const otherProviderThreadId = ProviderThreadId . make ( "provider-thread:other" ) ;
366- const latestRun = settledRun ( { ordinal : 3 , providerThreadId : otherProviderThreadId } ) ;
389+ const latestRun = settledRun ( { ordinal : 4 , providerThreadId : otherProviderThreadId } ) ;
367390 yield * sink . write ( {
368391 events : [
369- ...laterCodexRun . events ,
392+ ...watcherRun . events ,
393+ ...reviewerRun . events ,
370394 {
371395 id : EventId . make ( "provider-thread:other" ) ,
372396 type : "provider-thread.updated" ,
@@ -375,8 +399,8 @@ it.effect("Stop reaches background work an earlier provider thread still runs",
375399 payload : {
376400 ...codexProviderThread ,
377401 id : otherProviderThreadId ,
378- firstRunOrdinal : 3 ,
379- lastRunOrdinal : 3 ,
402+ firstRunOrdinal : 4 ,
403+ lastRunOrdinal : 4 ,
380404 } ,
381405 } ,
382406 ...latestRun . events ,
@@ -392,20 +416,21 @@ it.effect("Stop reaches background work an earlier provider thread still runs",
392416 yield * worker . drain ( ) ;
393417
394418 // Stop reaches both provider threads. The Codex one is interrupted at
395- // its latest pending work, so its settle covers both of its runs.
419+ // its latest pending work, the subagent's parent turn, so its settle
420+ // covers all three Codex runs.
396421 assert . sameDeepMembers (
397422 interrupts . map ( ( interrupt ) => [ interrupt . providerThread . id , interrupt . providerTurnId ] ) ,
398423 [
399424 [ otherProviderThreadId , latestRun . providerTurnId ] ,
400- [ codexProviderThread . id , laterCodexRun . providerTurnId ] ,
425+ [ codexProviderThread . id , reviewerRun . providerTurnId ] ,
401426 ] ,
402427 ) ;
403428 const after = yield * orchestrator . getThreadProjection ( threadId ) ;
404429 assert . deepEqual (
405- [ devServerId , watcherId ] . map (
430+ [ devServerId , watcherId , reviewerId ] . map (
406431 ( id ) => after . turnItems . find ( ( item ) => item . id === id ) ?. status ,
407432 ) ,
408- [ "interrupted" , "interrupted" ] ,
433+ [ "interrupted" , "interrupted" , "interrupted" ] ,
409434 ) ;
410435 } ) . pipe (
411436 Effect . provide (
0 commit comments