diff --git a/server/src/services/fresh-continuation-retry-delivery.test.ts b/server/src/services/fresh-continuation-retry-delivery.test.ts index af078c0c878..12b0a3d89a2 100644 --- a/server/src/services/fresh-continuation-retry-delivery.test.ts +++ b/server/src/services/fresh-continuation-retry-delivery.test.ts @@ -134,6 +134,18 @@ suite("a person's Retry while a continuation waits for delivery", () => { expect((await taskRuns(f)).map(row => row.id)).toEqual([run.id]); }, 60_000); + it.each(KINDS)("moves a recorded continuation forward as the one run when delivery has not happened yet (%s)", async kind => { + const f = await pendingContinuation(kind); + await occupySlot(); + const receipt = await requestTaskRetry({ db, companyId, issueId: f.issueId, actorId: userId, observedRunId: f.runId, + idempotencyKey: randomUUID(), actorSource: "local_implicit", retryAction: "move_forward" }); + expect(receipt).toMatchObject({ accepted: true }); + await heartbeatService(db).resumeTaskRetry(companyId, receipt.requestId!); + const run = await expectSingleContinuationRun(f, receipt.requestId!); + await deliver(); + expect((await taskRuns(f)).map(row => row.id)).toEqual([run.id]); + }, 60_000); + it.each(KINDS)("answers a Retry saved before delivery with the delivered continuation, never a second run (%s)", async kind => { const f = await pendingContinuation(kind); await occupySlot(); diff --git a/server/src/services/task-retry.ts b/server/src/services/task-retry.ts index 80a91e68ef3..61deed96b34 100644 --- a/server/src/services/task-retry.ts +++ b/server/src/services/task-retry.ts @@ -23,6 +23,7 @@ import { hasRequiredWorkspaceRecovery } from "./workspace-restore-recovery-state import { deferredChatInputPredicate, resumeDeferredChatWake, unadmittedChatWakeupCondition } from "./durable-chat-wakeup.js"; import { notifyDeferredExecutionWork } from "./deferred-execution-notifications.js"; import { hasPendingRunCleanup } from "./execution-blocker.js"; +import { undeliveredContinuation } from "./fresh-continuation-retry-fold.js"; import { PersistedExecutionWaitRefusal } from "./deferred-execution-wait.js"; import { rearmExhaustedNativeFinalization } from "./native-runtime/exhausted-finalization-retry.js"; import { NativeChatReviewPresentationContentionError } from "./native-runtime/native-chat-review-presentation.js"; @@ -319,7 +320,8 @@ function admitTaskRetry(input: TaskRetryRequest) { latest.agentId !== issue.assigneeAgentId || input.observedRunId !== latest.id) { return { requestId: null, accepted: false, stale: true, observedRunId: latest?.id ?? null, chatActionId: undefined }; } - if (input.retryAction === "move_forward" && !["queued", "running"].includes(latest.status)) + if (input.retryAction === "move_forward" && !["queued", "running"].includes(latest.status) && + !(await undeliveredContinuation(tx, { companyId: issue.companyId, issueId: issue.id }))) return { requestId: null, accepted: false, stale: false, alreadyMovedOn: true, observedRunId: latest.id, chatActionId: undefined }; let active = (await tx.select().from(agentWakeupRequests).where(and( eq(agentWakeupRequests.companyId, issue.companyId), eq(agentWakeupRequests.agentId, issue.assigneeAgentId),