@@ -159,6 +159,11 @@ const seedParentWithTerminalTask = (input: {
159159 readonly deliveryState : "delivered" | "claimed" | "acknowledged" | "disposed" ;
160160 readonly completionWake ?: "always" | "settled_only" ;
161161 readonly deliveryTaskIds ?: ReadonlyArray < NodeId > ;
162+ readonly parentRunStatus ?: "running" | "completed" ;
163+ readonly siblingTasks ?: ReadonlyArray < {
164+ readonly id : NodeId ;
165+ readonly deliveryState : "delivered" | "claimed" ;
166+ } > ;
162167 readonly now : DateTime . Utc ;
163168} ) =>
164169 Effect . gen ( function * ( ) {
@@ -241,10 +246,10 @@ const seedParentWithTerminalTask = (input: {
241246 userMessageId : MessageId . make ( `message:seed-user:${ input . threadId } ` ) ,
242247 rootNodeId : input . rootNodeId ,
243248 activeAttemptId : null ,
244- status : "running" ,
249+ status : input . parentRunStatus ?? "running" ,
245250 requestedAt : input . now ,
246251 startedAt : input . now ,
247- completedAt : null ,
252+ completedAt : input . parentRunStatus === "completed" ? input . now : null ,
248253 checkpointId : null ,
249254 contextHandoffId : null ,
250255 delegatedCompletion : {
@@ -261,22 +266,25 @@ const seedParentWithTerminalTask = (input: {
261266 } ,
262267 } ,
263268 } ,
264- {
265- id : EventId . make ( `event:seed-task:${ input . threadId } ` ) ,
266- type : "subagent.updated" ,
269+ ...[
270+ { id : input . taskId , deliveryState : input . deliveryState } ,
271+ ...( input . siblingTasks ?? [ ] ) ,
272+ ] . map ( ( task ) => ( {
273+ id : EventId . make ( `event:seed-task:${ input . threadId } :${ task . id } ` ) ,
274+ type : "subagent.updated" as const ,
267275 threadId : input . threadId ,
268276 runId : input . runId ,
269- nodeId : input . taskId ,
277+ nodeId : task . id ,
270278 driver,
271279 providerInstanceId : modelSelection . instanceId ,
272280 occurredAt : input . now ,
273281 payload : {
274- id : input . taskId ,
282+ id : task . id ,
275283 threadId : input . threadId ,
276284 runId : input . runId ,
277285 parentNodeId : input . rootNodeId ,
278- origin : "app_owned" ,
279- createdBy : "agent" ,
286+ origin : "app_owned" as const ,
287+ createdBy : "agent" as const ,
280288 driver,
281289 providerInstanceId : modelSelection . instanceId ,
282290 providerThreadId : null ,
@@ -287,16 +295,16 @@ const seedParentWithTerminalTask = (input: {
287295 model : null ,
288296 completionWake : input . completionWake ?? "settled_only" ,
289297 completionDelivery : {
290- state : input . deliveryState ,
291- observedByRunId : input . deliveryState === "acknowledged" ? input . runId : null ,
298+ state : task . deliveryState ,
299+ observedByRunId : task . deliveryState === "acknowledged" ? input . runId : null ,
292300 } ,
293- status : "completed" ,
301+ status : "completed" as const ,
294302 result : "child finished" ,
295303 startedAt : input . now ,
296304 completedAt : input . now ,
297305 updatedAt : input . now ,
298306 } ,
299- } ,
307+ } ) ) ,
300308 ] ,
301309 } ) ;
302310 } ) ;
@@ -683,6 +691,57 @@ it.layer(layerTest)("delegated completion delivery repairs", (it) => {
683691 } ) ,
684692 ) ;
685693
694+ it . effect ( "counts already delivered siblings in the completion notice" , ( ) =>
695+ Effect . gen ( function * ( ) {
696+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
697+ const now = yield * DateTime . now ;
698+ const threadId = ThreadId . make ( "thread:delegated-delivery-notice-count" ) ;
699+ const runId = RunId . make ( "run:delegated-delivery-notice-count" ) ;
700+ const firstTaskId = NodeId . make ( "node:delegated-delivery-notice-count-first" ) ;
701+ const secondTaskId = NodeId . make ( "node:delegated-delivery-notice-count-second" ) ;
702+
703+ yield * seedParentWithTerminalTask ( {
704+ threadId,
705+ projectId : ProjectId . make ( "project:delegated-delivery-notice-count" ) ,
706+ runId,
707+ rootNodeId : NodeId . make ( "node:delegated-delivery-notice-count-root" ) ,
708+ taskId : firstTaskId ,
709+ deliveryState : "claimed" ,
710+ completionWake : "always" ,
711+ deliveryTaskIds : [ firstTaskId , secondTaskId ] ,
712+ parentRunStatus : "completed" ,
713+ siblingTasks : [
714+ { id : secondTaskId , deliveryState : "claimed" } ,
715+ {
716+ id : NodeId . make ( "node:delegated-delivery-notice-count-earlier" ) ,
717+ deliveryState : "delivered" ,
718+ } ,
719+ ] ,
720+ now,
721+ } ) ;
722+
723+ yield * orchestrator . dispatch ( {
724+ type : "message.dispatch" ,
725+ commandId : CommandId . make ( "command:delegated-delivery-notice-count" ) ,
726+ threadId,
727+ messageId : MessageId . make ( `message:delegated-delivery:${ threadId } ` ) ,
728+ text : "Delegated tasks reached a terminal state." ,
729+ attachments : [ ] ,
730+ dispatchMode : { type : "queue_after_active" } ,
731+ createdBy : "agent" ,
732+ creationSource : "server" ,
733+ delegatedCompletion : { parentRunId : runId , generation : 1 , taskIds : [ firstTaskId ] } ,
734+ } ) ;
735+
736+ const projection = yield * orchestrator . getThreadProjection ( threadId ) ;
737+ const notice = projection . turnItems . find ( ( item ) => item . type === "notification" ) ;
738+ assert . match (
739+ notice ?. type === "notification" ? notice . summary : "" ,
740+ / ^ 2 o f 3 d e l e g a t e d t a s k s f i n i s h e d : / ,
741+ ) ;
742+ } ) ,
743+ ) ;
744+
686745 it . effect . each ( [
687746 {
688747 name : "oversized UTF-8 result" ,
0 commit comments