@@ -2330,7 +2330,10 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
23302330 commandId : CommandId . make ( `pr-watch-settle-${ mode } ` ) ,
23312331 threadId,
23322332 } ) ;
2333- const expected = before . pullRequests ?. map ( ( { watch : _watch , ...link } ) => link ) ;
2333+ const expected = before . pullRequests ?. map ( ( { watch, ...link } ) => ( {
2334+ ...link ,
2335+ endedWatch : watch ,
2336+ } ) ) ;
23342337 assert . deepEqual ( ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests , expected ) ;
23352338 assert . isTrue ( ( yield * maintenance . rebuild ) . valid ) ;
23362339 assert . deepEqual ( ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests , expected ) ;
@@ -2649,6 +2652,105 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
26492652 } ) ,
26502653 ) ;
26512654
2655+ it . effect ( "wakes once for a state it reported, across a restart and a new watch" , ( ) =>
2656+ Effect . gen ( function * ( ) {
2657+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
2658+ const threadId = ThreadId . make ( "runtime-pull-request-watch-told" ) ;
2659+ const projectId = ProjectId . make ( "pr-watch-told-project" ) ;
2660+ yield * seedProject ( {
2661+ projectId,
2662+ title : "Watch told" ,
2663+ workspaceRoot : "/workspace/watch-told" ,
2664+ defaultModelSelection : null ,
2665+ createdAt : "2026-10-01T00:00:00.000Z" ,
2666+ } ) ;
2667+ yield * orchestrator . dispatch ( {
2668+ type : "thread.create" ,
2669+ createdBy : "user" ,
2670+ creationSource : "web" ,
2671+ commandId : CommandId . make ( "pr-watch-told-create" ) ,
2672+ threadId,
2673+ projectId,
2674+ title : "Watch told" ,
2675+ modelSelection,
2676+ runtimeMode : "full-access" ,
2677+ interactionMode : "default" ,
2678+ branch : null ,
2679+ worktreePath : null ,
2680+ } ) ;
2681+ const watch = ( on : boolean , id : string ) =>
2682+ orchestrator . dispatch ( {
2683+ type : "thread.pull-request.watch" ,
2684+ commandId : CommandId . make ( `pr-watch-told-${ id } ` ) ,
2685+ threadId,
2686+ host : "github.com" ,
2687+ repository : "pingdotgg/t3code" ,
2688+ number : 12 ,
2689+ watching : on ,
2690+ link : { url : "https://github.com/pingdotgg/t3code/pull/12" , source : "agent" } ,
2691+ } ) ;
2692+ yield * watch ( true , "start" ) ;
2693+
2694+ let headSha = "ad70160aaa" ;
2695+ const host = Layer . mergeAll (
2696+ NodeServices . layer ,
2697+ Layer . mock ( PullRequestService . PullRequestService ) ( {
2698+ detail : ( ) =>
2699+ Effect . sync ( ( ) => ( {
2700+ ...watchedPullRequestDetail ( {
2701+ projectId,
2702+ number : 12 ,
2703+ at : "2026-10-02T12:00:00.000Z" ,
2704+ } ) ,
2705+ headSha,
2706+ checks : [ "lint" , "test" ] . map ( ( name ) => ( {
2707+ name,
2708+ status : "success" as const ,
2709+ description : null ,
2710+ url : null ,
2711+ required : true ,
2712+ } ) ) ,
2713+ } ) ) ,
2714+ activity : ( ) =>
2715+ Effect . succeed ( {
2716+ comments : [ ] ,
2717+ commentCount : 0 ,
2718+ commentsTruncated : false ,
2719+ reviewThreads : [ ] ,
2720+ commits : [ ] ,
2721+ } ) ,
2722+ } ) ,
2723+ ) ;
2724+ const summaries = Effect . map (
2725+ orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ,
2726+ ( { messages } ) => messages . flatMap ( ( message ) => message . notification ?. summary ?? [ ] ) ,
2727+ ) ;
2728+
2729+ const reactor = yield * PullRequestWatchReactor . make . pipe ( Effect . provide ( host ) ) ;
2730+ yield * reactor . sweep ;
2731+ yield * TestClock . adjust ( "10 minutes" ) ;
2732+ yield * reactor . sweep ;
2733+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" ] ) ;
2734+
2735+ // A restart keeps nothing in memory; the watch state is all it has.
2736+ const restarted = yield * PullRequestWatchReactor . make . pipe ( Effect . provide ( host ) ) ;
2737+ yield * restarted . sweep ;
2738+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" ] ) ;
2739+
2740+ // A new watch on the same pull request knows what the last one told.
2741+ yield * watch ( false , "stop" ) ;
2742+ yield * watch ( true , "again" ) ;
2743+ yield * restarted . sweep ;
2744+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" ] ) ;
2745+
2746+ headSha = "bbbbbbbbbb" ;
2747+ yield * TestClock . adjust ( "10 minutes" ) ;
2748+ yield * restarted . sweep ;
2749+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" , "#12: checks passed" ] ) ;
2750+ yield * watch ( false , "end" ) ;
2751+ } ) ,
2752+ ) ;
2753+
26522754 it . effect ( "reports how long an ended watch was quiet" , ( ) =>
26532755 Effect . gen ( function * ( ) {
26542756 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
0 commit comments