@@ -570,7 +570,10 @@ export async function executeSync(
570570 inArray ( document . processingStatus , [ 'pending' , 'failed' ] ) ,
571571 and (
572572 eq ( document . processingStatus , 'processing' ) ,
573- lt ( document . processingStartedAt , staleProcessingCutoff )
573+ or (
574+ isNull ( document . processingStartedAt ) ,
575+ lt ( document . processingStartedAt , staleProcessingCutoff )
576+ )
574577 )
575578 ) ,
576579 lt ( document . uploadedAt , syncStartedAt ) ,
@@ -605,8 +608,6 @@ export async function executeSync(
605608 }
606609 }
607610
608- await completeSyncLog ( syncLogId , 'completed' , result )
609-
610611 // Enqueue all added/updated documents for processing in a single batch
611612 if ( pendingProcessing . length > 0 ) {
612613 try {
@@ -617,14 +618,16 @@ export async function executeSync(
617618 crypto . randomUUID ( )
618619 )
619620 } catch ( error ) {
620- logger . warn ( 'Failed to enqueue documents for processing' , {
621+ logger . warn ( 'Failed to enqueue documents for processing — will retry on next sync ' , {
621622 connectorId,
622623 count : pendingProcessing . length ,
623624 error : error instanceof Error ? error . message : String ( error ) ,
624625 } )
625626 }
626627 }
627628
629+ await completeSyncLog ( syncLogId , 'completed' , result )
630+
628631 const [ { count : actualDocCount } ] = await db
629632 . select ( { count : sql < number > `count(*)::int` } )
630633 . from ( document )
0 commit comments