@@ -2643,21 +2643,22 @@ it.effect("settles native subagents when a workspace handoff completes the root
26432643 providerSessionId : ProviderSessionId . make ( "session:subagent-workspace-handoff" ) ,
26442644 session : {
26452645 events : Stream . empty ,
2646- subscribeEvents : Effect . succeed ( {
2647- // The provider event stream stays open: only settled children may end ingestion.
2648- events : Stream . concat (
2649- Stream . fromIterable ( [
2650- childThreadCreatedEvent ( ids ) ,
2651- { type : "subagent.updated" , driver, subagent : runningSubagent } ,
2652- { type : "node.updated" , driver, node : runningNode } ,
2653- { type : "node.updated" , driver, node : runningChildNode } ,
2654- { type : "turn_item.updated" , driver, turnItem : runningTurnItem } ,
2655- rootTerminalEvent ( ids , "interrupted" ) ,
2656- ] satisfies ReadonlyArray < ProviderAdapter . ProviderAdapterV2Event > ) ,
2657- Stream . never ,
2658- ) ,
2659- close : Deferred . succeed ( ingestionDone , undefined ) ,
2660- } ) ,
2646+ subscribeEvents : ( ) =>
2647+ Effect . succeed ( {
2648+ // The provider event stream stays open: only settled children may end ingestion.
2649+ events : Stream . concat (
2650+ Stream . fromIterable ( [
2651+ childThreadCreatedEvent ( ids ) ,
2652+ { type : "subagent.updated" , driver, subagent : runningSubagent } ,
2653+ { type : "node.updated" , driver, node : runningNode } ,
2654+ { type : "node.updated" , driver, node : runningChildNode } ,
2655+ { type : "turn_item.updated" , driver, turnItem : runningTurnItem } ,
2656+ rootTerminalEvent ( ids , "interrupted" ) ,
2657+ ] satisfies ReadonlyArray < ProviderAdapter . ProviderAdapterV2Event > ) ,
2658+ Stream . never ,
2659+ ) ,
2660+ close : Deferred . succeed ( ingestionDone , undefined ) ,
2661+ } ) ,
26612662 startTurn : ( ) => Effect . void ,
26622663 } as unknown as ProviderAdapter . ProviderAdapterV2SessionRuntime ,
26632664 run : {
@@ -2900,6 +2901,7 @@ it.effect("interrupts open tool items but preserves completed tools on a planned
29002901 const ids = backgroundScenarioIds ( key ) ;
29012902 const runningId = TurnItemId . make ( `${ ids . itemId } :running` ) ;
29022903 const completedId = TurnItemId . make ( `${ ids . itemId } :completed` ) ;
2904+ const now = yield * DateTime . now ;
29032905 const { ingested, observed } = yield * captureRootRunTermination ( {
29042906 key,
29052907 shouldFinalizeRun : ( ) => Effect . succeed ( true ) ,
@@ -2910,6 +2912,21 @@ it.effect("interrupts open tool items but preserves completed tools on a planned
29102912 backgroundTurnItemEvent ( ids , "dynamic_tool" , "pending" , 1 ) ,
29112913 backgroundTurnItemEvent ( ids , "dynamic_tool" , "running" , 2 , runningId ) ,
29122914 backgroundTurnItemEvent ( ids , "dynamic_tool" , "running" , 3 , completedId ) ,
2915+ {
2916+ type : "provider_turn.updated" as const ,
2917+ driver,
2918+ providerTurn : {
2919+ id : ProviderTurnId . make ( `${ ids . rootProviderTurnId } :continuation` ) ,
2920+ providerThreadId : ids . providerThreadId ,
2921+ nodeId : ids . rootNodeId ,
2922+ runAttemptId : ids . attemptId ,
2923+ nativeTurnRef : null ,
2924+ ordinal : 2 ,
2925+ status : "running" as const ,
2926+ startedAt : now ,
2927+ completedAt : null ,
2928+ } ,
2929+ } ,
29132930 backgroundTurnItemEvent ( ids , "dynamic_tool" , "completed" , 3 , completedId ) ,
29142931 ] ) ,
29152932 Stream . fail (
@@ -4250,27 +4267,28 @@ function runBackgroundItemScenario(
42504267 ...( options ?. hasPendingBackgroundWorkForThread === undefined
42514268 ? { }
42524269 : { hasPendingBackgroundWorkForThread : options . hasPendingBackgroundWorkForThread } ) ,
4253- subscribeEvents : ( ) => Effect . gen ( function * ( ) {
4254- yield * options ?. onSubscribe ?? Effect . void ;
4255- const source = makeEvents ( ids ) ;
4256- const events = ( Stream . isStream ( source ) ? source : Stream . fromIterable ( source ) ) . pipe (
4257- Stream . concat (
4258- Stream . fromEffect (
4259- Effect . andThen (
4260- options ?. onEventsConsumed ?? Effect . void ,
4261- options ?. afterEvents ?.( previewActivity ) ?? Effect . void ,
4262- ) ,
4263- ) . pipe ( Stream . drain ) ,
4264- ) ,
4265- ) ;
4266- return {
4267- events :
4268- options ?. keepEventStreamOpen === true
4269- ? events . pipe ( Stream . concat ( Stream . never ) )
4270- : events ,
4271- close : Deferred . succeed ( ingestionDone , undefined ) ,
4272- } ;
4273- } ) ,
4270+ subscribeEvents : ( ) =>
4271+ Effect . gen ( function * ( ) {
4272+ yield * options ?. onSubscribe ?? Effect . void ;
4273+ const source = makeEvents ( ids ) ;
4274+ const events = ( Stream . isStream ( source ) ? source : Stream . fromIterable ( source ) ) . pipe (
4275+ Stream . concat (
4276+ Stream . fromEffect (
4277+ Effect . andThen (
4278+ options ?. onEventsConsumed ?? Effect . void ,
4279+ options ?. afterEvents ?.( previewActivity ) ?? Effect . void ,
4280+ ) ,
4281+ ) . pipe ( Stream . drain ) ,
4282+ ) ,
4283+ ) ;
4284+ return {
4285+ events :
4286+ options ?. keepEventStreamOpen === true
4287+ ? events . pipe ( Stream . concat ( Stream . never ) )
4288+ : events ,
4289+ close : Deferred . succeed ( ingestionDone , undefined ) ,
4290+ } ;
4291+ } ) ,
42744292 startTurn : ( ) => Effect . void ,
42754293 } as unknown as ProviderAdapter . ProviderAdapterV2SessionRuntime ,
42764294 run : {
0 commit comments