mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-30 05:16:50 +01:00
Support provider-owned fresh retry workspaces (#17252)
## Thinking Path > - Paperclip coordinates AI agents and retains their work across failures. > - A retry can require a new workspace while preserving the failed attempt. > - Core rejects this recovery strategy for provider-owned storage. > - Providers should implement the required outcome using their own storage design. > - This pull request adds a semantic fresh-preparation contract and delegates recovery preparation. > - The benefit is that a supported provider can run a fresh retry without losing prior work. ## Linked Issues or Issue Description **What happened?** A retry that selects `fresh_isolated_workspace` fails with `fresh_workspace_storage_unsupported` for provider-owned storage. **Expected behavior** Core asks a capable provider to prepare new storage and attach verified recovery files. The failed workspace remains intact. **Steps to reproduce** Run a task in a task-capable plugin environment. Let the task fail without a verified workspace preservation receipt. Retry the task so Core selects a fresh attempt. **Paperclip version or commit**6204239cf(rebased on current master). **Deployment mode** Self-hosted server with a plugin task environment and managed workspace provider. Search found no duplicate implementation. This branch includes the default-provider changes from #17247 and preserves their source selection behavior. ## What Changed - Define an opt-in fresh-preparation contract with a stable attempt identity and verified recovery file descriptors. - Describe retained-storage and recovery-attachment guarantees without requiring a Git storage layout. - Reserve replacement task bindings with revision checks and keep the failed workspace intact. Projectless and project-backed task environments both replay their stable attempt reservation. - Reconcile an interrupted preparation against its reserved workspace and stable operation identity. - Stage verified recovery archives at stable transfer paths. Delegate attachment materialization to the provider. - Preserve projectless attempt directory identities through later turns and pin the intent into each execution lease. - Protect fresh intent and projectless ownership from caller metadata replacement or injection. ## Verification - SDK workspace-provider tests: 4 passed. - Targeted reservation and task-dispatch tests: 31 passed. - Recovery transfer staging and lifecycle focus: 7 passed. The separate cache-cleanup failure reconciliation case also passed. - After rebasing on current master, 7 focused preparation and ownership cases passed. These cover inherited provider defaults, fresh preparation, stable projectless identity, and authorization denial. - The focused metadata authority regression passed, including forged intent, replacement, and null metadata patches. - Three assembled interrupted task-reservation cases passed: projectless, project with a saved source, and project with a newly selected default source. - Targeted tests use worktree SDK sources. No full local build or typecheck ran. - Local checks remain targeted as requested. Latest-head GitHub CI passed: 54 successful checks, including typecheck, build, server suites, Runner validation, and E2E shards; 2 unrelated Storybook checks were skipped. - Greptile reviewed commit73595b0c61at 5/5 with zero unresolved threads. - Live VM E2E has not run. ## Risks - Existing providers retain their existing behavior. Fresh attempts require explicit version support. - The companion provider implementation must materialize recovery snapshots safely and preserve the old workspace. - Fresh retries require the companion provider implementation. Providers without the version marker fail closed. ## Model Used - OpenAI GPT-6.1 (`gpt-6.1-sol`), reasoning and coding tools. The runtime does not expose the context-window limit. ## 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 - [x] 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 --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
35bd7f6059
commit
989ee668e0
18 files changed
+592
-50
No files matched your search
@@ -108,6 +108,7 @@ export const environmentTaskResultSchema = z.discriminatedUnion("kind", [
|
||||
z.object({ kind: z.literal("description"), taskId: providerId,
|
||||
runner: z.object({ version: z.string().min(1), digest: z.string().regex(/^sha256:[a-f0-9]{64}$/) }).strict(),
|
||||
launchPreparationVersion: z.literal(1).optional(),
|
||||
freshWorkspaceVersion: z.literal(1).optional(),
|
||||
projectAuthCheckVersion: z.literal(1).optional(),
|
||||
}).strict(),
|
||||
z.object({
|
||||
@@ -150,6 +151,7 @@ export interface PluginEnvironmentTaskParams extends Omit<PluginEnvironmentDrive
|
||||
/** Company-validated projects to prepare on submit; empty during cleanup. */
|
||||
projectIds: string[];
|
||||
workspace?: import("@paperclipai/shared").WorkspaceProviderBinding;
|
||||
fresh?: import("./workspace-provider.js").PluginFreshWorkspace;
|
||||
operation: PluginEnvironmentTaskOperation;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { freshWorkspaceSchema } from "./workspace-provider.js";
|
||||
import { workspaceProviderBindingSchema } from "@paperclipai/shared";
|
||||
import { pluginWorkspaceParamsSchema, parseWorkspaceProviderResult } from "./workspace-provider.js";
|
||||
import { environmentTaskOperationSchema, parseEnvironmentTaskResult, type PluginEnvironmentTaskParams } from "./environment-tasks.js";
|
||||
@@ -1697,6 +1698,7 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost
|
||||
if (!plugin.definition.onEnvironmentTask) throw methodNotImplemented("environmentTask");
|
||||
const input = params as PluginEnvironmentTaskParams;
|
||||
if (input.workspace !== undefined) workspaceProviderBindingSchema.parse(input.workspace);
|
||||
if (input.fresh !== undefined) freshWorkspaceSchema.parse(input.fresh);
|
||||
const operation = environmentTaskOperationSchema.parse(input.operation);
|
||||
return parseEnvironmentTaskResult(operation, input.taskId, await plugin.definition.onEnvironmentTask({ ...input, operation }));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
import { z } from "zod";
|
||||
import { workspaceProviderBindingSchema } from "@paperclipai/shared";
|
||||
|
||||
const recoveryFile = z.object({
|
||||
path: z.string().min(1),
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/),
|
||||
byteSize: z.number().int().positive(),
|
||||
}).strict();
|
||||
export const freshWorkspaceSchema = z.object({
|
||||
attemptId: z.string().uuid(),
|
||||
sourceRunId: z.string().uuid(),
|
||||
previousWorkspaceId: z.string().uuid().nullable(),
|
||||
recoverySnapshots: z.array(z.object({
|
||||
operationId: z.string().uuid(), sourceRunId: z.string().uuid(),
|
||||
archive: recoveryFile, manifest: recoveryFile,
|
||||
}).strict()),
|
||||
}).strict();
|
||||
export type PluginFreshWorkspace = z.infer<typeof freshWorkspaceSchema>;
|
||||
|
||||
const sha = z.string().regex(/^[a-f0-9]{40,64}$/);
|
||||
export const workspaceProviderOperationSchema = z.discriminatedUnion("kind", [
|
||||
z
|
||||
@@ -25,6 +41,7 @@ export const workspaceProviderOperationSchema = z.discriminatedUnion("kind", [
|
||||
branchMode: z.enum(["create", "existing"]).optional(),
|
||||
baseRef: z.string().nullable(),
|
||||
existing: workspaceProviderBindingSchema.nullable(),
|
||||
fresh: freshWorkspaceSchema.optional(),
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
|
||||
@@ -85,6 +85,15 @@ describe("workspace provider SDK", () => {
|
||||
}),
|
||||
).toThrow();
|
||||
});
|
||||
it("expresses fresh outcomes without imposing Git storage layout", () => {
|
||||
const fresh = { attemptId: id(6), sourceRunId: id(7), previousWorkspaceId: id(8),
|
||||
recoverySnapshots: [{ operationId: id(9), sourceRunId: id(7),
|
||||
archive: { path: "/controller/recovery/archive.tar", sha256: "a".repeat(64), byteSize: 1024 },
|
||||
manifest: { path: "/controller/recovery/manifest.jsonl", sha256: "b".repeat(64), byteSize: 128 } }] };
|
||||
expect(workspaceProviderOperationSchema.parse({ ...params.operation, fresh })).toMatchObject({ fresh });
|
||||
expect(() => workspaceProviderOperationSchema.parse({ ...params.operation, fresh: { ...fresh, independentGitStorage: true } })).toThrow();
|
||||
expect(() => workspaceProviderOperationSchema.parse({ ...params.operation, fresh: { ...fresh, recoverySnapshots: [{ ...fresh.recoverySnapshots[0], archive: { ...fresh.recoverySnapshots[0].archive, sha256: "invalid" } }] } })).toThrow();
|
||||
});
|
||||
it("requires project lifecycle and storage management as one contract", () => {
|
||||
const manifest = {
|
||||
id: "test.storage",
|
||||
|
||||
Reference in new issue
Block a user