@@ -5761,6 +5761,81 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
57615761 } ) ,
57625762 ) ;
57635763
5764+ it . effect ( "keeps a pull request watch its agent started after asking to settle" , ( ) =>
5765+ Effect . gen ( function * ( ) {
5766+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
5767+ const eventSink = yield * EventSink . EventSinkV2 ;
5768+ const threadManagement = yield * ThreadManagementService . ThreadManagementService ;
5769+ const projectId = ProjectId . make ( "runtime-layer-settle-then-watch-project" ) ;
5770+ const threadId = ThreadId . make ( "runtime-layer-settle-then-watch-thread" ) ;
5771+
5772+ yield * orchestrator . dispatch ( {
5773+ type : "thread.create" ,
5774+ createdBy : "user" ,
5775+ creationSource : "web" ,
5776+ commandId : CommandId . make ( "runtime-layer-settle-then-watch-create" ) ,
5777+ threadId,
5778+ projectId,
5779+ title : "Settle then watch" ,
5780+ modelSelection,
5781+ runtimeMode : "full-access" ,
5782+ interactionMode : "default" ,
5783+ branch : null ,
5784+ worktreePath : "/tmp/runtime-layer-settle-then-watch" ,
5785+ } ) ;
5786+ yield * orchestrator . dispatch ( {
5787+ type : "message.dispatch" ,
5788+ createdBy : "user" ,
5789+ creationSource : "web" ,
5790+ commandId : CommandId . make ( "runtime-layer-settle-then-watch-message" ) ,
5791+ threadId,
5792+ messageId : MessageId . make ( "runtime-layer-settle-then-watch-message" ) ,
5793+ text : "Settle this thread, then watch the pull request." ,
5794+ attachments : [ ] ,
5795+ modelSelection,
5796+ dispatchMode : { type : "start_immediately" } ,
5797+ } ) ;
5798+ const run = ( yield * orchestrator . getThreadProjection ( threadId ) ) . runs [ 0 ] ;
5799+ if ( run === undefined ) return yield * Effect . die ( new Error ( "Run missing." ) ) ;
5800+
5801+ // The deferred settle `settleThread` forks for its own agent's active run.
5802+ const settleRequest = yield * threadManagement
5803+ . settleAfterRun ( { projectId, threadId, runId : run . id } )
5804+ . pipe ( Effect . forkChild ) ;
5805+ yield * orchestrator . dispatch ( {
5806+ type : "thread.pull-request.watch" ,
5807+ commandId : CommandId . make ( "runtime-layer-settle-then-watch-watch" ) ,
5808+ threadId,
5809+ host : "github.com" ,
5810+ repository : "pingdotgg/t3code" ,
5811+ number : 7 ,
5812+ watching : true ,
5813+ link : { url : "https://github.com/pingdotgg/t3code/pull/7" , source : "agent" } ,
5814+ } ) ;
5815+ assert . isDefined ( ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ) ;
5816+
5817+ const now = yield * DateTime . now ;
5818+ yield * eventSink . write ( {
5819+ commandId : CommandId . make ( "runtime-layer-settle-then-watch-completed" ) ,
5820+ events : [
5821+ {
5822+ id : EventId . make ( "runtime-layer-settle-then-watch-completed" ) ,
5823+ type : "run.updated" ,
5824+ threadId,
5825+ runId : run . id ,
5826+ occurredAt : now ,
5827+ payload : { ...run , status : "completed" , startedAt : now , completedAt : now } ,
5828+ } ,
5829+ ] ,
5830+ } ) ;
5831+ yield * Fiber . join ( settleRequest ) ;
5832+
5833+ const shell = yield * orchestrator . getThreadShell ( threadId ) ;
5834+ assert . isDefined ( shell ?. pullRequests ?. [ 0 ] ?. watch ) ;
5835+ assert . isNull ( shell ?. settledOverride ?? null ) ;
5836+ } ) ,
5837+ ) ;
5838+
57645839 it . effect ( "settles past held automatic runs but not held user messages" , ( ) =>
57655840 Effect . gen ( function * ( ) {
57665841 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
0 commit comments