From df321b8832a1e4358bf42ba384870de1995bd689 Mon Sep 17 00:00:00 2001 From: Richard R Date: Sat, 23 May 2026 05:55:22 -0600 Subject: [PATCH] fix(jobs): make TTS segment cache invalidation non-blocking in parsePdfJob Move TTS segment cache invalidation to a fire-and-forget promise after document update to prevent cache errors from blocking parse readiness. Log warnings for both cache invalidation failures and warnings, but do not interrupt the main job flow. This improves job robustness and avoids unnecessary failures due to cache issues. --- src/lib/server/jobs/parsePdfJob.ts | 31 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/lib/server/jobs/parsePdfJob.ts b/src/lib/server/jobs/parsePdfJob.ts index e753d4b..d8f4a24 100644 --- a/src/lib/server/jobs/parsePdfJob.ts +++ b/src/lib/server/jobs/parsePdfJob.ts @@ -71,18 +71,6 @@ export async function parsePdfJob(input: ParsePdfJobInput): Promise { parsedJsonKey = await putParsedDocumentBlob(input.documentId, parsedJson, input.namespace); } - const cleared = await clearTtsSegmentCache({ - userId: input.userId, - documentId: input.documentId, - readerType: 'pdf', - }); - if (cleared.warning) { - console.warn('[parsePdfJob] cache invalidation warning', { - documentId: input.documentId, - warning: cleared.warning, - }); - } - await db .update(documents) .set({ @@ -94,6 +82,25 @@ export async function parsePdfJob(input: ParsePdfJobInput): Promise { parsedJsonKey, }) .where(and(eq(documents.id, input.documentId), eq(documents.userId, input.userId))); + + // Best-effort cache invalidation should not block parse readiness. + void clearTtsSegmentCache({ + userId: input.userId, + documentId: input.documentId, + readerType: 'pdf', + }).then((cleared) => { + if (cleared.warning) { + console.warn('[parsePdfJob] cache invalidation warning', { + documentId: input.documentId, + warning: cleared.warning, + }); + } + }).catch((cacheError) => { + console.warn('[parsePdfJob] cache invalidation failed', { + documentId: input.documentId, + error: cacheError instanceof Error ? cacheError.message : String(cacheError), + }); + }); } catch (error) { const message = error instanceof Error ? error.message : String(error); const stack = error instanceof Error ? error.stack : undefined;