diff --git a/server/src/services/task-interruption-presentation.test.ts b/server/src/services/task-interruption-presentation.test.ts index 579cc7c9ae4..10970b0cfcf 100644 --- a/server/src/services/task-interruption-presentation.test.ts +++ b/server/src/services/task-interruption-presentation.test.ts @@ -436,8 +436,9 @@ describe("scheduled resource wait presentation", () => { }); it("keeps failure retries, user gates and failed Retry preparation authoritative", () => { - expect(projectTaskInterruption(issue, { run: { ...waiting, scheduledRetryReason: "transient_failure" }, - agent, paused: false, approval: false }, now)).toMatchObject({ state: "failed", canRetry: true }); + expect(projectTaskInterruption(issue, { run: { ...waiting, scheduledRetryReason: "transient_failure", + scheduledRetryAt: new Date(now - 10 * 60_000) }, agent, paused: false, approval: false }, now)) + .toMatchObject({ state: "failed", canRetry: true }); expect(projectTaskInterruption(issue, { run: waiting, agent, paused: true, approval: false }, now)) .toMatchObject({ state: "waiting_for_user", userAction: "resume" }); expect(projectTaskInterruption(issue, { run: waiting, agent, paused: false, approval: false, @@ -570,6 +571,15 @@ describe("automatic scheduled retry", () => { .toMatchObject({ state: "retry_scheduled", canRetry: false, nextRetryAt: new Date(now + 60_000).toISOString() }); }); + it.each(["transient_failure", "native_environment_blocker"])( + "keeps a just-due %s retry working while the dispatcher promotes it", scheduledRetryReason => { + for (const overdueMs of [0, 1_000, 30_000, 119_000]) { + expect(projectTaskInterruption({ ...issue, status: "in_progress" }, { run: { ...scheduled, runtimeMode: "native", + scheduledRetryReason, scheduledRetryAt: new Date(now - overdueMs) }, agent, paused: false, approval: false }, now)) + .toMatchObject({ state: "working", canRetry: false }); + } + }); + it("offers Retry once the scheduled retry is past due with nothing else pending", () => { expect(projectTaskInterruption(issue, { run: { ...scheduled, scheduledRetryAt: new Date(now - 10 * 60_000) }, agent, paused: false, approval: false }, now)).toMatchObject({ state: "failed", canRetry: true }); diff --git a/server/src/services/task-interruption-presentation.ts b/server/src/services/task-interruption-presentation.ts index 6debf54ce92..7222d614954 100644 --- a/server/src/services/task-interruption-presentation.ts +++ b/server/src/services/task-interruption-presentation.ts @@ -374,7 +374,8 @@ function projectTaskInterruptionState(issue: ProjectionIssue, input: ProjectionS if (retryAt && retryAt > now) return { ...base, state: "retry_scheduled", nextRetryAt: new Date(retryAt).toISOString(), canRetry: !preparationPending && !nativeResumeAt && run.status !== "scheduled_retry", ...(system?.nextAttemptAt && recoveryStep ? { recoveryStep } : {}) }; - if (nativeResumeAt && !system && now - nativeResumeAt < NATIVE_RESUME_DISPATCH_GRACE_MS) + const dispatchDueAt = nativeResumeAt ?? (run.status === "scheduled_retry" ? run.scheduledRetryAt?.getTime() : undefined); + if (dispatchDueAt && !system && now - dispatchDueAt < NATIVE_RESUME_DISPATCH_GRACE_MS) return { ...base, state: "working" }; if (recoveryRunning) return { ...base, state: "working", ...(recoveryStep ? { recoveryStep } : {}) }; const providerRecoveryAt = run.providerRecoveryAt?.getTime();