← reports

#7910 · Git plugin snapshots unnecessarily require ancestor objects

BugMedium priorityLow effortplugins · perf · confirmed-reproIssue2026-11-20 · base fab82665a3299fae8910f55d7519a3b034a03b9a

Verdict: REPRODUCED · Root-cause confidence: high

1. TL;DR

A git plugin is installed as a snapshot, but the installer first copies the repository's history. A plugin whose current snapshot is complete can therefore fail when an older, unused file object is unavailable. A newly authored service-level regression demonstrates this over a real local Git smart-HTTP transport. It fails on unchanged production code in two separate checkouts and passes with a depth-one fetch repair. The reported real-world download sizes and timing were not measured in this environment.

2. Claims vs findings

ClaimFindingEvidence
Managed git materialization clones without a history limit.VerifiedTrusted base lines 154–164; service regression fails in clone.
Installation, candidate probes, and update staging share the same behavior.VerifiedThree callers at trusted base lines 628, 795, and 1215.
Large histories cause substantial download time and timeouts.Mechanism verified; reported measurements unverifiedUnbounded clone and five-minute command timeout exist. No production download or timeout was induced.
Every selected commit is a full 40-character SHA.RefutedExplicit commit selectors accept 7–40 hex characters and bypass ls-remote expansion. The regression table covers both lengths.
A broken unrelated ref reliably prevents local cloning.Not reproduced with this Git versionAn initial local-path fixture passed on Git 2.39.5. It was replaced with a real HTTP transport and an unavailable ancestor blob, which reproduced the history dependency.

3. Environment

4. Minimal reproduction

  1. Start at the recorded base and install the repository's locked dependencies.
  2. Save the complete authored regression patch printed below as regression.patch. It modifies only tests, leaving production unchanged.
  3. Run:
    git checkout fab82665a3299fae8910f55d7519a3b034a03b9a
    pnpm install --frozen-lockfile --prefer-offline
    git apply regression.patch
    pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-install.test.ts -t 'unavailable ancestor|pinned commit'
  4. The fixture commits an older file, removes it in a later plugin release, and deletes only that older blob from the origin object store. It then serves the repository using Git's own http-backend and requests the intact current plugin commit. The deleted file is not present in the selected tree.

Expected: the selected plugin starts, its recorded commit matches the requested release, and .git is absent from the installed artifact. Only the current tree is required.

Actual on trusted base:

 FAIL  |@bb/server:isolated| test/services/plugins/plugin-install.test.ts > plugin install flows > git sources > installs a resolved commit without downloading unavailable ancestor blobs
Error: git clone failed (exit 128): error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500
fatal: the remote end hung up unexpectedly
 Test Files  1 failed (1)
      Tests  1 failed | 2 passed | 55 skipped (58)

The two ordinary pinned-commit control cases pass on the same transport. The depth-one repair makes all three cases pass. This fixture intentionally removes an ancestor blob to make excessive history access deterministic; it is not a claim that a normal large repository is corrupt.

Complete authored regression patch

diff --git a/apps/server/test/services/plugins/plugin-install.test.ts b/apps/server/test/services/plugins/plugin-install.test.ts
index 4bd00e040f..8efe26cd68 100644
--- a/apps/server/test/services/plugins/plugin-install.test.ts
+++ b/apps/server/test/services/plugins/plugin-install.test.ts
@@ -163,6 +163,61 @@ async function commitAll(repoDir: string, message: string): Promise<string> {
   return git(repoDir, ["rev-parse", "HEAD"]);
 }
 
