@@ -401,8 +401,6 @@ export async function executeSync(
401401
402402 const seenExternalIds = new Set < string > ( )
403403
404- const pendingProcessing : DocumentData [ ] = [ ]
405-
406404 const pendingOps : DocOp [ ] = [ ]
407405 for ( const extDoc of externalDocs ) {
408406 seenExternalIds . add ( extDoc . externalId )
@@ -508,10 +506,11 @@ export async function executeSync(
508506 } )
509507 )
510508
509+ const batchDocs : DocumentData [ ] = [ ]
511510 for ( let j = 0 ; j < settled . length ; j ++ ) {
512511 const outcome = settled [ j ]
513512 if ( outcome . status === 'fulfilled' ) {
514- pendingProcessing . push ( outcome . value )
513+ batchDocs . push ( outcome . value )
515514 if ( batch [ j ] . type === 'add' ) result . docsAdded ++
516515 else result . docsUpdated ++
517516 } else {
@@ -524,6 +523,23 @@ export async function executeSync(
524523 } )
525524 }
526525 }
526+
527+ if ( batchDocs . length > 0 ) {
528+ try {
529+ await processDocumentsWithQueue (
530+ batchDocs ,
531+ connector . knowledgeBaseId ,
532+ { } ,
533+ crypto . randomUUID ( )
534+ )
535+ } catch ( error ) {
536+ logger . warn ( 'Failed to enqueue batch for processing — will retry on next sync' , {
537+ connectorId,
538+ count : batchDocs . length ,
539+ error : error instanceof Error ? error . message : String ( error ) ,
540+ } )
541+ }
542+ }
527543 }
528544
529545 // Skip deletion reconciliation during incremental syncs — results only contain changed docs
@@ -608,24 +624,6 @@ export async function executeSync(
608624 }
609625 }
610626
611- // Enqueue all added/updated documents for processing in a single batch
612- if ( pendingProcessing . length > 0 ) {
613- try {
614- await processDocumentsWithQueue (
615- pendingProcessing ,
616- connector . knowledgeBaseId ,
617- { } ,
618- crypto . randomUUID ( )
619- )
620- } catch ( error ) {
621- logger . warn ( 'Failed to enqueue documents for processing — will retry on next sync' , {
622- connectorId,
623- count : pendingProcessing . length ,
624- error : error instanceof Error ? error . message : String ( error ) ,
625- } )
626- }
627- }
628-
629627 await completeSyncLog ( syncLogId , 'completed' , result )
630628
631629 const [ { count : actualDocCount } ] = await db
0 commit comments