mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
fix(workspaces): run projectless isolated tasks and chats without a repo (#22972)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Execution workspace isolation controls how each task and conversation gets a working directory > - When isolated workspaces are enabled (including with `enableIsolatedWorkspacesByDefault`), a task or conversation without a project or repository can resolve to `isolated_workspace` without an explicit `workspaceStrategy` > - Wakeup preflight synthesized the default `git_worktree` strategy and blocked projectless tasks with `workspace_worktree_requires_project`, while `shouldUseIsolatedTaskDirectory` only allowed `low_trust_review` + `sandbox` and failed standard local, sandbox, and plugin runs with `git_worktree_base_not_git_checkout` or `plugin_workspace_strategy_unsupported` > - This pull request admits repository-free isolated tasks and conversations into private isolated task directories across local, sandbox, and plugin environments while preserving explicit Git worktree validation, SSH preflight blocking, cross-task archived-workspace protection, and low-trust sandbox containment > - The benefit is that projectless tasks, projectless agent chats, and repository-free project tasks run cleanly with persistent isolated directories across turns, without weakening Git worktree isolation for repository-backed projects ## Linked Issues or Issue Description Fixes: #20962 Refs #20963, #19860, #14766, #13636 Relationship to #20963: #20963 enables private task directories for standard local repository-free tasks and guards `hasSelectedExecutionWorkspace`. This pull request builds on that direction by also: - Allowing repository-free isolated tasks without an explicit `workspaceStrategy` to pass wakeup preflight in `server/src/services/heartbeat/queue.ts` via the canonical `shouldUseIsolatedTaskDirectory` predicate with resolved trust preset and environment driver (otherwise projectless tasks and chats with `mode: "isolated_workspace"` are blocked with `workspace_worktree_requires_project` before environment selection runs, while SSH, explicit `git_worktree`, and cross-task/shared archived bindings remain blocked pre-dispatch). - Supporting standard `sandbox` (Paperclip Cloud) and `plugin` environments in `shouldUseIsolatedTaskDirectory` (including multi-turn ordinary plugin task directory reuse via `isBoundPluginTaskDirectory`), not only `local` / `null`. - Scoping `!hasSelectedExecutionWorkspace` strictly to `trustPreset === "standard"` so `low_trust_review` sandbox containment remains unchanged. - Preserving `nativeChatWorkspaceScope` isolation (zero referenced project roots) in `workspace-preparation.ts` when an external chat also uses a private task directory. ## What Changed - `server/src/services/isolated-task-directory.ts`: Extract `hasExplicitWorkspaceStrategy`, add a `standard`-scoped `hasSelectedExecutionWorkspace` guard, and allow `shouldUseIsolatedTaskDirectory` for `standard` trust on `local`, `sandbox`, `plugin`, and `null` drivers while keeping `low_trust_review` sandbox containment unchanged and keeping `ssh`, `denied`, selected standard workspaces, and explicit strategies excluded. - `server/src/services/provider-fresh-workspace.ts`: Add `isBoundPluginTaskDirectory` recognizing both fresh plugin attempt directories and ordinary task-owned plugin directories (`/workspaces/<issueId>` with matching `runnerTaskWorkspaceOwner`, `projectWorkspaceId === null`, and no `runnerTaskFreshWorkspace`) so multi-turn repository-free plugin tasks reuse their bound workspace without hitting `plugin_workspace_strategy_unsupported`. - `server/src/services/heartbeat/queue.ts`: Call the canonical `shouldUseIsolatedTaskDirectory` during wakeup preflight with resolved `trustPreset` (`resolveCoreTrustPreset`) and effective `environmentDriver` (honoring `executionWorkspaceSettings.environmentId` for `low_trust_review`, `executionMode === "kubernetes"`, and `enableManagedSandboxOnly`, and allowing verified exclusively task-owned archived/cleanup_failed task directories matching `readTaskDirectoryRetention` or `issue_terminal` cleanup while blocking cross-task/shared archived bindings) to resolve `effectivePreflightStrategy` to `"project_primary"` instead of adding a bypass flag on `isUnrunnableWorktreeCombo`. - `server/src/services/heartbeat/environment-selection.ts`: Use `isBoundPluginTaskDirectory` for bound plugin task directory reuse and pass `hasSelectedExecutionWorkspace` into `shouldUseIsolatedTaskDirectory` so existing or tampered standard workspace bindings still go through binding validation. - `server/src/services/heartbeat/workspace-preparation.ts`: Force `project_primary` strategy for host and plugin preparation when `useIsolatedTaskDirectory` is active (outside `remoteAuthority`), and keep projectless `nativeChatWorkspaceScope` runs on the external-chat directory branch so referenced projects are not attached. - `doc/experimental/issue-worktree-support.md`: Document private isolated task directory behavior for repository-free isolated tasks and conversations. - Tests: Extend `isolated-task-directory.test.ts`, `provider-fresh-workspace.test.ts`, `workspace-preparation.test.ts`, and `heartbeat-workspace-source-trust.test.ts` with unit and embedded-Postgres E2E coverage across local, sandbox, plugin, and SSH environments (projectless tasks, projectless chats, repo-free projects, 2-turn local/sandbox/plugin workspace reuse, git-backed project `git_worktree` regression, explicit projectless `git_worktree` block, SSH pre-dispatch block, low-trust projectless sandbox on SSH-default agent, cross-task archived workspace blocking, and exclusively task-owned archived directory reopening). ## Verification - `pnpm exec vitest run server/src/services/isolated-task-directory.test.ts server/src/services/provider-fresh-workspace.test.ts server/src/__tests__/execution-workspace-policy.test.ts` — 3 files, 101 passed (101). - `pnpm exec vitest run server/src/services/heartbeat/workspace-preparation.test.ts -t "prepares a repository-free local task directory|reuses a bound ordinary repository-free plugin task directory|names incompatible Core project storage"` — 3 passed (including 2-turn ordinary plugin task directory reuse + explicit `git_worktree` rejection). - `pnpm exec vitest run server/src/__tests__/heartbeat-workspace-source-trust.test.ts -t "in a company with no repository|still uses git_worktree"` — 9 passed with embedded Postgres (projectless tasks, projectless chats, repo-free projects on local and sandbox, git-backed project `git_worktree`, explicit projectless `git_worktree` block, SSH pre-dispatch block, low-trust projectless sandbox on SSH-default agent, cross-task archived workspace pre-dispatch block, and own archived isolated task directory reopening). - `pnpm exec vitest run server/src/__tests__/heartbeat-workspace-branch-containment.test.ts -t "blocks projectless isolated git-worktree issues before dispatch"` — 1 passed. - `pnpm --filter @paperclipai/server typecheck` — passed (0 errors across all 7 layers). - `node scripts/check-test-budget.mjs --files server/src/services/isolated-task-directory.test.ts server/src/services/provider-fresh-workspace.test.ts server/src/services/heartbeat/workspace-preparation.test.ts server/src/__tests__/heartbeat-workspace-source-trust.test.ts` — PASS (110 nightly suites validated, 4 test files checked). - `git diff --check` — clean; no secrets, artifacts, or internal IDs. - Sharded PR CI on `eb2b11ee9b`: **66/66** executed checks `SUCCESS` (0 failing, 0 pending, 7 skipped, 2 non-blocking neutral Paperclip Review), including `ci / verify`, `ci / e2e` + all 16 E2E shards, all 20 General server shards + chat + workspaces-b, all 9 Serialized server shards, all Verify Paperclip Runner lanes, `Build`, `Typecheck + Release Registry`, `policy`, `Superagent Security Scan`, `Socket Security`, `Contributor trust`, `commitperclip`, `Snyk`, and `Greptile Review` (5/5). ## Risks - Repository-free tasks and conversations with `mode: "isolated_workspace"` and no explicit `workspaceStrategy` now run in private task directories under `<instanceRoot>/isolated-workspaces/<companyId>/<issueId>` (or `/workspaces/<issueId>` on plugin environments / remote empty workspaces under `remoteAuthority`) instead of failing preflight or Git checkout validation. - Explicit `workspaceStrategy` requirements (including `git_worktree`, `existingBranch`, and `provisionCommand`), SSH pre-dispatch blocking, cross-task archived workspace blocking, low-trust sandbox confinement, tampered-binding checks (`hasSelectedExecutionWorkspace`), and `git_worktree` isolation for git-backed projects remain unchanged. - No database migrations, schema changes, or API contract changes. ## Model Used - Claude Opus 4.6 (`claude-opus-4-6`) in Antigravity with tool use, shell execution, and extended thinking. ## 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
560765988d
commit
cc5136ca02
10 files changed
+914
-25
No files matched your search
@@ -50,7 +50,9 @@ suite("heartbeat physical workspace source trust", () => {
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture owner", email: "owner@example.test", createdAt: new Date(), updatedAt: new Date() });
|
||||
heartbeat = heartbeatService(db);
|
||||
execute.mockImplementation(async (input) => {
|
||||
await db.update(issues).set({ status: "done" }).where(eq(issues.id, input.context.issueId));
|
||||
if (!input.context.conversationMode) {
|
||||
await db.update(issues).set({ status: "done" }).where(eq(issues.id, input.context.issueId));
|
||||
}
|
||||
return { exitCode: 0, signal: null, timedOut: false };
|
||||
});
|
||||
}, EMBEDDED_POSTGRES_TEST_TIMEOUT_MS);
|
||||
@@ -235,4 +237,527 @@ suite("heartbeat physical workspace source trust", () => {
|
||||
else expect(await readFile(marker, "utf8")).toBe("host-script-ran");
|
||||
}, 30_000);
|
||||
|
||||
it.each([
|
||||
{ kind: "projectless_task", placement: "local", settings: { mode: "isolated_workspace" as const } },
|
||||
{ kind: "projectless_task", placement: "sandbox", settings: { mode: "isolated_workspace" as const } },
|
||||
{ kind: "projectless_chat", placement: "local", settings: { mode: "isolated_workspace" as const } },
|
||||
{ kind: "projectless_chat", placement: "sandbox", settings: { mode: "isolated_workspace" as const } },
|
||||
{ kind: "projectless_chat", placement: "local", settings: null },
|
||||
{ kind: "projectless_chat", placement: "sandbox", settings: null },
|
||||
{ kind: "repo_free_project_task", placement: "local", settings: null },
|
||||
{ kind: "repo_free_project_task", placement: "sandbox", settings: null },
|
||||
] as const)(
|
||||
"runs $kind on $placement in a company with no repository when isolated workspaces by default is enabled (settings: $settings)",
|
||||
async ({ kind, placement, settings }) => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
const projectId = kind === "repo_free_project_task" ? randomUUID() : null;
|
||||
await instanceSettingsService(db).updateExperimental({
|
||||
enableIsolatedWorkspaces: true,
|
||||
enableIsolatedWorkspacesByDefault: true,
|
||||
});
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "No-repo company",
|
||||
issuePrefix: `NR${companyId.slice(0, 5).toUpperCase()}`,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId,
|
||||
principalType: "user",
|
||||
principalId: "responsible-user",
|
||||
status: "active",
|
||||
membershipRole: "owner",
|
||||
});
|
||||
if (projectId) {
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
name: "Docs project without repo",
|
||||
executionWorkspacePolicy: { enabled: true, defaultMode: "isolated_workspace" },
|
||||
});
|
||||
}
|
||||
const environmentId = placement === "sandbox" ? randomUUID() : null;
|
||||
if (environmentId) {
|
||||
await db.insert(environments).values({
|
||||
id: environmentId,
|
||||
name: `Cloud sandbox ${companyId}`,
|
||||
driver: "sandbox",
|
||||
status: "active",
|
||||
config: { provider: "fake", image: "fake:test" },
|
||||
});
|
||||
}
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "General worker",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
defaultEnvironmentId: environmentId,
|
||||
permissions: {},
|
||||
});
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId,
|
||||
principalType: "agent",
|
||||
principalId: agentId,
|
||||
status: "active",
|
||||
membershipRole: "member",
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
projectId,
|
||||
projectWorkspaceId: null,
|
||||
title: kind === "projectless_chat" ? "Chat with General worker" : "No-repo isolated task",
|
||||
status: kind === "projectless_chat" ? "in_review" : "todo",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
...(kind === "projectless_chat"
|
||||
? {
|
||||
conversationAgentId: agentId,
|
||||
conversationUserId: "responsible-user",
|
||||
conversationState: "waiting",
|
||||
}
|
||||
: {}),
|
||||
executionWorkspaceSettings: settings,
|
||||
});
|
||||
|
||||
const driver = placement === "sandbox"
|
||||
? heartbeatService(db, {
|
||||
environmentRuntime: {
|
||||
...environmentRuntimeService(db),
|
||||
execute: async (input) => ({
|
||||
exitCode: 0,
|
||||
stdout: execFileSync(input.command, input.args ?? [], {
|
||||
cwd: root,
|
||||
input: input.stdin,
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, ...input.env },
|
||||
}),
|
||||
stderr: "",
|
||||
signal: null,
|
||||
timedOut: false,
|
||||
}),
|
||||
},
|
||||
})
|
||||
: heartbeat;
|
||||
|
||||
const expectIsolated = settings?.mode === "isolated_workspace" || kind === "repo_free_project_task";
|
||||
|
||||
for (let turn = 0; turn < 2; turn += 1) {
|
||||
if (turn === 1 && kind !== "projectless_chat") {
|
||||
await db.update(issues).set({ status: "todo" }).where(eq(issues.id, issueId));
|
||||
}
|
||||
let wakeOptions: Parameters<typeof driver.wakeup>[1] = {
|
||||
source: "on_demand",
|
||||
triggerDetail: "manual",
|
||||
contextSnapshot: { issueId },
|
||||
};
|
||||
if (kind === "projectless_chat") {
|
||||
const comment = await issueService(db).addComment(issueId, `Chat turn ${turn + 1}`, {
|
||||
userId: "responsible-user",
|
||||
});
|
||||
wakeOptions = {
|
||||
source: "assignment",
|
||||
triggerDetail: "system",
|
||||
reason: "issue_commented",
|
||||
requestedByActorType: "user",
|
||||
requestedByActorId: "responsible-user",
|
||||
payload: { issueId, commentId: comment.id },
|
||||
contextSnapshot: {
|
||||
issueId,
|
||||
commentId: comment.id,
|
||||
wakeCommentId: comment.id,
|
||||
wakeReason: "issue_commented",
|
||||
},
|
||||
};
|
||||
}
|
||||
const run = await driver.wakeup(agentId, wakeOptions);
|
||||
expect(run).not.toBeNull();
|
||||
await vi.waitFor(
|
||||
async () => expect((await driver.getRun(run!.id))?.status).toMatch(/^(succeeded|failed)$/),
|
||||
{ timeout: 15_000 },
|
||||
);
|
||||
await drainHeartbeatRunsToQuiescence(db, driver);
|
||||
expect(await driver.getRun(run!.id)).toMatchObject({ status: "succeeded", errorCode: null });
|
||||
|
||||
const expectedDir = path.join(
|
||||
await realpath(resolvePaperclipInstanceRoot()),
|
||||
"isolated-workspaces",
|
||||
companyId,
|
||||
issueId,
|
||||
);
|
||||
const calls = execute.mock.calls.filter(([input]) => input.runId === run!.id);
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(calls[0][0].context.paperclipEnvironment.driver).toBe(placement);
|
||||
expect(await realpath(calls[0][0].context.paperclipWorkspace.cwd)).toBe(expectedDir);
|
||||
expect(calls[0][0].context.paperclipWorkspace.strategy).toBe("project_primary");
|
||||
if (expectIsolated) {
|
||||
expect(calls[0][0].context.paperclipWorkspace.mode).toBe("isolated_workspace");
|
||||
}
|
||||
}
|
||||
|
||||
const expectedDir = path.join(
|
||||
await realpath(resolvePaperclipInstanceRoot()),
|
||||
"isolated-workspaces",
|
||||
companyId,
|
||||
issueId,
|
||||
);
|
||||
const [bound] = await db.select().from(issues).where(eq(issues.id, issueId));
|
||||
expect(bound.status).not.toBe("blocked");
|
||||
expect(bound.executionWorkspaceId).toBeTruthy();
|
||||
const [workspace] = await db.select().from(executionWorkspaces).where(eq(executionWorkspaces.id, bound.executionWorkspaceId!));
|
||||
expect(workspace).toMatchObject({
|
||||
mode: expectIsolated ? "isolated_workspace" : "shared_workspace",
|
||||
strategyType: "project_primary",
|
||||
providerType: "local_fs",
|
||||
sourceIssueId: issueId,
|
||||
});
|
||||
expect(await realpath(workspace.cwd!)).toBe(expectedDir);
|
||||
},
|
||||
30_000,
|
||||
);
|
||||
|
||||
it("still uses git_worktree for git-backed projects under default isolation and still blocks explicit projectless git_worktree", async () => {
|
||||
const companyId = randomUUID();
|
||||
const projectId = randomUUID();
|
||||
const sourceId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const gitIssueId = randomUUID();
|
||||
const explicitWorktreeIssueId = randomUUID();
|
||||
await instanceSettingsService(db).updateExperimental({
|
||||
enableIsolatedWorkspaces: true,
|
||||
enableIsolatedWorkspacesByDefault: true,
|
||||
});
|
||||
const repoCwd = path.join(root, companyId, "git-project");
|
||||
await mkdir(repoCwd, { recursive: true });
|
||||
await writeFile(path.join(repoCwd, "README.md"), "# repo\n");
|
||||
const git = (...args: string[]) => execFileSync("git", args, { cwd: repoCwd, stdio: "ignore" });
|
||||
git("init", "-b", "main");
|
||||
git("add", ".");
|
||||
git("-c", "user.name=Fixture", "-c", "user.email=fixture@example.test", "commit", "-m", "init");
|
||||
|
||||
await db.insert(companies).values({
|
||||
id: companyId,
|
||||
name: "Git regression company",
|
||||
issuePrefix: `GR${companyId.slice(0, 5).toUpperCase()}`,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId,
|
||||
principalType: "user",
|
||||
principalId: "responsible-user",
|
||||
status: "active",
|
||||
membershipRole: "owner",
|
||||
});
|
||||
await db.insert(projects).values({ id: projectId, companyId, name: "Git project" });
|
||||
await db.insert(projectWorkspaces).values({
|
||||
id: sourceId,
|
||||
companyId,
|
||||
projectId,
|
||||
name: "Primary repo",
|
||||
sourceType: "local_path",
|
||||
cwd: repoCwd,
|
||||
isPrimary: true,
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
name: "Repo worker",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
permissions: {},
|
||||
});
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId,
|
||||
principalType: "agent",
|
||||
principalId: agentId,
|
||||
status: "active",
|
||||
membershipRole: "member",
|
||||
});
|
||||
await db.insert(issues).values([
|
||||
{
|
||||
id: gitIssueId,
|
||||
companyId,
|
||||
projectId,
|
||||
projectWorkspaceId: sourceId,
|
||||
title: "Git project task",
|
||||
status: "todo",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 1,
|
||||
identifier: `GR-1`,
|
||||
},
|
||||
{
|
||||
id: explicitWorktreeIssueId,
|
||||
companyId,
|
||||
projectId: null,
|
||||
projectWorkspaceId: null,
|
||||
title: "Explicit git worktree without project",
|
||||
status: "todo",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 2,
|
||||
identifier: `GR-2`,
|
||||
executionWorkspaceSettings: {
|
||||
mode: "isolated_workspace",
|
||||
workspaceStrategy: { type: "git_worktree" },
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const gitRun = await heartbeat.wakeup(agentId, {
|
||||
source: "on_demand",
|
||||
triggerDetail: "manual",
|
||||
contextSnapshot: { issueId: gitIssueId },
|
||||
});
|
||||
expect(gitRun).not.toBeNull();
|
||||
await vi.waitFor(
|
||||
async () => expect((await heartbeat.getRun(gitRun!.id))?.status).toMatch(/^(succeeded|failed)$/),
|
||||
{ timeout: 15_000 },
|
||||
);
|
||||
await drainHeartbeatRunsToQuiescence(db, heartbeat);
|
||||
expect(await heartbeat.getRun(gitRun!.id)).toMatchObject({ status: "succeeded", errorCode: null });
|
||||
const gitCalls = execute.mock.calls.filter(([input]) => input.runId === gitRun!.id);
|
||||
expect(gitCalls).toHaveLength(1);
|
||||
const gitWorkspace = gitCalls[0][0].context.paperclipWorkspace;
|
||||
expect(gitWorkspace.mode).toBe("isolated_workspace");
|
||||
expect(gitWorkspace.strategy).toBe("git_worktree");
|
||||
expect(
|
||||
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd: gitWorkspace.cwd, encoding: "utf8" }).trim(),
|
||||
).toBe("true");
|
||||
|
||||
const blockedRun = await heartbeat.wakeup(agentId, {
|
||||
source: "on_demand",
|
||||
triggerDetail: "manual",
|
||||
contextSnapshot: { issueId: explicitWorktreeIssueId },
|
||||
});
|
||||
expect(blockedRun).toBeNull();
|
||||
const [blockedIssue] = await db.select().from(issues).where(eq(issues.id, explicitWorktreeIssueId));
|
||||
expect(blockedIssue.status).toBe("blocked");
|
||||
|
||||
const sshEnvId = randomUUID();
|
||||
const sshAgentId = randomUUID();
|
||||
const sshIssueId = randomUUID();
|
||||
await db.insert(environments).values({
|
||||
id: sshEnvId,
|
||||
name: `SSH env ${companyId.slice(0, 6)}`,
|
||||
driver: "ssh",
|
||||
status: "active",
|
||||
config: { host: "fixture.invalid", port: 22, username: "fixture", remoteWorkspacePath: "/home/fixture/work" },
|
||||
});
|
||||
await db.insert(agents).values({
|
||||
id: sshAgentId,
|
||||
companyId,
|
||||
name: "SSH worker",
|
||||
status: "idle",
|
||||
adapterType: "codex_local",
|
||||
adapterConfig: {},
|
||||
permissions: {},
|
||||
defaultEnvironmentId: sshEnvId,
|
||||
});
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId,
|
||||
principalType: "agent",
|
||||
principalId: sshAgentId,
|
||||
status: "active",
|
||||
membershipRole: "member",
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: sshIssueId,
|
||||
companyId,
|
||||
projectId: null,
|
||||
projectWorkspaceId: null,
|
||||
title: "Projectless SSH isolated task",
|
||||
status: "todo",
|
||||
assigneeAgentId: sshAgentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 3,
|
||||
identifier: `GR-3`,
|
||||
executionWorkspaceSettings: { mode: "isolated_workspace" },
|
||||
});
|
||||
const sshBlockedRun = await heartbeat.wakeup(sshAgentId, {
|
||||
source: "on_demand",
|
||||
triggerDetail: "manual",
|
||||
contextSnapshot: { issueId: sshIssueId },
|
||||
});
|
||||
expect(sshBlockedRun).toBeNull();
|
||||
const [sshBlockedIssue] = await db.select().from(issues).where(eq(issues.id, sshIssueId));
|
||||
expect(sshBlockedIssue.status).toBe("blocked");
|
||||
|
||||
const sandboxEnvId = randomUUID();
|
||||
const lowTrustSandboxIssueId = randomUUID();
|
||||
await db.insert(environments).values({
|
||||
id: sandboxEnvId,
|
||||
name: `Low-trust sandbox ${companyId.slice(0, 6)}`,
|
||||
driver: "sandbox",
|
||||
status: "active",
|
||||
config: { provider: "fake", image: "fake:test" },
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: lowTrustSandboxIssueId,
|
||||
companyId,
|
||||
projectId: null,
|
||||
projectWorkspaceId: null,
|
||||
title: "Low-trust projectless sandbox task on SSH-default agent",
|
||||
status: "todo",
|
||||
assigneeAgentId: sshAgentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 4,
|
||||
identifier: `GR-4`,
|
||||
executionPolicy: {
|
||||
trustPreset: "low_trust_review",
|
||||
authorizationPolicy: {
|
||||
trustPreset: "low_trust_review",
|
||||
trustBoundary: { mode: "low_trust_review", companyId, issueIds: [lowTrustSandboxIssueId] },
|
||||
},
|
||||
},
|
||||
executionWorkspaceSettings: {
|
||||
mode: "isolated_workspace",
|
||||
environmentId: sandboxEnvId,
|
||||
},
|
||||
});
|
||||
const sandboxHeartbeat = heartbeatService(db, {
|
||||
environmentRuntime: {
|
||||
...environmentRuntimeService(db),
|
||||
execute: async (input) => ({
|
||||
exitCode: 0,
|
||||
stdout: execFileSync(input.command, input.args ?? [], {
|
||||
cwd: root,
|
||||
input: input.stdin,
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, ...input.env },
|
||||
}),
|
||||
stderr: "",
|
||||
signal: null,
|
||||
timedOut: false,
|
||||
}),
|
||||
},
|
||||
});
|
||||
const lowTrustRun = await sandboxHeartbeat.wakeup(sshAgentId, {
|
||||
source: "on_demand",
|
||||
triggerDetail: "manual",
|
||||
contextSnapshot: { issueId: lowTrustSandboxIssueId },
|
||||
});
|
||||
expect(lowTrustRun).not.toBeNull();
|
||||
await vi.waitFor(
|
||||
async () => expect((await sandboxHeartbeat.getRun(lowTrustRun!.id))?.status).toMatch(/^(succeeded|failed)$/),
|
||||
{ timeout: 15_000 },
|
||||
);
|
||||
await drainHeartbeatRunsToQuiescence(db, sandboxHeartbeat);
|
||||
expect(await sandboxHeartbeat.getRun(lowTrustRun!.id)).toMatchObject({ status: "succeeded", errorCode: null });
|
||||
const lowTrustCalls = execute.mock.calls.filter(([input]) => input.runId === lowTrustRun!.id);
|
||||
expect(lowTrustCalls).toHaveLength(1);
|
||||
expect(lowTrustCalls[0][0].context.paperclipEnvironment.driver).toBe("sandbox");
|
||||
expect(lowTrustCalls[0][0].context.paperclipWorkspace.strategy).toBe("project_primary");
|
||||
const [lowTrustIssue] = await db.select().from(issues).where(eq(issues.id, lowTrustSandboxIssueId));
|
||||
expect(lowTrustIssue.status).not.toBe("blocked");
|
||||
|
||||
const otherTaskId = randomUUID();
|
||||
const archivedWorkspaceId = randomUUID();
|
||||
const archivedBindingIssueId = randomUUID();
|
||||
await db.insert(issues).values({
|
||||
id: otherTaskId,
|
||||
companyId,
|
||||
projectId: null,
|
||||
projectWorkspaceId: null,
|
||||
title: "Other task with archived directory",
|
||||
status: "done",
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 5,
|
||||
identifier: `GR-5`,
|
||||
});
|
||||
await db.insert(executionWorkspaces).values({
|
||||
id: archivedWorkspaceId,
|
||||
companyId,
|
||||
sourceIssueId: otherTaskId,
|
||||
mode: "isolated_workspace",
|
||||
strategyType: "project_primary",
|
||||
providerType: "local_fs",
|
||||
name: "Archived other-task directory",
|
||||
status: "archived",
|
||||
cleanupReason: "issue_terminal_done",
|
||||
cwd: path.join(root, companyId, "archived-other-task"),
|
||||
});
|
||||
await db.insert(issues).values({
|
||||
id: archivedBindingIssueId,
|
||||
companyId,
|
||||
projectId: null,
|
||||
projectWorkspaceId: null,
|
||||
executionWorkspaceId: archivedWorkspaceId,
|
||||
executionWorkspacePreference: "reuse_existing",
|
||||
title: "Projectless task bound to another task's archived workspace",
|
||||
status: "todo",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 6,
|
||||
identifier: `GR-6`,
|
||||
executionWorkspaceSettings: { mode: "isolated_workspace" },
|
||||
});
|
||||
const archivedBlockedRun = await heartbeat.wakeup(agentId, {
|
||||
source: "on_demand",
|
||||
triggerDetail: "manual",
|
||||
contextSnapshot: { issueId: archivedBindingIssueId },
|
||||
});
|
||||
expect(archivedBlockedRun).toBeNull();
|
||||
const [archivedBlockedIssue] = await db.select().from(issues).where(eq(issues.id, archivedBindingIssueId));
|
||||
expect(archivedBlockedIssue.status).toBe("blocked");
|
||||
|
||||
const ownArchivedIssueId = randomUUID();
|
||||
const ownArchivedWorkspaceId = randomUUID();
|
||||
const ownArchivedCwd = path.join(
|
||||
await realpath(resolvePaperclipInstanceRoot()),
|
||||
"isolated-workspaces",
|
||||
companyId,
|
||||
ownArchivedIssueId,
|
||||
);
|
||||
await mkdir(ownArchivedCwd, { recursive: true });
|
||||
await db.insert(issues).values({
|
||||
id: ownArchivedIssueId,
|
||||
companyId,
|
||||
projectId: null,
|
||||
projectWorkspaceId: null,
|
||||
title: "Projectless task reopening its own archived directory",
|
||||
status: "todo",
|
||||
assigneeAgentId: agentId,
|
||||
responsibleUserId: "responsible-user",
|
||||
issueNumber: 7,
|
||||
identifier: `GR-7`,
|
||||
executionWorkspaceSettings: { mode: "isolated_workspace" },
|
||||
});
|
||||
await db.insert(executionWorkspaces).values({
|
||||
id: ownArchivedWorkspaceId,
|
||||
companyId,
|
||||
sourceIssueId: ownArchivedIssueId,
|
||||
mode: "isolated_workspace",
|
||||
strategyType: "project_primary",
|
||||
providerType: "local_fs",
|
||||
name: "Own archived directory",
|
||||
status: "archived",
|
||||
cleanupReason: "issue_terminal_done",
|
||||
cwd: ownArchivedCwd,
|
||||
});
|
||||
await db.update(issues).set({
|
||||
executionWorkspaceId: ownArchivedWorkspaceId,
|
||||
executionWorkspacePreference: "reuse_existing",
|
||||
}).where(eq(issues.id, ownArchivedIssueId));
|
||||
const ownArchivedRun = await heartbeat.wakeup(agentId, {
|
||||
source: "on_demand",
|
||||
triggerDetail: "manual",
|
||||
contextSnapshot: { issueId: ownArchivedIssueId },
|
||||
});
|
||||
expect(ownArchivedRun).not.toBeNull();
|
||||
await vi.waitFor(
|
||||
async () => expect((await heartbeat.getRun(ownArchivedRun!.id))?.status).toMatch(/^(succeeded|failed)$/),
|
||||
{ timeout: 15_000 },
|
||||
);
|
||||
await drainHeartbeatRunsToQuiescence(db, heartbeat);
|
||||
expect(await heartbeat.getRun(ownArchivedRun!.id)).toMatchObject({ status: "succeeded", errorCode: null });
|
||||
const [reopenedIssue] = await db.select().from(issues).where(eq(issues.id, ownArchivedIssueId));
|
||||
expect(reopenedIssue.status).not.toBe("blocked");
|
||||
}, 30_000);
|
||||
|
||||
});
|
||||
Reference in new issue
Block a user