+async function serveGitRepository(repoDir: string) {
+  const server = createServer((request, response) => {
+    const url = new URL(request.url ?? "/", "http://127.0.0.1");
+    const child = execFile(
+      "git",
+      ["http-backend"],
+      {
+        encoding: "buffer",
+        env: {
+          ...process.env,
+          GIT_PROJECT_ROOT: dirname(repoDir),
+          GIT_HTTP_EXPORT_ALL: "1",
+          PATH_INFO: url.pathname,
+          QUERY_STRING: url.search.slice(1),
+          REQUEST_METHOD: request.method ?? "GET",
+          CONTENT_TYPE: request.headers["content-type"] ?? "",
+        },
+      },
+      (error, stdout, stderr) => {
+        if (error) {
+          response.writeHead(500).end(stderr);
+          return;
+        }
+        const headerEnd = stdout.indexOf("\r\n\r\n");
+        for (const header of stdout
+          .subarray(0, headerEnd)
+          .toString()
+          .split("\r\n")) {
+          const separator = header.indexOf(":");
+          const name = header.slice(0, separator);
+          const value = header.slice(separator + 1).trim();
+          if (name.toLowerCase() === "status")
+            response.statusCode = Number.parseInt(value, 10);
+          else response.setHeader(name, value);
+        }
+        response.end(stdout.subarray(headerEnd + 4));
+      },
+    );
+    request.pipe(child.stdin!);
+  });
+  await new Promise<void>((resolvePromise) =>
+    server.listen(0, "127.0.0.1", resolvePromise),
+  );
+  const address = server.address();
+  if (address === null || typeof address === "string")
+    throw new Error("missing git server port");
+  return {
+    url: `http://127.0.0.1:${address.port}/${repoDir.slice(dirname(repoDir).length + 1)}`,
+    close: () =>
+      new Promise<void>((resolvePromise) =>
+        server.close(() => resolvePromise()),
+      ),
+  };
+}
+
 function artifactMeta(args: {
   artifactFormatVersion?: number;
   pluginId: string;
@@ -840,28 +895,82 @@ describe("plugin install flows", () => {
       expect(getInstalledPluginRegistration(db, "connect")).toBeUndefined();
     });
 
-    test("installs a pinned commit sha via clone + checkout", async ({
+    test("installs a resolved commit without downloading unavailable ancestor blobs", async ({
       fixture,
     }) => {
-      const { workDir, service } = fixture;
-
-      const repoDir = join(workDir, "repo-sha");
-      await writePluginFixture(repoDir, { name: "bb-plugin-shaman" });
+      const { db, workDir, service } = fixture;
+      const repoDir = join(workDir, "repo-selected-commit");
+      await writePluginFixture(repoDir, { name: "bb-plugin-selected-commit" });
       await initGitRepo(repoDir);
-      const sha = await commitAll(repoDir, "init");
-      await writePluginFixture(repoDir, {
-        name: "bb-plugin-shaman",
-        version: "9.9.9",
-      });
-      await commitAll(repoDir, "later");
+      await writeFile(
+        join(repoDir, "retired.txt"),
+        "content from an older release",
+      );
+      await commitAll(repoDir, "previous release");
+      const retiredBlob = await git(repoDir, ["rev-parse", "HEAD:retired.txt"]);
+      await rm(join(repoDir, "retired.txt"));
+      const commit = await commitAll(repoDir, "selected release");
+      await rm(
+        join(
+          repoDir,
+          ".git",
+          "objects",
+          retiredBlob.slice(0, 2),
+          retiredBlob.slice(2),
+        ),
+      );
+      const remote = await serveGitRepository(repoDir);
 
-      const entry = await service.install(`git:${repoDir}@${sha}`, {
-        kind: "root",
-      });
-      expect(entry.status).toBe("running");
-      expect(entry.version).toBe("0.1.0");
+      try {
+        const entry = await service.install(`git:${remote.url}@main`, {
+          kind: "root",
+        });
+
+        expect(entry).toMatchObject({
+          id: "selected-commit",
+          version: "0.1.0",
+          status: "running",
+        });
+        expect(getInstalledPluginRegistration(db, entry.id)).toMatchObject({
+          gitResolvedCommit: commit,
+        });
+        expect(existsSync(join(entry.rootDir, ".git"))).toBe(false);
+      } finally {
+        await remote.close();
+      }
     });
 
+    test.for([40, 7])(
+      "installs a pinned commit with a %i-character sha",
+      async (shaLength, { fixture }) => {
+        const { workDir, service } = fixture;
+
+        const repoDir = join(workDir, "repo-sha");
+        await writePluginFixture(repoDir, { name: "bb-plugin-shaman" });
+        await initGitRepo(repoDir);
+        const sha = await commitAll(repoDir, "init");
+        await writePluginFixture(repoDir, {
+          name: "bb-plugin-shaman",
+          version: "9.9.9",
+        });
+        await commitAll(repoDir, "later");
+
+        const remote = await serveGitRepository(repoDir);
+        try {
+          const entry = await service.install(
+            `git:${remote.url}@${sha.slice(0, shaLength)}`,
+            {
+              kind: "root",
+            },
+          );
+          expect(entry.status).toBe("running");
+          expect(entry.version).toBe("0.1.0");
+        } finally {
+          await remote.close();
+        }
+      },
+    );
+
     test("never reuses an exact-resolution artifact owned by another plugin", async ({
       fixture,
     }) => {

This patch reuses the existing service/database fixtures and includes the smart-HTTP helper and both pinned-commit controls.

5. Root cause

The shared git artifact materializer performs an unrestricted clone before detaching the selected commit and removing .git, so historical objects outside the selected snapshot are required.

6. Proposed fix

Initialize an empty staging repository and fetch the selected commit at depth one without tags. Keep exact checkout verification, .git cleanup, cancellation propagation, and a clean full-clone fallback for unsupported direct fetches and abbreviated commit IDs.

The local implementation remains in the existing materializer and leaves all public interfaces, persistence, package metadata, and CLI behavior unchanged. Fetch errors other than cancellation use the existing clone behavior; consequently unsupported servers and short commit IDs retain full-download cost. A transient fetch failure can also incur a second attempt. This is an explicit compatibility tradeoff, not a promise that every source becomes shallow.

7. Linked PR review

#7911 is closed and unmerged. Only its GitHub metadata and textual diff were read; its branch, test code, and commands were not run. It proposes the same broad shallow-first/fallback direction using a separate helper and FETCH_HEAD checkout, with cancellation propagation. That direction addresses the observed cause. Its local broken-ref expectation is Git-version-sensitive: an independently authored local-path probe did not fail on this machine. Verdict: directionally relevant, unverified as an implementation; no execution claim. No open issue-linked PR was found before fix work.

8. Related issues

#5373 is closed and concerns marketplace branch selection, rather than this materializer's history transfer.

9. Verification

The same agent repeated the reproduction in a second clean temporary checkout named verify, detached at fab82665a3299fae8910f55d7519a3b034a03b9a, with a fresh frozen install and successful scoped server build. Only the authored test patch was applied. Git confirmed production source remained unchanged. The identical command failed with the same clone error: one regression failed, both pinned-commit controls passed. Fixture caches, SQLite databases, and ephemeral loopback ports were newly allocated. This is a second clean run by the same agent, not an independent review.

After the production repair in the first checkout: three focused cases passed; five relevant existing suites passed, totaling 129 tests. Server typecheck, typed lint, server build, formatting, and git diff --check passed. The initial broken-ref fixture was discarded because it did not reproduce with Git 2.39.5; the final report is based on the HTTP/ancestor-blob fixture only.

10. Appendix

Raw evidence remains in the private local investigation directory, in accordance with this public site's artifact policy. The relevant output is reproduced here without checkout paths:

First unchanged-production run: 1 failed | 2 passed | 55 skipped (58)
Second clean unchanged-production run: 1 failed | 2 passed | 55 skipped (58)
Repaired focused run: 3 passed | 55 skipped (58)
Relevant suites: Test Files 5 passed (5); Tests 129 passed (129)
Typecheck: exit 0
Server build: exit 0
Typed lint: Found 0 warnings and 0 errors.
git diff --check: exit 0
pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-install.test.ts test/services/plugins/plugin-update.test.ts test/services/plugins/plugin-install-jobs.test.ts test/services/plugins/plugin-update-jobs.test.ts test/services/plugins/update-resolver.test.ts
pnpm exec turbo run typecheck --filter=@bb/server
pnpm exec turbo run lint:type-aware build --filter=@bb/server
pnpm exec oxfmt apps/server/src/services/plugins/managed-plugin-artifacts.ts apps/server/test/services/plugins/plugin-install.test.ts
git diff --check
git diff --numstat origin/main

Trust note: issue and linked-PR text were treated only as untrusted claims. No issue-provided script, patch, branch, binary, or external link was executed. Reproduction and fix code were authored from trusted repository source. Logs replace checkout paths with neutral labels. This is a nonvisual server defect, so no screenshots are appropriate.

> AGENT GENERATED