From e53cce2257a96a9f436fd83b2f34fd3d88e76520 Mon Sep 17 00:00:00 2001 From: Tiangao <53409436+tiangao88@users.noreply.github.com> Date: Fri, 4 Dec 2026 20:01:45 +0100 Subject: [PATCH] fix: accept nested git worktree folders for local adapters (#7957) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Local adapters such as `codex_local` need workspace validation before launching agent runs. > - The validator became too strict by requiring `.git` metadata directly inside the adapter cwd. > - Git itself treats subdirectories of a repository as valid worktree paths, and Codex can operate from those nested folders. > - Paperclip project folders can be configured as subdirectories inside a larger Git worktree. > - This pull request aligns Paperclip validation with Git's own worktree detection. > - The benefit is fewer false `workspace_validation_failed` errors while still rejecting folders outside any Git worktree. ## Linked Issues or Issue Description - Fixes: #7956 ## What Changed - Replace direct `cwd/.git` metadata checking with `git -C rev-parse --is-inside-work-tree`. - Add regression coverage for a workspace-linked issue whose adapter cwd is nested inside a parent Git worktree. - Clean up the temporary Git fixture created by that regression test. - Preserve rejection behavior for folders that are not inside any Git worktree. ## Verification - `pnpm --filter @paperclipai/server exec vitest run src/__tests__/heartbeat-workspace-session.test.ts` - `pnpm --filter @paperclipai/server typecheck` Local validation results: - `heartbeat-workspace-session.test.ts`: 107 tests passed. - Server typecheck passed. ## Risks - Low risk. This changes validation from a stricter direct `.git` file check to Git's own worktree detection. - Requires `git` to be available for git-sensitive local adapter validation. These adapters already require Git-compatible workspaces. - Still fails closed for missing, invalid, or non-git workspace paths. > 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 Codex, GPT-5.5, with repository inspection, shell execution, local runtime validation, and focused test execution. ## 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 run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [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 --------- Co-authored-by: zocomputer Co-authored-by: commitperclip[bot] <284812584+commitperclip[bot]@users.noreply.github.com> --- .../heartbeat-workspace-session.test.ts | 32 ++++++++++++++++++- server/src/services/heartbeat/workspaces.ts | 7 ++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/server/src/__tests__/heartbeat-workspace-session.test.ts b/server/src/__tests__/heartbeat-workspace-session.test.ts index bb6242fd2df..1a650cfa337 100644 --- a/server/src/__tests__/heartbeat-workspace-session.test.ts +++ b/server/src/__tests__/heartbeat-workspace-session.test.ts @@ -444,10 +444,40 @@ describe("assertGitSensitiveAdapterWorkspaceValid", () => { }, }), "missing_git_metadata", - "has no .git metadata", + "is not inside a git worktree", ); }); + it("accepts a workspace-linked issue when adapter cwd is a subdirectory inside a git worktree", async () => { + const root = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-git-parent-")); + try { + const cwd = path.join(root, "nested", "project"); + await fs.mkdir(cwd, { recursive: true }); + await execFile("git", ["init"], { cwd: root }); + + const input = buildWorkspaceValidationInput(); + + await expect( + assertGitSensitiveAdapterWorkspaceValid( + buildWorkspaceValidationInput({ + resolvedWorkspace: buildResolvedWorkspace({ cwd }), + executionWorkspace: { + ...input.executionWorkspace, + baseCwd: cwd, + cwd, + }, + persistedExecutionWorkspace: { + ...input.persistedExecutionWorkspace!, + cwd, + }, + }), + ), + ).resolves.toBeUndefined(); + } finally { + await fs.rm(root, { recursive: true, force: true }); + } + }); + it("does not apply the git-sensitive workspace guard to non-local execution targets", async () => { const input = buildWorkspaceValidationInput(); diff --git a/server/src/services/heartbeat/workspaces.ts b/server/src/services/heartbeat/workspaces.ts index 40a2b6e8733..e11de057b32 100644 --- a/server/src/services/heartbeat/workspaces.ts +++ b/server/src/services/heartbeat/workspaces.ts @@ -830,9 +830,8 @@ export function fingerprintFinalizeWorkspaceBranchValidation(input: { async function hasGitMetadata(cwd: string | null | undefined) { const normalized = readNonEmptyString(cwd); if (!normalized) return false; - return fs - .lstat(path.resolve(normalized, ".git")) - .then((entry) => entry.isDirectory() || entry.isFile()) + return execFile("git", ["-C", path.resolve(normalized), "rev-parse", "--is-inside-work-tree"]) + .then((result) => result.stdout.trim() === "true") .catch(() => false); } @@ -1278,7 +1277,7 @@ export async function assertGitSensitiveAdapterWorkspaceValid(input: { ) { fail( "missing_git_metadata", - `Issue ${issue.identifier ?? issue.id} expected a git workspace for ${input.adapterType}, but "${effectiveCwd}" has no .git metadata.`, + `Issue ${issue.identifier ?? issue.id} expected a git workspace for ${input.adapterType}, but "${effectiveCwd}" is not inside a git worktree.`, ); }