@@ -2622,6 +2622,127 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
26222622 } ) ,
26232623 ) ;
26242624
2625+ it . effect ( "finishes owed checks once after pending sweeps, a restart, and a re-watch" , ( ) =>
2626+ Effect . gen ( function * ( ) {
2627+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
2628+ const worker = yield * EffectWorker . OrchestrationEffectWorkerV2 ;
2629+ const threadId = ThreadId . make ( "runtime-pull-request-watch-owed" ) ;
2630+ const projectId = ProjectId . make ( "pr-watch-owed-project" ) ;
2631+ yield * seedProject ( {
2632+ projectId,
2633+ title : "Watch owed" ,
2634+ workspaceRoot : "/workspace/watch-owed" ,
2635+ defaultModelSelection : null ,
2636+ createdAt : "2026-10-01T00:00:00.000Z" ,
2637+ } ) ;
2638+ yield * orchestrator . dispatch ( {
2639+ type : "thread.create" ,
2640+ createdBy : "user" ,
2641+ creationSource : "web" ,
2642+ commandId : CommandId . make ( "pr-watch-owed-create" ) ,
2643+ threadId,
2644+ projectId,
2645+ title : "Watch owed" ,
2646+ modelSelection,
2647+ runtimeMode : "full-access" ,
2648+ interactionMode : "default" ,
2649+ branch : null ,
2650+ worktreePath : null ,
2651+ } ) ;
2652+ const watch = ( on : boolean , id : string ) =>
2653+ orchestrator . dispatch ( {
2654+ type : "thread.pull-request.watch" ,
2655+ commandId : CommandId . make ( `pr-watch-owed-${ id } ` ) ,
2656+ threadId,
2657+ host : "github.com" ,
2658+ repository : "pingdotgg/t3code" ,
2659+ number : 12 ,
2660+ watching : on ,
2661+ link : { url : "https://github.com/pingdotgg/t3code/pull/12" , source : "agent" } ,
2662+ } ) ;
2663+ yield * watch ( true , "start" ) ;
2664+
2665+ let remainingStatus : "pending" | "success" = "pending" ;
2666+ const host = Layer . mergeAll (
2667+ NodeServices . layer ,
2668+ Layer . mock ( PullRequestService . PullRequestService ) ( {
2669+ detail : ( ) =>
2670+ Effect . sync ( ( ) => ( {
2671+ ...watchedPullRequestDetail ( {
2672+ projectId,
2673+ number : 12 ,
2674+ at : "2026-10-02T12:00:00.000Z" ,
2675+ } ) ,
2676+ headSha : "ad70160aaa" ,
2677+ checks : [ "lint" , "test" ] . map ( ( name ) => ( {
2678+ name,
2679+ status : name === "test" ? remainingStatus : ( "success" as const ) ,
2680+ description : null ,
2681+ url : null ,
2682+ required : name === "lint" ,
2683+ } ) ) ,
2684+ } ) ) ,
2685+ activity : ( ) =>
2686+ Effect . succeed ( {
2687+ comments : [ ] ,
2688+ commentCount : 0 ,
2689+ commentsTruncated : false ,
2690+ reviewThreads : [ ] ,
2691+ commits : [ ] ,
2692+ } ) ,
2693+ } ) ,
2694+ ) ;
2695+ const summaries = Effect . map (
2696+ orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ,
2697+ ( { messages } ) => messages . flatMap ( ( message ) => message . notification ?. summary ?? [ ] ) ,
2698+ ) ;
2699+
2700+ const reactor = yield * PullRequestWatchReactor . make . pipe ( Effect . provide ( host ) ) ;
2701+ yield * reactor . sweep ;
2702+ yield * worker . drain ( ) ;
2703+ yield * TestClock . adjust ( "10 minutes" ) ;
2704+ yield * reactor . sweep ;
2705+ yield * worker . drain ( ) ;
2706+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" ] ) ;
2707+
2708+ assert . deepEqual (
2709+ ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ?. owedChecks ,
2710+ [ "test" ] ,
2711+ ) ;
2712+ // The fresh reactor reloads the nonempty obligation from the persisted watch.
2713+ const restarted = yield * PullRequestWatchReactor . make . pipe ( Effect . provide ( host ) ) ;
2714+ yield * restarted . sweep ;
2715+ yield * worker . drain ( ) ;
2716+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" ] ) ;
2717+
2718+ // A new watch on the same pull request knows what the last one told.
2719+ yield * watch ( false , "stop" ) ;
2720+ yield * watch ( true , "again" ) ;
2721+ yield * restarted . sweep ;
2722+ yield * worker . drain ( ) ;
2723+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" ] ) ;
2724+
2725+ assert . deepEqual (
2726+ ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ?. owedChecks ,
2727+ [ "test" ] ,
2728+ ) ;
2729+ remainingStatus = "success" ;
2730+ yield * TestClock . adjust ( "10 minutes" ) ;
2731+ yield * restarted . sweep ;
2732+ yield * worker . drain ( ) ;
2733+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" , "#12: checks passed" ] ) ;
2734+ yield * TestClock . adjust ( "10 minutes" ) ;
2735+ yield * restarted . sweep ;
2736+ yield * worker . drain ( ) ;
2737+ assert . deepEqual ( yield * summaries , [ "#12: checks passed" , "#12: checks passed" ] ) ;
2738+ assert . deepEqual (
2739+ ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ?. owedChecks ,
2740+ [ ] ,
2741+ ) ;
2742+ yield * watch ( false , "end" ) ;
2743+ } ) ,
2744+ ) ;
2745+
26252746 // regression: #21155 watching a pull request again repeated news the thread already got
26262747 it . effect ( "a watch that ends on the comment limit keeps what its last pass saw" , ( ) =>
26272748 Effect . gen ( function * ( ) {
0 commit comments