Fix generation progress getting stuck at 1% after Comfy finishes.

Poll Comfy history and the job snapshot so the browser still gets the video when the live stream is buffered or the websocket misses completion.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-08-25 18:23:23 -05:00
co-authored by Cursor
parent ca51fddea3
commit c4e6af9f77
8 changed files with 326 additions and 182 deletions
+8
View File
@@ -0,0 +1,8 @@
export default defineEventHandler((event) => {
const id = getRouterParam(event, 'id')
const job = id ? getJob(id) : undefined
if (!job) {
throw createError({ statusCode: 404, statusMessage: 'Job not found' })
}
return jobSnapshot(job)
})
+12 -11
View File
@@ -5,22 +5,18 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 404, statusMessage: 'Job not found' })
}
setResponseHeaders(event, {
'Cache-Control': 'no-cache, no-store, no-transform',
'X-Accel-Buffering': 'no',
Connection: 'keep-alive'
})
const stream = createEventStream(event)
const send = async (payload: unknown) => {
await stream.push(JSON.stringify(payload))
}
await send({
type: 'hello',
status: job.status,
message: job.message,
progress: job.progress,
step: job.step,
maxStep: job.maxStep,
promptId: job.promptId,
elapsedMs: Date.now() - job.startedAt
})
await send(jobSnapshot(job))
for (const past of job.events) {
await send(past)
}
@@ -33,7 +29,12 @@ export default defineEventHandler(async (event) => {
})
})
const ping = setInterval(() => {
void send(jobSnapshot(job))
}, 1000)
stream.onClosed(() => {
clearInterval(ping)
unsubscribe()
})