@@ -540,54 +540,70 @@ it.effect.each(["thread.stop", "run.interrupt"] as const)(
540540 } ) . pipe ( Effect . provide ( layerTest . pipe ( Layer . provideMerge ( TestClock . layer ( ) ) ) ) ) ,
541541) ;
542542
543- it . effect ( "a delegated task's async question closes once Stop ends the task" , ( ) =>
544- Effect . gen ( function * ( ) {
545- const orchestrator = yield * Orchestrator . OrchestratorV2 ;
546- const parentThreadId = ThreadId . make ( "thread:stop-question-parent" ) ;
547- yield * createWatchingThread ( parentThreadId , 20 ) ;
548- yield * send ( parentThreadId , "first" , "start_immediately" ) ;
549- const childThreadId = yield * delegate ( parentThreadId , "question task" ) ;
550- const childRun = ( yield * orchestrator . getThreadProjection ( childThreadId ) ) . runs [ 0 ] ! ;
551- // A Codex async question, which does not end the run that asked it.
552- const requestId = RuntimeRequestId . make ( "request:stop-question" ) ;
553- const nodeId = NodeId . make ( "node:stop-question" ) ;
554- const now = yield * DateTime . now ;
555- yield * ( yield * ProjectionStore . ProjectionStoreV2 ) . apply ( {
556- id : EventId . make ( "event:stop-question:request" ) ,
557- type : "runtime-request.updated" ,
558- threadId : childThreadId ,
559- runId : childRun . id ,
560- nodeId,
561- occurredAt : now ,
562- payload : {
563- id : requestId ,
543+ it . effect . each ( [
544+ { ending : "cancelled" , question : "resolved" } ,
545+ { ending : "completed" , question : "pending" } ,
546+ ] as const ) (
547+ "a $ending delegated task leaves its async question $question" ,
548+ ( { ending, question } ) =>
549+ Effect . gen ( function * ( ) {
550+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
551+ const parentThreadId = ThreadId . make ( `thread:stop-question-parent:${ ending } ` ) ;
552+ yield * createWatchingThread ( parentThreadId , 20 ) ;
553+ yield * send ( parentThreadId , "first" , "start_immediately" ) ;
554+ const childThreadId = yield * delegate ( parentThreadId , `question task ${ ending } ` ) ;
555+ const childRun = ( yield * orchestrator . getThreadProjection ( childThreadId ) ) . runs [ 0 ] ! ;
556+ // A Codex async question, which does not end the run that asked it.
557+ const requestId = RuntimeRequestId . make ( "request:stop-question" ) ;
558+ const nodeId = NodeId . make ( "node:stop-question" ) ;
559+ const now = yield * DateTime . now ;
560+ yield * ( yield * ProjectionStore . ProjectionStoreV2 ) . apply ( {
561+ id : EventId . make ( "event:stop-question:request" ) ,
562+ type : "runtime-request.updated" ,
563+ threadId : childThreadId ,
564+ runId : childRun . id ,
564565 nodeId,
565- providerTurnId : null ,
566- nativeRequestRef : null ,
567- kind : "user_input" ,
568- status : "pending" ,
569- responseCapability : { type : "message" } ,
570- createdAt : now ,
571- resolvedAt : null ,
572- } ,
573- } ) ;
574- const requestStatus = Effect . map (
575- orchestrator . getThreadProjection ( childThreadId ) ,
576- ( projection ) => projection . runtimeRequests [ 0 ] ?. status ,
577- ) ;
566+ occurredAt : now ,
567+ payload : {
568+ id : requestId ,
569+ nodeId,
570+ providerTurnId : null ,
571+ nativeRequestRef : null ,
572+ kind : "user_input" ,
573+ status : "pending" ,
574+ responseCapability : { type : "message" } ,
575+ createdAt : now ,
576+ resolvedAt : null ,
577+ } ,
578+ } ) ;
579+ const requestStatus = Effect . map (
580+ orchestrator . getThreadProjection ( childThreadId ) ,
581+ ( projection ) => projection . runtimeRequests [ 0 ] ?. status ,
582+ ) ;
578583
579- // While the task runs, its question stays open.
580- yield * orchestrator . recoverDelegatedTask ( childThreadId , childRun . id ) ;
581- assert . equal ( yield * requestStatus , "pending" ) ;
582- // What task_cancel dispatches.
583- yield * orchestrator . dispatch ( {
584- type : "thread.stop" ,
585- commandId : CommandId . make ( "stop-question-child" ) ,
586- threadId : childThreadId ,
587- } ) ;
588- yield * orchestrator . recoverDelegatedTask ( childThreadId , childRun . id ) ;
589- assert . equal ( yield * requestStatus , "resolved" ) ;
590- } ) . pipe ( Effect . provide ( layerTest ) ) ,
584+ // While the task runs, its question stays open.
585+ yield * orchestrator . recoverDelegatedTask ( childThreadId , childRun . id ) ;
586+ assert . equal ( yield * requestStatus , "pending" ) ;
587+ if ( ending === "cancelled" ) {
588+ // What task_cancel dispatches.
589+ yield * orchestrator . dispatch ( {
590+ type : "thread.stop" ,
591+ commandId : CommandId . make ( "stop-question-child" ) ,
592+ threadId : childThreadId ,
593+ } ) ;
594+ } else {
595+ yield * ( yield * ProjectionStore . ProjectionStoreV2 ) . apply ( {
596+ id : EventId . make ( "event:stop-question:completed" ) ,
597+ type : "run.updated" ,
598+ threadId : childThreadId ,
599+ runId : childRun . id ,
600+ occurredAt : now ,
601+ payload : { ...childRun , status : "completed" , startedAt : now , completedAt : now } ,
602+ } ) ;
603+ }
604+ yield * orchestrator . recoverDelegatedTask ( childThreadId , childRun . id ) ;
605+ assert . equal ( yield * requestStatus , question ) ;
606+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
591607) ;
592608
593609it . effect ( "a delegated task that cannot be stopped fails the walk after its siblings stop" , ( ) =>
0 commit comments