
























@@ -222,42 +222,39 @@ function resolveCompactionSteerRetryDelaysMs() {
222222 : ([1_000, 2_000, 4_000, 8_000] as const);
223223}
224224225-// Wake an active requester run, retrying through two transient outcomes:
226-// - transcript_commit_wait_unsupported: retry once without the transcript-commit
227-// wait (best-effort steering for runtimes that cannot wait for commit).
228-// - compacting: the run becomes steerable again once compaction finishes, so
229-// wait through compaction and retry the same wake, bounded by cancellation and
230-// a finite backoff schedule (well within the delivery timeout).
231-// Both the steer path and the generated-completion active wake use this helper so
232-// the retry behavior stays consistent. Other failure reasons are returned as-is
233-// for the caller's existing fallback handling. The two transient retries are
234-// handled in a single loop so a run that compacts and then reports
235-// transcript_commit_wait_unsupported still gets the best-effort retry.
225+// Wake an active requester run through transient compacting and transcript-wait
226+// outcomes. Both active-wake call sites use one loop so delivery deadlines and
227+// best-effort transcript retry stay consistent.
236228async function resolveActiveWakeWithRetries(
237229sessionId: string,
238230message: string,
239231wakeOptions: EmbeddedAgentQueueMessageOptions,
240232signal?: AbortSignal,
241233): Promise<EmbeddedAgentQueueMessageOutcome> {
242-let currentOptions = wakeOptions;
243-let outcome = await resolveQueueEmbeddedAgentMessageOutcome(
244-sessionId,
245-message,
246-currentOptions,
247-);
248-const compactionRetryDelaysMs = resolveCompactionSteerRetryDelaysMs();
249-let compactionRetryIndex = 0;
250-// Bound compaction waiting by the delivery timeout (the window the issue asks
251-// us to wait within), not just the fixed backoff schedule: a compaction that
252-// finishes after the schedule is exhausted but still inside the delivery
253-// timeout should keep being retried. The backoff schedule controls the gap
254-// between attempts; once it is exhausted the last delay is reused until the
255-// deadline. A missing/zero timeout falls back to the bounded schedule only.
234+// Bound the whole active wake by the caller's delivery window. Each retry
235+// passes only the remaining window into transcript-commit waiting so a
236+// near-deadline retry cannot add another full timeout.
256237const compactionDeadlineMs =
257-typeof wakeOptions.deliveryTimeoutMs === "number" &&
258-wakeOptions.deliveryTimeoutMs > 0
238+typeof wakeOptions.deliveryTimeoutMs === "number" && wakeOptions.deliveryTimeoutMs > 0
259239 ? Date.now() + wakeOptions.deliveryTimeoutMs
260240 : undefined;
241+let currentOptions = wakeOptions;
242+const resolveRetryOptions = (): EmbeddedAgentQueueMessageOptions | undefined => {
243+if (compactionDeadlineMs === undefined) {
244+return currentOptions;
245+}
246+const remainingDeliveryTimeoutMs = compactionDeadlineMs - Date.now();
247+if (remainingDeliveryTimeoutMs <= 0) {
248+return undefined;
249+}
250+return {
251+ ...currentOptions,
252+deliveryTimeoutMs: remainingDeliveryTimeoutMs,
253+};
254+};
255+let outcome = await resolveQueueEmbeddedAgentMessageOutcome(sessionId, message, currentOptions);
256+const compactionRetryDelaysMs = resolveCompactionSteerRetryDelaysMs();
257+let compactionRetryIndex = 0;
261258for (;;) {
262259if (outcome.queued || signal?.aborted) {
263260break;
@@ -269,19 +266,17 @@ async function resolveActiveWakeWithRetries(
269266const bestEffortOptions = { ...currentOptions };
270267delete bestEffortOptions.waitForTranscriptCommit;
271268currentOptions = bestEffortOptions;
272-outcome = await resolveQueueEmbeddedAgentMessageOutcome(
273-sessionId,
274-message,
275-currentOptions,
276-);
269+outcome = await resolveQueueEmbeddedAgentMessageOutcome(sessionId, message, currentOptions);
277270continue;
278271}
279272if (outcome.reason === "compacting") {
280-const withinDeadline =
281-compactionDeadlineMs === undefined
273+const remainingDeliveryTimeoutMs =
274+compactionDeadlineMs === undefined ? undefined : compactionDeadlineMs - Date.now();
275+const canRetry =
276+remainingDeliveryTimeoutMs === undefined
282277 ? compactionRetryIndex < compactionRetryDelaysMs.length
283- : Date.now() < compactionDeadlineMs;
284-if (!withinDeadline) {
278+ : remainingDeliveryTimeoutMs > 0;
279+if (!canRetry) {
285280break;
286281}
287282// Use the next scheduled backoff delay; once the schedule is exhausted,
@@ -294,22 +289,22 @@ async function resolveActiveWakeWithRetries(
294289// not sleep past the deadline (which would overrun the delivery timeout).
295290// If no time remains, stop retrying and let the fallback handle it.
296291const delayMs =
297-compactionDeadlineMs === undefined
292+remainingDeliveryTimeoutMs === undefined
298293 ? scheduledDelayMs
299- : Math.min(scheduledDelayMs, compactionDeadlineMs - Date.now());
300-if (delayMs <= 0 && compactionDeadlineMs !== undefined) {
294+ : Math.min(scheduledDelayMs, remainingDeliveryTimeoutMs);
295+if (delayMs <= 0 && remainingDeliveryTimeoutMs !== undefined) {
301296break;
302297}
303298await waitForAnnounceRetryDelay(delayMs, signal);
304299if (signal?.aborted) {
305300break;
306301}
307302compactionRetryIndex += 1;
308-outcome = await resolveQueueEmbeddedAgentMessageOutcome(
309- sessionId,
310-message,
311- currentOptions,
312-);
303+const retryOptions = resolveRetryOptions();
304+if (!retryOptions) {
305+break;
306+}
307+outcome = await resolveQueueEmbeddedAgentMessageOutcome(sessionId, message, retryOptions);
313308continue;
314309}
315310break;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。