@@ -6400,7 +6400,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
64006400 } ) ,
64016401 ) ;
64026402
6403- it . effect ( "settles past held automatic runs but not held user messages " , ( ) =>
6403+ it . effect ( "settles past held automatic messages but preserves a held user queue " , ( ) =>
64046404 Effect . gen ( function * ( ) {
64056405 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
64066406 const eventSink = yield * EventSink . EventSinkV2 ;
@@ -6432,20 +6432,33 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
64326432 modelSelection,
64336433 dispatchMode : { type : "start_immediately" } ,
64346434 } ) ;
6435- const queueMessage = ( id : string , automatic : boolean ) =>
6435+ const queueMessage = ( id : string , sender : "notification" | "agent" | "scheduled" | "user" ) =>
64366436 orchestrator . dispatch ( {
64376437 type : "message.dispatch" ,
6438- createdBy : automatic ? "agent" : "user" ,
6439- creationSource : automatic ? "provider" : "web" ,
6440- ...( automatic
6441- ? {
6438+ ...(
6439+ {
6440+ notification : {
6441+ createdBy : "agent" ,
6442+ creationSource : "provider" ,
64426443 notification : {
6443- source : { kind : "background_task" as const } ,
6444- outcome : "updated" as const ,
6444+ source : { kind : "background_task" } ,
6445+ outcome : "updated" ,
64456446 summary : "Background activity updated" ,
64466447 } ,
6447- }
6448- : { } ) ,
6448+ } ,
6449+ agent : {
6450+ createdBy : "agent" ,
6451+ creationSource : "mcp" ,
6452+ senderThreadId : ThreadId . make ( "settle-automatic-sender" ) ,
6453+ } ,
6454+ scheduled : {
6455+ createdBy : "user" ,
6456+ creationSource : "web" ,
6457+ scheduledTaskId : ScheduledTaskId . make ( "settle-automatic-schedule" ) ,
6458+ } ,
6459+ user : { createdBy : "user" , creationSource : "web" } ,
6460+ } as const
6461+ ) [ sender ] ,
64496462 commandId : CommandId . make ( id ) ,
64506463 threadId,
64516464 messageId : MessageId . make ( id ) ,
@@ -6454,7 +6467,9 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
64546467 modelSelection,
64556468 dispatchMode : { type : "queue_after_active" } ,
64566469 } ) ;
6457- yield * queueMessage ( "settle-automatic-notification" , true ) ;
6470+ yield * queueMessage ( "settle-automatic-notification" , "notification" ) ;
6471+ yield * queueMessage ( "settle-automatic-agent" , "agent" ) ;
6472+ yield * queueMessage ( "settle-automatic-scheduled" , "scheduled" ) ;
64586473
64596474 const holdQueueAfterRestart = ( commandId : string ) =>
64606475 Effect . gen ( function * ( ) {
@@ -6528,7 +6543,8 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
65286543 modelSelection,
65296544 dispatchMode : { type : "start_immediately" } ,
65306545 } ) ;
6531- yield * queueMessage ( "settle-automatic-user-queued" , false ) ;
6546+ yield * queueMessage ( "settle-automatic-user-queued" , "user" ) ;
6547+ yield * queueMessage ( "settle-automatic-agent-queued-2" , "agent" ) ;
65326548 yield * holdQueueAfterRestart ( "settle-automatic-restart-2" ) ;
65336549 const error = yield * orchestrator
65346550 . dispatch ( {
@@ -6542,6 +6558,12 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
65426558 error . cause ,
65436559 `Thread ${ threadId } has a queued message. Send it or remove it from the queue before settling.` ,
65446560 ) ;
6561+ const blocked = yield * orchestrator . getThreadProjection ( threadId ) ;
6562+ assert . isNull ( blocked . thread . settledAt ) ;
6563+ assert . deepEqual (
6564+ blocked . runs . filter ( ( run ) => run . status === "queued" ) . map ( ( run ) => run . userMessageId ) ,
6565+ [ "settle-automatic-user-queued" , "settle-automatic-agent-queued-2" ] ,
6566+ ) ;
65456567 } ) ,
65466568 ) ;
65476569
0 commit comments