diff --git a/lib/app/prompt.js b/lib/app/prompt.js index ef16989..75a9049 100644 --- a/lib/app/prompt.js +++ b/lib/app/prompt.js @@ -15,7 +15,7 @@ export const CLOSING = 'Apply them where they fit.'; // A Recipe still pending this close to the hook's deadline gives way to the single strategy, which needs the rest to be booked. const RECIPE_MARGIN_MS = 300; const LATE_RECIPE_WAIT_MS = 6_000; -// A recall that missed the prompt goes on in the background for the turn's first tool result, which comes later still. +// A recall that missed the prompt goes on in the background, for the turn's next model step or its first tool result. const DEFERRED_RECALL_MS = 30_000; const DEFER_GRACE_MS = 1_000; @@ -129,8 +129,9 @@ async function recalled(ports, sessionId, { turn, prompt, projectDir, waitMs, ke const context = session.task ? { task: session.task, trigger: 'turn_start' } : null; // Without a late answer the wait cancels every request when it ends anyway, so a request may run for all of it. A host // that sends a missed recall to the background needs the wait to end first: a request cut at or before it (the - // Proxy client's own default is 8 s) settles the recall empty, and it would never be deferred. - const timeoutMs = lateAtToolResult ? waitMs + DEFER_GRACE_MS : keepLate ? 0 : waitMs; + // Proxy client's own default is 8 s) settles the recall empty, and it would never be deferred. A late answer is that + // background already, and the Proxy's text recall alone can take 4–8 s, so its requests get the background window. + const timeoutMs = lateAtToolResult ? waitMs + DEFER_GRACE_MS : keepLate ? DEFERRED_RECALL_MS : waitMs; const { request: proxyFetch, signal, cancel } = recallRequestOf(ports.proxy, { timeoutMs }); const recipeCutoff = ports.clock.sleep(waitMs > 0 ? Math.max(0, waitMs - RECIPE_MARGIN_MS) : LATE_RECIPE_WAIT_MS, signal); const onWithheld = rememberWithheld(ports, sessionId, turn); diff --git a/test/app/recall-deadline.test.js b/test/app/recall-deadline.test.js index 08a4412..90bc2f3 100644 --- a/test/app/recall-deadline.test.js +++ b/test/app/recall-deadline.test.js @@ -67,10 +67,10 @@ test('a recall without a late answer lets each request run as long as the hook m assert.ok(requests.every(({ timeoutMs }) => timeoutMs === 10_000)); }); -test('a recall that may still answer late keeps the Proxy default per request', async () => { +test('a recall that may still answer late gives each request the background window, not the Proxy default of 8 s', async () => { const { ports, requests } = harness(); - const { late } = await promptSubmitted(ports, { sessionId: 's', prompt: PROMPT, waitMs: 0, keepLate: true }); + const { late } = await promptSubmitted(ports, { sessionId: 's', prompt: PROMPT, waitMs: 6_000, keepLate: true }); await late; assert.ok(requests.length > 0); - assert.ok(requests.every(({ timeoutMs }) => timeoutMs === undefined)); + assert.ok(requests.every(({ timeoutMs }) => timeoutMs === 30_000)); });