@@ -4094,110 +4094,133 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
40944094 } ) ,
40954095 ) ;
40964096
4097- // A busy thread queues its wakes, and a queued wake is dropped whole once outdated, so
4098- // there each pull request keeps its own wake.
40994097 it . effect . each ( [
41004098 [ "an idle" , false ] ,
41014099 [ "a busy" , true ] ,
4102- ] as const ) ( "wakes %s thread once per pass, or per pull request while it is busy" , ( [ , busy ] ) =>
4103- Effect . gen ( function * ( ) {
4104- const orchestrator = yield * Orchestrator . OrchestratorV2 ;
4105- const threadId = ThreadId . make ( `runtime-pull-request-watch-pass-${ busy } ` ) ;
4106- const projectId = ProjectId . make ( `pr-watch-pass-project-${ busy } ` ) ;
4107- yield * seedProject ( {
4108- projectId,
4109- title : "Watch pass" ,
4110- workspaceRoot : "/workspace/watch-pass" ,
4111- defaultModelSelection : null ,
4112- createdAt : "2026-10-01T00:00:00.000Z" ,
4113- } ) ;
4114- yield * orchestrator . dispatch ( {
4115- type : "thread.create" ,
4116- createdBy : "user" ,
4117- creationSource : "web" ,
4118- commandId : CommandId . make ( `pr-watch-pass-create-${ busy } ` ) ,
4119- threadId,
4120- projectId,
4121- title : "Watch pass" ,
4122- modelSelection,
4123- runtimeMode : "full-access" ,
4124- interactionMode : "default" ,
4125- branch : null ,
4126- worktreePath : null ,
4127- } ) ;
4128- const numbers = [ 12 , 13 , 14 ] ;
4129- for ( const number of numbers ) {
4130- yield * orchestrator . dispatch ( {
4131- type : "thread.pull-request.watch" ,
4132- commandId : CommandId . make ( `pr-watch-pass-start-${ busy } -${ number } ` ) ,
4133- threadId,
4134- host : "github.com" ,
4135- repository : "pingdotgg/t3code" ,
4136- number,
4137- watching : true ,
4138- link : { url : `https://github.com/pingdotgg/t3code/pull/${ number } ` , source : "agent" } ,
4100+ ] as const ) (
4101+ "wakes %s thread once for a pass that changed several of its pull requests" ,
4102+ ( [ , busy ] ) =>
4103+ Effect . gen ( function * ( ) {
4104+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
4105+ const threadId = ThreadId . make ( `runtime-pull-request-watch-pass-${ busy } ` ) ;
4106+ const projectId = ProjectId . make ( `pr-watch-pass-project-${ busy } ` ) ;
4107+ yield * seedProject ( {
4108+ projectId,
4109+ title : "Watch pass" ,
4110+ workspaceRoot : "/workspace/watch-pass" ,
4111+ defaultModelSelection : null ,
4112+ createdAt : "2026-10-01T00:00:00.000Z" ,
41394113 } ) ;
4140- }
4141- if ( busy ) {
41424114 yield * orchestrator . dispatch ( {
4143- type : "message.dispatch " ,
4115+ type : "thread.create " ,
41444116 createdBy : "user" ,
41454117 creationSource : "web" ,
4146- commandId : CommandId . make ( " pr-watch-pass-busy" ) ,
4118+ commandId : CommandId . make ( ` pr-watch-pass-create- ${ busy } ` ) ,
41474119 threadId,
4148- messageId : MessageId . make ( "pr-watch-pass-busy" ) ,
4149- text : "Keep this run active." ,
4150- attachments : [ ] ,
4120+ projectId,
4121+ title : "Watch pass" ,
41514122 modelSelection,
4152- dispatchMode : { type : "start_immediately" } ,
4123+ runtimeMode : "full-access" ,
4124+ interactionMode : "default" ,
4125+ branch : null ,
4126+ worktreePath : null ,
41534127 } ) ;
4154- }
4155- const host = Layer . mergeAll (
4156- NodeServices . layer ,
4157- NodeCrypto . layer ,
4158- Layer . mock ( PullRequestService . PullRequestService ) ( {
4159- detail : ( input ) =>
4160- Effect . succeed ( {
4161- ...watchedPullRequestDetail ( {
4162- projectId,
4163- number : input . number ,
4164- at : "2026-10-02T12:00:00.000Z" ,
4128+ const numbers = [ 12 , 13 , 14 ] ;
4129+ for ( const number of numbers ) {
4130+ yield * orchestrator . dispatch ( {
4131+ type : "thread.pull-request.watch" ,
4132+ commandId : CommandId . make ( `pr-watch-pass-start-${ busy } -${ number } ` ) ,
4133+ threadId,
4134+ host : "github.com" ,
4135+ repository : "pingdotgg/t3code" ,
4136+ number,
4137+ watching : true ,
4138+ link : { url : `https://github.com/pingdotgg/t3code/pull/${ number } ` , source : "agent" } ,
4139+ } ) ;
4140+ }
4141+ if ( busy ) {
4142+ yield * orchestrator . dispatch ( {
4143+ type : "message.dispatch" ,
4144+ createdBy : "user" ,
4145+ creationSource : "web" ,
4146+ commandId : CommandId . make ( "pr-watch-pass-busy" ) ,
4147+ threadId,
4148+ messageId : MessageId . make ( "pr-watch-pass-busy" ) ,
4149+ text : "Keep this run active." ,
4150+ attachments : [ ] ,
4151+ modelSelection,
4152+ dispatchMode : { type : "start_immediately" } ,
4153+ } ) ;
4154+ }
4155+ const host = Layer . mergeAll (
4156+ NodeServices . layer ,
4157+ NodeCrypto . layer ,
4158+ Layer . mock ( PullRequestService . PullRequestService ) ( {
4159+ detail : ( input ) =>
4160+ Effect . succeed ( {
4161+ ...watchedPullRequestDetail ( {
4162+ projectId,
4163+ number : input . number ,
4164+ at : "2026-10-02T12:00:00.000Z" ,
4165+ } ) ,
4166+ headSha : `head${ input . number } ` ,
4167+ checks : [
4168+ { name : "test" , status : "failure" , description : null , url : null , required : true } ,
4169+ ] ,
41654170 } ) ,
4166- headSha : `head${ input . number } ` ,
4167- checks : [
4168- { name : "test" , status : "failure" , description : null , url : null , required : true } ,
4169- ] ,
4170- } ) ,
4171- activity : ( ) =>
4172- Effect . succeed ( {
4173- comments : [ ] ,
4174- commentCount : 0 ,
4175- commentsTruncated : false ,
4176- reviewThreads : [ ] ,
4177- commits : [ ] ,
4178- } ) ,
4179- } ) ,
4180- ) ;
4171+ activity : ( ) =>
4172+ Effect . succeed ( {
4173+ comments : [ ] ,
4174+ commentCount : 0 ,
4175+ commentsTruncated : false ,
4176+ reviewThreads : [ ] ,
4177+ commits : [ ] ,
4178+ } ) ,
4179+ } ) ,
4180+ ) ;
41814181
4182- const reactor = yield * PullRequestWatchReactor . make . pipe ( Effect . provide ( host ) ) ;
4183- yield * reactor . sweep ;
4184- const { messages } = yield * orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ;
4185- const wakes = messages . filter ( ( message ) => message . notification !== undefined ) ;
4186- const stamps = wakes . map ( ( { notification } ) =>
4187- notification ?. source . kind === "monitor"
4188- ? [ notification . source . pullRequest , ...( notification . source . otherPullRequests ?? [ ] ) ]
4189- . map ( ( stamp ) => stamp ?. number )
4190- . toSorted ( )
4191- : [ ] ,
4192- ) ;
4193- assert . deepEqual (
4194- stamps . toSorted ( ( left , right ) => left [ 0 ] ! - right [ 0 ] ! ) ,
4195- busy ? numbers . map ( ( number ) => [ number ] ) : [ numbers ] ,
4196- ) ;
4197- for ( const number of numbers ) {
4198- assert . isTrue ( wakes . some ( ( wake ) => wake . text . includes ( `#${ number } ` ) ) ) ;
4199- }
4200- } ) ,
4182+ const reactor = yield * PullRequestWatchReactor . make . pipe ( Effect . provide ( host ) ) ;
4183+ yield * reactor . sweep ;
4184+ const { messages } = yield * orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ;
4185+ const wakes = messages . filter ( ( message ) => message . notification !== undefined ) ;
4186+ const stamps = wakes . map ( ( { notification } ) =>
4187+ notification ?. source . kind === "monitor"
4188+ ? [ notification . source . pullRequest , ...( notification . source . otherPullRequests ?? [ ] ) ]
4189+ . map ( ( stamp ) => stamp ?. number )
4190+ . toSorted ( )
4191+ : [ ] ,
4192+ ) ;
4193+ assert . deepEqual ( stamps , [ numbers ] ) ;
4194+ for ( const number of numbers ) assert . include ( wakes [ 0 ] ! . text , `#${ number } ` ) ;
4195+ if ( ! busy ) return ;
4196+
4197+ // A pull request unwatched while the wake waited leaves it; the others still start.
4198+ yield * orchestrator . dispatch ( {
4199+ type : "thread.pull-request.watch" ,
4200+ commandId : CommandId . make ( "pr-watch-pass-stop-12" ) ,
4201+ threadId,
4202+ host : "github.com" ,
4203+ repository : "pingdotgg/t3code" ,
4204+ number : 12 ,
4205+ watching : false ,
4206+ } ) ;
4207+ const active = ( yield * orchestrator . getThreadProjection ( threadId ) ) . runs [ 0 ] ! ;
4208+ yield * orchestrator . dispatch ( {
4209+ type : "run.interrupt" ,
4210+ commandId : CommandId . make ( "pr-watch-pass-interrupt" ) ,
4211+ threadId,
4212+ runId : active . id ,
4213+ } ) ;
4214+ yield * orchestrator . resumeQueuedRuns ;
4215+ const after = yield * orchestrator . getThreadProjection ( threadId ) ;
4216+ const woken = after . messages . find ( ( message ) => message . id === wakes [ 0 ] ! . id ) ! ;
4217+ assert . notInclude ( woken . text , "#12" ) ;
4218+ for ( const number of [ 13 , 14 ] ) assert . include ( woken . text , `#${ number } ` ) ;
4219+ assert . notEqual (
4220+ after . runs . find ( ( run ) => run . userMessageId === woken . id ) ?. status ,
4221+ "cancelled" ,
4222+ ) ;
4223+ } ) ,
42014224 ) ;
42024225
42034226 it . effect . each ( [ "pending" , "action-required" ] as const ) ( "recovers %s watches" , ( initialStatus ) =>
0 commit comments