@@ -3416,6 +3416,202 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
34163416 } ) ,
34173417 ) ;
34183418
3419+ // regression: watched #26248 merged and its agent kept saying it was still watching
3420+ it . effect ( "wakes once when a watched pull request merges, naming the merge commit" , ( ) =>
3421+ Effect . gen ( function * ( ) {
3422+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
3423+ const threadId = ThreadId . make ( "runtime-pull-request-watch-merged" ) ;
3424+ const projectId = ProjectId . make ( "pr-watch-merged-project" ) ;
3425+ yield * seedProject ( {
3426+ projectId,
3427+ title : "Watch merged" ,
3428+ workspaceRoot : "/workspace/watch-merged" ,
3429+ defaultModelSelection : null ,
3430+ createdAt : "2026-10-01T00:00:00.000Z" ,
3431+ } ) ;
3432+ yield * orchestrator . dispatch ( {
3433+ type : "thread.create" ,
3434+ createdBy : "user" ,
3435+ creationSource : "web" ,
3436+ commandId : CommandId . make ( "pr-watch-merged-create" ) ,
3437+ threadId,
3438+ projectId,
3439+ title : "Watch merged" ,
3440+ modelSelection,
3441+ runtimeMode : "full-access" ,
3442+ interactionMode : "default" ,
3443+ branch : null ,
3444+ worktreePath : null ,
3445+ } ) ;
3446+ yield * orchestrator . dispatch ( {
3447+ type : "thread.pull-request.watch" ,
3448+ commandId : CommandId . make ( "pr-watch-merged-start" ) ,
3449+ threadId,
3450+ host : "github.com" ,
3451+ repository : "pingdotgg/t3code" ,
3452+ number : 15 ,
3453+ watching : true ,
3454+ link : { url : "https://github.com/pingdotgg/t3code/pull/15" , source : "agent" } ,
3455+ } ) ;
3456+ const reactor = yield * PullRequestWatchReactor . make . pipe (
3457+ Effect . provide (
3458+ Layer . mergeAll (
3459+ NodeServices . layer ,
3460+ NodeCrypto . layer ,
3461+ Layer . mock ( PullRequestService . PullRequestService ) ( {
3462+ detail : ( ) =>
3463+ Effect . succeed ( {
3464+ ...watchedPullRequestDetail ( {
3465+ projectId,
3466+ number : 15 ,
3467+ at : "2026-10-02T12:00:00.000Z" ,
3468+ } ) ,
3469+ state : "merged" as const ,
3470+ mergedAt : "2026-10-02T12:00:00.000Z" ,
3471+ mergeCommitSha : "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9" ,
3472+ mergedBy : { login : "juliusmarminge" , name : null , avatarUrl : null } ,
3473+ } ) ,
3474+ activity : ( ) =>
3475+ Effect . succeed ( {
3476+ comments : [ ] ,
3477+ commentCount : 0 ,
3478+ commentsTruncated : false ,
3479+ reviewThreads : [ ] ,
3480+ commits : [ ] ,
3481+ } ) ,
3482+ } ) ,
3483+ ) ,
3484+ ) ,
3485+ ) ;
3486+ yield * reactor . sweep ;
3487+ yield * TestClock . adjust ( "10 minutes" ) ;
3488+ yield * reactor . sweep ;
3489+
3490+ assert . isUndefined ( ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ) ;
3491+ const wakes = ( yield * orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ) . messages . filter (
3492+ ( message ) => message . notification != null ,
3493+ ) ;
3494+ assert . deepEqual (
3495+ wakes . map ( ( message ) => message . notification ?. summary ) ,
3496+ [ "#15: merged, stopped watching" ] ,
3497+ ) ;
3498+ assert . include ( wakes [ 0 ] ! . text , "merged into main by juliusmarminge as 3b2f958" ) ;
3499+ } ) ,
3500+ ) ;
3501+
3502+ it . effect ( "a pull request closed, reopened, and then merged wakes once for each end" , ( ) =>
3503+ Effect . gen ( function * ( ) {
3504+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
3505+ const threadId = ThreadId . make ( "runtime-pull-request-watch-reopened" ) ;
3506+ const projectId = ProjectId . make ( "pr-watch-reopened-project" ) ;
3507+ yield * seedProject ( {
3508+ projectId,
3509+ title : "Watch reopened" ,
3510+ workspaceRoot : "/workspace/watch-reopened" ,
3511+ defaultModelSelection : null ,
3512+ createdAt : "2026-10-01T00:00:00.000Z" ,
3513+ } ) ;
3514+ yield * orchestrator . dispatch ( {
3515+ type : "thread.create" ,
3516+ createdBy : "user" ,
3517+ creationSource : "web" ,
3518+ commandId : CommandId . make ( "pr-watch-reopened-create" ) ,
3519+ threadId,
3520+ projectId,
3521+ title : "Watch reopened" ,
3522+ modelSelection,
3523+ runtimeMode : "full-access" ,
3524+ interactionMode : "default" ,
3525+ branch : null ,
3526+ worktreePath : null ,
3527+ } ) ;
3528+ const key = { host : "github.com" , repository : "pingdotgg/t3code" , number : 16 } ;
3529+ const watch = ( id : string ) =>
3530+ orchestrator . dispatch ( {
3531+ type : "thread.pull-request.watch" ,
3532+ commandId : CommandId . make ( `pr-watch-reopened-${ id } ` ) ,
3533+ threadId,
3534+ ...key ,
3535+ watching : true ,
3536+ link : { url : "https://github.com/pingdotgg/t3code/pull/16" , source : "agent" } ,
3537+ } ) ;
3538+ yield * watch ( "start" ) ;
3539+
3540+ let state : PullRequestDetail [ "state" ] = "closed" ;
3541+ const host = Layer . mergeAll (
3542+ NodeServices . layer ,
3543+ NodeCrypto . layer ,
3544+ Layer . mock ( PullRequestService . PullRequestService ) ( {
3545+ detail : ( ) =>
3546+ Effect . sync ( ( ) => ( {
3547+ ...watchedPullRequestDetail ( {
3548+ projectId,
3549+ number : 16 ,
3550+ at : "2026-10-02T12:00:00.000Z" ,
3551+ } ) ,
3552+ state,
3553+ checks : [ { name : "lint" , status : "pending" as const , description : null , url : null } ] ,
3554+ } ) ) ,
3555+ activity : ( ) =>
3556+ Effect . succeed ( {
3557+ comments : [ ] ,
3558+ commentCount : 0 ,
3559+ commentsTruncated : false ,
3560+ reviewThreads : [ ] ,
3561+ commits : [ ] ,
3562+ } ) ,
3563+ } ) ,
3564+ ) ;
3565+ const summaries = Effect . map (
3566+ orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ,
3567+ ( { messages } ) => messages . flatMap ( ( message ) => message . notification ?. summary ?? [ ] ) ,
3568+ ) ;
3569+ const watching = Effect . map (
3570+ orchestrator . getThreadShell ( threadId ) ,
3571+ ( thread ) => thread ?. pullRequests ?. [ 0 ] ?. watch !== undefined ,
3572+ ) ;
3573+ const reactor = yield * PullRequestWatchReactor . make . pipe ( Effect . provide ( host ) ) ;
3574+ yield * reactor . sweep ;
3575+ assert . deepEqual ( yield * summaries , [ "#16: closed, stopped watching" ] ) ;
3576+ assert . isFalse ( yield * watching ) ;
3577+
3578+ // Reopening does not restart the watch; the agent was told to watch again.
3579+ state = "open" ;
3580+ yield * watch ( "again" ) ;
3581+ yield * TestClock . adjust ( "10 minutes" ) ;
3582+ yield * reactor . sweep ;
3583+ assert . isTrue ( yield * watching ) ;
3584+ assert . deepEqual ( yield * summaries , [ "#16: closed, stopped watching" ] ) ;
3585+
3586+ // The link's own sync can see the merge before the watch reads it.
3587+ state = "merged" ;
3588+ yield * orchestrator . dispatch ( {
3589+ type : "thread.pull-request-link.sync" ,
3590+ commandId : CommandId . make ( "pr-watch-reopened-synced" ) ,
3591+ threadId,
3592+ ...key ,
3593+ snapshot : {
3594+ state : "merged" ,
3595+ title : "Watched pull request" ,
3596+ headBranch : "feature" ,
3597+ baseBranch : "main" ,
3598+ isDraft : false ,
3599+ updatedAt : null ,
3600+ syncedAt : "2026-10-02T12:30:00.000Z" ,
3601+ mergedAt : "2026-10-02T12:30:00.000Z" ,
3602+ } ,
3603+ stack : null ,
3604+ } ) ;
3605+ yield * TestClock . adjust ( "10 minutes" ) ;
3606+ yield * reactor . sweep ;
3607+ assert . deepEqual ( yield * summaries , [
3608+ "#16: closed, stopped watching" ,
3609+ "#16: merged, stopped watching" ,
3610+ ] ) ;
3611+ assert . isFalse ( yield * watching ) ;
3612+ } ) ,
3613+ ) ;
3614+
34193615 it . effect ( "wakes once for a state it reported, across a restart and a new watch" , ( ) =>
34203616 Effect . gen ( function * ( ) {
34213617 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
0 commit comments