mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
fix(workspaces): name incompatible Core project storage on plugin environments (#22849)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - A repository project belongs to one storage owner: Core / local storage or an installed workspace-storage plugin. > - A task keeps its selected workspace source when it moves to another project, so the source project's storage owner still governs compatibility. > - Merged #22398 already reports `configuration_incomplete` (`project_storage_environment_incompatible`) when a plugin-storage project runs on a Core environment on a volume-free server. > - In the opposite direction — a Core-storage project source paired with an active workspace-storage plugin environment — workspace preparation fell through to `workspace_validation_failed` (`plugin_workspace_strategy_unsupported`), claiming the plugin environment does not support Core Git worktree preparation. > - That message hid the true storage mismatch, skipped the owner-action "Workspace storage unavailable" notice, and sent pre-dispatch Sentry noise. > - This pull request checks `projectStorageForEnvironment` inside that refusal path and reports the same `configuration_incomplete` / `project_storage_environment_incompatible` outcome when the plugin environment owns separate workspace storage. > - Generic task-only plugin environments, disabled storage plugins, and project-less tasks keep `plugin_workspace_strategy_unsupported`. ## Linked Issues or Issue Description Related: #22398 (names incompatible plugin project storage when a volume-free server refuses a Core environment), #17552 (a moved task keeps its selected workspace source). Verified non-overlapping with open #21625, which only touches local non-Git task directories where `!pluginTaskWorkspace`. **What happened?** A task had an isolated workspace source belonging to a Core-storage project (for example after moving the task into a plugin-storage project while retaining its original source). The assigned Paperclip Runner agent ran in an active workspace-storage plugin environment. Because the source project used Core / local storage rather than the plugin's storage, `preparePluginWorkspace` returned `null` and workspace preparation refused the run with `workspace_validation_failed` (`plugin_workspace_strategy_unsupported`): `"The selected plugin environment does not support Core Git worktree preparation."` That message falsely blamed the plugin environment for not supporting Git worktrees, did not show the "Workspace storage unavailable" owner-action notice, and was not filtered as a known pre-dispatch configuration mismatch by run-failure reporting. **Expected behavior** The refusal names the actual storage mismatch (`Core / local` storage vs the selected plugin environment), fails with `configuration_incomplete` (`reason: "project_storage_environment_incompatible"`), triggers the existing `"Workspace storage unavailable"` task notice with the owner action, and avoids pre-dispatch Sentry noise. Generic task-only plugin environments, disabled storage plugins, and project-less tasks still fail closed with `workspace_validation_failed` (`plugin_workspace_strategy_unsupported`). **Steps to reproduce** 1. Install and enable a workspace-storage plugin that also registers a task-capable environment driver (`supportsTasks: true`). 2. Create a Core-storage project with a Git workspace and a plugin-storage project owned by that plugin. 3. Create an isolated task (`mode: "isolated_workspace"`) backed by the Core-storage project workspace, then move the task to the plugin-storage project (retaining its selected workspace source) and assign it to a Paperclip Runner agent using the plugin environment. 4. Prepare the workspace for a run. Before this fix, `prepareHeartbeatWorkspace` rejects with `WorkspaceValidationFailure` (`workspace_validation_failed`, `reason: "plugin_workspace_strategy_unsupported"`). **Paperclip version or commit** Reproduced against `origin/master` at `fb900bf0fe4361e6b6a43814da952c87957a3299`. **Deployment mode** Self-hosted / Cloud server. Verified locally on macOS arm64 with embedded PostgreSQL. ## What Changed - `server/src/services/heartbeat/workspace-preparation.ts`: inside the existing `pluginTaskWorkspace && !pluginPrepared && latestWorkspaceStrategyType === "git_worktree"` refusal branch, check `projectStorageForEnvironment(selectedEnvironmentForConfig, await listProjectWorkspaceProviders(db, agent.companyId))` when a resolved Core-storage project workspace source is present (`!projectExecutionWorkspacePolicy?.storageProviderPluginId && resolvedWorkspace.projectId && resolvedWorkspace.workspaceId`). When the selected plugin environment belongs to an active workspace-storage plugin, throw `ConfigurationIncompleteFailure` with `reason: PROJECT_STORAGE_ENVIRONMENT_INCOMPATIBLE`, naming `Core / local` storage and the selected environment, with `projectId: resolvedWorkspace.projectId`, `storageProviderPluginId: null`, `environmentId`, stable fingerprint `project_storage_environment:core:${environmentId}`, and `actionUrl`. (This adds 26 lines to `workspace-preparation.ts`, which is already above 1,000 lines, directly inside the owning refusal guard so no new indirection is introduced.) - `server/src/services/heartbeat/workspace-preparation.test.ts`: add a behavioral regression simulating a moved task retaining a Core-storage source on an active storage-plugin environment, plus negative safety assertions confirming disabled storage plugins and project-less tasks retain `workspace_validation_failed` / `plugin_workspace_strategy_unsupported` with zero lease acquisition or workspace creation. - `doc/project-environment-compatibility.md`: document the symmetric Core-storage-project vs workspace-storage-plugin-environment refusal contract. ## Verification - **Red (before production edit)**: - `pnpm --filter @paperclipai/server exec vitest run src/services/heartbeat/workspace-preparation.test.ts -t "names incompatible Core project storage|rejects Core Git worktree preparation"` - `names incompatible Core project storage when a storage-plugin environment refuses a Core Git worktree` failed with `WorkspaceValidationFailure` (`code: "workspace_validation_failed"`, `resultJson: { reason: "plugin_workspace_strategy_unsupported" }`); existing `rejects Core Git worktree preparation for a plugin-owned workspace` passed. - **Green (at `218312be90a5a116d0f4cc7643bdb671a3e76df3`)**: - `pnpm --filter @paperclipai/server typecheck` — passed. - `pnpm --filter @paperclipai/server exec vitest run src/services/heartbeat/workspace-preparation.test.ts -t "names incompatible Core project storage|rejects Core Git worktree preparation|names an incompatible project storage environment"` — 3/3 passed. - `pnpm --filter @paperclipai/server exec vitest run src/services/heartbeat/workspace-preparation.test.ts` — 155/155 passed. - Companion suites (`src/__tests__/project-environments.test.ts` 16/16, `src/services/__tests__/run-failure-report.test.ts`, `src/services/recovery/stranded-notice.test.ts`) — all passed (511/511 total tests across the 4 files; an earlier combined run hit an embedded Postgres `afterAll` shutdown timeout under parallel host load, so `workspace-preparation.test.ts` was re-run standalone cleanly to exit 0). - `pnpm verify --explain` exited 2 because `doc/project-environment-compatibility.md` is a global CI input; required GitHub Actions CI supplies the broad suite coverage. - Live deployment/recovery is outside this PR's scope; local verification covers the real workspace-preparation, database, and plugin-storage compatibility boundary. ## Risks - Low risk. The new classification runs strictly inside the existing `pluginTaskWorkspace && !pluginPrepared && latestWorkspaceStrategyType === "git_worktree"` refusal guard, so no run that previously succeeded can fail now. - One extra `listProjectWorkspaceProviders` read occurs only on that refusal path. - Existing `stranded-notice.ts`, `recovery/service.ts`, and `run-failure-report.ts` already handle `configuration_incomplete` / `project_storage_environment_incompatible`. - A task that moves projects still retains its selected workspace source; the owner still resolves the mismatch by choosing a compatible agent environment or selecting a workspace source from a compatible project. ## Model Used - Google Gemini (Antigravity agentic coding assistant) with tool use, shell execution, and local test verification. Exact deployment model ID and context window are not exposed to the session. ## 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 - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
This commit is contained in:
1 parent
0e12237d16
commit
6b070dc749
3 files changed
+123
-8
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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" });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user