fix(knowledge): move completeSyncLog after doc enqueue, handle NULL processingStartedAt in stuck doc query

This commit is contained in:
Waleed Latif
2026-03-24 20:55:09 -07:00
parent 85d9fcb216
commit b22c2869f6

View File

@@ -570,7 +570,10 @@ export async function executeSync(
inArray(document.processingStatus, ['pending', 'failed']),
and(
eq(document.processingStatus, 'processing'),
lt(document.processingStartedAt, staleProcessingCutoff)
or(
isNull(document.processingStartedAt),
lt(document.processingStartedAt, staleProcessingCutoff)
)
)
),
lt(document.uploadedAt, syncStartedAt),
@@ -605,8 +608,6 @@ export async function executeSync(
}
}
await completeSyncLog(syncLogId, 'completed', result)
// Enqueue all added/updated documents for processing in a single batch
if (pendingProcessing.length > 0) {
try {
@@ -617,7 +618,7 @@ export async function executeSync(
crypto.randomUUID()
)
} catch (error) {
logger.warn('Failed to enqueue documents for processing', {
logger.warn('Failed to enqueue documents for processing — will retry on next sync', {
connectorId,
count: pendingProcessing.length,
error: error instanceof Error ? error.message : String(error),
@@ -625,6 +626,8 @@ export async function executeSync(
}
}
await completeSyncLog(syncLogId, 'completed', result)
const [{ count: actualDocCount }] = await db
.select({ count: sql<number>`count(*)::int` })
.from(document)