diff --git a/doc/project-environment-compatibility.md b/doc/project-environment-compatibility.md index 65e1807fc63..6a1031201ef 100644 --- a/doc/project-environment-compatibility.md +++ b/doc/project-environment-compatibility.md @@ -76,7 +76,12 @@ workspace provider operation, with a message naming the storage and environment. On a volume-free server, execution admission refuses that run earlier. When the task source's project storage cannot serve the selected environment, the run fails `configuration_incomplete` with reason -`project_storage_environment_incompatible` and the same message. The task notice +`project_storage_environment_incompatible` and the same message. The same +`configuration_incomplete` / `project_storage_environment_incompatible` outcome +applies in the opposite direction when a task's Core-storage project source +requires Git worktree preparation in a workspace-storage plugin environment +that cannot consume Core storage; generic task-only plugin environments and +project-less tasks keep `plugin_workspace_strategy_unsupported`. The task notice names the owner action, and run-failure reporting does not send it to Sentry. A task that moves to another project keeps its selected source, so the source project's storage still decides compatibility. diff --git a/server/src/services/heartbeat/workspace-preparation.test.ts b/server/src/services/heartbeat/workspace-preparation.test.ts index 4bb60c0e667..0a4c09e3996 100644 --- a/server/src/services/heartbeat/workspace-preparation.test.ts +++ b/server/src/services/heartbeat/workspace-preparation.test.ts @@ -2014,6 +2014,83 @@ describe.skipIf(!support.supported && !externalDatabaseUrl)("heartbeat workspace expect(acquire).not.toHaveBeenCalled(); }); + it("names incompatible Core project storage when a storage-plugin environment refuses a Core Git worktree", async () => { + const { input, issue, envOrchestrator } = await fixture(true); + const coreProjectId = issue.projectId!; + const coreProjectWorkspaceId = issue.projectWorkspaceId!; + const storage = await createPluginWorkspaceFixture(db, input.agent.companyId); + const [plugin] = await db.select().from(plugins).where(eq(plugins.id, storage.pluginId)); + await db.update(plugins).set({ + manifestJson: { + ...plugin.manifestJson, + capabilities: [...plugin.manifestJson.capabilities, "environment.drivers.register"], + environmentDrivers: [{ driverKey: "tasks", supportsTasks: true, displayName: "Agent Computer", configSchema: { type: "object", properties: {} } }], + }, + }).where(eq(plugins.id, storage.pluginId)); + const [pluginProject] = await db.insert(projects).values({ + companyId: input.agent.companyId, + name: "Plugin-storage project", + executionWorkspacePolicy: { enabled: true, storageProviderPluginId: storage.pluginId }, + }).returning(); + await db.update(issues).set({ + projectId: pluginProject.id, + projectWorkspaceId: coreProjectWorkspaceId, + workspaceSelection: { version: 1, source: "project", selection: { kind: "configured_source", mode: "managed_isolated", projectWorkspaceId: coreProjectWorkspaceId } }, + }).where(eq(issues.id, issue.id)); + input.task.issueRef = { ...issue, projectId: pluginProject.id, projectWorkspaceId: coreProjectWorkspaceId }; + input.task.workspaceSelection = { version: 1, source: "project", selection: { kind: "configured_source", mode: "managed_isolated", projectWorkspaceId: coreProjectWorkspaceId } }; + input.task.context = { issueId: issue.id, projectId: pluginProject.id }; + input.agent.adapterType = "paperclip_runner"; + const pluginEnvironment = { + ...input.environment.localEnvironment, + id: randomUUID(), + name: "Agent Computer", + driver: "plugin" as const, + config: { pluginKey: plugin.pluginKey, driverKey: "tasks", driverConfig: {} }, + }; + input.environment.selectedEnvironmentId = pluginEnvironment.id; + input.environment.selectedEnvironmentForConfig = pluginEnvironment; + const acquire = vi.spyOn(envOrchestrator, "acquireForRun"); + + await expect(prepareHeartbeatWorkspace(db, input)).rejects.toMatchObject({ + name: "ConfigurationIncompleteFailure", + code: "configuration_incomplete", + message: `This project's workspace storage (Core / local) does not support the environment "Agent Computer". Use an agent in a compatible environment, or choose a workspace source from a project for this environment.`, + resultJson: { + configurationIncomplete: { + reason: "project_storage_environment_incompatible", + companyId: input.agent.companyId, + agentId: input.agent.id, + issueId: issue.id, + projectId: coreProjectId, + storageProviderPluginId: null, + environmentId: pluginEnvironment.id, + fingerprint: `project_storage_environment:core:${pluginEnvironment.id}`, + actionUrl: `/agents/${input.agent.id}/runtime`, + }, + }, + }); + expect(acquire).not.toHaveBeenCalled(); + expect(await db.select().from(executionWorkspaces).where(eq(executionWorkspaces.companyId, input.agent.companyId))).toHaveLength(0); + + await db.update(plugins).set({ status: "disabled" }).where(eq(plugins.id, storage.pluginId)); + await expect(prepareHeartbeatWorkspace(db, input)).rejects.toMatchObject({ + code: "workspace_validation_failed", + resultJson: { reason: "plugin_workspace_strategy_unsupported" }, + }); + + await db.update(plugins).set({ status: "ready" }).where(eq(plugins.id, storage.pluginId)); + await db.update(issues).set({ projectId: null, projectWorkspaceId: null, workspaceSelection: null }).where(eq(issues.id, issue.id)); + input.task.issueRef = { ...issue, projectId: null, projectWorkspaceId: null }; + input.task.workspaceSelection = null; + input.task.context = { issueId: issue.id }; + await expect(prepareHeartbeatWorkspace(db, input)).rejects.toMatchObject({ + code: "workspace_validation_failed", + resultJson: { reason: "plugin_workspace_strategy_unsupported" }, + }); + expect(acquire).not.toHaveBeenCalled(); + }); + it.each([true, false])("forwards only authorized plugin project IDs without staging (remote enabled: %s)", async enabled => { const { input, issue, envOrchestrator } = await fixture(); vi.stubEnv("PAPERCLIP_MULTI_PROJECT_WORKSPACE_SYNC", "true"); diff --git a/server/src/services/heartbeat/workspace-preparation.ts b/server/src/services/heartbeat/workspace-preparation.ts index b050796c038..c75967d70fe 100644 --- a/server/src/services/heartbeat/workspace-preparation.ts +++ b/server/src/services/heartbeat/workspace-preparation.ts @@ -2,7 +2,7 @@ import { NATIVE_REMOTE_RECOVERY_LEASE_MISMATCH, remoteRecoveryLeaseMismatch } fr 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 { assertProjectStorageEnvironment, listProjectWorkspaceProviders } from "../project-workspace-provider.js"; +import { assertProjectStorageEnvironment, listProjectWorkspaceProviders, projectStorageForEnvironment } from "../project-workspace-provider.js"; import { PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE } from "../project-storage-environment-reason.js"; import { ConfigurationIncompleteFailure } from "./run-preparation.js"; import { WorkspaceBusyDeferral } from "./retries.js"; @@ -286,6 +286,25 @@ async function prepareHeartbeatWorkspaceLocked(db: Db, input: HeartbeatWorkspace && !projectExecutionWorkspacePolicy?.storageProviderPluginId, existingWorkspace: reusableExistingExecutionWorkspace ?? existingExecutionWorkspace, }); + const projectStorageEnvironmentIncompleteFailure = (details: { + message: string; + projectId: string | null; + storageProviderPluginId: string | null; + environmentId: string; + }) => new ConfigurationIncompleteFailure(details.message, { + configurationIncomplete: { + reason: PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE, + companyId: agent.companyId, + agentId: agent.id, + issueId: issueId ?? null, + projectId: details.projectId, + storageProviderPluginId: details.storageProviderPluginId, + environmentId: details.environmentId, + fingerprint: `project_storage_environment:${details.storageProviderPluginId ?? "core"}:${details.environmentId}`, + actionUrl: `/agents/${agent.id}/runtime`, + missingBindings: [], + }, + }); // A volume-free server rejects execution without durable task storage. When // the source project's storage provider cannot serve the selected // environment, that mismatch is the cause and only an owner can repair it. @@ -302,12 +321,11 @@ async function prepareHeartbeatWorkspaceLocked(db: Db, input: HeartbeatWorkspace try { assertProjectStorageEnvironment(provider, selectedEnvironmentForConfig); } catch (mismatch) { - throw new ConfigurationIncompleteFailure(mismatch instanceof Error ? mismatch.message : String(mismatch), { - configurationIncomplete: { reason: PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE, companyId: agent.companyId, - agentId: agent.id, issueId: issueId ?? null, projectId: issueRef?.projectId ?? null, - storageProviderPluginId: provider.id, environmentId: selectedEnvironmentForConfig.id, - fingerprint: `project_storage_environment:${provider.id}:${selectedEnvironmentForConfig.id}`, - actionUrl: `/agents/${agent.id}/runtime`, missingBindings: [] }, + throw projectStorageEnvironmentIncompleteFailure({ + message: mismatch instanceof Error ? mismatch.message : String(mismatch), + projectId: issueRef?.projectId ?? null, + storageProviderPluginId: provider.id, + environmentId: selectedEnvironmentForConfig.id, }); } } @@ -790,6 +808,21 @@ async function prepareHeartbeatWorkspaceLocked(db: Db, input: HeartbeatWorkspace } satisfies ExecutionWorkspaceInput; const latestWorkspaceStrategyType = resolveEffectiveWorkspaceStrategyType(requestedExecutionWorkspaceMode, hostExecutionWorkspaceConfig); if (pluginTaskWorkspace && !pluginPrepared && latestWorkspaceStrategyType === "git_worktree") { + if (selectedEnvironmentForConfig && !projectExecutionWorkspacePolicy?.storageProviderPluginId + && resolvedWorkspace.projectId && resolvedWorkspace.workspaceId) { + const environmentStorage = projectStorageForEnvironment( + selectedEnvironmentForConfig, + await listProjectWorkspaceProviders(db, agent.companyId), + ); + if (environmentStorage?.pluginId) { + throw projectStorageEnvironmentIncompleteFailure({ + message: `This project's workspace storage (Core / local) does not support the environment "${selectedEnvironmentForConfig.name}". Use an agent in a compatible environment, or choose a workspace source from a project for this environment.`, + projectId: resolvedWorkspace.projectId, + storageProviderPluginId: null, + environmentId: selectedEnvironmentForConfig.id, + }); + } + } throw new WorkspaceValidationFailure("The selected plugin environment does not support Core Git worktree preparation.", { reason: "plugin_workspace_strategy_unsupported" }); }