@@ -633,6 +633,82 @@ describe("V2 environment commands", () => {
633633 } ) . pipe ( Effect . provide ( layerTestCrypto ) ) ,
634634 ) ;
635635
636+ it . effect ( "stops completed run background work when a newer queued run is held" , ( ) =>
637+ Effect . gen ( function * ( ) {
638+ const completedRun = {
639+ id : RunId . make ( "run-completed" ) ,
640+ threadId : v2ThreadId ,
641+ ordinal : 1 ,
642+ providerInstanceId : v2Projection . thread . providerInstanceId ,
643+ modelSelection : v2Projection . thread . modelSelection ,
644+ providerThreadId : null ,
645+ userMessageId : MessageId . make ( "message-completed" ) ,
646+ rootNodeId : null ,
647+ activeAttemptId : null ,
648+ status : "completed" as const ,
649+ requestedAt : v2Now ,
650+ startedAt : v2Now ,
651+ completedAt : v2Now ,
652+ checkpointId : null ,
653+ contextHandoffId : null ,
654+ } ;
655+ const projection : OrchestrationV2ThreadProjection = {
656+ ...v2Projection ,
657+ runs : [
658+ completedRun ,
659+ {
660+ ...completedRun ,
661+ id : RunId . make ( "run-held" ) ,
662+ ordinal : 2 ,
663+ userMessageId : MessageId . make ( "message-held" ) ,
664+ status : "queued" ,
665+ queuePosition : 1 ,
666+ queueHeld : true ,
667+ startedAt : null ,
668+ completedAt : null ,
669+ } ,
670+ ] ,
671+ turnItems : [
672+ {
673+ id : TurnItemId . make ( "background-command" ) ,
674+ threadId : v2ThreadId ,
675+ runId : completedRun . id ,
676+ nodeId : null ,
677+ providerThreadId : null ,
678+ providerTurnId : null ,
679+ nativeItemRef : null ,
680+ parentItemId : null ,
681+ ordinal : 1 ,
682+ status : "running" ,
683+ title : null ,
684+ startedAt : v2Now ,
685+ completedAt : null ,
686+ updatedAt : v2Now ,
687+ type : "command_execution" ,
688+ input : "vp run dev" ,
689+ } ,
690+ ] ,
691+ } ;
692+ const commands : OrchestrationV2Command [ ] = [ ] ;
693+ const supervisor = yield * makeSupervisor ( { commands, projects : [ ] , projection } ) ;
694+
695+ const result = yield * interruptThreadTurn ( { threadId : v2ThreadId } ) . pipe (
696+ Effect . provideService ( EnvironmentSupervisor . EnvironmentSupervisor , supervisor ) ,
697+ ) ;
698+
699+ expect ( commands ) . toEqual ( [
700+ {
701+ type : "run.interrupt" ,
702+ commandId : expect . any ( String ) ,
703+ threadId : v2ThreadId ,
704+ runId : completedRun . id ,
705+ holdQueue : true ,
706+ } ,
707+ ] ) ;
708+ expect ( result ) . toEqual ( { sequence : 1 } ) ;
709+ } ) . pipe ( Effect . provide ( layerTestCrypto ) ) ,
710+ ) ;
711+
636712 it . effect (
637713 "dispatches V2-native relationship and queue commands without compatibility shaping" ,
638714 ( ) =>
0 commit comments