Skip to content

Commit 3df4d3a

Browse files
committed
fix(web): finish recording jobs after transcription failures
1 parent ea509a5 commit 3df4d3a

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎apps/web/__tests__/unit/finalize-desktop-recording.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,30 @@ describe("durable post-publication transcription enqueue", () => {
317317
expect(mocks.claim).not.toHaveBeenCalled();
318318
});
319319

320+
it("finishes after repeated transcription queue failures", async () => {
321+
withCurrent({ state: "verified" });
322+
mocks.transcribe.mockResolvedValue({
323+
success: false,
324+
message: "Queue unavailable",
325+
});
326+
mocks.sleep.mockImplementation(async () => {
327+
if (mocks.transcribe.mock.calls.length >= 12) {
328+
throw new Error("Transcription retry limit exceeded");
329+
}
330+
});
331+
332+
await expect(
333+
finalizeDesktopRecordingWorkflow({
334+
videoId,
335+
userId,
336+
generation: fixture.generation,
337+
}),
338+
).resolves.toEqual({ success: true });
339+
expect(mocks.transcribe).toHaveBeenCalledTimes(12);
340+
expect(mocks.fetch).not.toHaveBeenCalled();
341+
expect(mocks.claim).not.toHaveBeenCalled();
342+
});
343+
320344
it.each(["unconfigured", "deleted"])(
321345
"skips %s transcription without retrying forever",
322346
async (reason) => {

‎apps/web/workflows/finalize-desktop-recording.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const PRESIGNED_EXPIRES_SECONDS = 6 * 60 * 60;
8585
const MULTIPART_OUTPUT_PART_SIZE_BYTES = 64 * 1024 * 1024;
8686
const SOURCE_COMMIT_BATCH_MAX_CHECKPOINTS = 32;
8787
const SOURCE_COMMIT_BATCH_DURATION_MS = 15_000;
88+
const TRANSCRIPTION_QUEUE_MAX_ATTEMPTS = 12;
8889

8990
function getErrorMessage(error: unknown) {
9091
return error instanceof Error ? error.message : String(error);
@@ -190,7 +191,7 @@ export async function finalizeDesktopRecordingWorkflow(
190191
if (retained !== "retry") return { success: false, reason: retained };
191192
}
192193
}
193-
for (let attempt = 0; ; attempt++) {
194+
for (let attempt = 0; attempt < TRANSCRIPTION_QUEUE_MAX_ATTEMPTS; attempt++) {
194195
let queued: boolean;
195196
try {
196197
queued = await queueFinalizedRecordingTranscription(
@@ -201,7 +202,9 @@ export async function finalizeDesktopRecordingWorkflow(
201202
queued = false;
202203
}
203204
if (queued) break;
204-
await sleep(Math.min(15_000 * 2 ** Math.min(attempt, 5), 300_000));
205+
if (attempt + 1 < TRANSCRIPTION_QUEUE_MAX_ATTEMPTS) {
206+
await sleep(Math.min(15_000 * 2 ** Math.min(attempt, 5), 300_000));
207+
}
205208
}
206209
return mediaServerUnavailable
207210
? { success: false, reason: "media-server-unconfigured" }
@@ -780,7 +783,7 @@ async function queueFinalizedRecordingTranscription(
780783
);
781784
if (result.success) return true;
782785
console.warn(
783-
"[finalizeDesktopRecordingWorkflow] Transcription enqueue will retry",
786+
"[finalizeDesktopRecordingWorkflow] Transcription enqueue failed",
784787
{ videoId, message: result.message },
785788
);
786789
} catch (error) {

0 commit comments

Comments
 (0)