@@ -36,6 +36,7 @@ export class RunFinalizationObserver extends Context.Reference<{
3636 readonly cwd : string ;
3737 readonly threadId : ThreadId ;
3838 readonly runId : RunId ;
39+ readonly followBranch ?: ( branch : string ) => Effect . Effect < void > ;
3940 } ) => Effect . Effect < string | null , RunFinalizationRefreshError > ;
4041} > ( "t3/orchestration-v2/RunFinalizationObserver" , {
4142 defaultValue : ( ) => ( {
@@ -76,6 +77,7 @@ const make = Effect.gen(function* () {
7677 if (
7778 ! thread ||
7879 thread . branch === null ||
80+ isTemporaryWorktreeBranch ( thread . branch ) ||
7981 thread . branch === input . checkedOutBranch ||
8082 thread . worktreePath !== input . cwd
8183 ) {
@@ -95,8 +97,6 @@ const make = Effect.gen(function* () {
9597 expectedBranch : thread . branch ,
9698 expectedWorktreePath : input . cwd ,
9799 } ) ;
98- // The first refresh skipped the PR lookup because the thread still had the old branch.
99- yield * observer . refresh ( { cwd : input . cwd , threadId : thread . id , runId : input . runId } ) ;
100100 } ,
101101 ( effect , input ) =>
102102 effect . pipe (
@@ -129,8 +129,19 @@ const make = Effect.gen(function* () {
129129 const cwd = projection . checkpointScopes . find ( ( scope ) => scope . id === input . scopeId ) ?. cwd ;
130130 if ( cwd !== undefined ) {
131131 // Retrying a display refresh after the checkpoint is durable blocks the next turn.
132- const checkedOutBranch = yield * observer
133- . refresh ( { cwd, threadId : input . threadId , runId : input . runId } )
132+ yield * observer
133+ . refresh ( {
134+ cwd,
135+ threadId : input . threadId ,
136+ runId : input . runId ,
137+ followBranch : ( checkedOutBranch ) =>
138+ followWorktreeBranch ( {
139+ threadId : input . threadId ,
140+ runId : input . runId ,
141+ cwd,
142+ checkedOutBranch,
143+ } ) ,
144+ } )
134145 . pipe (
135146 Effect . catchTags ( {
136147 RunFinalizationRefreshError : ( cause ) =>
@@ -140,14 +151,6 @@ const make = Effect.gen(function* () {
140151 } ) . pipe ( Effect . as ( null ) ) ,
141152 } ) ,
142153 ) ;
143- if ( checkedOutBranch !== null ) {
144- yield * followWorktreeBranch ( {
145- threadId : input . threadId ,
146- runId : input . runId ,
147- cwd,
148- checkedOutBranch,
149- } ) ;
150- }
151154 }
152155 } ) ;
153156 return RunFinalizationService . of ( { finalize } ) ;
@@ -166,12 +169,13 @@ export const layerObserver = Layer.effect(
166169 return {
167170 refreshAfterTurn : pullRequests . refreshAfterTurn ,
168171 refresh : Effect . fn ( "RunFinalizationService.refresh" ) (
169- function * ( { cwd, threadId, runId } ) {
172+ function * ( { cwd, threadId, runId, followBranch } ) {
170173 const [ , local ] = yield * Effect . all (
171174 [ workspaceEntries . refresh ( cwd ) , vcsStatus . refreshLocalStatus ( cwd ) ] ,
172175 { concurrency : "unbounded" } ,
173176 ) ;
174177 if ( local . refName === null ) return null ;
178+ if ( followBranch ) yield * followBranch ( local . refName ) ;
175179 if ( local . isDefaultRef ) return local . refName ;
176180 const thread = yield * projections . getThreadShell ( threadId ) ;
177181 if ( ! thread || thread . branch !== local . refName ) return local . refName ;
0 commit comments