fix: skip queueLength===0 completion branch when session returns 404

This commit is contained in:
Ousama Ben Younes
2026-04-11 08:16:35 +00:00
parent 2f19eab9c2
commit edc8535ac1
+4 -3
View File
@@ -94,9 +94,11 @@ export const summarizeHandler: EventHandler = {
const statusResponse = await workerHttpRequest(`/api/sessions/status?contentSessionId=${encodeURIComponent(sessionId)}`, {
timeoutMs: 5000
});
if (statusResponse.ok) {
const status = await statusResponse.json() as { queueLength?: number; summaryStored?: boolean | null };
if ((status.queueLength ?? 0) === 0) {
const queueLength = status.queueLength ?? 0;
// Only treat an empty queue as completion when the session exists (non-404).
// A 404 means the session was not found — not that processing finished.
if (queueLength === 0 && statusResponse.status !== 404) {
summaryStored = status.summaryStored ?? null;
logger.info('HOOK', 'Summary processing complete', {
waitedMs: Date.now() - waitStart,
@@ -112,7 +114,6 @@ export const summarizeHandler: EventHandler = {
}
break;
}
}
} catch {
// Worker may be busy — keep polling
}