@@ -65,6 +65,7 @@ import * as Effect from "effect/Effect";
6565import * as Exit from "effect/Exit" ;
6666import * as FileSystem from "effect/FileSystem" ;
6767import * as Fiber from "effect/Fiber" ;
68+ import * as Option from "effect/Option" ;
6869import * as Path from "effect/Path" ;
6970import * as Queue from "effect/Queue" ;
7071import * as Ref from "effect/Ref" ;
@@ -4419,11 +4420,40 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
44194420 yield * Effect . forEach (
44204421 liveIds ,
44214422 ( taskId ) =>
4422- Effect . tryPromise ( {
4423- // Invoke through the query object: SDK methods rely on `this`.
4424- try : ( ) => context . query . stopTask ! ( taskId ) ,
4425- catch : ( ) => undefined ,
4426- } ) . pipe ( Effect . timeoutOption ( "3 seconds" ) , Effect . ignore ) ,
4423+ Effect . gen ( function * ( ) {
4424+ const stopAcknowledged = yield * Effect . tryPromise ( {
4425+ // Invoke through the query object: SDK methods rely on `this`.
4426+ try : ( ) => context . query . stopTask ! ( taskId ) ,
4427+ catch : ( ) => undefined ,
4428+ } ) . pipe (
4429+ Effect . timeoutOption ( "3 seconds" ) ,
4430+ Effect . orElseSucceed ( ( ) => Option . none ( ) ) ,
4431+ ) ;
4432+ if ( Option . isNone ( stopAcknowledged ) || ! context . liveTaskIds . delete ( taskId ) ) {
4433+ return ;
4434+ }
4435+
4436+ // stopTask only acknowledges the control request. Its separate
4437+ // task_notification can lose the race with interrupt(), so make
4438+ // the acknowledged stop authoritative for the durable UI state.
4439+ const stamp = yield * makeEventStamp ( ) ;
4440+ yield * offerRuntimeEvent ( {
4441+ type : "task.completed" ,
4442+ eventId : stamp . eventId ,
4443+ provider : PROVIDER ,
4444+ createdAt : stamp . createdAt ,
4445+ threadId : context . session . threadId ,
4446+ ...( context . turnState
4447+ ? { turnId : asCanonicalTurnId ( context . turnState . turnId ) }
4448+ : { } ) ,
4449+ payload : {
4450+ taskId : RuntimeTaskId . make ( taskId ) ,
4451+ status : "stopped" ,
4452+ ...taskLinkageFor ( context . taskAgents , taskId ) ,
4453+ } ,
4454+ providerRefs : nativeProviderRefs ( context ) ,
4455+ } ) ;
4456+ } ) . pipe ( Effect . ignore ) ,
44274457 { concurrency : 8 , discard : true } ,
44284458 ) . pipe ( Effect . timeoutOption ( "10 seconds" ) , Effect . ignore ) ;
44294459 }
0 commit comments