@@ -656,16 +656,20 @@ async function runWorkerEncodePipelineLoop(
656656 await drainPrev ( ) ;
657657}
658658
659+ const STALL_RESUMES_BEFORE_FALLBACK = 3 ;
660+
659661/** A sequential stall resumes at the first unwritten frame when frames landed since the last resume. */
660662function resumesAfterStall (
661663 error : unknown ,
662664 abortSignal : AbortSignal | undefined ,
663665 resume : { from : number ; written : number } ,
666+ resumes : number ,
664667) : boolean {
665668 return (
666669 error instanceof SequentialCaptureStallError &&
667670 abortSignal ?. aborted !== true &&
668- resume . written > resume . from
671+ resume . written > resume . from &&
672+ resumes < STALL_RESUMES_BEFORE_FALLBACK
669673 ) ;
670674}
671675
@@ -786,6 +790,7 @@ export async function runCaptureStreamingStage(
786790 let parallelGuardRan = false ;
787791 let writtenFrames = 0 ;
788792 let resumeFrom = 0 ;
793+ let resumes = 0 ;
789794 let workerResults : Awaited < ReturnType < typeof executeParallelCapture > > ;
790795 for ( ; ; ) {
791796 const parallelReorder = createFrameReorderBuffer ( resumeFrom , totalFrames ) ;
@@ -932,13 +937,19 @@ export async function runCaptureStreamingStage(
932937 } catch ( err ) {
933938 // A wedged worker loses nothing already written: fresh workers continue from the first
934939 // unwritten frame. A stall before any new frame landed falls through.
935- if ( stalled && abortSignal ?. aborted !== true && writtenFrames > resumeFrom ) {
940+ if (
941+ stalled &&
942+ abortSignal ?. aborted !== true &&
943+ writtenFrames > resumeFrom &&
944+ resumes < STALL_RESUMES_BEFORE_FALLBACK
945+ ) {
936946 log . warn ( "[Render] Parallel capture stalled; resuming from the first unwritten frame" , {
937947 resumeFrom : writtenFrames ,
938948 totalFrames,
939949 workerPhases : phaseSummary ( ) ,
940950 } ) ;
941951 resumeFrom = writtenFrames ;
952+ resumes ++ ;
942953 continue ;
943954 }
944955 // Surface the TYPED drain error (DrawElementVerificationError) so the
@@ -983,6 +994,7 @@ export async function runCaptureStreamingStage(
983994 // Sequential capture → streaming encode
984995
985996 const resume = { from : 0 , written : 0 } ;
997+ let resumes = 0 ;
986998 for ( ; ; ) {
987999 const videoInjector = createRenderVideoFrameInjector ( ) ;
9881000 const session =
@@ -1117,14 +1129,15 @@ export async function runCaptureStreamingStage(
11171129 // fallow-ignore-next-line code-duplication
11181130 } catch ( error ) {
11191131 lastBrowserConsole = session . browserConsoleBuffer ;
1120- if ( ! resumesAfterStall ( error , abortSignal , resume ) ) {
1132+ if ( ! resumesAfterStall ( error , abortSignal , resume , resumes ) ) {
11211133 throw wrapCaptureStageError ( error , lastBrowserConsole ) ;
11221134 }
11231135 log . warn ( "[Render] Sequential capture stalled; resuming from the first unwritten frame" , {
11241136 resumeFrom : resume . written ,
11251137 totalFrames,
11261138 } ) ;
11271139 resume . from = resume . written ;
1140+ resumes ++ ;
11281141 resumed = true ;
11291142 } finally {
11301143 // Keep the latest console buffer for success and cleanup-error summaries.
0 commit comments