@@ -573,6 +573,7 @@ export interface RunExecutionServiceV2StartRootRunInput {
573573 readonly shouldStartProviderTurn ?: ( ) => Effect . Effect < boolean , ProjectionStoreV2Error > ;
574574 readonly shouldFinalizeRun ?: ( ) => Effect . Effect < boolean , ProjectionStoreV2Error > ;
575575 readonly hasUnpairedRunInterruptRequest ?: ( ) => Effect . Effect < boolean , never > ;
576+ readonly loadRunInterruptReason ?: ( ) => Effect . Effect < string | undefined , never > ;
576577 readonly message : ProviderAdapter . ProviderAdapterV2TurnMessage ;
577578 readonly modelSelection : ModelSelection ;
578579 readonly runtimePolicy : ProviderAdapter . ProviderAdapterV2RuntimePolicy ;
@@ -621,6 +622,7 @@ export const layer: Layer.Layer<
621622 readonly attempt : OrchestrationV2RunAttempt ;
622623 readonly shouldFinalizeRun ?: ( ) => Effect . Effect < boolean , ProjectionStoreV2Error > ;
623624 readonly hasUnpairedRunInterruptRequest ?: ( ) => Effect . Effect < boolean , never > ;
625+ readonly loadRunInterruptReason ?: ( ) => Effect . Effect < string | undefined , never > ;
624626 readonly openRunOwnedSubagents ?: OpenRunOwnedSubagentProjection ;
625627 readonly interruptedProviderTurn ?: OrchestrationV2ProviderTurn ;
626628 readonly terminal : ProviderTerminalEvent ;
@@ -647,6 +649,10 @@ export const layer: Layer.Layer<
647649 ? false
648650 : yield * input . hasUnpairedRunInterruptRequest ( ) ;
649651 if ( hasUnpairedRequest ) {
652+ const reason =
653+ input . loadRunInterruptReason === undefined
654+ ? undefined
655+ : yield * input . loadRunInterruptReason ( ) ;
650656 yield * eventSink . writeWithEffects ( {
651657 effects : [ ] ,
652658 events : [
@@ -663,6 +669,7 @@ export const layer: Layer.Layer<
663669 run : input . run ,
664670 rootNode : input . rootNode ,
665671 providerThread : input . providerThread ,
672+ reason,
666673 completedAt,
667674 } ) ,
668675 } ,
@@ -674,6 +681,10 @@ export const layer: Layer.Layer<
674681 return ;
675682 }
676683 const allocateEventId = ( ) => idAllocator . allocate . event ( { threadId : input . run . threadId } ) ;
684+ const reason =
685+ input . terminal . status === "interrupted" && input . loadRunInterruptReason !== undefined
686+ ? yield * input . loadRunInterruptReason ( )
687+ : undefined ;
677688 const open = input . openRunOwnedSubagents ?? emptyOpenRunOwnedSubagentProjection ( ) ;
678689 const hasOpenSubagentProjection =
679690 open . subagents . size > 0 ||
@@ -791,6 +802,7 @@ export const layer: Layer.Layer<
791802 run : input . run ,
792803 rootNode : input . rootNode ,
793804 providerThread : input . providerThread ,
805+ reason,
794806 completedAt,
795807 } ) ,
796808 } ,
@@ -1060,6 +1072,9 @@ export const layer: Layer.Layer<
10601072 : {
10611073 hasUnpairedRunInterruptRequest : input . hasUnpairedRunInterruptRequest ,
10621074 } ) ,
1075+ ...( input . loadRunInterruptReason === undefined
1076+ ? { }
1077+ : { loadRunInterruptReason : input . loadRunInterruptReason } ) ,
10631078 openRunOwnedSubagents : openSubagents ,
10641079 terminal,
10651080 failureItemPersisted : terminal . status === "failed" ,
@@ -1684,11 +1699,19 @@ export const layer: Layer.Layer<
16841699 } ) ,
16851700) ;
16861701
1702+ /**
1703+ * Clients send Stop without a reason; server callers acting for an agent
1704+ * always set one, so a missing reason means a person stopped the run.
1705+ */
1706+ export const USER_STOP_REASON = "Stopped by user" ;
1707+
16871708export function makeInterruptResultTurnItem ( input : {
16881709 readonly idAllocator : IdAllocator . IdAllocatorV2 [ "Service" ] ;
16891710 readonly run : OrchestrationV2Run ;
16901711 readonly rootNode : OrchestrationV2ExecutionNode ;
16911712 readonly providerThread : OrchestrationV2ProviderThread ;
1713+ /** The Stop's own reason, from its run_interrupt_request item. */
1714+ readonly reason : string | undefined ;
16921715 readonly completedAt : DateTime . Utc ;
16931716} ) : OrchestrationV2TurnItem {
16941717 return {
@@ -1713,6 +1736,6 @@ export function makeInterruptResultTurnItem(input: {
17131736 completedAt : input . completedAt ,
17141737 updatedAt : input . completedAt ,
17151738 type : "run_interrupt_result" ,
1716- message : "Run interrupted by user ",
1739+ message : input . reason ?? "Stopped by the provider ",
17171740 } ;
17181741}
0 commit comments