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.
This commit is contained in:
alkor2000
2026-05-26 17:07:51 +08:00
committed by Peter Steinberger
parent a7b8e6a5a9
commit ea2e9ce8bd
+11 -1
View File
@@ -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;