@@ -3875,128 +3875,8 @@ it.layer(layerTest)("delegated tasks across a server restart", (it) => {
38753875 } ) ,
38763876 ) ;
38773877
3878- it . effect ( "a delivery its run already answered is not sent again when the run is cut" , ( ) =>
3879- Effect . gen ( function * ( ) {
3880- const orchestrator = yield * Orchestrator . OrchestratorV2 ;
3881- const eventSink = yield * EventSink . EventSinkV2 ;
3882- const now = yield * DateTime . now ;
3883- const name = "delivery-answered-cut" ;
3884- const threadId = ThreadId . make ( `thread:${ name } ` ) ;
3885- const runId = RunId . make ( `run:${ name } ` ) ;
3886- const taskId = NodeId . make ( `node:${ name } -task` ) ;
3887- const messageId = MessageId . make ( `message:delegated-delivery:${ threadId } ` ) ;
3888- const answerId = MessageId . make ( `message:${ name } :answer` ) ;
3889- const deliveryRunId = RunId . make ( `run:${ name } :delivery` ) ;
3890- yield * seedParentWithTerminalTask ( {
3891- threadId,
3892- projectId : ProjectId . make ( `project:${ name } ` ) ,
3893- runId,
3894- rootNodeId : NodeId . make ( `node:${ name } -root` ) ,
3895- taskId,
3896- deliveryState : "claimed" ,
3897- completionWake : "always" ,
3898- deliveryTaskIds : [ taskId ] ,
3899- now,
3900- } ) ;
3901- yield * eventSink . writeWithEffects ( {
3902- commandId : reconcileCommandId ( name ) ,
3903- events : [
3904- {
3905- id : EventId . make ( `event:${ name } :delivery-message` ) ,
3906- type : "message.updated" ,
3907- threadId,
3908- runId : deliveryRunId ,
3909- occurredAt : now ,
3910- payload : {
3911- id : messageId ,
3912- threadId,
3913- runId : deliveryRunId ,
3914- nodeId : null ,
3915- role : "user" ,
3916- text : `Delegated task ${ taskId } reached a terminal state.` ,
3917- attachments : [ ] ,
3918- streaming : false ,
3919- createdBy : "agent" ,
3920- creationSource : "server" ,
3921- createdAt : now ,
3922- updatedAt : now ,
3923- delegatedCompletion : { parentRunId : runId , generation : 1 , taskIds : [ taskId ] } ,
3924- } ,
3925- } ,
3926- {
3927- id : EventId . make ( `event:${ name } :answer-message` ) ,
3928- type : "message.updated" ,
3929- threadId,
3930- runId : deliveryRunId ,
3931- occurredAt : now ,
3932- payload : {
3933- id : answerId ,
3934- threadId,
3935- runId : deliveryRunId ,
3936- nodeId : null ,
3937- role : "assistant" ,
3938- text : "The child finished; I merged its findings." ,
3939- attachments : [ ] ,
3940- streaming : false ,
3941- createdBy : "agent" ,
3942- creationSource : "provider" ,
3943- createdAt : now ,
3944- updatedAt : now ,
3945- } ,
3946- } ,
3947- {
3948- id : EventId . make ( `event:${ name } :answer-item` ) ,
3949- type : "turn-item.updated" ,
3950- threadId,
3951- runId : deliveryRunId ,
3952- occurredAt : now ,
3953- payload : {
3954- id : TurnItemId . make ( `item:${ name } :answer` ) ,
3955- threadId,
3956- runId : deliveryRunId ,
3957- nodeId : null ,
3958- providerThreadId : parentProviderThreadId ( threadId ) ,
3959- providerTurnId : null ,
3960- nativeItemRef : null ,
3961- parentItemId : null ,
3962- ordinal : 1 ,
3963- status : "completed" ,
3964- title : null ,
3965- startedAt : now ,
3966- completedAt : now ,
3967- updatedAt : now ,
3968- type : "assistant_message" ,
3969- messageId : answerId ,
3970- text : "The child finished; I merged its findings." ,
3971- streaming : false ,
3972- } ,
3973- } ,
3974- runEvent ( {
3975- threadId,
3976- runId : deliveryRunId ,
3977- ordinal : 2 ,
3978- status : "cancelled" ,
3979- now,
3980- providerThreadId : parentProviderThreadId ( threadId ) ,
3981- userMessageId : messageId ,
3982- } ) ,
3983- ] ,
3984- effects : [ ] ,
3985- } ) ;
3986-
3987- yield * orchestrator . recoverDelegatedTasks ;
3988-
3989- const projection = yield * orchestrator . getThreadProjection ( threadId ) ;
3990- assert . equal (
3991- projection . subagents . find ( ( row ) => row . id === taskId ) ?. completionDelivery ?. state ,
3992- "delivered" ,
3993- "a cut delivery run that already answered should not offer the result again" ,
3994- ) ;
3995- assert . isNull ( projection . runs . find ( ( row ) => row . id === runId ) ?. delegatedCompletion ?. delivery ) ;
3996- } ) ,
3997- ) ;
3998-
39993878 it . effect . each ( [
3879+ { item : "reply" , state : "delivered" } ,
40003880 { item : "provider_native subagent" , state : "delivered" } ,
40013881 { item : "app_owned subagent" , state : "claimed" } ,
40023882 { item : "question" , state : "delivered" } ,
@@ -4068,26 +3948,33 @@ it.layer(layerTest)("delegated tasks across a server restart", (it) => {
40683948 startedAt : now ,
40693949 completedAt : null ,
40703950 updatedAt : now ,
4071- ...( input . item === "question "
3951+ ...( input . item === "reply "
40723952 ? {
4073- type : "user_input_request " as const ,
4074- requestId : RuntimeRequestId . make ( `request :${ name } ` ) ,
4075- questions : [ ] ,
4076- responseMode : "message" as const ,
3953+ type : "assistant_message " as const ,
3954+ messageId : MessageId . make ( `message :${ name } :reply ` ) ,
3955+ text : "The child finished; I merged its findings." ,
3956+ streaming : false ,
40773957 }
4078- : {
4079- type : "subagent" as const ,
4080- subagentId : NodeId . make ( `node:${ name } -launched` ) ,
4081- origin :
4082- input . item === "provider_native subagent"
4083- ? ( "provider_native" as const )
4084- : ( "app_owned" as const ) ,
4085- driver,
4086- providerInstanceId : modelSelection . instanceId ,
4087- childThreadId : null ,
4088- prompt : "Check the merged findings." ,
4089- result : null ,
4090- } ) ,
3958+ : input . item === "question"
3959+ ? {
3960+ type : "user_input_request" as const ,
3961+ requestId : RuntimeRequestId . make ( `request:${ name } ` ) ,
3962+ questions : [ ] ,
3963+ responseMode : "message" as const ,
3964+ }
3965+ : {
3966+ type : "subagent" as const ,
3967+ subagentId : NodeId . make ( `node:${ name } -launched` ) ,
3968+ origin :
3969+ input . item === "provider_native subagent"
3970+ ? ( "provider_native" as const )
3971+ : ( "app_owned" as const ) ,
3972+ driver,
3973+ providerInstanceId : modelSelection . instanceId ,
3974+ childThreadId : null ,
3975+ prompt : "Check the merged findings." ,
3976+ result : null ,
3977+ } ) ,
40913978 } ,
40923979 } ,
40933980 runEvent ( {
0 commit comments