From ab79cb9cdd2448b6d65f30994c15208e40ff2fa8 Mon Sep 17 00:00:00 2001 From: paperclipbugbot Date: Fri, 4 Dec 2026 15:31:15 -0800 Subject: [PATCH] fix(heartbeat): wait for an updating runtime before workspace setup fails (#23779) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Before a run starts its agent, Paperclip prepares the task workspace through a workspace provider plugin > - A hosted agent computer can apply an update. While it updates, it finishes its running tasks and refuses new workspaces > - The provider can only report this refusal as a generic `remote_incomplete` failure. Setup retries that failure two times in about 90 seconds (#23764), but an update can wait for running tasks for an hour > - So each new task on that computer fails setup, reports an error, and stops, although it only had to wait > - This pull request adds the closed provider reason `runtime_updating` and a separate wait lane for it. Setup holds the run and retries the same workspace every 2 minutes for up to 1 hour. The wait does not use the failure retry budget, and Paperclip does not report the run as a failure while the wait continues > - The benefit is that new tasks wait for an updating agent computer and then start, instead of failing ## Linked Issues or Issue Description Refs #23764, #23362 **What happened?** A hosted agent computer refused every new workspace preparation while it applied an update and finished its long running tasks. The provider reported each refusal as `remote_incomplete`. Setup failed each new run. Every retry of the same workspace failed the same way, and each failure was reported to error tracking. On one staging stack this happened 34 times in two hours, for two agents. **Expected behavior** A provider can say that the selected runtime is updating. Setup then holds the run and retries the same workspace after the update. The retry does not spend the failure budget. Paperclip reports the failure only if the wait ends without success. **Steps to reproduce** 1. Start a legacy run whose workspace preparation calls a workspace provider plugin. 2. Have the provider reject preparation because its runtime is updating. Before this change, the only fitting reason is `remote_incomplete`. 3. Setup records `workspace_storage_incomplete` and retries two times (30 s and 60 s). Then the task stops and the failure is reported, while the runtime is still updating. **Paperclip version or commit** `master` at `30334c1f03`. **Deployment mode** Hosted (Paperclip Cloud agent computers). A self-hosted workspace provider can use the same reason. ## What Changed - `packages/plugins/sdk/src/workspace-operation-error.ts`: add the closed reason `runtime_updating` ("the selected runtime is applying an update and refuses new workspaces until it finishes"). - `server/src/services/workspace-provider-failure.ts`: give `runtime_updating` a fixed, retryable message. Map it to the new setup code `workspace_runtime_updating`. Add `WORKSPACE_RUNTIME_UPDATING_RETRY` (reason `runtime_update_wait`, 30 attempts, 2 minutes apart). Add the code to `WORKSPACE_STORAGE_RETRY_CODES`, so the existing deferred error report also covers it. - `server/src/services/heartbeat/run-completion.ts` and `heartbeat/retries.ts`: schedule a failed pre-dispatch `workspace_runtime_updating` run with the wait lane, and use the lane's budget in `failedRunRetryBudgetSpent`. This is the same pattern as `runner_revision_mismatch`. - `server/src/services/execution-recovery-attempt.ts`, `modules/run-dispatch/domain/wake-context.ts`, `task-interruption-presentation.ts`: `runtime_update_wait` is an uncharged preparation wait. An answered interaction keeps its continuation through the wait, and the task shows a wait, not a failure. - `failed-preparation-retry.ts`, `legacy-execution-recovery.ts`, `recovery/service.ts`, `agent-task-run-telemetry.ts`: treat `workspace_runtime_updating` like the other transient workspace preparation codes. - `recovery/stranded-notice.ts`: add a notice for a wait that ended without success ("Agent computer was still updating"). ## Verification - Red before the change (test files only, source reverted): 9 new tests fail in `workspace-provider-failure.test.ts`, `execution-recovery-attempt.test.ts`, `heartbeat/retries.test.ts`, `heartbeat/run-completion.test.ts` and `run-failure-report-sandbox-resume.test.ts`. - `pnpm verify` did not run: its workspace link repair failed for `plugin-orchestration-smoke-example`, before test selection. The SDK change also affects many packages, so CI supplies the broad coverage. - Green after the change: the same 5 files pass (267 tests). Related files also pass: `task-interruption-automatic-path`, `task-interruption-query`, `wake-context`, `stranded-notice-remote-workspace-environment`, `task-interruption-presentation` (181 tests); `agent-task-run-telemetry`, `legacy-continuation-authority`, `heartbeat-retry-scheduling` (179 tests); plugin SDK `workspace-operation-error`, `workspace-provider` (20 tests). - `pnpm --dir server typecheck` and `pnpm --filter @paperclipai/plugin-sdk typecheck`: pass (server typecheck run with `PAPERCLIP_TYPECHECK_LOW_MEMORY=1` because of a local memory limit). - CI supplies the full suite. - Review follow-up (`cf73701742`, `d7540263bd`): update waits keep their count in `executionRetryAccounting` (`runtimeUpdateWaits`) across other retry lanes. An answered interaction whose update wait runs out is escalated like an exhausted storage wait. The pinned SDK input registry is refreshed. The two new tests failed before the fix and pass after it. `execution-recovery-attempt`, `heartbeat/retries`, `workspace-provider-failure` and `run-failure-report-sandbox-resume` pass (83 tests). `heartbeat/run-completion` and `modules/wake-queue` pass (577 tests). `tests/runner-e2e/source-sdk-public-inputs` passes (13 tests). `pnpm --dir server typecheck` passes. ## Risks - Low risk. No schema, migration, API route or wire protocol shape change. The reason set is closed and validated on both sides. An older Core that receives `runtime_updating` treats it as an unknown provider failure, as before. - A provider must not send `runtime_updating` before the new SDK is available to it. The SDK constructor rejects an unknown reason, so a provider update has to follow this change. - The wait is a bounded scheduled retry after a real refusal, not idle polling: at most 30 retries in one hour per waiting run. Each retry is one workspace preparation call. When the wait ends without success, the run is reported and the task shows a named notice with a Retry action. - Only legacy runs that fail before provider dispatch use the lane. Started and native runs keep `setup_failed`. ## Model Used - Anthropic Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code with tool use (code search, file edits, shell, local test execution, GitHub CLI). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../sdk/src/workspace-operation-error.ts | 6 ++++ .../workspace-provider-failure.test.ts | 24 +++++++++++++- .../run-dispatch/domain/wake-context.ts | 4 ++- server/src/modules/run-dispatch/index.ts | 1 + .../modules/wake-queue/adapters/postgres.ts | 2 +- .../run-failure-report-sandbox-resume.test.ts | 18 +++++++++- .../src/services/agent-task-run-telemetry.ts | 1 + .../execution-recovery-attempt.test.ts | 33 +++++++++++++++++-- .../services/execution-recovery-attempt.ts | 12 ++++++- .../src/services/failed-preparation-retry.ts | 3 +- server/src/services/heartbeat/retries.test.ts | 31 +++++++++++++++++ server/src/services/heartbeat/retries.ts | 10 ++++-- .../services/heartbeat/run-completion.test.ts | 30 ++++++++++++++++- .../src/services/heartbeat/run-completion.ts | 10 ++++-- .../src/services/legacy-execution-recovery.ts | 3 +- server/src/services/recovery/service.ts | 3 +- .../src/services/recovery/stranded-notice.ts | 1 + .../src/services/run-failure-diagnostics.ts | 4 +-- server/src/services/run-failure-report.ts | 5 +-- .../task-interruption-presentation.ts | 4 +-- .../services/workspace-provider-failure.ts | 20 +++++++++++ .../runner-e2e/source-sdk-public-inputs.json | 2 +- 22 files changed, 204 insertions(+), 23 deletions(-) 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",