Recover finished Comfy videos after relay restarts.

Persist queued jobs to disk, import leftover MP4s from Comfy history, and do not mark a run complete until the saved video exists.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-08-25 18:43:15 -05:00
co-authored by Cursor
parent f0f80b5873
commit b7196ecde3
10 changed files with 342 additions and 77 deletions
+18
View File
@@ -125,6 +125,24 @@ async function runGeneration(
const queued = await queuePrompt(graph, job.clientId)
job.promptId = queued.prompt_id
job.status = 'running'
if (job.library && job.promptId) {
writePendingJob({
jobId: job.id,
promptId: job.promptId,
clientId: job.clientId,
ownerKey: job.library.ownerKey,
folderId: job.library.folderId,
hideThumbnail: job.library.hideThumbnail,
prompt: job.library.prompt,
aspect: job.library.aspect,
width: job.library.width,
height: job.library.height,
steps: job.library.steps,
turbo: job.library.turbo,
seed: job.library.seed,
startedAt: job.startedAt
})
}
emitJob(job, { type: 'status', message: 'Job queued on ComfyUI', progress: 8 })
await done
}
+20 -5
View File
@@ -1,8 +1,23 @@
export default defineEventHandler((event) => {
export default defineEventHandler(async (event) => {
const id = getRouterParam(event, 'id')
const job = id ? getJob(id) : undefined
if (!job) {
throw createError({ statusCode: 404, statusMessage: 'Job not found' })
const live = id ? getJob(id) : undefined
if (live) return jobSnapshot(live)
if (id) {
const pending = readPendingJob(id)
if (pending) {
const done = await completePendingIfReady(pending).catch(() => null)
if (done) return done
return {
type: 'snapshot',
status: 'running',
message: 'Reconnecting to ComfyUI...',
progress: 90,
promptId: pending.promptId,
elapsedMs: Date.now() - pending.startedAt
}
}
}
return jobSnapshot(job)
throw createError({ statusCode: 404, statusMessage: 'Job not found' })
})
+40
View File
@@ -0,0 +1,40 @@
export default defineEventHandler(async (event) => {
const body = await readBody<{ jobId?: string }>(event).catch(() => ({} as { jobId?: string }))
const jobId = String(body?.jobId || '')
const live = jobId ? getJob(jobId) : undefined
if (live) return jobSnapshot(live)
if (jobId) {
const pending = readPendingJob(jobId)
if (pending) {
const done = await completePendingIfReady(pending)
if (done) return done
return {
type: 'snapshot',
status: 'running',
message: 'Reconnecting to ComfyUI...',
progress: 90,
promptId: pending.promptId,
elapsedMs: Date.now() - pending.startedAt
}
}
}
const { owner } = assertLibraryOwner(event)
const library = publicLibrary(event)
const folderId = library.folders.find(folder => folder.unlocked)?.id
const imported = folderId ? await importMissingComfyVideos(owner, folderId) : []
const newest = imported[imported.length - 1]
if (!newest) {
throw createError({ statusCode: 404, statusMessage: 'No finished ComfyUI video to recover' })
}
return {
type: 'complete',
status: 'complete',
message: 'Recovered video from ComfyUI',
progress: 100,
clipId: newest.id,
filename: newest.comfyFilename,
hideThumbnail: newest.hideThumbnail
}
})
+9 -1
View File
@@ -1,3 +1,11 @@
export default defineEventHandler((event) => {
export default defineEventHandler(async (event) => {
const library = publicLibrary(event)
try {
const { owner } = assertLibraryOwner(event)
const folderId = library.folders.find(folder => folder.unlocked)?.id
if (folderId) await importMissingComfyVideos(owner, folderId)
} catch {
return library
}
return publicLibrary(event)
})