fix(workspaces): move a managed folder online when its records name a repository that is not there (#22722)

## 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
> - The online pass moves a managed folder with no repository as an
ordinary folder: it copies the files under the folder's source locks
> - On staging, two stacks keep 33 workspaces blocked with
`workspaces:source_scope_not_git_source`
> - Those records carry a repository URL or branch, so the ordinary path
skips them, but their folder holds no repository, so the Git path
refuses them too
> - The offline move copies the same folder as files
> - This pull request lets the ordinary path prove a managed folder
whose records name a repository that is not there
> - The benefit is that these workspaces move online exactly as they
move offline, with the same fence as every other ordinary folder

## Linked Issues or Issue Description

Refs #22644

**What happened?**
After repeated online passes on staging (Core 4434d12e), one stack
reports `source_scope_not_git_source` x30 (29 of them also
`overlapping_workspace_requires_maintenance`), and another reports it
x3.

**Expected behavior**
The online move accepts what the offline move accepts for the same data,
with a fence that is checked again under lock at publication. Offline
copies a folder with no repository as files, whatever its records say
about Git.

**Steps to reproduce**
1. Create a managed project folder with three task records that point at
it.
2. Set `repoUrl` and `branchName` on the records. Do not create a
repository in the folder.
3. Run `inventoryRemoteWorkspaceMigration` online. It reports
`online_workspace_source_scope_unproven` with `not_git_source`.

**Why it is safe**
- The source locks come from the folder's physical path, not from the
record's Git fields. Writers to the folder take the same project or task
lock.
- The ordinary capture runs with `requireNoGit`. If a `.git` entry
appears during the capture, the capture fails and nothing is published.
- The ordinary proof still checks every member: provider, task binding,
strategy, status, restoration state, foreign aliases. The publication
checks the scope again under lock.
- The published source keeps the record's repository URL and base ref,
the same as offline.

## What Changed

- `explainOnlineOrdinarySource` no longer skips a `local_fs` record
because it has `repoUrl` or `branchName`. It still skips such a record
when the folder has a `.git` entry, so real checkouts keep the Git path
and its cost does not change.
- `ordinaryMemberUnproven` accepts a `local_fs` member with `repoUrl` or
`branchName`. Non-`local_fs` members are still `ordinary_member_git`.
- A member with an unfinished Git cache expiration is now
`member_git_expiration_pending` on the ordinary path too. The Git path
already refuses it.

## Verification

- Rebased onto `origin/master` after #22718 and #22721. Both behaviours
are kept: members are compared by physical path (#22721), and a
`local_fs` member may carry Git fields when the folder has no repository
(this PR).
- Red on `origin/master` (b908678ea3): the never-cloned folder reports
`not_git_source` and is not eligible. The expiration guard test also
reports `not_git_source`.
- Green with the fix. The never-cloned folder is eligible, its source is
`ordinary` with all three records, and the migration publishes. The
published source is `{ kind: "git", repoUrl, ref: "main" }`. The
restored archive holds the saved file, and the local folder is
unchanged. The member with an unfinished expiration stays blocked with
no workspace operation.
- `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/remote-workspace-migration-concurrency.test.ts
src/services/online-durable-data-migration.test.ts
src/services/remote-workspace-snapshot-archive.test.ts`: 6 files, 532
tests passed after the rebase (embedded PostgreSQL).
- `cd server && pnpm typecheck`: passed.

## Risks

- Medium. More folders become movable online. The fence and the capture
are the same ones that ordinary folders already use.
- A folder with a `.git` entry that is not a repository still goes to
the Git path and stays blocked.
- A `local_fs` record at an unmanaged folder with no repository now
reports `ordinary_root_unmanaged` instead of `git_checkout_missing`
(#22718), because the unmanaged root is the reason it stays blocked. A
`git_worktree` record in the same state still reports
`git_checkout_missing`. The test covers both.

## 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:
DottaandClaude Opus 5.5 authored and GitHub committed 2026-11-23 20:06:05 -06:00
1 parent f144bdee34
commit dd6db295a3
2 files changed
+39 -5

No files matched your search

@@ -98,19 +98,22 @@ function ordinaryMemberUnproven(row: { cwd: string | null; providerRef: string |
if (physical.some(cwd => cwd.startsWith(`${root}/`))) return "ordinary_member_nested";
if (physical.some(cwd => root.startsWith(`${cwd}/`))) return "ordinary_member_encloses_root";
if (!row.cwd || physical.some(cwd => cwd !== root)) return "ordinary_member_locator_mismatch";
if (row.providerType !== "local_fs" || row.repoUrl || row.branchName) return "ordinary_member_git";
if (row.providerType !== "local_fs") return "ordinary_member_git";
if (!row.sourceIssueId || isolatedIssueId && row.sourceIssueId !== isolatedIssueId) return "ordinary_member_task_binding";
if (row.strategyType !== "project_primary" || !["isolated_workspace", "shared_workspace"].includes(row.mode)) return "ordinary_member_strategy_unsupported";
if (!["active", "idle", "in_review", "archived"].includes(row.status)) return "member_status_unsupported";
if (row.metadata?.remoteWorkspace) return "member_already_remote";
if (row.metadata?.gitCacheRestoration || row.metadata?.nestedCloneMigrationPending) return "ordinary_member_restoration_pending";
if (row.metadata?.gitCacheExpiration) return "member_git_expiration_pending";
return null;
}
export async function explainOnlineOrdinarySource(db: ReadDb, workspace: Workspace): Promise<OrdinarySource | { unproven: string } | null> {
const unproven = (code: string) => ({ unproven: code });
if (!workspace.cwd || workspace.providerType !== "local_fs" || workspace.repoUrl || workspace.branchName) return null;
if (!workspace.cwd || workspace.providerType !== "local_fs") return null;
const root = await physicalPath(workspace.cwd);
if ((workspace.repoUrl || workspace.branchName) && await fs.lstat(path.join(root, ".git")).then(() => true,
(error: NodeJS.ErrnoException) => { if (error.code !== "ENOENT") throw error; return false; })) return null;
const instance = await physicalPath(resolvePaperclipInstanceRoot());
const parts = path.relative(instance, root).split(path.sep);
const isolated = workspace.sourceIssueId && ["isolated_workspace", "shared_workspace"].includes(workspace.mode)
@@ -130,6 +133,8 @@ export async function explainOnlineOrdinarySource(db: ReadDb, workspace: Workspa
strategyType: executionWorkspaces.strategyType, mode: executionWorkspaces.mode, status: executionWorkspaces.status,
metadata: sql<Record<string, unknown>>`jsonb_build_object(
'gitCacheRestoration', ${executionWorkspaces.metadata}->'gitCacheRestoration',
'gitCacheExpiration', case when ${executionWorkspaces.metadata}->'gitCacheExpiration'->>'schema' = 'paperclip.git-cache-expiration.v1'
and coalesce(${executionWorkspaces.metadata}->'gitCacheExpiration'->>'completed', 'false') <> 'true' then true end,
'nestedCloneMigrationPending', ${executionWorkspaces.metadata}->'nestedCloneMigrationPending',
'remoteWorkspace', ${executionWorkspaces.metadata}->'remoteWorkspace')`,
};
@@ -156,6 +156,34 @@ describe.skipIf(!support.supported)("online ordinary physical source fence", ()
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true })).rejects.toThrow("online_workspace_source_scope_unproven");
expect(await db.select().from(workspaceOperations)).toEqual([]);
});
it("imports a managed folder whose records name a repository that was never checked out", async () => {
const f = await fixture(), repoUrl = "https://example.invalid/never-cloned.git";
for (const alias of f.aliases) await db.update(executionWorkspaces).set({ repoUrl, branchName: "main", baseRef: "main" })
.where(eq(executionWorkspaces.id, alias.workspace.id));
expect(await inventoryRemoteWorkspaceMigration(db, f)).toMatchObject({ eligible: true, reasons: [] });
expect(await inspectOnlineWorkspaceSource(db, await stored(f.workspaceId))).toMatchObject({ kind: "ordinary",
workspaceIds: f.aliases.map(alias => alias.workspace.id).sort() });
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true })).resolves.toMatchObject({ applied: true });
const authority = readRemoteWorkspaceAuthority((await stored(f.workspaceId)).metadata)!;
expect(authority.source).toMatchObject({ kind: "git", repoUrl, ref: "main" });
const reference = await getWorkspaceSnapshot(db, { ...f, snapshotId: authority.snapshotId! });
const archivePath = path.join(home, "never-cloned.pcws"), targetDir = path.join(home, "never-cloned-restored");
await loadWorkspaceSnapshotArchive({ storage, reference: reference!, targetPath: archivePath });
await restoreRemoteWorkspaceArchive({ archivePath, targetDir, expectedManifestDigest: reference!.manifestDigest });
expect(await fs.readFile(path.join(targetDir, "saved.txt"), "utf8")).toBe("saved legacy edits\n");
expect(await fs.readFile(path.join(f.cwd, "saved.txt"), "utf8")).toBe("saved legacy edits\n");
});
it("keeps a managed folder without a repository blocked while a member's Git cache expiration is unfinished", async () => {
const f = await fixture(), alias = f.aliases[1].workspace;
for (const { workspace } of f.aliases) await db.update(executionWorkspaces).set({ repoUrl: "https://example.invalid/expiring.git", branchName: "main" })
.where(eq(executionWorkspaces.id, workspace.id));
await db.update(executionWorkspaces).set({ metadata: { gitCacheExpiration: { schema: "paperclip.git-cache-expiration.v1", completed: false } } })
.where(eq(executionWorkspaces.id, alias.id));
expect(await inventoryRemoteWorkspaceMigration(db, f)).toMatchObject({ eligible: false,
reasons: expect.arrayContaining(["online_workspace_source_scope_unproven"]), sourceScopeUnproven: "member_git_expiration_pending" });
await expect(migrateRemoteWorkspace({ db, storage, ...f, apply: true })).rejects.toThrow("online_workspace_source_scope_unproven");
expect(await db.select().from(workspaceOperations)).toEqual([]);
});
it.each([false, true])("does not admit a Git fragment as an ordinary migration source (objects: %s)", async objects => {
const f = await fixture(), info = path.join(f.cwd, ".git", "info");
await fs.mkdir(info, { recursive: true });
@@ -167,15 +195,16 @@ describe.skipIf(!support.supported)("online ordinary physical source fence", ()
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 () => {
it.each([["local_fs", "ordinary_root_unmanaged"], ["git_worktree", "git_checkout_missing"]] as const)(
"names a %s Git record whose unmanaged directory holds no repository", async (providerType, code) => {
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" })
await db.update(executionWorkspaces).set({ cwd, providerRef: cwd, providerType, 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" });
reasons: ["online_workspace_source_scope_unproven"], sourceScopeUnproven: code });
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");
});