diff --git a/packages/plugins/sdk/src/workspace-operation-error.ts b/packages/plugins/sdk/src/workspace-operation-error.ts index 2cd247d002d..6bee7252ff5 100644 --- a/packages/plugins/sdk/src/workspace-operation-error.ts +++ b/packages/plugins/sdk/src/workspace-operation-error.ts @@ -18,6 +18,12 @@ export const WORKSPACE_OPERATION_FAILURE_REASONS = [ "storage_pending", /** The selected runtime is not ready. */ "runtime_unavailable", + /** + * The selected runtime is applying an update and refuses new workspaces until + * it finishes. Core holds the run and retries the same workspace for longer + * than a transient failure. + */ + "runtime_updating", /** The selected runtime's saved connection is invalid. */ "runtime_connection_invalid", /** A remote storage or runtime request failed or returned an unusable result. */ diff --git a/server/src/__tests__/workspace-provider-failure.test.ts b/server/src/__tests__/workspace-provider-failure.test.ts index a314de8eaa1..913a4a8646d 100644 --- a/server/src/__tests__/workspace-provider-failure.test.ts +++ b/server/src/__tests__/workspace-provider-failure.test.ts @@ -17,6 +17,7 @@ import { import { HttpError } from "../errors.js"; import { findPluginWorkerUnavailableError, PluginWorkerUnavailableError } from "../services/plugin-worker-unavailable-error.js"; import { + findRetryableWorkspaceStorageSetupCode, findWorkspaceProviderFailure, readWorkspaceProviderFailure, workspaceProviderCallFailure, @@ -94,7 +95,7 @@ describe("workspace provider call failures", () => { }); it("gives every reason a fixed message and a retry decision", () => { - const transient = new Set(["storage_pending", "runtime_unavailable", "remote_incomplete", "context_changed", "deadline_exceeded"]); + const transient = new Set(["storage_pending", "runtime_unavailable", "runtime_updating", "remote_incomplete", "context_changed", "deadline_exceeded"]); for (const reason of WORKSPACE_OPERATION_FAILURE_REASONS) { const failure = workspaceProviderCallFailure(new JsonRpcCallError({ code: PLUGIN_RPC_ERROR_CODES.WORKER_ERROR, message: "private provider text", data: { schema: "paperclip/workspace-operation-error/v1", reason } })); @@ -196,4 +197,25 @@ describe("workspace provider call failures", () => { expect(notice.body).toContain("no agent work started"); expect(notice.body).not.toMatch(/retried automatically|tries again automatically/); }); + + it("waits for an updating runtime in its own setup lane and names it when that wait ends", async () => { + const failure = workspaceProviderCallFailure(await providerRejection( + new PluginWorkspaceOperationError("runtime_updating", "private fence holder text"))); + expect(failure.summary()).toEqual({ kind: "provider", reason: "runtime_updating", retryable: true }); + expect(failure.message).toBe("The selected runtime is updating; retry the same workspace after the update"); + expect(failure.message).not.toContain("private"); + expect(findRetryableWorkspaceStorageSetupCode(new Error("setup failed", { cause: failure }))).toBe("workspace_runtime_updating"); + + const saved = readWorkspaceProviderFailure({ workspaceProviderFailure: failure.summary() }); + const notice = buildStrandedRecoveryEscalationNotice({ + seed: buildNoRunningExecutionNoticeSeed({ status: "in_progress", workspaceProviderFailure: saved }), + recoveryActionId: id(16), + recoveryOwner: null, + sourceRun: { id: id(17), status: "failed", errorCode: "workspace_runtime_updating", + errorSummary: workspaceProviderFailureMessage(saved) }, + }); + expect(JSON.stringify(notice.presentation)).toContain("Agent computer was still updating"); + expect(notice.body).toContain("no agent work started"); + expect(notice.body).not.toMatch(/retried automatically|tries again automatically/); + }); }); diff --git a/server/src/modules/run-dispatch/domain/wake-context.ts b/server/src/modules/run-dispatch/domain/wake-context.ts index 4e45d97e4b6..685aa30bfc1 100644 --- a/server/src/modules/run-dispatch/domain/wake-context.ts +++ b/server/src/modules/run-dispatch/domain/wake-context.ts @@ -24,9 +24,11 @@ export const AI_CONNECTION_POOL_WAIT_RETRY_REASON = "ai_connection_pool_wait"; export const AI_CONNECTION_BUSY_RETRY_REASON = "ai_connection_busy"; export const RUNNER_REVISION_WAIT_RETRY_REASON = "runner_revision_wait"; export const STORAGE_UNAVAILABLE_WAIT_RETRY_REASON = "storage_unavailable_wait"; +/** Waits for an agent computer that refused new workspaces while it updates. */ +export const RUNTIME_UPDATE_WAIT_RETRY_REASON = "runtime_update_wait"; export const AGENT_DIRECTORY_BUSY_RETRY_REASON = "agent_directory_busy"; export const PREPARATION_WAIT_RETRY_REASONS: ReadonlySet = new Set([ - RUNNER_REVISION_WAIT_RETRY_REASON, STORAGE_UNAVAILABLE_WAIT_RETRY_REASON, + RUNNER_REVISION_WAIT_RETRY_REASON, STORAGE_UNAVAILABLE_WAIT_RETRY_REASON, RUNTIME_UPDATE_WAIT_RETRY_REASON, ]); export function isPreparationWaitRetryReason(reason: string | null | undefined): boolean { return typeof reason === "string" && PREPARATION_WAIT_RETRY_REASONS.has(reason); diff --git a/server/src/modules/run-dispatch/index.ts b/server/src/modules/run-dispatch/index.ts index 6d7678b2cd0..111afa3244b 100644 --- a/server/src/modules/run-dispatch/index.ts +++ b/server/src/modules/run-dispatch/index.ts @@ -16,6 +16,7 @@ export { AI_CONNECTION_POOL_WAIT_RETRY_REASON, RUNNER_REVISION_WAIT_RETRY_REASON, STORAGE_UNAVAILABLE_WAIT_RETRY_REASON, + RUNTIME_UPDATE_WAIT_RETRY_REASON, AGENT_DIRECTORY_BUSY_RETRY_REASON, PREPARATION_WAIT_RETRY_REASONS, isPreparationWaitRetryReason, diff --git a/server/src/modules/wake-queue/adapters/postgres.ts b/server/src/modules/wake-queue/adapters/postgres.ts index 3fb1d435835..68d43ab5e60 100644 --- a/server/src/modules/wake-queue/adapters/postgres.ts +++ b/server/src/modules/wake-queue/adapters/postgres.ts @@ -147,7 +147,7 @@ function toRunSnapshot(row: ReleaseRun): RunSnapshot { function carriedRetryAccounting(row: ReleaseRun): Record | null { const accounting = executionRetryAccounting(row); return accounting.failureRetries > 0 || accounting.maxTurnContinuations > 0 || (accounting.interruptedPreparations ?? 0) > 0 - || (accounting.storageWaits ?? 0) > 0 || (accounting.agentDirectoryWaits ?? 0) > 0 + || (accounting.storageWaits ?? 0) > 0 || (accounting.agentDirectoryWaits ?? 0) > 0 || (accounting.runtimeUpdateWaits ?? 0) > 0 || (accounting.serverRestarts ?? 0) > 0 ? { ...accounting } : null; } diff --git a/server/src/services/__tests__/run-failure-report-sandbox-resume.test.ts b/server/src/services/__tests__/run-failure-report-sandbox-resume.test.ts index 7109d66c990..977784b2b57 100644 --- a/server/src/services/__tests__/run-failure-report-sandbox-resume.test.ts +++ b/server/src/services/__tests__/run-failure-report-sandbox-resume.test.ts @@ -15,7 +15,7 @@ vi.mock("../../sentry.js", () => ({ import { environmentResumeErrorData, JsonRpcCallError, PLUGIN_RPC_ERROR_CODES, PluginWorkspaceOperationError, workspaceOperationErrorData } from "@paperclipai/plugin-sdk"; import { reportRunFailure } from "../run-failure-report.js"; import { REUSABLE_SANDBOX_RESUME_FAILED_CODE, ReusableSandboxResumeError } from "../reusable-sandbox-resume-error.js"; -import { WORKSPACE_STORAGE_INCOMPLETE_CODE, WORKSPACE_STORAGE_PENDING_CODE, workspaceProviderCallFailure } from "../workspace-provider-failure.js"; +import { WORKSPACE_RUNTIME_UPDATING_CODE, WORKSPACE_STORAGE_INCOMPLETE_CODE, WORKSPACE_STORAGE_PENDING_CODE, workspaceProviderCallFailure } from "../workspace-provider-failure.js"; const testDatabaseUrl = process.env.PAPERCLIP_TEST_DATABASE_URL; const embeddedPostgresSupport = testDatabaseUrl ? { supported: true } : await getEmbeddedPostgresTestSupport(); @@ -229,4 +229,20 @@ describeEmbeddedPostgres("reportRunFailure setup retry decisions", () => { expect(mockCaptureRunFailure.mock.calls[0]![0]).toMatchObject({ errorCode: run.errorCode, runStatus: "failed" }); expect(JSON.stringify(mockCaptureRunFailure.mock.calls[0]![0])).not.toContain("private provider text"); }); + + it("keeps an updating runtime local while its wait is scheduled and reports it once the wait ends", async () => { + const error = workspaceProviderCallFailure(new JsonRpcCallError({ code: PLUGIN_RPC_ERROR_CODES.WORKER_ERROR, + message: "private provider text", data: workspaceOperationErrorData(new PluginWorkspaceOperationError("runtime_updating")) })); + const run = storageIncompleteRun({ errorCode: WORKSPACE_RUNTIME_UPDATING_CODE, + error: "The selected runtime is updating; retry the same workspace after the update", + resultJson: { executionRecovery: { kind: "bootstrap", providerWorkStarted: false }, + workspaceProviderFailure: { kind: "provider", reason: "runtime_updating", retryable: true } } }); + await reportRunFailure(db, run, { phase: "setup", error, workspaceStorageRetry: "pending" }); + await reportRunFailure(db, run, { phase: "setup", error, workspaceStorageRetry: "scheduled" }); + expect(mockCaptureRunFailure).not.toHaveBeenCalled(); + await reportRunFailure(db, run, { phase: "setup", error, workspaceStorageRetry: "not_scheduled" }); + expect(mockCaptureRunFailure).toHaveBeenCalledOnce(); + expect(mockCaptureRunFailure.mock.calls[0]![0]).toMatchObject({ errorCode: WORKSPACE_RUNTIME_UPDATING_CODE, runStatus: "failed" }); + expect(JSON.stringify(mockCaptureRunFailure.mock.calls[0]![0])).not.toContain("private provider text"); + }); }); diff --git a/server/src/services/agent-task-run-telemetry.ts b/server/src/services/agent-task-run-telemetry.ts index d8870664e39..11e5d58fce5 100644 --- a/server/src/services/agent-task-run-telemetry.ts +++ b/server/src/services/agent-task-run-telemetry.ts @@ -44,6 +44,7 @@ const PLATFORM_FAILURE_CODES = new Set([ "plugin_worker_unavailable", "workspace_storage_pending", "workspace_storage_incomplete", + "workspace_runtime_updating", "native_workspace_sync_out_retry_exhausted", "queued_run_claim_rejected", ]); diff --git a/server/src/services/execution-recovery-attempt.test.ts b/server/src/services/execution-recovery-attempt.test.ts index 128cccbe3a9..c2de87a09b7 100644 --- a/server/src/services/execution-recovery-attempt.test.ts +++ b/server/src/services/execution-recovery-attempt.test.ts @@ -2,7 +2,9 @@ import { describe, expect, it } from "vitest"; import { accountingForScheduledRetry, AGENT_DIRECTORY_WAIT_RETRY_REASON, executionFailureRetryCount, executionRetryAttemptCount, INTERRUPTED_PREPARATION_RETRY_MAX_ATTEMPTS, INTERRUPTED_PREPARATION_RETRY_REASON } from "./execution-recovery-attempt.js"; import { AGENT_DIRECTORY_BUSY_MAX_DEFERRALS } from "./heartbeat/agent-directory-busy.js"; import { RUNNER_REVISION_WAIT_RETRY_REASON } from "./runner-revision-mismatch.js"; -import { RUNNER_REVISION_WAIT_RETRY_REASON as DISPATCH_RUNNER_REVISION_WAIT_RETRY_REASON } from "../modules/run-dispatch/index.js"; +import { isPreparationWaitRetryReason, RUNNER_REVISION_WAIT_RETRY_REASON as DISPATCH_RUNNER_REVISION_WAIT_RETRY_REASON, + RUNTIME_UPDATE_WAIT_RETRY_REASON as DISPATCH_RUNTIME_UPDATE_WAIT_RETRY_REASON } from "../modules/run-dispatch/index.js"; +import { RUNTIME_UPDATE_WAIT_RETRY_REASON } from "./workspace-provider-failure.js"; describe("failure attempts across resource waits", () => { it("preserves prior failures through subscription waits without trusting unrelated context", () => { @@ -30,7 +32,7 @@ describe("failure attempts across resource waits", () => { }); describe("persisted independent accounting", () => { - it.each(["max_turns_continuation", "issue_disposition_repair", "workspace_busy", "ai_connection_busy", "ai_connection_pool_wait", "runner_revision_wait", "storage_unavailable_wait"])("%s cannot erase prior infrastructure debits or spend more", scheduledRetryReason => { + it.each(["max_turns_continuation", "issue_disposition_repair", "workspace_busy", "ai_connection_busy", "ai_connection_pool_wait", "runner_revision_wait", "storage_unavailable_wait", "runtime_update_wait"])("%s cannot erase prior infrastructure debits or spend more", scheduledRetryReason => { expect(executionFailureRetryCount({ scheduledRetryReason, scheduledRetryAttempt: 20, contextSnapshot: { executionRetryAccounting: { version: 1, failureRetries: 2, maxTurnContinuations: 1 } }, })).toBe(2); @@ -123,6 +125,21 @@ describe("storage outage waits", () => { }); }); +describe("runtime update waits", () => { + it("keep their count through an intervening workspace wait", () => { + const afterUpdateWait = { scheduledRetryReason: "runtime_update_wait", scheduledRetryAttempt: 29, + contextSnapshot: { executionRetryAccounting: { version: 1, failureRetries: 1, maxTurnContinuations: 0 } } }; + const ledger = accountingForScheduledRetry(afterUpdateWait, "workspace_busy", 1); + expect(ledger).toMatchObject({ runtimeUpdateWaits: 29, failureRetries: 1 }); + const afterWorkspaceWait = { scheduledRetryReason: "workspace_busy", scheduledRetryAttempt: 1, + contextSnapshot: { executionRetryAccounting: ledger } }; + // The update-wait limit does not restart after another lane's retry. + expect(executionRetryAttemptCount(afterWorkspaceWait, "runtime_update_wait")).toBe(29); + expect(accountingForScheduledRetry(afterWorkspaceWait, "runtime_update_wait", 30)).toMatchObject({ runtimeUpdateWaits: 30, failureRetries: 1 }); + expect(executionFailureRetryCount(afterWorkspaceWait)).toBe(1); + }); +}); + describe("agent directory waits", () => { it("keep their count through alternating workspace waits and stop at the bound", () => { let run: { scheduledRetryReason: string; scheduledRetryAttempt: number; contextSnapshot: Record } = { @@ -143,3 +160,15 @@ describe("agent directory waits", () => { expect(executionFailureRetryCount(run)).toBe(1); }); }); + +describe("updating-runtime waits", () => { + it("use the same retry reason as run dispatch and never spend the failure retry budget", () => { + expect(RUNTIME_UPDATE_WAIT_RETRY_REASON).toBe(DISPATCH_RUNTIME_UPDATE_WAIT_RETRY_REASON); + expect(isPreparationWaitRetryReason(RUNTIME_UPDATE_WAIT_RETRY_REASON)).toBe(true); + const waited = { scheduledRetryReason: "runtime_update_wait", scheduledRetryAttempt: 29, + contextSnapshot: { executionRetryAccounting: { version: 1, failureRetries: 1, maxTurnContinuations: 0 } } }; + expect(executionRetryAttemptCount(waited, "runtime_update_wait")).toBe(29); + expect(accountingForScheduledRetry(waited, "runtime_update_wait", 30)).toMatchObject({ failureRetries: 1 }); + expect(executionFailureRetryCount(waited)).toBe(1); + }); +}); diff --git a/server/src/services/execution-recovery-attempt.ts b/server/src/services/execution-recovery-attempt.ts index f7d3499b24a..885eee70dda 100644 --- a/server/src/services/execution-recovery-attempt.ts +++ b/server/src/services/execution-recovery-attempt.ts @@ -1,6 +1,7 @@ import { RUNNER_REVISION_WAIT_RETRY_REASON } from "./runner-revision-mismatch.js"; import { STORAGE_UNAVAILABLE_WAIT_RETRY_REASON } from "../storage/storage-unavailable.js"; import { ENVIRONMENT_PROVIDER_WAIT_RETRY_REASON } from "./environment-provider-wait.js"; +import { RUNTIME_UPDATE_WAIT_RETRY_REASON } from "./workspace-provider-failure.js"; import { PROVIDER_ATTEMPT_CREDIT_GENERATION_LIMIT } from "./native-runtime/provider-attempt-outcome.js"; import { NATIVE_RESUME_REFUSED_CONTINUATION_CODE } from "./native-runtime/native-resume-refused-continuation.js"; import { AGENT_DIRECTORY_BUSY_RETRY_REASON } from "../modules/run-dispatch/index.js"; @@ -33,7 +34,7 @@ export const SERVER_RESTART_RETRY_WINDOW_MS = 60 * 60_000; const UNCHARGED_RETRY_LANES: ReadonlySet = new Set([ "workspace_busy", "ai_connection_busy", "ai_connection_pool_wait", AGENT_DIRECTORY_WAIT_RETRY_REASON, RUNNER_REVISION_WAIT_RETRY_REASON, INTERRUPTED_PREPARATION_RETRY_REASON, STORAGE_UNAVAILABLE_WAIT_RETRY_REASON, SERVER_RESTART_RETRY_REASON, - ENVIRONMENT_PROVIDER_WAIT_RETRY_REASON, NATIVE_RESUME_REFUSED_CONTINUATION_CODE, + ENVIRONMENT_PROVIDER_WAIT_RETRY_REASON, NATIVE_RESUME_REFUSED_CONTINUATION_CODE, RUNTIME_UPDATE_WAIT_RETRY_REASON, ]); type RetryRun = { @@ -57,6 +58,8 @@ export interface ExecutionRetryAccounting { storageWaits?: number; /** Agent-directory waits in this chain, kept across intervening resource waits. Omitted while zero. */ agentDirectoryWaits?: number; + /** Updating-runtime waits in this chain, kept across intervening resource waits. Omitted while zero. */ + runtimeUpdateWaits?: number; /** Server-restart continuations in the current window. Omitted while zero. */ serverRestarts?: number; /** Start of the current server-restart window (ISO time). Saved with serverRestarts. */ @@ -77,6 +80,7 @@ function savedAccounting(run: RetryRun): ExecutionRetryAccounting | null { const interruptedPreparations = count(saved.interruptedPreparations) ?? 0; const storageWaits = count(saved.storageWaits) ?? 0; const agentDirectoryWaits = count(saved.agentDirectoryWaits) ?? 0; + const runtimeUpdateWaits = count(saved.runtimeUpdateWaits) ?? 0; const serverRestarts = count(saved.serverRestarts) ?? 0; const windowStartedAt = typeof saved.serverRestartWindowStartedAt === "string" && Number.isFinite(Date.parse(saved.serverRestartWindowStartedAt)) ? saved.serverRestartWindowStartedAt : null; @@ -84,6 +88,7 @@ function savedAccounting(run: RetryRun): ExecutionRetryAccounting | null { ...(interruptedPreparations > 0 ? { interruptedPreparations } : {}), ...(storageWaits > 0 ? { storageWaits } : {}), ...(agentDirectoryWaits > 0 ? { agentDirectoryWaits } : {}), + ...(runtimeUpdateWaits > 0 ? { runtimeUpdateWaits } : {}), ...(serverRestarts > 0 && windowStartedAt ? { serverRestarts, serverRestartWindowStartedAt: windowStartedAt } : {}) }; } @@ -111,6 +116,8 @@ export function executionRetryAccounting(run: RetryRun): ExecutionRetryAccountin reason === STORAGE_UNAVAILABLE_WAIT_RETRY_REASON ? count(run.scheduledRetryAttempt) ?? 0 : 0); const agentDirectoryWaits = Math.max(saved?.agentDirectoryWaits ?? 0, reason === AGENT_DIRECTORY_WAIT_RETRY_REASON ? count(run.scheduledRetryAttempt) ?? 0 : 0); + const runtimeUpdateWaits = Math.max(saved?.runtimeUpdateWaits ?? 0, + reason === RUNTIME_UPDATE_WAIT_RETRY_REASON ? count(run.scheduledRetryAttempt) ?? 0 : 0); return { version: 1, failureRetries: Math.max(saved?.failureRetries ?? 0, saved && nonFailureLane ? 0 : historicalFailureCount(run)), @@ -119,6 +126,7 @@ export function executionRetryAccounting(run: RetryRun): ExecutionRetryAccountin ...(interruptedPreparations > 0 ? { interruptedPreparations } : {}), ...(storageWaits > 0 ? { storageWaits } : {}), ...(agentDirectoryWaits > 0 ? { agentDirectoryWaits } : {}), + ...(runtimeUpdateWaits > 0 ? { runtimeUpdateWaits } : {}), ...(saved?.serverRestarts ? { serverRestarts: saved.serverRestarts, serverRestartWindowStartedAt: saved.serverRestartWindowStartedAt } : {}), }; @@ -146,6 +154,7 @@ export function executionRetryAttemptCount(run: RetryRun, reason: string): numbe if (reason === INTERRUPTED_PREPARATION_RETRY_REASON) return executionRetryAccounting(run).interruptedPreparations ?? 0; if (reason === STORAGE_UNAVAILABLE_WAIT_RETRY_REASON) return executionRetryAccounting(run).storageWaits ?? 0; if (reason === AGENT_DIRECTORY_WAIT_RETRY_REASON) return executionRetryAccounting(run).agentDirectoryWaits ?? 0; + if (reason === RUNTIME_UPDATE_WAIT_RETRY_REASON) return executionRetryAccounting(run).runtimeUpdateWaits ?? 0; if (UNCHARGED_RETRY_LANES.has(reason)) { return run.scheduledRetryReason === reason ? count(run.scheduledRetryAttempt) ?? 0 : 0; } @@ -165,6 +174,7 @@ export function accountingForScheduledRetry(run: RetryRun, reason: string, attem else if (reason === INTERRUPTED_PREPARATION_RETRY_REASON) accounting.interruptedPreparations = attempt; else if (reason === STORAGE_UNAVAILABLE_WAIT_RETRY_REASON) accounting.storageWaits = attempt; else if (reason === AGENT_DIRECTORY_WAIT_RETRY_REASON) accounting.agentDirectoryWaits = attempt; + else if (reason === RUNTIME_UPDATE_WAIT_RETRY_REASON) accounting.runtimeUpdateWaits = attempt; else if (!UNCHARGED_RETRY_LANES.has(reason)) accounting.failureRetries = attempt; return accounting; } diff --git a/server/src/services/failed-preparation-retry.ts b/server/src/services/failed-preparation-retry.ts index bdb59400d58..a07130867cf 100644 --- a/server/src/services/failed-preparation-retry.ts +++ b/server/src/services/failed-preparation-retry.ts @@ -10,7 +10,7 @@ import { REUSABLE_SANDBOX_RESUME_FAILED_CODE } from "./reusable-sandbox-resume-e import { REVIEWED_CHAT_BINDING_NOT_READY } from "./reviewed-chat-binding-diagnostics.js"; import { RUNNER_REVISION_MISMATCH_CODE } from "./runner-revision-mismatch.js"; import { WORKSPACE_GIT_SCAN_ERROR_CODES } from "./workspace-git-operation-scheduler.js"; -import { WORKSPACE_STORAGE_INCOMPLETE_CODE, WORKSPACE_STORAGE_PENDING_CODE } from "./workspace-provider-failure.js"; +import { WORKSPACE_RUNTIME_UPDATING_CODE, WORKSPACE_STORAGE_INCOMPLETE_CODE, WORKSPACE_STORAGE_PENDING_CODE } from "./workspace-provider-failure.js"; type HeartbeatRun = typeof heartbeatRuns.$inferSelect; @@ -21,6 +21,7 @@ export const TRANSIENT_WORKSPACE_PREPARATION_CODES: readonly string[] = [ RUNNER_REVISION_MISMATCH_CODE, ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE, REPOSITORY_CATALOG_UNAVAILABLE_CODE, REVIEWED_CHAT_BINDING_NOT_READY, STORAGE_UNAVAILABLE_CODE, WORKSPACE_STORAGE_PENDING_CODE, WORKSPACE_STORAGE_INCOMPLETE_CODE, + WORKSPACE_RUNTIME_UPDATING_CODE, ]; /** Transient setup codes whose accepted-interaction wakes stay on the interaction continuation retry lane. */ diff --git a/server/src/services/heartbeat/retries.test.ts b/server/src/services/heartbeat/retries.test.ts index 10ea547bbad..acf157f1c46 100644 --- a/server/src/services/heartbeat/retries.test.ts +++ b/server/src/services/heartbeat/retries.test.ts @@ -141,6 +141,25 @@ describe("heartbeat retry module callbacks", () => { expect(database.access).not.toHaveBeenCalled(); }); + it("gives every caller the updating-runtime wait budget and reports its exhaustion", async () => { + const database = guardedDatabase(); + const deps = callbacks(); + const run = { ...unitRun(), status: "failed", errorCode: "workspace_runtime_updating", scheduledRetryReason: "runtime_update_wait", scheduledRetryAttempt: 30, + contextSnapshot: { issueId: "issue", executionRetryAccounting: { version: 1, failureRetries: 0, maxTurnContinuations: 0 } } } as Run; + const retry = await extracted.createHeartbeatRetries(database.db, deps).scheduleBoundedRetryForRun(run, { adapterType: "codex_local" } as Agent); + expect(retry).toMatchObject({ outcome: "retry_exhausted", attempt: 31, maxAttempts: 30 }); + expect(deps.appendRunEvent).toHaveBeenCalledWith(run, expect.objectContaining({ + retryExhaustion: { retryReason: "runtime_update_wait", scheduledRetryAttempt: 30, maxAttempts: 30 }, + })); + expect(extracted.failedRunRetryBudgetSpent(run)).toBe(true); + // Two transient failures before the update began do not shorten the wait. + expect(extracted.failedRunRetryBudgetSpent({ ...run, scheduledRetryAttempt: 29, contextSnapshot: { issueId: "issue", + executionRetryAccounting: { version: 1, failureRetries: 2, maxTurnContinuations: 0 } } })).toBe(false); + expect(extracted.failedRunRetryBudgetSpent({ ...run, scheduledRetryReason: "transient_failure", scheduledRetryAttempt: 2, + contextSnapshot: { issueId: "issue", executionRetryAccounting: { version: 1, failureRetries: 2, maxTurnContinuations: 0 } } })).toBe(false); + expect(database.access).not.toHaveBeenCalled(); + }); + it("ends an answered interaction's storage wait at its limit and escalates it", async () => { const database = guardedDatabase(); const deps = callbacks(); @@ -153,6 +172,18 @@ describe("heartbeat retry module callbacks", () => { expect(deps.escalatePlanApprovalResumeFailureNeedsAttention).toHaveBeenCalledWith(expect.objectContaining({ run, maxAttempts: 10 })); }); + it("ends an answered interaction's runtime update wait at its limit and escalates it", async () => { + const database = guardedDatabase(); + const deps = callbacks(); + const run = { ...unitRun(), status: "failed", errorCode: "workspace_runtime_updating", scheduledRetryReason: "runtime_update_wait", scheduledRetryAttempt: 30, + contextSnapshot: { issueId: "issue", interactionId: "interaction-1", interactionStatus: "accepted", interactionKind: "request_confirmation", + mutation: "interaction", retryReason: "runtime_update_wait", + executionRetryAccounting: { version: 1, failureRetries: 0, maxTurnContinuations: 0 } } } as Run; + const retry = await extracted.createHeartbeatRetries(database.db, deps).scheduleBoundedRetryForRun(run, { adapterType: "codex_local" } as Agent); + expect(retry).toMatchObject({ outcome: "retry_exhausted", maxAttempts: 30 }); + expect(deps.escalatePlanApprovalResumeFailureNeedsAttention).toHaveBeenCalledWith(expect.objectContaining({ run, maxAttempts: 30 })); + }); + it("leaves successor work to the committed case handoff without retry escalation", async () => { const database = guardedDatabase(); const deps = callbacks(); diff --git a/server/src/services/heartbeat/retries.ts b/server/src/services/heartbeat/retries.ts index 1250864ed21..b0318a15106 100644 --- a/server/src/services/heartbeat/retries.ts +++ b/server/src/services/heartbeat/retries.ts @@ -41,6 +41,7 @@ import { REPOSITORY_CATALOG_UNAVAILABLE_CODE } from "../repository-catalog-unava import { REVIEWED_CHAT_BINDING_NOT_READY } from "../reviewed-chat-binding-diagnostics.js"; import { RUNNER_REVISION_MISMATCH_CODE, RUNNER_REVISION_MISMATCH_RETRY, RUNNER_REVISION_WAIT_RETRY_REASON } from "../runner-revision-mismatch.js"; import { STORAGE_UNAVAILABLE_CODE, STORAGE_UNAVAILABLE_RETRY, STORAGE_UNAVAILABLE_WAIT_RETRY_REASON } from "../../storage/storage-unavailable.js"; +import { WORKSPACE_RUNTIME_UPDATING_CODE, WORKSPACE_RUNTIME_UPDATING_RETRY } from "../workspace-provider-failure.js"; import { CONTROLLER_LEASE_LOST_FAILURE_CODE } from "../legacy-controller-lease.js"; import { ENVIRONMENT_PROVIDER_WAIT_KEY, ENVIRONMENT_PROVIDER_WAIT_RETRY_REASON, environmentProviderWaitFor, environmentProviderWaitRetry } from "../environment-provider-wait.js"; import { randomUUID } from "node:crypto"; @@ -201,7 +202,9 @@ export function failedRunRetryBudgetSpent(run: Parameters= RUNNER_REVISION_MISMATCH_RETRY.maxAttempts : run.errorCode === STORAGE_UNAVAILABLE_CODE ? executionRetryAttemptCount(run, STORAGE_UNAVAILABLE_WAIT_RETRY_REASON) >= STORAGE_UNAVAILABLE_RETRY.maxAttempts - : executionFailureRetryCount(run) >= BOUNDED_TRANSIENT_HEARTBEAT_RETRY_MAX_ATTEMPTS + : run.errorCode === WORKSPACE_RUNTIME_UPDATING_CODE + ? executionRetryAttemptCount(run, WORKSPACE_RUNTIME_UPDATING_RETRY.retryReason) >= WORKSPACE_RUNTIME_UPDATING_RETRY.maxAttempts + : executionFailureRetryCount(run) >= BOUNDED_TRANSIENT_HEARTBEAT_RETRY_MAX_ATTEMPTS || executionRetryAttemptCount(run, INTERRUPTED_PREPARATION_RETRY_REASON) >= INTERRUPTED_PREPARATION_RETRY_MAX_ATTEMPTS; } @@ -530,6 +533,7 @@ export function createHeartbeatRetries(db: Db, dependencies: HeartbeatRetryDepen } if (!opts?.retryReason && run.errorCode === RUNNER_REVISION_MISMATCH_CODE) opts = { ...RUNNER_REVISION_MISMATCH_RETRY, ...opts }; if (!opts?.retryReason && run.errorCode === STORAGE_UNAVAILABLE_CODE) opts = { ...STORAGE_UNAVAILABLE_RETRY, ...opts }; + if (!opts?.retryReason && run.errorCode === WORKSPACE_RUNTIME_UPDATING_CODE) opts = { ...WORKSPACE_RUNTIME_UPDATING_RETRY, ...opts }; if (!opts?.retryReason && run.errorCode === ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE && (run.scheduledRetryReason === ENVIRONMENT_PROVIDER_WAIT_RETRY_REASON || executionFailureRetryCount(run) >= BOUNDED_TRANSIENT_HEARTBEAT_RETRY_MAX_ATTEMPTS)) { @@ -657,7 +661,9 @@ export function createHeartbeatRetries(db: Db, dependencies: HeartbeatRetryDepen payload: exhaustion, retryExhaustion: exhaustion, }); - if (retryReason === INTERACTION_CONTINUATION_INFRA_RETRY_REASON || (retryReason === STORAGE_UNAVAILABLE_WAIT_RETRY_REASON + // An answered interaction whose preparation wait ran out gets the same handoff as an exhausted interaction retry. + if (retryReason === INTERACTION_CONTINUATION_INFRA_RETRY_REASON || ((retryReason === STORAGE_UNAVAILABLE_WAIT_RETRY_REASON + || retryReason === WORKSPACE_RUNTIME_UPDATING_RETRY.retryReason) && isResolvedInteractionContinuationWakeContext(run.contextSnapshot))) { await escalatePlanApprovalResumeFailureNeedsAttention({ run, diff --git a/server/src/services/heartbeat/run-completion.test.ts b/server/src/services/heartbeat/run-completion.test.ts index b0f061a6407..1d8b872ed18 100644 --- a/server/src/services/heartbeat/run-completion.test.ts +++ b/server/src/services/heartbeat/run-completion.test.ts @@ -36,7 +36,7 @@ import { environmentTaskErrorCodeData, JsonRpcCallError, PLUGIN_RPC_ERROR_CODES, import { RUNNER_REVISION_MISMATCH_RETRY } from "../runner-revision-mismatch.js"; import { STORAGE_CREDENTIALS_REJECTED_HELD_MESSAGE, STORAGE_UNAVAILABLE_CODE, STORAGE_UNAVAILABLE_EXHAUSTED_MESSAGE, STORAGE_UNAVAILABLE_HELD_MESSAGE, STORAGE_UNAVAILABLE_MESSAGE, STORAGE_UNAVAILABLE_RETRY } from "../../storage/storage-unavailable.js"; import { withS3FailureDiagnostics } from "../../storage/s3-failure.js"; -import { workspaceProviderCallFailure } from "../workspace-provider-failure.js"; +import { WORKSPACE_RUNTIME_UPDATING_RETRY, workspaceProviderCallFailure } from "../workspace-provider-failure.js"; import { logger } from "../../middleware/logger.js"; import { unprocessable } from "../../errors.js"; import { ACCOUNTING_CONTENTION_MESSAGE, AccountingContentionError } from "../accounting-transaction.js"; @@ -1875,6 +1875,34 @@ describe.skipIf(!support.supported && !process.env.PAPERCLIP_TEST_DATABASE_URL)( } else expect(f.deps.scheduleBoundedRetryForRun).not.toHaveBeenCalled(); }); + const runtimeUpdating = () => workspaceProviderCallFailure(new JsonRpcCallError({ code: PLUGIN_RPC_ERROR_CODES.WORKER_ERROR, + message: "private provider text", data: workspaceOperationErrorData(new PluginWorkspaceOperationError("runtime_updating")) })); + + it.each(["fresh", "started", "retained"] as const)("waits for an updating runtime after a %s refusal instead of the two-attempt bootstrap retry", async scenario => { + const f = await fixture({ runtimeMode: scenario === "retained" ? "native" : "legacy" }); + f.deps.scheduleBoundedRetryForRun.mockResolvedValueOnce({ outcome: "not_scheduled", reason: "Fixture scheduler boundary", issueId: null }); + await f.completion.failRunSetup(f.setup(runtimeUpdating(), scenario === "started")); + const failed = await read(f.run.id); + expect(failed).toMatchObject({ status: "failed", errorCode: scenario === "fresh" ? "workspace_runtime_updating" : "setup_failed", + error: "The selected runtime is updating; retry the same workspace after the update" }); + expect(failed.error).not.toContain("private"); + if (scenario === "fresh") { + expect(failed.resultJson).toMatchObject({ executionRecovery: { kind: "bootstrap", providerWorkStarted: false }, + workspaceProviderFailure: { kind: "provider", reason: "runtime_updating", retryable: true } }); + expect(f.deps.scheduleBoundedRetryForRun).toHaveBeenCalledWith(expect.objectContaining({ id: f.run.id }), f.agent, WORKSPACE_RUNTIME_UPDATING_RETRY); + } else expect(f.deps.scheduleBoundedRetryForRun).not.toHaveBeenCalled(); + }); + + it("waits for an updating runtime on an answered interaction instead of its two-attempt continuation retry", async () => { + const f = await fixture({ contextSnapshot: { interactionId: "interaction-1", interactionStatus: "answered", interactionKind: "ask_user_questions", + mutation: "interaction", wakeReason: "issue_commented" } }); + f.deps.scheduleBoundedRetryForRun.mockResolvedValueOnce({ outcome: "not_scheduled", reason: "Fixture scheduler boundary", issueId: null }); + await f.completion.failRunSetup(f.setup(runtimeUpdating())); + expect(await read(f.run.id)).toMatchObject({ status: "failed", errorCode: "workspace_runtime_updating" }); + expect(f.deps.scheduleBoundedRetryForRun).toHaveBeenCalledWith(expect.objectContaining({ id: f.run.id }), f.agent, WORKSPACE_RUNTIME_UPDATING_RETRY); + expect(f.deps.scheduleInteractionContinuationInfrastructureRetryIfEligible).not.toHaveBeenCalled(); + }); + it.each(["context_changed", "deadline_exceeded"] as const)("keeps a retryable %s provider answer a generic setup failure", async reason => { const f = await fixture(); await f.completion.failRunSetup(f.setup(workspaceProviderCallFailure(new JsonRpcCallError({ code: PLUGIN_RPC_ERROR_CODES.WORKER_ERROR, diff --git a/server/src/services/heartbeat/run-completion.ts b/server/src/services/heartbeat/run-completion.ts index 2739bede80d..13ede6a8124 100644 --- a/server/src/services/heartbeat/run-completion.ts +++ b/server/src/services/heartbeat/run-completion.ts @@ -40,7 +40,8 @@ import { findReusableSandboxResumeError } from "../reusable-sandbox-resume-error import { findPluginWorkerUnavailableError, PLUGIN_WORKER_UNAVAILABLE_CODE } from "../plugin-worker-unavailable-error.js"; import { ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE, findEnvironmentProviderUnavailableError } from "../environment-provider-unavailable-error.js"; import { REPOSITORY_CATALOG_UNAVAILABLE_CODE, findRepositoryCatalogUnavailableError } from "../repository-catalog-unavailable-error.js"; -import { findRetryableWorkspaceStorageSetupCode, findWorkspaceProviderFailure, WORKSPACE_STORAGE_RETRY_CODES } from "../workspace-provider-failure.js"; +import { findRetryableWorkspaceStorageSetupCode, findWorkspaceProviderFailure, WORKSPACE_RUNTIME_UPDATING_CODE, WORKSPACE_RUNTIME_UPDATING_RETRY, + WORKSPACE_STORAGE_RETRY_CODES } from "../workspace-provider-failure.js"; import { isRunnerRevisionMismatch, RUNNER_REVISION_MISMATCH_CODE, RUNNER_REVISION_MISMATCH_RETRY } from "../runner-revision-mismatch.js"; import { readPluginTaskError } from "../environment-task-runtime.js"; import { isStorageUnavailableError, STORAGE_CREDENTIALS_REJECTED_MESSAGE, STORAGE_UNAVAILABLE_CODE, STORAGE_UNAVAILABLE_EXHAUSTED_MESSAGE, STORAGE_UNAVAILABLE_MESSAGE, STORAGE_UNAVAILABLE_RETRY, storageUnavailableHeldMessage, storageUnavailableMessage } from "../../storage/storage-unavailable.js"; @@ -1736,7 +1737,8 @@ export function createHeartbeatRunCompletion(db: Db, dependencies: HeartbeatRunC const pluginWorkerUnavailableFailure = !providerDispatchStarted && run.runtimeMode === "legacy" && run.nativeSessionId === null && run.runnerInstanceId === null ? findPluginWorkerUnavailableError(outerErr) : null; // Retryable pre-dispatch workspace storage failures (`storage_pending` and - // `remote_incomplete`) retry the same workspace within the bootstrap budget. + // `remote_incomplete`) retry the same workspace within the bootstrap budget; + // an updating runtime (`runtime_updating`) waits in its own lane. const workspaceStorageRetryCode = !providerDispatchStarted && run.runtimeMode === "legacy" && run.nativeSessionId === null && run.runnerInstanceId === null ? findRetryableWorkspaceStorageSetupCode(outerErr) : null; @@ -1976,7 +1978,9 @@ export function createHeartbeatRunCompletion(db: Db, dependencies: HeartbeatRunC ? scheduleBoundedRetryForRun(livenessRun, failedAgent, RUNNER_REVISION_MISMATCH_RETRY) : livenessRun.errorCode === STORAGE_UNAVAILABLE_CODE ? scheduleBoundedRetryForRun(livenessRun, failedAgent, STORAGE_UNAVAILABLE_RETRY) - : scheduleBoundedRetryForRun(livenessRun, failedAgent) + : livenessRun.errorCode === WORKSPACE_RUNTIME_UPDATING_CODE + ? scheduleBoundedRetryForRun(livenessRun, failedAgent, WORKSPACE_RUNTIME_UPDATING_RETRY) + : scheduleBoundedRetryForRun(livenessRun, failedAgent) : scheduleNativePreDispatchRetry(livenessRun, failedAgent).then(nativeRetry => nativeRetry ?? scheduleInteractionContinuationInfrastructureRetryIfEligible(livenessRun, failedAgent)) ).catch((retryError) => { diff --git a/server/src/services/legacy-execution-recovery.ts b/server/src/services/legacy-execution-recovery.ts index 7d3980ab94d..e06c38919ee 100644 --- a/server/src/services/legacy-execution-recovery.ts +++ b/server/src/services/legacy-execution-recovery.ts @@ -10,7 +10,7 @@ import { isPreDispatchExecutionWaitVerified } from "./pre-dispatch-execution-wai import { REMOTE_WORKSPACE_PREPARATION_TIMEOUT_CODE, REMOTE_WORKSPACE_RESTORE_FAILED_CODE } from "./remote-workspace-transport.js"; import { REUSABLE_SANDBOX_RESUME_FAILED_CODE } from "./reusable-sandbox-resume-error.js"; import { PLUGIN_WORKER_UNAVAILABLE_CODE } from "./plugin-worker-unavailable-error.js"; -import { WORKSPACE_STORAGE_INCOMPLETE_CODE, WORKSPACE_STORAGE_PENDING_CODE } from "./workspace-provider-failure.js"; +import { WORKSPACE_RUNTIME_UPDATING_CODE, WORKSPACE_STORAGE_INCOMPLETE_CODE, WORKSPACE_STORAGE_PENDING_CODE } from "./workspace-provider-failure.js"; import { ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE } from "./environment-provider-unavailable-error.js"; import { REPOSITORY_CATALOG_UNAVAILABLE_CODE } from "./repository-catalog-unavailable-error.js"; import { RUNNER_REVISION_MISMATCH_CODE } from "./runner-revision-mismatch.js"; @@ -91,6 +91,7 @@ export function legacyExecutionNeedsReconciliation( || run.errorCode === REMOTE_WORKSPACE_PREPARATION_TIMEOUT_CODE || run.errorCode === REUSABLE_SANDBOX_RESUME_FAILED_CODE || run.errorCode === REMOTE_WORKSPACE_RESTORE_FAILED_CODE || run.errorCode === PLUGIN_WORKER_UNAVAILABLE_CODE || run.errorCode === WORKSPACE_STORAGE_PENDING_CODE || run.errorCode === WORKSPACE_STORAGE_INCOMPLETE_CODE + || run.errorCode === WORKSPACE_RUNTIME_UPDATING_CODE || run.errorCode === RUNNER_REVISION_MISMATCH_CODE || run.errorCode === ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE || run.errorCode === REPOSITORY_CATALOG_UNAVAILABLE_CODE) && evidence?.kind === "bootstrap" && evidence.providerWorkStarted === false) return false; diff --git a/server/src/services/recovery/service.ts b/server/src/services/recovery/service.ts index 7359fa46f75..a02a151b952 100644 --- a/server/src/services/recovery/service.ts +++ b/server/src/services/recovery/service.ts @@ -201,7 +201,7 @@ import { } from "./origins.js"; import { withRecoveryContext } from "./status-only-context.js"; import { getExecutionBlocker } from "../execution-blocker.js"; -import { readWorkspaceProviderFailure, WORKSPACE_STORAGE_INCOMPLETE_CODE, WORKSPACE_STORAGE_PENDING_CODE } from "../workspace-provider-failure.js"; +import { readWorkspaceProviderFailure, WORKSPACE_RUNTIME_UPDATING_CODE, WORKSPACE_STORAGE_INCOMPLETE_CODE, WORKSPACE_STORAGE_PENDING_CODE } from "../workspace-provider-failure.js"; import { currentRunFailureText } from "../native-runtime/native-exact-resume-failure.js"; import { isAutomaticRecoverySuppressedByPauseHold } from "./pause-hold-guard.js"; import { rehomeStrandedLegacyWorkspaceTasks } from "./legacy-workspace-rehome.js"; @@ -661,6 +661,7 @@ const NON_RETRYABLE_CONTINUATION_ERROR_CODES = new Set([ PLUGIN_WORKER_UNAVAILABLE_CODE, WORKSPACE_STORAGE_PENDING_CODE, WORKSPACE_STORAGE_INCOMPLETE_CODE, + WORKSPACE_RUNTIME_UPDATING_CODE, ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE, RUNNER_REVISION_MISMATCH_CODE, "low_trust_isolation_unavailable", diff --git a/server/src/services/recovery/stranded-notice.ts b/server/src/services/recovery/stranded-notice.ts index 9de2029ccd7..0cce199deb9 100644 --- a/server/src/services/recovery/stranded-notice.ts +++ b/server/src/services/recovery/stranded-notice.ts @@ -84,6 +84,7 @@ const WORKSPACE_SCAN_NOTICES: Record([WORKSPACE_BUSY_RETRY_REASON, AI_CONNECTION_BUSY_RETRY_REASON, AI_CONNECTION_POOL_WAIT_RETRY_REASON, RUNNER_REVISION_WAIT_RETRY_REASON, STORAGE_UNAVAILABLE_WAIT_RETRY_REASON, - AGENT_DIRECTORY_WAIT_RETRY_REASON]); + AGENT_DIRECTORY_WAIT_RETRY_REASON, RUNTIME_UPDATE_WAIT_RETRY_REASON]); // A due same-run resume dispatches within seconds; past this, offer Retry. const NATIVE_RESUME_DISPATCH_GRACE_MS = 2 * 60_000; diff --git a/server/src/services/workspace-provider-failure.ts b/server/src/services/workspace-provider-failure.ts index 5f6531e2efb..4810ef2479c 100644 --- a/server/src/services/workspace-provider-failure.ts +++ b/server/src/services/workspace-provider-failure.ts @@ -35,6 +35,8 @@ const REASONS: Record([ WORKSPACE_STORAGE_PENDING_CODE, WORKSPACE_STORAGE_INCOMPLETE_CODE, + WORKSPACE_RUNTIME_UPDATING_CODE, ]); const RETRYABLE_PROVIDER_REASON_TO_SETUP_CODE: Partial> = { storage_pending: WORKSPACE_STORAGE_PENDING_CODE, remote_incomplete: WORKSPACE_STORAGE_INCOMPLETE_CODE, + runtime_updating: WORKSPACE_RUNTIME_UPDATING_CODE, }; /** Classify a retryable pre-dispatch workspace provider reason to its transient setup code. */ diff --git a/tests/runner-e2e/source-sdk-public-inputs.json b/tests/runner-e2e/source-sdk-public-inputs.json index af82e40c0b1..52b16ea8e4b 100644 --- a/tests/runner-e2e/source-sdk-public-inputs.json +++ b/tests/runner-e2e/source-sdk-public-inputs.json @@ -30,7 +30,7 @@ "packages/plugins/sdk/src/ui/runtime.ts": "998428e9701eba3b762d3417236d32c2d0d5763d", "packages/plugins/sdk/src/ui/types.ts": "5a5644acf6554d2e5e1d000bfd03b97d57001eb2", "packages/plugins/sdk/src/worker-rpc-host.ts": "1fe5ce2c81362af765db249a4c804dfd04688683", - "packages/plugins/sdk/src/workspace-operation-error.ts": "2cd247d002d83b163239229e631bca4e519e5075", + "packages/plugins/sdk/src/workspace-operation-error.ts": "6bee7252ff52d755e0207c72219c1964bbc63796", "packages/plugins/sdk/src/workspace-provider.ts": "38e945b807f22150710c11b136af0a28aab2cb7c", "packages/plugins/sdk/tsconfig.json": "d62ebdff94bc4b75dabf1fcad187e1e7a90fc794", "packages/shared/package.json": "0d417d9a3db4fd099b1fe2e0c0a3fa52eee243cf",