mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
fix(workspaces): move a workspace with only a task warning online, as offline already does (#22650)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - A hosted server moves each local workspace to shared storage in bounded online passes while it serves work > - A task can carry a recovery warning that is only about the task, for example a stranded assignment or a missing disposition > - The offline move keeps such a warning unchanged and moves the files. The online move with a source proof does the same > - The online move without a source proof refuses the workspace with `workspace_recovery_unresolved`, for example an archived workspace that is kept as a restore point > - Staging stacks stay blocked by this code (scott-test10 reports only this code, for 15 workspaces) > - This pull request gives the online move without a source proof the same result as the other two paths > - The benefit is fewer workspaces that block an online move, with no change to the warning or the files ## Linked Issues or Issue Description Refs #22270, #22294 **What happened?** Repeated online passes on staging stacks leave workspaces blocked with `workspaces:workspace_recovery_unresolved`. For a workspace without an online source proof, any active recovery action on its task blocks the online move, also a warning that is only about the task. **Expected behavior** A task-only warning does not block the online move, the same as in the offline move and in the online move with a source proof. The warning stays unchanged. Warnings that are about files or a run still block. **Steps to reproduce** 1. Create a local workspace for a task. Add an active `stranded_assigned_issue` recovery action to the task. 2. Run `migrateRemoteWorkspace` online (without `writersStopped`). 3. See that it fails with `workspace_recovery_unresolved`. The offline move of the same workspace succeeds. ## What Changed - `isTaskDispositionRecovery` names the existing task-only rule: kind `stranded_assigned_issue`, `configuration_validation`, `missing_disposition` or `deliberate_wait_without_target`, no workspace export cause, and no file or run evidence. The proven online hold uses it, with no change in behavior. - The online move without a source proof records such a warning as an online recovery hold with its fingerprint, as the proven path does. Publication locks the action row and checks that the fingerprint did not change. - All other recovery actions still block the online move without a source proof. ## Verification - `cd server && npx vitest run src/services/remote-workspace-migration.test.ts src/services/remote-workspace-online-source.test.ts src/services/remote-workspace-cohort-migration.test.ts src/services/online-remote-workspace-recovery-hold.test.ts src/services/online-legacy-workspace-recovery.test.ts src/services/finalized-workspace-recovery-migration.test.ts` (embedded PostgreSQL): 6 files, 410 tests passed. - Red/green: the four new online cases of "preserves a task-only warning" fail on `origin/master` and pass with this change. The online case checks that the warning row is unchanged and that the restored archive has the saved file. - New tests: a task warning that gets file evidence during the online upload still blocks publication. A `workspace_validation`, an `active_run_watchdog` and an export-cause action still block the online move. - `pnpm --filter @paperclipai/server typecheck`: passed. ## Risks - The online move now proceeds for a workspace whose task has only a task-only warning. A run that the warning wakes is still fenced by the existing `active_execution` and `task_writer_bound` checks at reservation and at publication, the same as for an idle workspace with no warning. - If the warning changes during the upload, publication refuses and the workspace stays local. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in Claude Code. ## 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 - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9a6e61cf36
commit
571b4bcae9
3 files changed
+46
-14
No files matched your search
@@ -209,6 +209,13 @@ async function coveredHistoricalSource(db: ReadDb, workspace: Workspace, recover
|
||||
}
|
||||
}
|
||||
|
||||
const TASK_RECOVERY_FILE_KEYS = ["workspaceRestoreRecovery", "workspaceRecovery", "historicalWorkspaceSource", "systemRecovery", "nativeFailureBlock"];
|
||||
|
||||
export function isTaskDispositionRecovery(recovery: Pick<Recovery, "kind" | "cause" | "evidence">) {
|
||||
return ["stranded_assigned_issue", "configuration_validation", "missing_disposition", "deliberate_wait_without_target"].includes(recovery.kind)
|
||||
&& !workspaceExportCauses.includes(recovery.cause) && !TASK_RECOVERY_FILE_KEYS.some(key => recovery.evidence?.[key] != null);
|
||||
}
|
||||
|
||||
export async function inspectOnlineLegacyWorkspaceRecoveryHold(db: ReadDb, input: {
|
||||
workspace: Workspace; recovery: Recovery;
|
||||
}): Promise<OnlineLegacyWorkspaceRecoveryHold | null> {
|
||||
@@ -216,11 +223,7 @@ export async function inspectOnlineLegacyWorkspaceRecoveryHold(db: ReadDb, input
|
||||
if (recovery.companyId !== input.workspace.companyId || !["active", "escalated"].includes(recovery.status) || !await isLegacyWorkspaceTaskRelated(db, {
|
||||
companyId: input.workspace.companyId, issueId: recovery.sourceIssueId, sourceIssueId: input.workspace.sourceIssueId,
|
||||
})) return null;
|
||||
const fileKeys = ["workspaceRestoreRecovery", "workspaceRecovery", "historicalWorkspaceSource", "systemRecovery", "nativeFailureBlock"];
|
||||
if (["stranded_assigned_issue", "configuration_validation", "missing_disposition", "deliberate_wait_without_target"].includes(recovery.kind)
|
||||
&& !workspaceExportCauses.includes(recovery.cause) && !fileKeys.some(key => recovery.evidence?.[key] != null)) {
|
||||
return { fingerprint: fingerprint(recovery), finalizedHold: null };
|
||||
}
|
||||
if (isTaskDispositionRecovery(recovery)) return { fingerprint: fingerprint(recovery), finalizedHold: null };
|
||||
if (typeof recovery.evidence?.runId !== "string") return null;
|
||||
const remote = await inspectRemoteRecoveryHold(db, input);
|
||||
if (remote) return remote;
|
||||
@@ -240,7 +243,7 @@ export async function inspectOnlineLegacyWorkspaceRecoveryHold(db: ReadDb, input
|
||||
&& failureBlock?.runId === settled.run.id
|
||||
&& Number.isSafeInteger(failureBlock.statusVersion) && Number(failureBlock.statusVersion) > 0
|
||||
&& recovery.fingerprint === createHash("sha256").update(`${settled.run.id}:${recovery.cause}`).digest("hex")
|
||||
&& !fileKeys.filter(key => key !== "nativeFailureBlock").some(key => recovery.evidence?.[key] != null)) {
|
||||
&& !TASK_RECOVERY_FILE_KEYS.filter(key => key !== "nativeFailureBlock").some(key => recovery.evidence?.[key] != null)) {
|
||||
const [task] = await db.select({ id: issues.id, status: issues.status, statusVersion: issues.statusVersion,
|
||||
executionRunId: issues.executionRunId, checkoutRunId: issues.checkoutRunId }).from(issues).where(and(
|
||||
eq(issues.companyId, input.workspace.companyId), eq(issues.id, recovery.sourceIssueId)));
|
||||
@@ -255,7 +258,7 @@ export async function inspectOnlineLegacyWorkspaceRecoveryHold(db: ReadDb, input
|
||||
&& settled.owner.failureCode === recovery.cause && recovery.ownerType === "board"
|
||||
&& recovery.ownerAgentId === null && recovery.returnOwnerAgentId === settled.run.agentId && recovery.wakePolicy === null
|
||||
&& recovery.fingerprint === nativeSha256({ runId: settled.run.id, failureCode: recovery.cause })
|
||||
&& !fileKeys.some(key => recovery.evidence?.[key] != null)) {
|
||||
&& !TASK_RECOVERY_FILE_KEYS.some(key => recovery.evidence?.[key] != null)) {
|
||||
const source = await inspectOnlineLegacyWorkspaceRecoverySource(db, { workspace: input.workspace, runId: settled.run.id });
|
||||
if (source?.reference?.state === "prepared" && source.issueId === recovery.sourceIssueId)
|
||||
return { fingerprint: fingerprint({ recovery, source }), finalizedHold: null, preparedSource: source };
|
||||
|
||||
@@ -376,14 +376,17 @@ describe.skipIf(!support.supported)("remote workspace migration", () => {
|
||||
expect((await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, run!.id)))[0]).toEqual(run);
|
||||
expect(readRemoteWorkspaceAuthority((await workspace(f.workspaceId)).metadata)).not.toBeNull();
|
||||
});
|
||||
it.each([["stranded_assigned_issue", "stranded_assigned_issue"], ["configuration_validation", "configuration_incomplete"],
|
||||
["missing_disposition", "successful_run_missing_state"], ["deliberate_wait_without_target", "deliberate_wait_without_target"]])("preserves a task-only %s warning through offline file migration", async (kind, cause) => {
|
||||
it.each([["stranded_assigned_issue", "stranded_assigned_issue", "offline"], ["configuration_validation", "configuration_incomplete", "offline"],
|
||||
["missing_disposition", "successful_run_missing_state", "offline"], ["deliberate_wait_without_target", "deliberate_wait_without_target", "offline"],
|
||||
["stranded_assigned_issue", "stranded_assigned_issue", "online"], ["configuration_validation", "configuration_incomplete", "online"],
|
||||
["missing_disposition", "successful_run_missing_state", "online"], ["deliberate_wait_without_target", "deliberate_wait_without_target", "online"],
|
||||
])("preserves a task-only %s warning (%s) through %s file migration", async (kind, cause, mode) => {
|
||||
const f = await seed();
|
||||
const [action] = await db.insert(issueRecoveryActions).values({ companyId: f.companyId, sourceIssueId: f.issueId,
|
||||
kind, cause, fingerprint: randomUUID(), nextAction: "Keep the existing task warning", evidence: { latestRunStatus: "failed" } }).returning();
|
||||
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true })).rejects.toThrow("workspace_recovery_unresolved");
|
||||
vi.stubEnv("PAPERCLIP_EPHEMERAL_MIGRATION", "true");
|
||||
await migrateRemoteWorkspace({ db, storage, ...f, apply: true, writersStopped: true });
|
||||
if (mode === "offline") vi.stubEnv("PAPERCLIP_EPHEMERAL_MIGRATION", "true");
|
||||
expect(await inventoryRemoteWorkspaceMigration(db, { ...f, writersStopped: mode === "offline" })).toMatchObject({ eligible: true, reasons: [] });
|
||||
await migrateRemoteWorkspace({ db, storage, ...f, apply: true, ...(mode === "offline" ? { writersStopped: true } : {}) });
|
||||
expect((await db.select().from(issueRecoveryActions).where(eq(issueRecoveryActions.id, action!.id)))[0]).toEqual(action);
|
||||
const authority = readRemoteWorkspaceAuthority((await workspace(f.workspaceId)).metadata)!;
|
||||
const ref = await getWorkspaceSnapshot(db, { ...f, snapshotId: authority.snapshotId! });
|
||||
@@ -415,6 +418,26 @@ describe.skipIf(!support.supported)("remote workspace migration", () => {
|
||||
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true, writersStopped: true })).rejects.toThrow("workspace_recovery_unresolved");
|
||||
expect(readRemoteWorkspaceAuthority((await workspace(f.workspaceId)).metadata)).toBeNull();
|
||||
});
|
||||
it("rechecks a task warning that becomes file recovery during an online upload", async () => {
|
||||
const f = await seed();
|
||||
const [action] = await db.insert(issueRecoveryActions).values({ companyId: f.companyId, sourceIssueId: f.issueId,
|
||||
kind: "stranded_assigned_issue", cause: "stranded_assigned_issue", fingerprint: randomUUID(), nextAction: "Assign the task" }).returning();
|
||||
const put = storage.putFile.bind(storage);
|
||||
storage.putFile = async input => { const result = await put(input);
|
||||
await db.update(issueRecoveryActions).set({ evidence: { historicalWorkspaceSource: { schema: "paperclip.historical-workspace-source.v1" } } })
|
||||
.where(eq(issueRecoveryActions.id, action!.id)); return result; };
|
||||
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true })).rejects.toThrow("workspace_recovery_unresolved");
|
||||
expect(readRemoteWorkspaceAuthority((await workspace(f.workspaceId)).metadata)).toBeNull();
|
||||
});
|
||||
it.each(["workspace_validation", "active_run_watchdog", "export-cause"])("keeps an online blocker for file or execution recovery without a source proof (%s)", async mode => {
|
||||
const f = await seed();
|
||||
await db.insert(issueRecoveryActions).values({ companyId: f.companyId, sourceIssueId: f.issueId,
|
||||
kind: mode === "export-cause" ? "configuration_validation" : mode,
|
||||
cause: mode === "export-cause" ? "native_workspace_sync_out_unrecoverable" : mode === "workspace_validation" ? "workspace_validation_failed" : "native_session_interrupted",
|
||||
fingerprint: randomUUID(), nextAction: "Preserve unresolved recovery" });
|
||||
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true })).rejects.toThrow("workspace_recovery_unresolved");
|
||||
expect(readRemoteWorkspaceAuthority((await workspace(f.workspaceId)).metadata)).toBeNull();
|
||||
});
|
||||
it("detects overlapping folders reached through symlinked parent directories", async () => {
|
||||
const f = await seed(), alias = path.join(root, "alias"); await fs.symlink(root, alias);
|
||||
await db.insert(executionWorkspaces).values({ companyId: f.companyId, name: "Physical alias", mode: "isolated_workspace",
|
||||
|
||||
@@ -27,7 +27,7 @@ import { createNestedWorkspaceImportVerifier, onlineOrdinarySourceBlockers, offl
|
||||
|
||||
import { inspectOnlineWorkspaceSource, requiresOnlineWorkspaceSource, type OnlineWorkspaceSource } from "./online-workspace-source.js";
|
||||
import { withWorkspaceSourceLocks, withIndependentWorkspaceSourceLocks, IsolatedRepositorySourceBusy } from "./workspace-source-lock.js";
|
||||
import { inspectOnlineLegacyWorkspaceRecoverySource, inspectOnlineLegacyWorkspaceRecoveryHold, lockOnlineLegacyWorkspaceRecoverySources, ONLINE_LEGACY_WORKSPACE_PRESERVATION, type OnlineLegacyWorkspaceRecoveryHold } from "./online-legacy-workspace-recovery.js";
|
||||
import { inspectOnlineLegacyWorkspaceRecoverySource, inspectOnlineLegacyWorkspaceRecoveryHold, isTaskDispositionRecovery, lockOnlineLegacyWorkspaceRecoverySources, ONLINE_LEGACY_WORKSPACE_PRESERVATION, type OnlineLegacyWorkspaceRecoveryHold } from "./online-legacy-workspace-recovery.js";
|
||||
import { inspectNativeWorkspaceMigration, nativeWorkspaceMigrationMarker } from "./native-runtime/native-workspace-migration.js";
|
||||
import { readGitCacheExpiration, GIT_CACHE_EXPIRATION_REASON } from "./git-workspace-restoration.js";
|
||||
|
||||
@@ -300,7 +300,13 @@ async function inspect(db: ReadDb, input: { companyId: string; workspaceId: stri
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!input.writersStopped || object(recovery.evidence?.systemRecovery).state === "running") {
|
||||
if (!input.writersStopped) {
|
||||
const held = isTaskDispositionRecovery(recovery) ? await inspectOnlineLegacyWorkspaceRecoveryHold(db, { workspace, recovery }) : null;
|
||||
if (held && !held.finalizedHold && !held.preparedSource && !held.remoteHold) onlineRecoveryHolds.push({ actionId: recovery.id, ...held });
|
||||
else reasons.push("workspace_recovery_unresolved");
|
||||
continue;
|
||||
}
|
||||
if (object(recovery.evidence?.systemRecovery).state === "running") {
|
||||
reasons.push("workspace_recovery_unresolved"); continue;
|
||||
}
|
||||
if (legacyRecoverySources.some(source => source.runId === recovery.evidence?.runId && source.reference?.state !== "finalized")) continue;
|
||||
|
||||
Reference in new issue
Block a user