mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
fix(workspaces): name the overlap and missing-Git cases that keep a workspace from moving online (#22718)
## 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 stack moves only when the online pass reports no blockers, so each blocker must name its exact cause > - On staging, one stack reports `workspaces:overlapping_workspace_requires_maintenance` x6 with no detail code, and two stacks report `workspaces:source_scope_not_git_source` x33 > - The overlap code has no detail when the workspace does not need a proven source scope, and `not_git_source` joins two different cases > - This pull request names how the paths overlap, why the source scope is unproven, and which of the two Git cases applies > - The benefit is that the next pass on each blocked stack shows which rule applies, so the matching fix can follow ## Linked Issues or Issue Description Refs #22644, #22696 **What happened?** After repeated online passes on staging (Core4434d12e), one stack reports `overlapping_workspace_requires_maintenance` x6 with no `source_scope_*` code. Two other stacks report `source_scope_not_git_source` x30 and x3. **Expected behavior** Each blocked workspace names the exact cause. An overlap names how the paths overlap and why the source scope is unproven. A missing Git source says if the directory has a `.git` entry that is not a repository, or no repository at all. **Steps to reproduce** 1. Create a workspace at an unmanaged path, and a second task workspace in a subfolder of it. 2. Run `inventoryRemoteWorkspaceMigration` online for either workspace. 3. The result has only `overlapping_workspace_requires_maintenance`. It has no detail and no `sourceScopeUnproven`. **Why no detail was emitted** The inventory reported `sourceScopeUnproven` only when the workspace needs a proven source scope (`requiresOnlineWorkspaceSource`). A non-Git directory outside the managed roots does not need one. The overlap check then blocks it, and nothing names the cause. ## What Changed - `workspaceMigrationLayoutBlockers` returns a state with each overlap: `same_directory`, `nested_workspace`, `enclosing_workspace` or `imported_child_unrecorded`. The inventory adds it as `overlapping_workspace_requires_maintenance:<state>` in `details`. The online pass already reports details as `workspaces:<reason>:<state>`. - The inventory now reports `sourceScopeUnproven` also when the workspace is blocked by an overlap. Example: `ordinary_root_unmanaged`. - `not_git_source` is now one of two codes: - `git_marker_not_repository`: the directory has a `.git` entry that is not a readable repository. - `git_checkout_missing`: the record says Git (repository URL, branch or worktree strategy), but the directory has no repository. - The `reasons` list does not change. No rule changes: every case that was blocked stays blocked. ## Verification - Red on `origin/master` (b908678ea3): the four new or changed assertions fail. The overlap result has no `details` and no `sourceScopeUnproven`. The Git fragment and the declared Git record report `not_git_source`. - Green with the fix: `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-durable-data-migration.test.ts src/services/remote-workspace-migration-concurrency.test.ts`: 5 files, 392 tests passed (embedded PostgreSQL). - `cd server && pnpm typecheck`: passed. ## Risks - Low risk. Only names change. The set of blocked workspaces and the `reasons` list do not change. - The online pass reports one more deferral key per overlapping workspace (`workspaces:overlapping_workspace_requires_maintenance:<state>`). This is the same form that #22696 uses. ## 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
2b8ae371d3
commit
f144bdee34
5 files changed
+44
-9
No files matched your search
@@ -112,7 +112,13 @@ export async function explainOnlineWorkspaceSource(db: ReadDb, workspace: Worksp
|
||||
}
|
||||
} catch { return unproven("git_identity_unreadable"); }
|
||||
const captureRoot = await physicalPath(cwd), gitSources = selected.git ? [selected.git] : nestedGit;
|
||||
if (!gitSources.length) return unproven(ordinaryUnproven ?? "not_git_source");
|
||||
if (!gitSources.length) {
|
||||
if (ordinaryUnproven) return unproven(ordinaryUnproven);
|
||||
const marker = await fs.lstat(path.join(captureRoot, ".git")).catch((error: NodeJS.ErrnoException) => {
|
||||
if (error.code !== "ENOENT") throw error; return null;
|
||||
});
|
||||
return unproven(marker ? "git_marker_not_repository" : "git_checkout_missing");
|
||||
}
|
||||
if (selected.git && selected.git.root !== captureRoot) return unproven("git_root_mismatch");
|
||||
if (selected.unownedPaths.length) return unproven("unowned_path");
|
||||
if (!workspace.sourceIssueId) return unproven("task_binding_missing");
|
||||
|
||||
@@ -246,8 +246,13 @@ export async function onlineOrdinarySourceBlockers(db: Pick<Db, "execute">, comp
|
||||
|
||||
/** Only the maintenance entry point can acknowledge that every old deployment
|
||||
* has stopped. A task-level migration hold cannot fence other path aliases. */
|
||||
export async function workspaceMigrationLayoutBlockers(db: ReadDb, workspace: Workspace, writersStopped = false, onlineSource?: WorkspaceSourceScope) {
|
||||
if (writersStopped) return offlineWorkspaceMigrationBlockers(db);
|
||||
export type WorkspaceLayoutBlocker = { reason: string; state?: string };
|
||||
const overlapState = (root: string, physical: string) =>
|
||||
physical === root ? "same_directory" : physical.startsWith(`${root}/`) ? "nested_workspace" : "enclosing_workspace";
|
||||
|
||||
export async function workspaceMigrationLayoutBlockers(db: ReadDb, workspace: Workspace, writersStopped = false,
|
||||
onlineSource?: WorkspaceSourceScope): Promise<WorkspaceLayoutBlocker[]> {
|
||||
if (writersStopped) return (await offlineWorkspaceMigrationBlockers(db)).map(reason => ({ reason }));
|
||||
const cwd = rootOf(workspace);
|
||||
if (!cwd) return [];
|
||||
const local = await db.select({ id: executionWorkspaces.id, cwd: executionWorkspaces.cwd,
|
||||
@@ -261,9 +266,10 @@ export async function workspaceMigrationLayoutBlockers(db: ReadDb, workspace: Wo
|
||||
const physical = await physicalPath(cwd);
|
||||
if (onlineSource?.gitSourceRoots && physical.startsWith(`${root}/.paperclip/worktrees/`)) {
|
||||
const entry = await fs.lstat(physical).catch((error: NodeJS.ErrnoException) => { if (error.code !== "ENOENT") throw error; return null; });
|
||||
if (entry) return ["nested_workspace_import_required"];
|
||||
if (entry) return [{ reason: "nested_workspace_import_required" }];
|
||||
}
|
||||
if (!onlineSource?.workspaceIds.includes(row.id) && overlaps(root, physical)) return ["overlapping_workspace_requires_maintenance"];
|
||||
if (!onlineSource?.workspaceIds.includes(row.id) && overlaps(root, physical))
|
||||
return [{ reason: "overlapping_workspace_requires_maintenance", state: overlapState(root, physical) }];
|
||||
}
|
||||
}
|
||||
const migrated = await db.select({ id: workspaceOperations.id, cwd: workspaceOperations.cwd }).from(workspaceOperations).where(and(
|
||||
@@ -275,7 +281,7 @@ export async function workspaceMigrationLayoutBlockers(db: ReadDb, workspace: Wo
|
||||
const sourcePath = await physicalPath(row.cwd);
|
||||
if (sourcePath.startsWith(`${root}/.paperclip/worktrees/`)
|
||||
&& !(onlineSource?.gitSourceRoots && onlineSource.importedChildren?.some(child => child.operationId === row.id && child.sourcePath === sourcePath)))
|
||||
return ["overlapping_workspace_requires_maintenance"];
|
||||
return [{ reason: "overlapping_workspace_requires_maintenance", state: "imported_child_unrecorded" }];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -404,6 +404,12 @@ describe.skipIf(!support.supported)("remote workspace migration", () => {
|
||||
}
|
||||
it("requires offline maintenance for overlapping physical workspace paths", async () => {
|
||||
const { parent, child } = await nestedFixture();
|
||||
expect(await inventoryRemoteWorkspaceMigration(db, child)).toMatchObject({ eligible: false,
|
||||
reasons: ["overlapping_workspace_requires_maintenance"], sourceScopeUnproven: "ordinary_root_unmanaged",
|
||||
details: ["overlapping_workspace_requires_maintenance:enclosing_workspace"] });
|
||||
expect(await inventoryRemoteWorkspaceMigration(db, parent)).toMatchObject({ eligible: false,
|
||||
reasons: ["overlapping_workspace_requires_maintenance"], sourceScopeUnproven: "ordinary_root_unmanaged",
|
||||
details: ["overlapping_workspace_requires_maintenance:nested_workspace"] });
|
||||
await expect(migrateRemoteWorkspace({ db, storage, ...child, apply: true })).rejects.toThrow("overlapping_workspace_requires_maintenance");
|
||||
await expect(migrateRemoteWorkspace({ db, storage, ...parent, apply: true })).rejects.toThrow("overlapping_workspace_requires_maintenance");
|
||||
expect(await fs.readFile(path.join(child.cwd, "child.txt"), "utf8")).toBe("saved child edits\n");
|
||||
|
||||
@@ -210,7 +210,11 @@ async function inspect(db: ReadDb, input: { companyId: string; workspaceId: stri
|
||||
filesGone = !entry && !retainedDirectory && !archivedGitSource && workspace.status === "archived"
|
||||
&& !reasons.includes("restore_point_expired") && !reasons.includes("restore_point_invalid")
|
||||
&& await workspaceFilesProvenGone(db, workspace);
|
||||
if (entry?.isDirectory() && !entry.isSymbolicLink()) reasons.push(...await workspaceMigrationLayoutBlockers(db, workspace, input.writersStopped, input.onlineSource));
|
||||
if (entry?.isDirectory() && !entry.isSymbolicLink()) {
|
||||
for (const blocker of await workspaceMigrationLayoutBlockers(db, workspace, input.writersStopped, input.onlineSource)) {
|
||||
if (blocker.state) detail(blocker.reason, blocker.state); else reasons.push(blocker.reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
const [issue] = workspace.sourceIssueId ? await db.select().from(issues).where(and(eq(issues.companyId, workspace.companyId), eq(issues.id, workspace.sourceIssueId))) : [];
|
||||
// Historical records still own their saved files after the task selects a
|
||||
@@ -412,8 +416,9 @@ export async function inventoryRemoteWorkspaceMigration(db: Db, input: { company
|
||||
const onlineSource = explained && !("unproven" in explained) ? explained : undefined;
|
||||
const onlineSourceUnproven = Boolean(workspace && explained && !onlineSource && await requiresOnlineWorkspaceSource(workspace));
|
||||
const result = await inspect(db, { ...input, onlineSource, onlineSourceUnproven });
|
||||
const scopeNamed = onlineSourceUnproven || result.reasons.includes("overlapping_workspace_requires_maintenance");
|
||||
return { companyId: input.companyId, workspaceId: input.workspaceId, eligible: result.reasons.length === 0,
|
||||
...(onlineSourceUnproven && explained && "unproven" in explained ? { sourceScopeUnproven: explained.unproven } : {}),
|
||||
...(scopeNamed && explained && "unproven" in explained ? { sourceScopeUnproven: explained.unproven } : {}),
|
||||
...(result.details.length ? { details: result.details } : {}),
|
||||
alreadyMigrated: Boolean(result.authority), ...(result.filesGone ? { filesUnavailable: true } : {}), reasons: result.reasons, localPath: result.workspace.cwd ?? result.workspace.providerRef,
|
||||
source: result.source, operationId: typeof result.marker.operationId === "string" ? result.marker.operationId : null,
|
||||
|
||||
@@ -162,11 +162,23 @@ describe.skipIf(!support.supported)("online ordinary physical source fence", ()
|
||||
await fs.writeFile(path.join(info, "exclude"), "/.paperclip-repositories/\n");
|
||||
if (objects) await fs.mkdir(path.join(f.cwd, ".git", "objects"));
|
||||
expect(await inventoryRemoteWorkspaceMigration(db, f)).toMatchObject({ eligible: false,
|
||||
reasons: expect.arrayContaining(["online_workspace_source_scope_unproven"]) });
|
||||
reasons: expect.arrayContaining(["online_workspace_source_scope_unproven"]), sourceScopeUnproven: objects ? "git_head_missing" : "git_marker_not_repository" });
|
||||
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true })).rejects.toThrow("online_workspace_source_scope_unproven");
|
||||
expect(await db.select().from(workspaceOperations)).toEqual([]);
|
||||
expect(await fs.readFile(path.join(info, "exclude"), "utf8")).toBe("/.paperclip-repositories/\n");
|
||||
});
|
||||
it("names a Git record whose unmanaged directory holds no repository", async () => {
|
||||
const f = await fixture(), cwd = path.join(home, "declared-git-without-checkout");
|
||||
await fs.mkdir(cwd); await fs.writeFile(path.join(cwd, "saved.txt"), "kept\n");
|
||||
for (const alias of f.aliases.slice(1)) await db.update(executionWorkspaces).set({ providerType: "plugin" })
|
||||
.where(eq(executionWorkspaces.id, alias.workspace.id));
|
||||
await db.update(executionWorkspaces).set({ cwd, providerRef: cwd, repoUrl: "https://example.invalid/declared.git", branchName: "main" })
|
||||
.where(eq(executionWorkspaces.id, f.workspaceId));
|
||||
expect(await inventoryRemoteWorkspaceMigration(db, f)).toMatchObject({ eligible: false,
|
||||
reasons: ["online_workspace_source_scope_unproven"], sourceScopeUnproven: "git_checkout_missing" });
|
||||
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true })).rejects.toThrow("online_workspace_source_scope_unproven");
|
||||
expect(await fs.readFile(path.join(cwd, "saved.txt"), "utf8")).toBe("kept\n");
|
||||
});
|
||||
it("preserves unmanaged Git import in genuine offline mode while retaining online and drain guards", async () => {
|
||||
const f = await fixture(), cwd = path.join(home, "self-hosted-repository"), repoUrl = "https://example.invalid/self-hosted.git";
|
||||
await fs.mkdir(cwd); await git(cwd, "init", "-q", "-b", "main");
|
||||
|
||||
Reference in new issue
Block a user