Skip to content

Commit ee5d348

Browse files
committed
fix: generation timeout
1 parent 278acb4 commit ee5d348

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/server/service/chat/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ const executeImageGeneration = async (params: GenerationParams, ctx: RequestCont
397397
referImages = await lastMessageImage();
398398
}
399399

400+
const now = new Date();
400401
const result = await providerInstance.generate(
401402
{
402403
providerId,
@@ -414,12 +415,12 @@ const executeImageGeneration = async (params: GenerationParams, ctx: RequestCont
414415
.set({
415416
status: "failed",
416417
errorReason: result.errorReason,
418+
updatedAt: now.toISOString(),
417419
})
418420
.where(eq(messageGenerations.id, generationId));
419421
return;
420422
}
421423

422-
const now = new Date();
423424
// Save generated files to database
424425
const fileIds = await saveFiles(result.images, userId);
425426
// Update generation with result URLs
@@ -439,6 +440,7 @@ const executeImageGeneration = async (params: GenerationParams, ctx: RequestCont
439440
.set({
440441
status: "failed",
441442
errorReason: error instanceof ConfigInvalidError ? "CONFIG_INVALID" : "UNKNOWN",
443+
updatedAt: new Date().toISOString(),
442444
})
443445
.where(eq(messageGenerations.id, generationId));
444446
return;
@@ -574,9 +576,9 @@ const getGenerationStatus = async (req: GetGenerationStatus, ctx: RequestContext
574576

575577
// Check if generation is still pending/generating but has exceeded 5 minutes
576578
if (generation.status === "pending" || generation.status === "generating") {
577-
const createdAt = new Date(generation.createdAt);
579+
const lastGenTime = new Date(generation.updatedAt);
578580
const now = new Date();
579-
const elapsedMinutes = (now.getTime() - createdAt.getTime()) / 1000 / 60;
581+
const elapsedMinutes = (now.getTime() - lastGenTime.getTime()) / 1000 / 60;
580582

581583
if (elapsedMinutes > 5) {
582584
// Mark as failed due to timeout

0 commit comments

Comments
 (0)