From ea2e9ce8bdab75068177b0ee7022cce509ebbd78 Mon Sep 17 00:00:00 2001 From: alkor2000 <200923177@qq.com> Date: Tue, 26 May 2026 17:07:51 +0800 Subject: [PATCH] fix(agents): clamp compaction steer retry wait to remaining delivery window The compaction retry loop checked the delivery-timeout deadline before choosing a fixed backoff delay, then slept that whole delay. When the remaining window was shorter than the next backoff entry, the final retry could sleep past the deadline, overrunning the delivery timeout the retry is meant to stay within. Clamp the wait to the remaining window (min(scheduledDelay, deadline - now)) and stop retrying once no time remains, so compaction waiting never exceeds the delivery timeout. Addresses the near-deadline overrun raised in ClawSweeper review of #86606. --- src/agents/subagent-announce-delivery.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/agents/subagent-announce-delivery.ts b/src/agents/subagent-announce-delivery.ts index 3225ee7956eb..9ee2ae27ec32 100644 --- a/src/agents/subagent-announce-delivery.ts +++ b/src/agents/subagent-announce-delivery.ts @@ -286,10 +286,20 @@ async function resolveActiveWakeWithRetries( } // Use the next scheduled backoff delay; once the schedule is exhausted, // keep using its last entry until the deadline is reached. - const delayMs = + const scheduledDelayMs = compactionRetryDelaysMs[ Math.min(compactionRetryIndex, compactionRetryDelaysMs.length - 1) ] ?? 0; + // Clamp the wait to the remaining delivery window so the final retry does + // not sleep past the deadline (which would overrun the delivery timeout). + // If no time remains, stop retrying and let the fallback handle it. + const delayMs = + compactionDeadlineMs === undefined + ? scheduledDelayMs + : Math.min(scheduledDelayMs, compactionDeadlineMs - Date.now()); + if (delayMs <= 0 && compactionDeadlineMs !== undefined) { + break; + } await waitForAnnounceRetryDelay(delayMs, signal); if (signal?.aborted) { break;