From 8b7b2a070107616a7850ea10d8d7ed0c3558dcc2 Mon Sep 17 00:00:00 2001 From: "commitperclip[bot]" <284812584+commitperclip[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:59:22 -0600 Subject: [PATCH] fix: Recognize Git mount-boundary absence diagnostics in workspace checks (#21048) > [!NOTE] > Opened by Prospector's automated issue-fix pipeline. A maintainer reviews and decides; nothing here merges on its own. > [!WARNING] > This change crosses a trust boundary. See Risks. ## Thinking Path - Issue #20525 reports a defect in paperclipai/paperclip. - Root cause, as the fixing agent read it: Both callers recognized only the ordinary Git absence diagnostic. Preserve the earlier exact boundary matcher and all existing exit, signal, environment, and filesystem checks. - This pull request: Recognize Git mount-boundary absence diagnostics in workspace checks ## What Changed - `server/src/services/git-mount-boundary-message.ts`: Retain the shared complete-diagnostic matcher, which rejects partial and appended output. - `server/src/services/managed-repository-checkout.ts`: Retain boundary recognition without changing ordinary-diagnostic behavior or fallback guards. - `server/src/services/heartbeat/workspaces.ts`: Retain boundary recognition and ancestor metadata inspection. - `server/src/__tests__/git-mount-boundary.test.ts`: Add root mount, CRLF, and embedded-line-break cases through both callers. Confirmed six failures with boundary recognition disabled; restored implementation passes this suite, both neighboring suites, and typecheck. ## Verification - Reproducing test(s), added in this PR: `server/src/__tests__/git-mount-boundary.test.ts` - They fail on the base commit and pass with the fix, each twice in a fresh sandbox. - The repository's compile command passes with the fix applied. - 10 existing test file(s) near the change passed. - The full test suite passes except for the 16 file(s) that already fail on the base commit. ## Risks - Written by an automated pipeline, not a person: review it as you would an outside contribution. - Risk tier of the touched paths: 2. - It crosses a trust boundary. Check each crossing against what the issue asked for, and against who asked: - validation (server/src/services/heartbeat/workspaces.ts:860): Broadens the accepted Git absence diagnostics to include the mount-boundary message when classifying a checkout failure as an expected non-repository result. - validation (server/src/services/managed-repository-checkout.ts:265): Allows the mount-boundary diagnostic to bypass a previously thrown Git error when plainTaskDirectory and the existing exit, signal, and environment conditions hold. ## Model Used - opus (Anthropic Claude, via Claude Code), writing and checking the change in an isolated sandbox. - opus (Anthropic Claude, via Claude Code), reviewing it independently. ## Linked Issues Fixes #20525 #20525 also mentions, without asking this fix for it: - Non-Git directories in close readiness. (The report explicitly identifies merged #19553 as handling 'a different caller'; this patch does not modify close readiness.) - Initial managed-clone readiness. (The report says '#2977 concerns initial managed-clone readiness, rather than this diagnostic matcher.') - CI jobs 131047332629 and 131040975860 fail; fix the change only if it causes the failures. (This earlier-round conditional comment supplies no demonstrated matcher defect. .github/workflows/pr-trusted.yml:1801-1804 asserts aggregate shard status, while server/src/services/tool-access/catalog/health.ts:222 reports MCP health failures; neither changed here. Historical job causation cannot be) A search of paperclipai/paperclip's open and closed pull requests found no other pull request that names #20525. ## 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) - [ ] 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) - [ ] 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 - [ ] 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 - [ ] I will address all Greptile and reviewer comments before requesting merge Co-authored-by: commitperclip[bot] <284812584+commitperclip[bot]@users.noreply.github.com> --- .../src/__tests__/git-mount-boundary.test.ts | 80 +++++++++++++++++++ .../services/git-mount-boundary-message.ts | 5 ++ server/src/services/heartbeat/workspaces.ts | 4 +- .../services/managed-repository-checkout.ts | 4 +- 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 server/src/__tests__/git-mount-boundary.test.ts create mode 100644 server/src/services/git-mount-boundary-message.ts diff --git a/server/src/__tests__/git-mount-boundary.test.ts b/server/src/__tests__/git-mount-boundary.test.ts new file mode 100644 index 00000000000..a855c5d4690 --- /dev/null +++ b/server/src/__tests__/git-mount-boundary.test.ts @@ -0,0 +1,80 @@ +import fs from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import { describe, expect, it, vi } from "vitest"; +import { ensureManagedRepositoriesIgnored } from "../services/managed-repository-checkout.js"; +import { assertGitWorktreeBaseWorkspaceReady } from "../services/heartbeat/workspaces.js"; + +const boundary = "fatal: not a git repository (or any parent up to mount point /mounted workspace)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)."; + +describe("Git mount-boundary absence classification", () => { + it("allows managed exclusions to fall back for a complete boundary diagnostic", async () => { + const cwd = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-managed-boundary-")); + try { + await fs.mkdir(path.join(cwd, ".git")); + await fs.mkdir(path.join(cwd, "bin")); + await fs.writeFile(path.join(cwd, "bin", "git"), `#!/bin/sh\nprintf '%s' '${boundary}\n' >&2\nexit 128\n`, { mode: 0o755 }); + vi.stubEnv("PATH", path.join(cwd, "bin")); + for (const key of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR"]) vi.stubEnv(key, ""); + await expect(ensureManagedRepositoriesIgnored(cwd, { plainTaskDirectory: true })).resolves.toBeUndefined(); + } finally { + vi.unstubAllEnvs(); + await fs.rm(cwd, { recursive: true, force: true }); + } + }); + + it.each([ + { stderr: boundary, accepted: true }, + { stderr: boundary.replace("/mounted workspace", "/"), accepted: true }, + { stderr: boundary.replaceAll("\n", "\r\n"), accepted: true }, + { stderr: boundary + "\n", accepted: true }, + { stderr: boundary.replaceAll("\n", "\r\n") + "\r\n", accepted: true }, + { stderr: boundary.split("\n")[0], accepted: false }, + { stderr: boundary.split("\n")[1], accepted: false }, + { stderr: boundary + "\nfatal: I/O error\n", accepted: false }, + { stderr: boundary + "\n\n", accepted: false }, + { stderr: "prefix\n" + boundary, accepted: false }, + { stderr: boundary.replace("not set", "set"), accepted: false }, + { stderr: boundary.replace("/mounted workspace", ""), accepted: false }, + { stderr: boundary.replace("/mounted workspace", "/mounted\ninjected"), accepted: false }, + { stderr: boundary.replace("/mounted workspace", "/mounted\rinjected"), accepted: false }, + { stderr: "fatal: cannot open .git: Permission denied\n", accepted: false }, + { stderr: "fatal: detected dubious ownership in repository\n", accepted: false }, + { stderr: "fatal: bad object HEAD\n", accepted: false }, + { stderr: boundary, accepted: false, code: 1 }, + { stderr: boundary, accepted: false, override: true }, + { stderr: boundary, accepted: false, killed: true }, + ])("classifies complete absence in both callers: %j", async ({ stderr, accepted, code = 128, override = false, killed = false }) => { + const root = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-boundary-")); + const cwd = path.join(root, "workspace"); + const bin = path.join(root, "bin"); + try { + await fs.mkdir(cwd); + await fs.mkdir(bin); + await fs.writeFile(path.join(bin, "git"), `#!/bin/sh\nprintf '%s' '${stderr}' >&2\n${killed ? "kill -TERM $$" : `exit ${code}`}\n`, { mode: 0o755 }); + vi.stubEnv("PATH", bin); + for (const key of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR"]) vi.stubEnv(key, ""); + if (override) vi.stubEnv("GIT_DIR", path.join(root, "override")); + const input: Parameters[0] = { + requestedExecutionWorkspaceMode: "isolated_workspace", + config: { workspaceStrategy: { type: "git_worktree" } }, + issue: { id: "issue-1", identifier: null, projectId: "project-1", projectWorkspaceId: "workspace-1" }, + base: { baseCwd: cwd, source: "project_primary", projectId: "project-1", workspaceId: "workspace-1", repoUrl: null, repoRef: null }, + anchor: { localPathOnlyWorkspace: true, baseCwdFallback: false, materializationFailures: [] }, + }; + const failure = await assertGitWorktreeBaseWorkspaceReady(input).catch((error) => error); + expect(failure.code).toBe("workspace_validation_failed"); + expect(failure.resultJson.workspaceValidation.configurationReason).toBe(accepted ? "local_path_requires_git_checkout" : undefined); + await fs.mkdir(path.join(cwd, ".git")); + const metadataFailure = await assertGitWorktreeBaseWorkspaceReady(input).catch((error) => error); + expect(metadataFailure.resultJson.workspaceValidation.configurationReason).toBeUndefined(); + const ignore = ensureManagedRepositoriesIgnored(cwd, { plainTaskDirectory: true }); + if (accepted) await expect(ignore).resolves.toBeUndefined(); + else await expect(ignore).rejects.toBeInstanceOf(Error); + await expect(ensureManagedRepositoriesIgnored(cwd)).rejects.toBeInstanceOf(Error); + } finally { + vi.unstubAllEnvs(); + await fs.rm(root, { recursive: true, force: true }); + } + }); +}); diff --git a/server/src/services/git-mount-boundary-message.ts b/server/src/services/git-mount-boundary-message.ts new file mode 100644 index 00000000000..d55c56ee0a4 --- /dev/null +++ b/server/src/services/git-mount-boundary-message.ts @@ -0,0 +1,5 @@ +export function isGitMountBoundaryMessage(stderr: unknown): boolean { + if (typeof stderr !== "string") return false; + const match = /^fatal: not a git repository \(or any parent up to mount point [^\r\n]+\)\r?\nStopping at filesystem boundary \(GIT_DISCOVERY_ACROSS_FILESYSTEM not set\)\.\r?\n?$/.exec(stderr); + return match?.[0] === stderr; +} diff --git a/server/src/services/heartbeat/workspaces.ts b/server/src/services/heartbeat/workspaces.ts index 1d1e566c28f..5e352f2b582 100644 --- a/server/src/services/heartbeat/workspaces.ts +++ b/server/src/services/heartbeat/workspaces.ts @@ -1,4 +1,5 @@ import { retainCurrentWorkspaceSource } from "../workspace-source-lock.js"; +import { isGitMountBoundaryMessage } from "../git-mount-boundary-message.js"; import { localWorkspaceSourcePaths } from "../execution-workspace-source-roots.js"; import { effectiveProjectWorkspacePolicy } from "../project-workspace-provider.js"; import { canonicalRepositoryRoot } from "../execution-workspace-source-roots.js"; @@ -856,7 +857,8 @@ async function probeGitWorktreeBase(cwd: string) { // corruption and I/O failures must remain reportable in Sentry. const notRepository = failure.code === 128 && failure.signal == null && typeof failure.stderr === "string" && - /^fatal: not a git repository \(or any of the parent directories\): \.git\r?\n?$/.test(failure.stderr) && + (/^fatal: not a git repository \(or any of the parent directories\): \.git\r?\n?$/.test(failure.stderr) || + isGitMountBoundaryMessage(failure.stderr)) && !process.env.GIT_DIR && !process.env.GIT_WORK_TREE && !process.env.GIT_COMMON_DIR && await hasNoGitMetadataInWorkspaceAncestors(cwd); return { isCheckout: false, notRepository }; diff --git a/server/src/services/managed-repository-checkout.ts b/server/src/services/managed-repository-checkout.ts index 73a452733fe..db8a25a84d6 100644 --- a/server/src/services/managed-repository-checkout.ts +++ b/server/src/services/managed-repository-checkout.ts @@ -1,4 +1,5 @@ import { retainCurrentWorkspaceSource } from "./workspace-source-lock.js"; +import { isGitMountBoundaryMessage } from "./git-mount-boundary-message.js"; import fs from "node:fs/promises"; import path from "node:path"; import { execFile as execFileCallback } from "node:child_process"; @@ -261,7 +262,8 @@ export async function ensureManagedRepositoriesIgnored(cwd: string, options: { p } catch (error) { const failure = error as { code?: unknown; signal?: unknown; stderr?: unknown }; if (options.plainTaskDirectory && failure.code === 128 && failure.signal == null && - failure.stderr === "fatal: not a git repository (or any of the parent directories): .git\n" && + (failure.stderr === "fatal: not a git repository (or any of the parent directories): .git\n" || + isGitMountBoundaryMessage(failure.stderr)) && !process.env.GIT_DIR && !process.env.GIT_WORK_TREE && !process.env.GIT_COMMON_DIR) return; throw error; }