@@ -7937,7 +7937,17 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
79377937 driver : providerThread . driver ,
79387938 providerInstanceId : providerThread . providerInstanceId ,
79397939 occurredAt : input . now ,
7940- payload : { ...providerThread , pendingBackgroundTasks : [ ] , updatedAt : input . now } ,
7940+ payload : {
7941+ ...providerThread ,
7942+ status :
7943+ providerThread . status === "active" &&
7944+ providerThread . lastRunOrdinal !== null &&
7945+ providerThread . lastRunOrdinal <= input . throughRunOrdinal
7946+ ? "idle"
7947+ : providerThread . status ,
7948+ pendingBackgroundTasks : [ ] ,
7949+ updatedAt : input . now ,
7950+ } ,
79417951 } ) ;
79427952 }
79437953 } ) ;
@@ -7951,7 +7961,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
79517961 > ;
79527962 readonly projection : Pick <
79537963 OrchestrationV2ThreadProjection ,
7954- "runs" | "attempts" | "nodes" | "subagents" | "runtimeRequests"
7964+ | "runs"
7965+ | "attempts"
7966+ | "nodes"
7967+ | "subagents"
7968+ | "runtimeRequests"
7969+ | "messages"
7970+ | "turnItems"
7971+ | "providerThreads"
79557972 > ;
79567973 readonly providerTurn : OrchestrationV2ProviderTurn ;
79577974 readonly events : Ref . Ref < Array < OrchestrationV2DomainEvent > > ;
@@ -8000,6 +8017,45 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
80008017 completedAt : input . now ,
80018018 } ,
80028019 } ) ;
8020+ const providerThread = input . projection . providerThreads . find (
8021+ ( candidate ) => candidate . id === input . providerTurn . providerThreadId ,
8022+ ) ;
8023+ if ( providerThread ?. status === "active" && providerThread . lastRunOrdinal === run . ordinal ) {
8024+ yield * emitEvent ( {
8025+ ...base ,
8026+ type : "provider-thread.updated" ,
8027+ payload : { ...providerThread , status : "idle" , updatedAt : input . now } ,
8028+ } ) ;
8029+ }
8030+ for ( const message of input . projection . messages ) {
8031+ if ( message . runId !== run . id || ! message . streaming ) continue ;
8032+ yield * emitEvent ( {
8033+ ...base ,
8034+ ...( message . nodeId === null ? { } : { nodeId : message . nodeId } ) ,
8035+ type : "message.updated" ,
8036+ payload : { ...message , streaming : false , updatedAt : input . now } ,
8037+ } ) ;
8038+ }
8039+ for ( const item of input . projection . turnItems ) {
8040+ if (
8041+ item . runId !== run . id ||
8042+ ( item . type !== "assistant_message" && item . type !== "reasoning" ) ||
8043+ ! [ "pending" , "running" , "waiting" ] . includes ( item . status )
8044+ )
8045+ continue ;
8046+ yield * emitEvent ( {
8047+ ...base ,
8048+ ...( item . nodeId === null ? { } : { nodeId : item . nodeId } ) ,
8049+ type : "turn-item.updated" ,
8050+ payload : {
8051+ ...item ,
8052+ status : "interrupted" ,
8053+ streaming : false ,
8054+ completedAt : input . now ,
8055+ updatedAt : input . now ,
8056+ } ,
8057+ } ) ;
8058+ }
80038059 const delegatedNodeIds = new Set (
80048060 input . projection . subagents
80058061 . filter ( ( subagent ) => subagent . origin === "app_owned" )
@@ -8137,7 +8193,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
81378193 "providerThreads" ,
81388194 ] ,
81398195 {
8140- turnItemTypes : [ "command_execution" , "dynamic_tool" , "subagent" ] ,
8196+ turnItemTypes : [
8197+ "command_execution" ,
8198+ "dynamic_tool" ,
8199+ "subagent" ,
8200+ "assistant_message" ,
8201+ "reasoning" ,
8202+ ] ,
81418203 turnItemStatuses : [ "pending" , "running" , "waiting" ] ,
81428204 } ,
81438205 ) ,
@@ -8161,10 +8223,20 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
81618223 )
81628224 return ;
81638225 const now = yield * DateTime . now ;
8164- if ( stopped . providerTurn !== undefined ) {
8226+ if ( stopped . providerTurn ?. status === "running" && stoppedRun . status === "running" ) {
8227+ const output = yield * projectionStore
8228+ . getThreadRecords ( command . threadId , [ "messages" ] , {
8229+ messageRunIds : [ stoppedRun . id ] ,
8230+ messageRoles : [ "assistant" ] ,
8231+ } )
8232+ . pipe (
8233+ Effect . mapError (
8234+ ( cause ) => new OrchestratorProjectionError ( { threadId : command . threadId , cause } ) ,
8235+ ) ,
8236+ ) ;
81658237 yield * settleInterruptedRun ( {
81668238 command,
8167- projection,
8239+ projection : { ... projection , messages : output . messages } ,
81688240 providerTurn : stopped . providerTurn ,
81698241 events,
81708242 effects,
@@ -8214,7 +8286,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
82148286 // Thread-wide, like the Waiting strip: a settled thread's background
82158287 // work can belong to an earlier run than the one Stop targets.
82168288 {
8217- turnItemTypes : [ "command_execution" , "dynamic_tool" , "subagent" ] ,
8289+ turnItemTypes : [
8290+ "command_execution" ,
8291+ "dynamic_tool" ,
8292+ "subagent" ,
8293+ "assistant_message" ,
8294+ "reasoning" ,
8295+ ] ,
82188296 turnItemStatuses : [ "pending" , "running" , "waiting" ] ,
82198297 } ,
82208298 ) ;
0 commit comments