From 3b380c6b15f5c5ce3a89c07dd4638f7a121c507e Mon Sep 17 00:00:00 2001 From: paperclipbugbot Date: Wed, 2 Dec 2026 22:51:09 -0800 Subject: [PATCH] fix(workspaces): name a saved remote workspace the agent's environment cannot use (#23586) 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. > - Paperclip can keep a task's workspace in remote storage. Only a Paperclip Runner agent in a sandbox environment, or a supported agent in an SSH environment, can restore and save that workspace. > - An agent can move to another environment, for example from a sandbox to a plugin computer. Its tasks keep their saved remote workspaces. > - When such a task woke, workspace preparation threw a bare 409: "This workspace requires a supported remote execution environment." The run ended `setup_failed`. The task offered Retry, and each Retry failed the same way. Sentry received each refusal as an unexpected run failure. > - This is a known configuration state that only an owner can repair, like the project-storage mismatch from #22398. > - This pull request refuses that run as `configuration_incomplete` with a named reason, and it tells the owner what to do. > - The benefit is an actionable task notice, no Retry loop, and no Sentry noise for this state. ## Linked Issues or Issue Description Refs #22398 (the same treatment for a source project's storage that the environment cannot serve). Refs #23568 (that change gave this refusal its own run-failure group, so it became visible as a separate error). **What happened?** A task's workspace was saved in remote storage by an agent in a Daytona sandbox. The agent was later moved to a plugin computer environment. An automatic wake on the task failed setup with "This workspace requires a supported remote execution environment." The run ended `setup_failed`. The task notice said to press Retry. Retry cannot help, because the agent's environment still cannot use the saved workspace. Sentry received the refusal as an unexpected run failure. **Expected behavior** The refusal names the cause: the saved workspace is in remote storage, and the agent's environment cannot use it. The run fails `configuration_incomplete`. The task notice tells the owner to assign the task to an agent that can use the saved workspace, or to change the agent's environment. Sentry does not receive this known configuration state. The saved workspace stays unchanged. **Steps to reproduce** 1. Save a task workspace in remote storage with a Paperclip Runner agent in a sandbox environment. 2. Change the agent's environment to a plugin computer (or assign the task to an agent in another environment). 3. Wake the agent on the task. The run fails `setup_failed` with the bare 409 message. **Paperclip version or commit** Seen on hosted staging. The new regression tests fail on `master` at fc09515c7e and pass with this change. ## What Changed - `remote-workspaces.ts`: extract `supportsRemoteWorkspaceExecution(adapterType, driver)`. `shouldUseRemoteWorkspaces` uses it. Its own behavior is unchanged. - `workspace-preparation.ts`: when the task's existing workspace has remote authority and the selected executor cannot use it, preparation throws `ConfigurationIncompleteFailure` with reason `remote_workspace_environment_incompatible`. This happens before workspace resolution and environment acquisition. The payload records the workspace, environment, driver, adapter, a stable fingerprint, and the agent runtime action URL. Controller-only runs keep their existing path. - `run-failure-report.ts`: the exact pre-dispatch outcome is skipped, together with `project_storage_environment_incompatible`. A marker after provider work started, during execution, under another error code, or outside the setup report is still reported. `PAPERCLIP_SENTRY_RUN_FAILURES=all` still reports it. - `stranded-notice.ts` and `recovery/service.ts`: the task notice and the recovery next action name the owner action. Before this change, the unknown reason fell back to the "missing secret" text. - `doc/workspace-storage.md`: describe the new outcome. ## Verification - Red before the fix, green after (red captured on fc09515c7e with only the tests applied): - `server/src/services/heartbeat/workspace-preparation.test.ts` › "names a remote-storage workspace that the agent's environment cannot use as an owner configuration gap". Before: the run failed with the bare 409 "This workspace requires a supported remote execution environment." After: `configuration_incomplete` with the named reason and payload. The test also confirms that no workspace is resolved, no environment is acquired, the saved remote authority is unchanged, and the task keeps its workspace binding. - `server/src/services/__tests__/run-failure-report-remote-workspace-environment.test.ts` › "keeps a remote workspace the agent's environment cannot use on the task before dispatch". Before: Sentry received the run. - `server/src/services/recovery/stranded-notice-remote-workspace-environment.test.ts`. Before: the notice said that a secret was missing. - Safety cases (pass before and after): 11 marker variants are still reported (other status, `setup_failed`, executing stage, exit code, signal, no bootstrap marker, provider work started, other reason, no setup phase, execute phase, `all` mode). The existing remote-workspaces integration cases "preserves enrolled workspaces after disabling enrollment and rejects a legacy writer" and "keeps enrollment conditional…" pass. The full `workspace-preparation.test.ts` (161 tests) passes, including the sandbox enrollment paths. - Commands (local, Node 24.23, embedded Postgres): - `pnpm exec vitest run src/services/recovery/stranded-notice-remote-workspace-environment.test.ts src/services/__tests__/run-failure-report-remote-workspace-environment.test.ts src/services/__tests__/run-failure-report-project-access.test.ts src/services/heartbeat/workspace-preparation.test.ts src/__tests__/run-failure-sentry.test.ts` (server) - `pnpm exec vitest run src/services/remote-workspaces.integration.test.ts -t "preserves enrolled workspaces|keeps enrollment conditional"` (server) - `PAPERCLIP_TYPECHECK_LOW_MEMORY=1 pnpm --filter @paperclipai/server typecheck` (passed) - `pnpm verify` selected a broad plan because a doc changed. Required CI supplies the broad coverage. ## Risks - Low risk. The new path runs only where `shouldUseRemoteWorkspaces` already threw. No run that started before can fail now. - For those refused runs, only the failure code, the message, the notice, and the Sentry decision change. - The saved remote workspace and the task's binding are not changed. The owner still chooses a compatible agent or environment. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in a sandboxed workspace. ## 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 - [ ] 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 --- doc/workspace-storage.md | 11 ++ ...eport-remote-workspace-environment.test.ts | 132 ++++++++++++++++++ .../heartbeat/workspace-preparation.test.ts | 48 +++++++ .../heartbeat/workspace-preparation.ts | 28 +++- server/src/services/recovery/service.ts | 4 + ...otice-remote-workspace-environment.test.ts | 19 +++ .../src/services/recovery/stranded-notice.ts | 11 ++ .../remote-workspace-environment-reason.ts | 1 + server/src/services/remote-workspaces.ts | 8 +- server/src/services/run-failure-report.ts | 11 +- 10 files changed, 266 insertions(+), 7 deletions(-) create mode 100644 server/src/services/__tests__/run-failure-report-remote-workspace-environment.test.ts create mode 100644 server/src/services/recovery/stranded-notice-remote-workspace-environment.test.ts create mode 100644 server/src/services/remote-workspace-environment-reason.ts diff --git a/doc/workspace-storage.md b/doc/workspace-storage.md index a34af183503..4753a96de7e 100644 --- a/doc/workspace-storage.md +++ b/doc/workspace-storage.md @@ -378,6 +378,17 @@ ends the run `configuration_incomplete` (reason `project_storage_environment_incompatible`). See [project-environment-compatibility.md](project-environment-compatibility.md). +A workspace already saved in remote storage stays there. Only a Paperclip +Runner agent in a sandbox environment, or a supported agent in an SSH +environment, can restore and save it. When the task's agent now runs in another +environment (for example, it moved to a plugin computer), preparation refuses +the run before any workspace or environment work and ends it +`configuration_incomplete` (reason `remote_workspace_environment_incompatible`). +The saved workspace and the task's binding to it are unchanged. The task +notice asks the owner to assign the task to an agent that can use the saved +workspace, or to change the agent's environment. Run-failure reporting skips +this pre-dispatch outcome. + A replacement controller reconstructs an active remote agent-directory cache from the registered sandbox, including unsaved files. The remote directory, lease and save baseline remain unchanged; current canonical files are never diff --git a/server/src/services/__tests__/run-failure-report-remote-workspace-environment.test.ts b/server/src/services/__tests__/run-failure-report-remote-workspace-environment.test.ts new file mode 100644 index 00000000000..af8d2bf2c55 --- /dev/null +++ b/server/src/services/__tests__/run-failure-report-remote-workspace-environment.test.ts @@ -0,0 +1,132 @@ +import { randomUUID } from "node:crypto"; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { agents, applyPendingMigrations, closeRegisteredClients, companies, createDb, heartbeatRuns } from "@paperclipai/db"; +import { + getEmbeddedPostgresTestSupport, + startEmbeddedPostgresTestDatabase, +} from "../../__tests__/helpers/embedded-postgres.js"; + +const mockCaptureRunFailure = vi.hoisted(() => vi.fn()); + +vi.mock("../../sentry.js", () => ({ + captureRunFailure: mockCaptureRunFailure, +})); + +import { reportRunFailure } from "../run-failure-report.js"; + +const testDatabaseUrl = process.env.PAPERCLIP_TEST_DATABASE_URL; +const embeddedPostgresSupport = testDatabaseUrl ? { supported: true } : await getEmbeddedPostgresTestSupport(); +const describeEmbeddedPostgres = embeddedPostgresSupport.supported ? describe : describe.skip; + +describeEmbeddedPostgres("reportRunFailure remote workspace environment gaps", () => { + let db!: ReturnType; + let tempDb: Awaited> | null = null; + let companyId!: string; + let agentId!: string; + let inheritedEnv: NodeJS.ProcessEnv; + + beforeAll(async () => { + if (testDatabaseUrl) { + await applyPendingMigrations(testDatabaseUrl); + db = createDb(testDatabaseUrl); + } else { + tempDb = await startEmbeddedPostgresTestDatabase("paperclip-run-failure-remote-workspace-environment-"); + db = createDb(tempDb.connectionString); + } + }, 20_000); + + beforeEach(async () => { + inheritedEnv = process.env; + process.env = Object.fromEntries( + ["PATH", "HOME", "USER", "USERNAME", "LOGNAME", "USERPROFILE", "TMPDIR", "TEMP", "TMP"] + .flatMap((key) => inheritedEnv[key] === undefined ? [] : [[key, inheritedEnv[key]]]), + ); + process.env.PAPERCLIP_SENTRY_RUN_FAILURES = "unexpected"; + companyId = randomUUID(); + agentId = randomUUID(); + await db.insert(companies).values({ + id: companyId, + name: "Paperclip", + issuePrefix: `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`, + requireBoardApprovalForNewAgents: false, + defaultResponsibleUserId: "responsible-user", + }); + await db.insert(agents).values({ + id: agentId, + companyId, + name: "Runner", + role: "engineer", + status: "active", + adapterType: "paperclip_runner", + adapterConfig: {}, + runtimeConfig: {}, + permissions: {}, + }); + }); + + afterEach(async () => { + vi.clearAllMocks(); + vi.unstubAllEnvs(); + process.env = inheritedEnv; + await db.delete(heartbeatRuns); + await db.delete(agents); + await db.delete(companies); + }); + + afterAll(async () => { + if (testDatabaseUrl) await closeRegisteredClients(testDatabaseUrl); + await tempDb?.cleanup(); + }); + + const configurationIncomplete = () => ({ + reason: "remote_workspace_environment_incompatible", executionWorkspaceId: randomUUID(), environmentId: randomUUID(), + environmentDriver: "plugin", adapterType: "paperclip_runner", + }); + + function remoteWorkspaceEnvironmentRun( + overrides: Partial = {}, + ): typeof heartbeatRuns.$inferSelect { + return { + id: randomUUID(), + companyId, + agentId, + status: "failed", + error: "This task's saved workspace is kept in remote workspace storage, which the environment \"Agent Computer\" cannot use.", + errorCode: "configuration_incomplete", + executionStage: "preparing", + nativeIssueId: randomUUID(), + contextSnapshot: null, + resultJson: { + configurationIncomplete: configurationIncomplete(), + executionRecovery: { kind: "bootstrap", providerWorkStarted: false }, + }, + ...overrides, + } as unknown as typeof heartbeatRuns.$inferSelect; + } + + it("keeps a remote workspace the agent's environment cannot use on the task before dispatch", async () => { + await reportRunFailure(db, remoteWorkspaceEnvironmentRun(), { phase: "setup" }); + expect(mockCaptureRunFailure).not.toHaveBeenCalled(); + }); + + it.each([ + { status: "timed_out" }, { errorCode: "setup_failed" }, { executionStage: "executing" }, { exitCode: 1 }, { signal: "SIGTERM" }, + { resultJson: { configurationIncomplete: configurationIncomplete() } }, + { resultJson: { configurationIncomplete: configurationIncomplete(), executionRecovery: { kind: "bootstrap", providerWorkStarted: true } } }, + { resultJson: { configurationIncomplete: { reason: "something_else" }, executionRecovery: { kind: "bootstrap", providerWorkStarted: false } } }, + ])("reports remote workspace environment markers without an exact pre-dispatch outcome: %j", async (overrides) => { + await reportRunFailure(db, remoteWorkspaceEnvironmentRun(overrides), { phase: "setup" }); + expect(mockCaptureRunFailure).toHaveBeenCalledTimes(1); + }); + + it.each([undefined, "execute"] as const)("reports remote workspace environment markers outside the setup report: %s", async (phase) => { + await reportRunFailure(db, remoteWorkspaceEnvironmentRun(), { phase }); + expect(mockCaptureRunFailure).toHaveBeenCalledTimes(1); + }); + + it("reports the remote workspace environment gap when every run failure is reported", async () => { + vi.stubEnv("PAPERCLIP_SENTRY_RUN_FAILURES", "all"); + await reportRunFailure(db, remoteWorkspaceEnvironmentRun(), { phase: "setup" }); + expect(mockCaptureRunFailure).toHaveBeenCalledTimes(1); + }); +}); diff --git a/server/src/services/heartbeat/workspace-preparation.test.ts b/server/src/services/heartbeat/workspace-preparation.test.ts index c0c234c23a8..9ab2c78591b 100644 --- a/server/src/services/heartbeat/workspace-preparation.test.ts +++ b/server/src/services/heartbeat/workspace-preparation.test.ts @@ -254,6 +254,54 @@ describe.skipIf(!support.supported && !externalDatabaseUrl)("heartbeat workspace expect((await db.select().from(executionWorkspaces))[0]?.metadata?.remoteWorkspace).toBeUndefined(); }); + it("names a remote-storage workspace that the agent's environment cannot use as an owner configuration gap", async () => { + const { input, issue, envOrchestrator } = await fixture(); + const remoteWorkspace = { schema: "paperclip.remote-workspace.v1", epoch: 3, snapshotId: randomUUID(), + source: { kind: "empty" }, location: null, writerRunId: null, dirty: false }; + const [workspace] = await db.insert(executionWorkspaces).values({ companyId: issue.companyId, + sourceIssueId: issue.id, projectId: issue.projectId, projectWorkspaceId: issue.projectWorkspaceId, + name: "Saved sandbox workspace", cwd: null, providerType: "cloud_sandbox", strategyType: "git_worktree", + mode: "isolated_workspace", status: "active", metadata: { remoteWorkspace } }).returning(); + await db.update(issues).set({ executionWorkspaceId: workspace.id }).where(eq(issues.id, issue.id)); + input.reuse.existingExecutionWorkspace = toExecutionWorkspace(workspace); + input.reuse.reusableExistingExecutionWorkspace = toExecutionWorkspace(workspace); + input.reuse.requestedShouldReuseExisting = true; + input.agent.adapterType = "paperclip_runner"; + const computer = { ...input.environment.localEnvironment, id: randomUUID(), name: "Agent Computer", + driver: "plugin" as const, config: { pluginKey: "agent-computers", driverKey: "tasks", driverConfig: {} } }; + input.environment.selectedEnvironmentId = computer.id; + input.environment.selectedEnvironmentForConfig = computer; + const resolve = vi.spyOn(input.services, "resolveWorkspaceForRun"); + const acquire = vi.spyOn(envOrchestrator, "acquireForRun"); + + await expect(prepareHeartbeatWorkspace(db, input)).rejects.toMatchObject({ + name: "ConfigurationIncompleteFailure", + code: "configuration_incomplete", + message: `This task's saved workspace is kept in remote workspace storage, which the environment "Agent Computer" cannot use. ` + + "Only a Paperclip Runner agent in a sandbox environment, or a supported agent in an SSH environment, can continue it.", + resultJson: { + configurationIncomplete: { + reason: "remote_workspace_environment_incompatible", + companyId: issue.companyId, + agentId: input.agent.id, + issueId: issue.id, + executionWorkspaceId: workspace.id, + environmentId: computer.id, + environmentDriver: "plugin", + adapterType: "paperclip_runner", + fingerprint: `remote_workspace_environment:${workspace.id}:${computer.id}`, + actionUrl: `/agents/${input.agent.id}/runtime`, + }, + }, + }); + expect(resolve).not.toHaveBeenCalled(); + expect(acquire).not.toHaveBeenCalled(); + const [unchanged] = await db.select().from(executionWorkspaces).where(eq(executionWorkspaces.id, workspace.id)); + expect(unchanged?.metadata).toEqual(workspace.metadata); + expect(unchanged?.metadata?.remoteWorkspace).toEqual(remoteWorkspace); + expect((await readIssue(issue.id)).executionWorkspaceId).toBe(workspace.id); + }); + it.each([ { kind: "empty", repoUrl: null, branchMode: null, fresh: false, strategyChange: false, ephemeral: true }, { kind: "git", repoUrl: "https://github.com/example/remote.git", branchMode: null, fresh: false, strategyChange: false }, diff --git a/server/src/services/heartbeat/workspace-preparation.ts b/server/src/services/heartbeat/workspace-preparation.ts index fc660ec5d77..37c30c46f07 100644 --- a/server/src/services/heartbeat/workspace-preparation.ts +++ b/server/src/services/heartbeat/workspace-preparation.ts @@ -1,9 +1,10 @@ import { NATIVE_REMOTE_RECOVERY_LEASE_MISMATCH, remoteRecoveryLeaseMismatch } from "../native-runtime/remote-recovery-lease-mismatch.js"; import { readInheritedRunnerRetainedSandbox } from "../native-runtime/native-inherited-runner-retry.js"; import { resolveProviderApiPlacement } from "../native-runtime/provider-api-placement.js"; -import { assertEphemeralWorkspaceExecution, readRemoteWorkspaceAuthority, RemoteWorkspaceWriterActiveError, reserveRemoteWorkspace, shouldUseRemoteWorkspaces } from "../remote-workspaces.js"; +import { assertEphemeralWorkspaceExecution, readRemoteWorkspaceAuthority, RemoteWorkspaceWriterActiveError, reserveRemoteWorkspace, shouldUseRemoteWorkspaces, supportsRemoteWorkspaceExecution } from "../remote-workspaces.js"; import { assertProjectStorageEnvironment, listProjectWorkspaceProviders, projectStorageForEnvironment } from "../project-workspace-provider.js"; import { PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE } from "../project-storage-environment-reason.js"; +import { REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE } from "../remote-workspace-environment-reason.js"; import { ConfigurationIncompleteFailure } from "./run-preparation.js"; import { WorkspaceBusyDeferral } from "./retries.js"; import { remoteWorkspaceHoldRefusesStart } from "../remote-workspace-writer-hold.js"; @@ -280,7 +281,30 @@ async function prepareHeartbeatWorkspaceLocked(db: Db, input: HeartbeatWorkspace { reason: "remote_workspace_migration_in_progress" }); } } - const enrolledRemoteAuthority = readRemoteWorkspaceAuthority((reusableExistingExecutionWorkspace ?? existingExecutionWorkspace)?.metadata) !== null; + const enrolledRemoteWorkspace = reusableExistingExecutionWorkspace ?? existingExecutionWorkspace; + const enrolledRemoteAuthority = readRemoteWorkspaceAuthority(enrolledRemoteWorkspace?.metadata) !== null; + if (!controllerOnly && enrolledRemoteAuthority + && !supportsRemoteWorkspaceExecution(agent.adapterType, selectedEnvironmentForConfig?.driver ?? null)) { + const environmentId = selectedEnvironmentForConfig?.id ?? selectedEnvironmentId ?? null; + throw new ConfigurationIncompleteFailure( + `This task's saved workspace is kept in remote workspace storage, which the environment "${selectedEnvironmentForConfig?.name ?? "unknown"}" cannot use. ` + + "Only a Paperclip Runner agent in a sandbox environment, or a supported agent in an SSH environment, can continue it.", + { + configurationIncomplete: { + reason: REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE, + companyId: agent.companyId, + agentId: agent.id, + issueId: issueId ?? null, + executionWorkspaceId: enrolledRemoteWorkspace!.id, + environmentId, + environmentDriver: selectedEnvironmentForConfig?.driver ?? null, + adapterType: agent.adapterType, + fingerprint: `remote_workspace_environment:${enrolledRemoteWorkspace!.id}:${environmentId ?? "none"}`, + actionUrl: `/agents/${agent.id}/runtime`, + }, + }, + ); + } let remoteAuthority = !controllerOnly && shouldUseRemoteWorkspaces({ adapterType: agent.adapterType, environmentDriver: selectedEnvironmentForConfig?.driver ?? null, diff --git a/server/src/services/recovery/service.ts b/server/src/services/recovery/service.ts index 21fcd5ff2be..dbd949354c7 100644 --- a/server/src/services/recovery/service.ts +++ b/server/src/services/recovery/service.ts @@ -30,6 +30,7 @@ import { onboardingFirstTaskAwaitingUserSql } from "./onboarding-first-task-wait import { isAiAuthenticationBlocked } from "../ai-auth-failure.js"; import { RESTRICTED_WORKSPACE_SOURCE_REASON } from "../workspace-source-restriction.js"; import { PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE } from "../project-storage-environment-reason.js"; +import { REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE } from "../remote-workspace-environment-reason.js"; import { hasCommittedNativePlanWait } from "../native-runtime/native-plan-wait.js"; import { ensureNativePlanReviewCard } from "../native-runtime/native-plan-review-card.js"; import { hasCommittedNativeConversationTurnWait, hasCommittedNativeResponseWakeWait } from "../native-runtime/native-response-wake-wait.js"; @@ -183,6 +184,7 @@ import { DOT_CONFIGURATION_INCOMPLETE_REASONS, SANDBOX_PROVIDER_PLUGIN_NOT_READY_REASON, PROJECT_STORAGE_ENVIRONMENT_NEXT_ACTION, + REMOTE_WORKSPACE_ENVIRONMENT_NEXT_ACTION, sandboxProviderPluginRemedy, buildConfigurationIncompleteRecoveryNoticeSeed, buildExecutionReviewParticipantRecoveryNoticeSeed, @@ -2877,6 +2879,8 @@ export function recoveryService( ? "Retry the task." : readConfigurationIncompletePayload(input.latestRun)?.reason === PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE ? PROJECT_STORAGE_ENVIRONMENT_NEXT_ACTION + : readConfigurationIncompletePayload(input.latestRun)?.reason === REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE + ? REMOTE_WORKSPACE_ENVIRONMENT_NEXT_ACTION : readConfigurationIncompletePayload(input.latestRun) ?.reason === SANDBOX_PROVIDER_PLUGIN_NOT_READY_REASON ? `The plugin that starts this agent's sandbox is not running. To fix it, ${sandboxProviderPluginRemedy( diff --git a/server/src/services/recovery/stranded-notice-remote-workspace-environment.test.ts b/server/src/services/recovery/stranded-notice-remote-workspace-environment.test.ts new file mode 100644 index 00000000000..95427e149e5 --- /dev/null +++ b/server/src/services/recovery/stranded-notice-remote-workspace-environment.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it } from "vitest"; +import { buildConfigurationIncompleteRecoveryNoticeSeed } from "./stranded-notice.js"; + +describe("remote workspace environment configuration notice", () => { + it("names the saved remote workspace instead of a missing secret", () => { + const notice = buildConfigurationIncompleteRecoveryNoticeSeed({ + reason: "remote_workspace_environment_incompatible", environmentDriver: "plugin", adapterType: "paperclip_runner", + }); + + expect(notice).toEqual({ + title: "Saved workspace needs a compatible environment", + body: "The agent did not start because this task's saved workspace is kept in remote workspace storage, " + + "and the agent's environment cannot use it. Only a Paperclip Runner agent in a sandbox environment, or a supported agent in an SSH environment, can continue this workspace.", + nextAction: "Assign the task to an agent whose environment can use this saved workspace, or change this agent's environment, then press Retry.", + tone: "danger", + }); + expect(JSON.stringify(notice)).not.toMatch(/secret/i); + }); +}); diff --git a/server/src/services/recovery/stranded-notice.ts b/server/src/services/recovery/stranded-notice.ts index 8642c15a6d8..b2f5d8e558d 100644 --- a/server/src/services/recovery/stranded-notice.ts +++ b/server/src/services/recovery/stranded-notice.ts @@ -2,6 +2,7 @@ import type { IssueCommentMetadata, IssueCommentPresentation } from "@paperclipa import type { PluginWorkspaceOperationFailureReason } from "@paperclipai/plugin-sdk"; import { ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE } from "../environment-provider-unavailable-error.js"; import { PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE } from "../project-storage-environment-reason.js"; +import { REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE } from "../remote-workspace-environment-reason.js"; import { workspaceProviderFailureMessage, type WorkspaceProviderFailureSummary, @@ -145,6 +146,7 @@ export function buildWorkspaceValidationRecoveryNoticeSeed(): StrandedRecoveryNo } export const SANDBOX_PROVIDER_PLUGIN_NOT_READY_REASON = "sandbox_provider_plugin_not_ready"; +export const REMOTE_WORKSPACE_ENVIRONMENT_NEXT_ACTION = "Assign the task to an agent whose environment can use this saved workspace, or change this agent's environment, then press Retry."; export const PROJECT_STORAGE_ENVIRONMENT_NEXT_ACTION = "Assign the task to an agent whose environment can use this project's workspace storage, or choose a workspace from a project for this agent's environment, then press Retry."; function readNonEmptyStringField(payload: Record | null | undefined, key: string): string | null { @@ -259,6 +261,15 @@ export function buildConfigurationIncompleteRecoveryNoticeSeed( tone: "danger", }; } + if (readNonEmptyStringField(configurationIncomplete, "reason") === REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE) { + return { + title: "Saved workspace needs a compatible environment", + body: "The agent did not start because this task's saved workspace is kept in remote workspace storage, " + + "and the agent's environment cannot use it. Only a Paperclip Runner agent in a sandbox environment, or a supported agent in an SSH environment, can continue this workspace.", + nextAction: REMOTE_WORKSPACE_ENVIRONMENT_NEXT_ACTION, + tone: "danger", + }; + } if (readNonEmptyStringField(configurationIncomplete, "reason") === "dot_subscription_expired") { return { title: "Dot event subscription expired", diff --git a/server/src/services/remote-workspace-environment-reason.ts b/server/src/services/remote-workspace-environment-reason.ts new file mode 100644 index 00000000000..cd536e5aab4 --- /dev/null +++ b/server/src/services/remote-workspace-environment-reason.ts @@ -0,0 +1 @@ +export const REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE = "remote_workspace_environment_incompatible"; diff --git a/server/src/services/remote-workspaces.ts b/server/src/services/remote-workspaces.ts index 8c1f286adf0..8311367959e 100644 --- a/server/src/services/remote-workspaces.ts +++ b/server/src/services/remote-workspaces.ts @@ -99,12 +99,16 @@ export function supportsSshRemoteWorkspace(adapterType: string, environmentDrive return environmentDriver === "ssh" && adapterSupportsRemoteManagedEnvironments(adapterType); } +export function supportsRemoteWorkspaceExecution(adapterType: string, environmentDriver: string | null | undefined) { + return adapterType === "paperclip_runner" && environmentDriver === "sandbox" + || supportsSshRemoteWorkspace(adapterType, environmentDriver); +} + export function shouldUseRemoteWorkspaces(input: { adapterType: string; environmentDriver: string | null; experimentalEnabled: boolean; existingWorkspace?: { metadata?: Record | null } | null; }) { const enrolled = readRemoteWorkspaceAuthority(input.existingWorkspace?.metadata) !== null; - const supported = input.adapterType === "paperclip_runner" && input.environmentDriver === "sandbox" - || supportsSshRemoteWorkspace(input.adapterType, input.environmentDriver); + const supported = supportsRemoteWorkspaceExecution(input.adapterType, input.environmentDriver); if (enrolled && !supported) { throw conflict("This workspace requires a supported remote execution environment.", { code: "remote_workspace_execution_required" }); } diff --git a/server/src/services/run-failure-report.ts b/server/src/services/run-failure-report.ts index 516daf9715a..67d0d8a4cfb 100644 --- a/server/src/services/run-failure-report.ts +++ b/server/src/services/run-failure-report.ts @@ -19,6 +19,7 @@ import { readRunFailureReportingMode, type RunFailureReportingMode } from "../se import { RESTRICTED_WORKSPACE_SOURCE_REASON } from "./workspace-source-restriction.js"; import { PLUGIN_RUNNER_AI_CONNECTION_REQUIRED } from "./plugin-runner-ai-connection.js"; import { PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE } from "./project-storage-environment-reason.js"; +import { REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE } from "./remote-workspace-environment-reason.js"; import { NATIVE_PROVIDER_OVERLOADED_CODE } from "./native-runtime/native-provider-failure.js"; import { NATIVE_TOOL_RECEIPT_LIMIT_CODE } from "./native-runtime/native-tool-receipt-limit.js"; import { PROJECT_ACCESS_DENIED } from "./project-access-denial.js"; @@ -180,8 +181,12 @@ function isPluginRunnerAiConnectionRequiredBlocker(run: HeartbeatRun, options: R recovery?.kind === "bootstrap" && recovery.providerWorkStarted === false; } +const WORKSPACE_STORAGE_ENVIRONMENT_REASONS: ReadonlySet = new Set([ + PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE, REMOTE_WORKSPACE_ENVIRONMENT_INCOMPATIBLE, +]); + /** The source project's storage cannot serve the agent's environment, refused before dispatch; the task notice names the owner action. */ -function isProjectStorageEnvironmentBlocker(run: HeartbeatRun, options: RunFailureReportOptions): boolean { +function isWorkspaceStorageEnvironmentBlocker(run: HeartbeatRun, options: RunFailureReportOptions): boolean { if ( run.status !== "failed" || run.errorCode !== "configuration_incomplete" || run.executionStage !== "preparing" || options.phase !== "setup" || @@ -189,7 +194,7 @@ function isProjectStorageEnvironmentBlocker(run: HeartbeatRun, options: RunFailu ) return false; const configuration = asRecord(run.resultJson?.configurationIncomplete); const recovery = asRecord(run.resultJson?.executionRecovery); - return configuration?.reason === PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE && + return WORKSPACE_STORAGE_ENVIRONMENT_REASONS.has(configuration?.reason) && recovery?.kind === "bootstrap" && recovery.providerWorkStarted === false; } @@ -432,7 +437,7 @@ export function reportRunFailure(db: Db, run: HeartbeatRun, options: RunFailureR isLocalPathWorkspaceConfigurationBlocker(run, options) || isRestrictedWorkspaceSourceBlocker(run, options) || isPluginRunnerAiConnectionRequiredBlocker(run, options) || - isProjectStorageEnvironmentBlocker(run, options) || + isWorkspaceStorageEnvironmentBlocker(run, options) || isProjectAccessDenialBlocker(run, options) || isGitConnectionFailure(run, options) || isProviderQuotaFailure(run, options) ||