@@ -2894,197 +2894,105 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
28942894 ) ;
28952895
28962896 // regression: watched #26248 merged and its agent kept saying it was still watching
2897- it . effect ( "wakes once when a watched pull request merges, naming the merge commit" , ( ) =>
2898- Effect . gen ( function * ( ) {
2899- const orchestrator = yield * Orchestrator . OrchestratorV2 ;
2900- const threadId = ThreadId . make ( "runtime-pull-request-watch-merged" ) ;
2901- const projectId = ProjectId . make ( "pr-watch-merged-project" ) ;
2902- yield * seedProject ( {
2903- projectId,
2904- title : "Watch merged" ,
2905- workspaceRoot : "/workspace/watch-merged" ,
2906- defaultModelSelection : null ,
2907- createdAt : "2026-10-01T00:00:00.000Z" ,
2908- } ) ;
2909- yield * orchestrator . dispatch ( {
2910- type : "thread.create" ,
2911- createdBy : "user" ,
2912- creationSource : "web" ,
2913- commandId : CommandId . make ( "pr-watch-merged-create" ) ,
2914- threadId,
2915- projectId,
2916- title : "Watch merged" ,
2917- modelSelection,
2918- runtimeMode : "full-access" ,
2919- interactionMode : "default" ,
2920- branch : null ,
2921- worktreePath : null ,
2922- } ) ;
2923- yield * orchestrator . dispatch ( {
2924- type : "thread.pull-request.watch" ,
2925- commandId : CommandId . make ( "pr-watch-merged-start" ) ,
2926- threadId,
2927- host : "github.com" ,
2928- repository : "pingdotgg/t3code" ,
2929- number : 15 ,
2930- watching : true ,
2931- link : { url : "https://github.com/pingdotgg/t3code/pull/15" , source : "agent" } ,
2932- } ) ;
2933- const reactor = yield * PullRequestWatchReactor . make . pipe (
2934- Effect . provide (
2935- Layer . mergeAll (
2936- NodeServices . layer ,
2937- Layer . mock ( PullRequestService . PullRequestService ) ( {
2938- detail : ( ) =>
2939- Effect . succeed ( {
2940- ...watchedPullRequestDetail ( {
2941- projectId,
2942- number : 15 ,
2943- at : "2026-10-02T12:00:00.000Z" ,
2944- } ) ,
2945- state : "merged" as const ,
2946- mergedAt : "2026-10-02T12:00:00.000Z" ,
2947- mergeCommitSha : "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9" ,
2948- mergedBy : { login : "juliusmarminge" , name : null , avatarUrl : null } ,
2949- } ) ,
2950- activity : ( ) =>
2951- Effect . succeed ( {
2952- comments : [ ] ,
2953- commentCount : 0 ,
2954- commentsTruncated : false ,
2955- reviewThreads : [ ] ,
2956- commits : [ ] ,
2957- } ) ,
2958- } ) ,
2959- ) ,
2960- ) ,
2961- ) ;
2962- yield * reactor . sweep ;
2963- yield * TestClock . adjust ( "10 minutes" ) ;
2964- yield * reactor . sweep ;
2965-
2966- assert . isUndefined ( ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ) ;
2967- const wakes = ( yield * orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ) . messages . filter (
2968- ( message ) => message . notification != null ,
2969- ) ;
2970- assert . deepEqual (
2971- wakes . map ( ( message ) => message . notification ?. summary ) ,
2972- [ "#15: merged, stopped watching" ] ,
2973- ) ;
2974- assert . include ( wakes [ 0 ] ! . text , "merged into main by juliusmarminge as 3b2f958" ) ;
2975- } ) ,
2976- ) ;
2977-
2978- it . effect ( "a pull request closed, reopened, and then merged wakes once for each end" , ( ) =>
2979- Effect . gen ( function * ( ) {
2980- const orchestrator = yield * Orchestrator . OrchestratorV2 ;
2981- const threadId = ThreadId . make ( "runtime-pull-request-watch-reopened" ) ;
2982- const projectId = ProjectId . make ( "pr-watch-reopened-project" ) ;
2983- yield * seedProject ( {
2984- projectId,
2985- title : "Watch reopened" ,
2986- workspaceRoot : "/workspace/watch-reopened" ,
2987- defaultModelSelection : null ,
2988- createdAt : "2026-10-01T00:00:00.000Z" ,
2989- } ) ;
2990- yield * orchestrator . dispatch ( {
2991- type : "thread.create" ,
2992- createdBy : "user" ,
2993- creationSource : "web" ,
2994- commandId : CommandId . make ( "pr-watch-reopened-create" ) ,
2995- threadId,
2996- projectId,
2997- title : "Watch reopened" ,
2998- modelSelection,
2999- runtimeMode : "full-access" ,
3000- interactionMode : "default" ,
3001- branch : null ,
3002- worktreePath : null ,
3003- } ) ;
3004- const key = { host : "github.com" , repository : "pingdotgg/t3code" , number : 16 } ;
3005- const watch = ( id : string ) =>
3006- orchestrator . dispatch ( {
2897+ it . effect . each ( [ "the watch's read" , "the link's sync" ] ) (
2898+ "wakes once when a watched pull request merges, naming the merge commit: seen by %s" ,
2899+ ( seenBy ) =>
2900+ Effect . gen ( function * ( ) {
2901+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
2902+ const threadId = ThreadId . make ( "runtime-pull-request-watch-merged" ) ;
2903+ const projectId = ProjectId . make ( "pr-watch-merged-project" ) ;
2904+ yield * seedProject ( {
2905+ projectId,
2906+ title : "Watch merged" ,
2907+ workspaceRoot : "/workspace/watch-merged" ,
2908+ defaultModelSelection : null ,
2909+ createdAt : "2026-10-01T00:00:00.000Z" ,
2910+ } ) ;
2911+ yield * orchestrator . dispatch ( {
2912+ type : "thread.create" ,
2913+ createdBy : "user" ,
2914+ creationSource : "web" ,
2915+ commandId : CommandId . make ( "pr-watch-merged-create" ) ,
2916+ threadId,
2917+ projectId,
2918+ title : "Watch merged" ,
2919+ modelSelection,
2920+ runtimeMode : "full-access" ,
2921+ interactionMode : "default" ,
2922+ branch : null ,
2923+ worktreePath : null ,
2924+ } ) ;
2925+ const key = { host : "github.com" , repository : "pingdotgg/t3code" , number : 15 } ;
2926+ yield * orchestrator . dispatch ( {
30072927 type : "thread.pull-request.watch" ,
3008- commandId : CommandId . make ( ` pr-watch-reopened- ${ id } ` ) ,
2928+ commandId : CommandId . make ( " pr-watch-merged-start" ) ,
30092929 threadId,
30102930 ...key ,
30112931 watching : true ,
3012- link : { url : "https://github.com/pingdotgg/t3code/pull/16 " , source : "agent" } ,
2932+ link : { url : "https://github.com/pingdotgg/t3code/pull/15 " , source : "agent" } ,
30132933 } ) ;
3014- yield * watch ( "start" ) ;
3015-
3016- let state : PullRequestDetail [ "state" ] = "closed" ;
3017- const host = Layer . mergeAll (
3018- NodeServices . layer ,
3019- Layer . mock ( PullRequestService . PullRequestService ) ( {
3020- detail : ( ) =>
3021- Effect . sync ( ( ) => ( {
3022- ...watchedPullRequestDetail ( {
3023- projectId,
3024- number : 16 ,
3025- at : "2026-10-02T12:00:00.000Z" ,
2934+ if ( seenBy === "the link's sync" ) {
2935+ yield * orchestrator . dispatch ( {
2936+ type : "thread.pull-request-link.sync" ,
2937+ commandId : CommandId . make ( "pr-watch-merged-synced" ) ,
2938+ threadId,
2939+ ...key ,
2940+ snapshot : {
2941+ state : "merged" ,
2942+ title : "Watched pull request" ,
2943+ headBranch : "feature" ,
2944+ baseBranch : "main" ,
2945+ isDraft : false ,
2946+ updatedAt : null ,
2947+ syncedAt : "2026-10-02T12:00:00.000Z" ,
2948+ mergedAt : "2026-10-02T12:00:00.000Z" ,
2949+ } ,
2950+ stack : null ,
2951+ } ) ;
2952+ }
2953+ const reactor = yield * PullRequestWatchReactor . make . pipe (
2954+ Effect . provide (
2955+ Layer . mergeAll (
2956+ NodeServices . layer ,
2957+ Layer . mock ( PullRequestService . PullRequestService ) ( {
2958+ detail : ( ) =>
2959+ Effect . succeed ( {
2960+ ...watchedPullRequestDetail ( {
2961+ projectId,
2962+ number : 15 ,
2963+ at : "2026-10-02T12:00:00.000Z" ,
2964+ } ) ,
2965+ state : "merged" as const ,
2966+ mergedAt : "2026-10-02T12:00:00.000Z" ,
2967+ mergeCommitSha : "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9" ,
2968+ mergedBy : { login : "juliusmarminge" , name : null , avatarUrl : null } ,
2969+ } ) ,
2970+ activity : ( ) =>
2971+ Effect . succeed ( {
2972+ comments : [ ] ,
2973+ commentCount : 0 ,
2974+ commentsTruncated : false ,
2975+ reviewThreads : [ ] ,
2976+ commits : [ ] ,
2977+ } ) ,
30262978 } ) ,
3027- state,
3028- checks : [ { name : "lint" , status : "pending" as const , description : null , url : null } ] ,
3029- } ) ) ,
3030- activity : ( ) =>
3031- Effect . succeed ( {
3032- comments : [ ] ,
3033- commentCount : 0 ,
3034- commentsTruncated : false ,
3035- reviewThreads : [ ] ,
3036- commits : [ ] ,
3037- } ) ,
3038- } ) ,
3039- ) ;
3040- const summaries = Effect . map (
3041- orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ,
3042- ( { messages } ) => messages . flatMap ( ( message ) => message . notification ?. summary ?? [ ] ) ,
3043- ) ;
3044- const watching = Effect . map (
3045- orchestrator . getThreadShell ( threadId ) ,
3046- ( thread ) => thread ?. pullRequests ?. [ 0 ] ?. watch !== undefined ,
3047- ) ;
3048- const reactor = yield * PullRequestWatchReactor . make . pipe ( Effect . provide ( host ) ) ;
3049- yield * reactor . sweep ;
3050- assert . deepEqual ( yield * summaries , [ "#16: closed, stopped watching" ] ) ;
3051- assert . isFalse ( yield * watching ) ;
3052-
3053- // Reopening does not restart the watch; the agent was told to watch again.
3054- state = "open" ;
3055- yield * watch ( "again" ) ;
3056- yield * TestClock . adjust ( "10 minutes" ) ;
3057- yield * reactor . sweep ;
3058- assert . isTrue ( yield * watching ) ;
3059- assert . deepEqual ( yield * summaries , [ "#16: closed, stopped watching" ] ) ;
2979+ ) ,
2980+ ) ,
2981+ ) ;
2982+ yield * reactor . sweep ;
2983+ yield * TestClock . adjust ( "10 minutes" ) ;
2984+ yield * reactor . sweep ;
30602985
3061- // The link's own sync can see the merge before the watch reads it.
3062- state = "merged" ;
3063- yield * orchestrator . dispatch ( {
3064- type : "thread.pull-request-link.sync" ,
3065- commandId : CommandId . make ( "pr-watch-reopened-synced" ) ,
3066- threadId,
3067- ...key ,
3068- snapshot : {
3069- state : "merged" ,
3070- title : "Watched pull request" ,
3071- headBranch : "feature" ,
3072- baseBranch : "main" ,
3073- isDraft : false ,
3074- updatedAt : null ,
3075- syncedAt : "2026-10-02T12:30:00.000Z" ,
3076- mergedAt : "2026-10-02T12:30:00.000Z" ,
3077- } ,
3078- stack : null ,
3079- } ) ;
3080- yield * TestClock . adjust ( "10 minutes" ) ;
3081- yield * reactor . sweep ;
3082- assert . deepEqual ( yield * summaries , [
3083- "#16: closed, stopped watching" ,
3084- "#16: merged, stopped watching" ,
3085- ] ) ;
3086- assert . isFalse ( yield * watching ) ;
3087- } ) ,
2986+ const thread = yield * orchestrator . getThreadShell ( threadId ) ;
2987+ assert . isUndefined ( thread ?. pullRequests ?. [ 0 ] ?. watch ) ;
2988+ const { messages } = yield * orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ;
2989+ const wakes = messages . filter ( ( message ) => message . notification != null ) ;
2990+ assert . deepEqual (
2991+ wakes . map ( ( message ) => message . notification ?. summary ) ,
2992+ [ "#15: merged, stopped watching" ] ,
2993+ ) ;
2994+ assert . include ( wakes [ 0 ] ! . text , "merged into main by juliusmarminge as 3b2f958" ) ;
2995+ } ) ,
30882996 ) ;
30892997
30902998 it . effect ( "wakes once for a state it reported, across a restart and a new watch" , ( ) =>
0 commit comments