review: catch follow-up poll errors + re-check done before push
Two fixes on top of the follow-up pre-task-script work: 1. The void async IIFE inside the interval handler had no catch, so a throw from the dynamic import or applyPreTaskScripts escaped as an unhandled rejection — terminating the container. The initial-batch path is wrapped by processQuery's outer try/catch; the follow-up path needs its own. Now logs the error and lets the next tick retry. 2. Re-check `done` immediately before query.push. The flag can flip true while applyPreTaskScripts is awaited (outer stream finishes during the script execution); without the re-check we'd push into a closed query. Claimed messages get released by the host's processing-claim sweep — same recovery posture as the rest of the poller. Co-Authored-By: Michael Zazon <mzazon@gmail.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -302,12 +302,23 @@ async function processQuery(
|
|||||||
// MODULE-HOOK:scheduling-pre-task-followup:end
|
// MODULE-HOOK:scheduling-pre-task-followup:end
|
||||||
|
|
||||||
if (keep.length === 0) return;
|
if (keep.length === 0) return;
|
||||||
|
// Re-check done — the outer query may have finished while the script
|
||||||
|
// was awaited. Pushing into a closed stream is wasted work; the
|
||||||
|
// claimed messages get released by the host's processing-claim sweep.
|
||||||
|
if (done) return;
|
||||||
|
|
||||||
const keptIds = keep.map((m) => m.id);
|
const keptIds = keep.map((m) => m.id);
|
||||||
const prompt = formatMessages(keep);
|
const prompt = formatMessages(keep);
|
||||||
log(`Pushing ${keep.length} follow-up message(s) into active query`);
|
log(`Pushing ${keep.length} follow-up message(s) into active query`);
|
||||||
query.push(prompt);
|
query.push(prompt);
|
||||||
markCompleted(keptIds);
|
markCompleted(keptIds);
|
||||||
|
} catch (err) {
|
||||||
|
// Without this catch the rejection escapes the void IIFE and Node
|
||||||
|
// terminates the container on unhandled-rejection. The initial-batch
|
||||||
|
// path is wrapped by processQuery's outer try/catch; the follow-up
|
||||||
|
// path is not, so it needs its own.
|
||||||
|
const errMsg = err instanceof Error ? err.message : String(err);
|
||||||
|
log(`Follow-up poll error: ${errMsg}`);
|
||||||
} finally {
|
} finally {
|
||||||
pollInFlight = false;
|
pollInFlight = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user