mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 18:35:33 +01:00
## 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
106 lines
6.3 KiB
Markdown
106 lines
6.3 KiB
Markdown
# Project environments and repository storage
|
|
|
|
A repository project belongs to one storage owner. Creation shows **Available in**
|
|
when the configured environments require more than one owner. Each choice names
|
|
all environments that use that owner. The choice selects storage only. It is not
|
|
an allowlist, and it does not override an agent's run environment. A project has
|
|
no run environment of its own.
|
|
|
|
## Compatibility rule
|
|
|
|
Use the existing workspace execution contract, not environment names, driver
|
|
names alone, images, operating systems, endpoints, or complete config equality:
|
|
|
|
- Local, SSH, and sandbox environments use core repository staging. They can use
|
|
the same repository project even across driver types and sandbox providers.
|
|
- Plugin-managed storage belongs to an installed plugin ID. It can be consumed
|
|
only by that plugin's registered `environment_driver` with `supportsTasks: true`.
|
|
Its manifest must declare `environment.drivers.register`, `workspaces.manage`,
|
|
a workspace provider, and the project resource lifecycle.
|
|
- Two task environments from that installed plugin share its project storage
|
|
contract, even when their other settings differ. Storage operations are scoped
|
|
by company, project, and plugin; they do not take an environment configuration.
|
|
Separate installed storage plugins remain incompatible even when both use the
|
|
`plugin` driver. Core cannot transfer their managed bindings between them.
|
|
- Unknown plugin drivers and the probe-only fake sandbox do not establish a
|
|
compatible project storage contract. They are excluded from creation choices.
|
|
|
|
These are project repository compatibility rules. They do not assert that
|
|
arbitrary local paths exist remotely, that a retained task workspace can switch
|
|
hosts, or that an adapter, credential, image, or running worker is ready. Existing
|
|
run-time validation still checks those conditions. Cross-plugin storage sharing
|
|
would require a new execution/storage contract; matching config fields cannot
|
|
establish it.
|
|
|
|
## Defaults and validation
|
|
|
|
For an agent API request, use that agent's default environment. For a person,
|
|
use their primary agent's default environment when present. Fall back to the
|
|
instance default, then local execution. There is no separate user or company
|
|
`defaultEnvironmentId` setting today. Managed-only and forced Kubernetes policies
|
|
retain their execution restrictions and default redirection.
|
|
|
|
`GET /api/companies/:companyId/project-environments` returns environment IDs and
|
|
names grouped by storage owner, plus the caller's effective default. It excludes
|
|
archived environments, disabled/uninstalled storage plugins, and managed
|
|
environments bound only to another company. It does not contact workers or return
|
|
provider configs, credentials, endpoints, or host paths. A cold worker does not
|
|
change a durable storage choice.
|
|
|
|
`POST /api/companies/:companyId/projects` accepts an optional `environmentId`.
|
|
The server validates the choice again and stores only its storage owner. The
|
|
project is then available to the compatible environments in that group; no single
|
|
run environment is saved. An explicit `executionWorkspacePolicy.storageProviderPluginId`
|
|
continues to work. The UI sends both the environment and its observed storage
|
|
owner in `expectedStorageProviderPluginId`, so a changed environment cannot
|
|
silently select different storage. This guard does not create a workspace-mode
|
|
policy; instance task-isolation defaults remain inherited. An explicit policy
|
|
and environment must agree when both are supplied. Without either,
|
|
storage follows the caller's effective environment. A plugin's
|
|
`defaultForProjects` claim alone no longer attaches a project to that plugin.
|
|
|
|
The hidden repository-free “My private tasks” project is independent of
|
|
environment/storage availability, so creating a private note never requires
|
|
repairing an environment.
|
|
|
|
When the configured default is unavailable and only one storage owner is
|
|
available, that owner becomes the default, because there is nothing to choose.
|
|
When two or more owners are available, an unavailable default produces an error
|
|
and permits an explicit available choice. It does not silently select another
|
|
storage owner. The UI shows the **Available in** selector only when there are two
|
|
or more storage owners. Existing
|
|
projects keep their stored owner. This change does not migrate managed storage
|
|
or detach projects that contain existing work. A managed project run in an
|
|
incompatible environment fails with `project_environment_incompatible` before a
|
|
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 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.
|
|
|
|
## Project Configuration
|
|
|
|
Storage is fixed when the project is created. `PATCH /api/projects/:id` rejects a
|
|
change of `executionWorkspacePolicy.storageProviderPluginId` with `409`
|
|
`project_storage_locked`, in both directions: core to plugin and plugin to core.
|
|
A policy update that omits the storage owner keeps the stored owner.
|
|
|
|
Project Configuration has no storage or environment control. When a storage plugin
|
|
is installed, or the project uses one, it shows an advisory **Available in** list:
|
|
the environments that can use the project's storage. If the project's storage
|
|
plugin is no longer installed, it shows **Storage plugin unavailable**. Without a
|
|
storage plugin, the advisory is hidden.
|
|
|
|
Runs use the agent default, then the instance default, then local execution. An
|
|
operator-selected low-trust task sandbox and enforced sandbox policies retain
|
|
precedence. A project does not change run placement. Older clients may still send
|
|
`executionWorkspacePolicy.environmentId`; the service drops it.
|