From a47bcb03abd4289f731adadfcccd35346becfc20 Mon Sep 17 00:00:00 2001 From: Agent Date: Sat, 10 Oct 2026 21:34:03 +0000 Subject: [PATCH] Clear race timers so waits never outlive the operation --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9a21a26..35a21f0 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,10 @@ export function apply(ctx, config = {}) { // At the end of a turn: deliver late advice; a blocker forces one more step. disposers.push(agent.ctx.on('agent/turn-stopping', async ({ signal }) => { - if (st.pending) await Promise.race([st.pending, new Promise((r) => setTimeout(r, cfg.blocking ? cfg.timeoutMs : 4000))]) + if (st.pending) { + let t + await Promise.race([st.pending, new Promise((r) => { t = setTimeout(r, cfg.blocking ? cfg.timeoutMs : 4000) })]).finally(() => clearTimeout(t)) + } const notes = st.queue.splice(0) const block = notes.find((n) => n.verdict === 'blocker') if (block && !signal?.aborted) {