@@ -20,6 +20,7 @@ import * as Effect from "effect/Effect";
2020import * as Exit from "effect/Exit" ;
2121import * as Fiber from "effect/Fiber" ;
2222import * as Layer from "effect/Layer" ;
23+ import * as Option from "effect/Option" ;
2324import * as PubSub from "effect/PubSub" ;
2425import * as Queue from "effect/Queue" ;
2526import * as Ref from "effect/Ref" ;
@@ -67,6 +68,10 @@ export interface ProjectCloneHooks {
6768}
6869
6970const DONE_RETENTION = "30 seconds" ;
71+ // Git prints nothing while a transfer waits on the network, and the kernel can
72+ // take 15+ minutes to give up on a dead connection. Without this the banner
73+ // keeps showing the last transfer speed as if data were still arriving.
74+ const STALL_AFTER = "20 seconds" ;
7075
7176function clampText ( text : string , maxLength : number ) : string {
7277 return text . length <= maxLength ? text : `${ text . slice ( 0 , maxLength - 1 ) } …` ;
@@ -165,9 +170,28 @@ export const make = Effect.gen(function* () {
165170 percent : update . percent ,
166171 detail :
167172 update . detail === null ? null : clampText ( update . detail , PROJECT_CLONE_DETAIL_MAX_LENGTH ) ,
173+ stalled : false ,
168174 } ,
169175 } ) ) . pipe ( Effect . asVoid ) ;
170176
177+ const markStalled = ( projectId : ProjectId ) =>
178+ modify ( projectId , ( tracked ) => ( {
179+ ...tracked ,
180+ snapshot : { ...tracked . snapshot , stalled : true } ,
181+ } ) ) . pipe ( Effect . asVoid ) ;
182+
183+ /** Marks the clone stalled once, then waits for git to speak again. */
184+ const watchForStall = ( projectId : ProjectId , pulses : Queue . Dequeue < void > ) =>
185+ Queue . take ( pulses ) . pipe (
186+ Effect . timeoutOption ( STALL_AFTER ) ,
187+ Effect . flatMap ( ( pulse ) =>
188+ Option . isSome ( pulse )
189+ ? Effect . void
190+ : markStalled ( projectId ) . pipe ( Effect . andThen ( Queue . take ( pulses ) ) ) ,
191+ ) ,
192+ Effect . forever ,
193+ ) ;
194+
171195 const finish = Effect . fn ( "ProjectCloneTracker.finish" ) ( function * (
172196 projectId : ProjectId ,
173197 phase : "done" | "failed" | "cancelled" ,
@@ -182,12 +206,29 @@ export const make = Effect.gen(function* () {
182206 phase,
183207 endedAt,
184208 percent : phase === "done" ? 100 : tracked . snapshot . percent ,
209+ stalled : false ,
185210 error : error === null ? null : clampText ( error , PROJECT_CLONE_ERROR_MAX_LENGTH ) ,
186211 } ,
187212 } ) ) ;
188213 if ( phase === "done" ) yield * scheduleRemoval ( projectId ) ;
189214 } ) ;
190215
216+ const cloneWatchingForStall = Effect . fn ( "ProjectCloneTracker.cloneWatchingForStall" ) ( function * (
217+ projectId : ProjectId ,
218+ tracked : TrackedClone ,
219+ ) {
220+ const pulses = yield * Queue . sliding < void > ( 1 ) ;
221+ yield * watchForStall ( projectId , pulses ) . pipe ( Effect . forkScoped ) ;
222+ return yield * repositories . cloneRepository (
223+ { remoteUrl : tracked . input . cloneUrl , destinationPath : tracked . input . destinationPath } ,
224+ {
225+ onProgress : ( update ) =>
226+ Queue . offer ( pulses , undefined ) . pipe ( Effect . andThen ( progress ( projectId , update ) ) ) ,
227+ timeoutMs : null ,
228+ } ,
229+ ) ;
230+ } , Effect . scoped ) ;
231+
191232 /**
192233 * Runs in its own fiber; the tracker records the outcome through `onExit`,
193234 * which still runs when the fiber is interrupted (a `matchCause` handler
@@ -196,26 +237,21 @@ export const make = Effect.gen(function* () {
196237 * checkout.
197238 */
198239 const runClone = ( projectId : ProjectId , tracked : TrackedClone ) =>
199- repositories
200- . cloneRepository (
201- { remoteUrl : tracked . input . cloneUrl , destinationPath : tracked . input . destinationPath } ,
202- { onProgress : ( update ) => progress ( projectId , update ) , timeoutMs : null } ,
203- )
204- . pipe (
205- Effect . onExit ( ( exit ) =>
206- Exit . isSuccess ( exit )
207- ? finish ( projectId , "done" , null )
208- : Cause . hasInterruptsOnly ( exit . cause )
209- ? finish ( projectId , "cancelled" , null )
210- : finish ( projectId , "failed" , describeCloneFailure ( exit . cause ) ) ,
211- ) ,
212- Effect . flatMap ( ( ) =>
213- tracked . hooks
214- . onCloned ( { projectId, workspaceRoot : tracked . input . destinationPath } )
215- . pipe ( Effect . ignoreCause ( { log : true } ) ) ,
216- ) ,
217- Effect . ignoreCause ( ) ,
218- ) ;
240+ cloneWatchingForStall ( projectId , tracked ) . pipe (
241+ Effect . onExit ( ( exit ) =>
242+ Exit . isSuccess ( exit )
243+ ? finish ( projectId , "done" , null )
244+ : Cause . hasInterruptsOnly ( exit . cause )
245+ ? finish ( projectId , "cancelled" , null )
246+ : finish ( projectId , "failed" , describeCloneFailure ( exit . cause ) ) ,
247+ ) ,
248+ Effect . flatMap ( ( ) =>
249+ tracked . hooks
250+ . onCloned ( { projectId, workspaceRoot : tracked . input . destinationPath } )
251+ . pipe ( Effect . ignoreCause ( { log : true } ) ) ,
252+ ) ,
253+ Effect . ignoreCause ( ) ,
254+ ) ;
219255
220256 const launch = Effect . fn ( "ProjectCloneTracker.launch" ) ( function * ( projectId : ProjectId ) {
221257 const current = yield * Ref . get ( clones ) ;
@@ -244,6 +280,7 @@ export const make = Effect.gen(function* () {
244280 stage : "connecting" ,
245281 percent : null ,
246282 detail : null ,
283+ stalled : false ,
247284 error : null ,
248285 startedAt,
249286 endedAt : null ,
@@ -346,6 +383,7 @@ export const make = Effect.gen(function* () {
346383 stage : "connecting" ,
347384 percent : null ,
348385 detail : null ,
386+ stalled : false ,
349387 error : null ,
350388 startedAt,
351389 endedAt : null ,
0 commit comments