Repository navigation
Fetch only the resolved commit for git plugin installs - #7911
Merged
Merged
Conversation
Install, update, and install-probe for git: sources ran a full git clone of the repository, checked out the resolved commit, and deleted .git. For repositories with a long history this dominated install time and could hit the install command timeout. cloneGitCommit now runs git init + git fetch --depth 1 <url> <commit> and checks out FETCH_HEAD. When the server refuses to serve the commit directly (protocol v0 servers reject unadvertised objects) it falls back to the full clone and checkout as before. Fixes get-bb#7910
Contributor
|
Thanks for the pull request, @afn. It was closed automatically because it does not meet the requirements below yet. This is an automated check, not a review of the change. Contributor approval. bb reviews pull requests only from approved contributors, and you are not on the list yet. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ), post a link to your pull request, and explain what it changes and why. A maintainer then adds you to the list and reopens the pull request. See CONTRIBUTING.md for details. |
A plain-path clone hardlinks objects and copies refs without a connectivity check on some git builds (Apple git 2.54), so the dangling-ref fixture let the full clone succeed and the test failed on its own precondition. The fixture now drops an ancestor blob that only the full history needs and routes the local path through the file transport with url.<file-url>.insteadOf, which keeps the cache path free of a host:port segment. Pinned commits are covered at 40 and 7 characters, since abbreviated SHAs take the full-clone fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
/approve @afn |
Contributor
|
Approved @afn for PRs. The name now stays on the allow list. The author can open a PR now. |
ymichael
added a commit
that referenced
this pull request
Nov 21, 2026
## Human comments ## What was wrong Two tests added in #7911, "fetches only the resolved commit instead of the whole repository" and "falls back to a full clone when the server refuses to serve the commit directly", sit in the same `describe.concurrent` block of `apps/server/test/services/plugins/plugin-install.test.ts`. Each one configures git by writing `GIT_CONFIG_COUNT`/`GIT_CONFIG_KEY_0`/`GIT_CONFIG_VALUE_0` into `process.env`, then restores the old values. The plugin service has no other way to receive git config: `runInstallCommand` spawns git with `process.env`. When both tests overlap, the shallow test overwrites `GIT_CONFIG_KEY_0` (`protocol.version` becomes `url.….insteadOf`) or its restore deletes the variables. The fallback test's probe `git fetch --depth 1 <repo> <sha>` then runs over protocol v2, which serves any commit, so it succeeds. That produces the CI failure `AssertionError: promise resolved "{ stdout: '', …(1) }" instead of rejecting` seen on #7893 and #7869. ## What changed - The two tests move into their own non-concurrent `describe.skipIf(!hasGit)("git sources configured through the server process environment")`, placed between the two concurrent suites. Vitest runs a non-concurrent sibling as its own group, after the preceding concurrent group finishes and before the next one starts (`partitionSuiteChildren` in `@vitest/runner`). So nothing else in the file runs while `process.env` holds their git config. Moving them out of "git sources" is required: `describe.concurrent` makes the suite itself concurrent, so "git sources" and "multi-plugin repositories" run in parallel, and `test.sequential` inside "git sources" would still overlap the other suite. - The probe git commands (`git clone` and `git fetch`) get their config through the child `env` option (`gitConfigEnv`) instead of `process.env`. `withProcessGitConfig` now wraps only the `service.install` call, which has no other config channel. - Nothing else in the file mutates `process.env` inside a concurrent block. The npm-config tests sit in sequential describes, and the file already gets an isolated worker because it mutates `process.env`. Test-only change; production code is untouched. ## How you verified - Reproduced on main by running only the two tests, so they always overlap: `vitest run test/services/plugins/plugin-install.test.ts -t "fetches only the resolved commit|falls back to a full clone"` failed **15/15** runs with the exact CI error (the fetch printed `* branch <sha> -> FETCH_HEAD`). - Same command with this change: **20/20** passed. - Full file, 8 consecutive runs: 8/8 passed (64/64 tests each). - `pnpm exec turbo run typecheck --filter=@bb/server` and `pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-install.test.ts` both passed. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Nov 24, 2026
Plugin git installs check out the whole repository tree when only one subdirectory is selected
#8115
Closed
ymichael
added a commit
that referenced
this pull request
Nov 25, 2026
…#8128) ## Human comments Related to #7911 and #8116, this PR speeds up adding/updating git-hosted marketplaces, which can be painfully slow. ## What was wrong `materializeGit` in `apps/server/src/services/plugin-catalog/marketplace-source.ts` ran `git clone --no-checkout <url>` with no depth or filter, resolved the ref with `rev-parse`, checked out the whole tree, and deleted `.git` — on every `bb marketplace add`, every manual refresh, and every periodic refresh, without ever comparing the ref against the stored `sourceGitCommit`. For a marketplace monorepo with a long history that is ~87 s of download per refresh to read a 346 KB `marketplace.json` and 152 KB of icons. #7911 fixed the same clone for plugin installs; the marketplace path had its own. Fixes #8127. ## What changed - `marketplace-source.ts`: `materializeGit` first resolves the ref with `resolveGitRef` (one `ls-remote`, the same resolver plugin installs use). If it resolves to the stored commit, the stored catalog is returned as `unchanged: true` with no checkout, like the https path does on a 304. If the ref moved (or there is no stored commit), the commit is fetched with `git init` + `fetch --depth 1 --no-tags --filter=blob:none origin <sha>` into a cone-mode sparse checkout: for a root marketplace, `sparse-checkout set --cone` (repository-root files only), then after reading `marketplace.json` `sparse-checkout add` of the directories its local icons live in; for a `subdirectory` marketplace, the subdirectory itself. The manifest and icons are then read exactly as before. If `ls-remote` cannot resolve the ref (for example `origin/<branch>`, which the existing `rev-parse` fallback accepts), the server refuses the fetch, the manifest, the subdirectory, or a local icon path crosses a symlink (whose target may lie outside the sparse tree), `sparse-checkout add` fails, or an icon directory or the subdirectory contains sparse-pattern characters, the code falls back to the previous full clone + checkout (`sparse-checkout disable` where a sparse tree already exists), so the caller sees the same tree a full clone would. Servers that do not advertise partial clone ignore `--filter` with a warning and the sparse working tree still applies. - `marketplace-icons.ts`: `onlyMissing` now also reuses cached *local* icons whose source path is unchanged, and skips local icons that are not cached, so an unchanged git refresh never reads from a checkout that was not made. Local icons only occur for `git:` and `path:` sources; `path:` is never `unchanged`, and at the same commit the files are identical. Remote icons behave as before. - `plugin-catalog-service.ts`: the refresh passes `row.sourceGitCommit` into `cached`. The add path passes `cached: null` and takes the sparse-fetch path. A stored catalog that fails to parse is re-read from the repository with a warning rather than failing the refresh. - No wire, CLI, or guide changes; which ref and subdirectory a marketplace reads is unchanged. ## How you verified - New test `refreshes an unchanged ref from the stored catalog without fetching the repository` (third-party-marketplaces.test.ts): after `addMarketplace`, deletes the fixture repository's loose objects so `ls-remote` still answers but any clone or fetch fails, then asserts `refreshMarketplaces` returns `ok: true` with the same commit, the stored icon's content hash is unchanged, no warnings were emitted, and the staging directory is empty. Fails on `main` (`fatal: … nonexistent object`). - New tests `fetches only the catalog and its icons when the ref moved` (root) and `fetches only the subdirectory when the ref moved` (subdirectory): serve the fixture over `file://` through an `insteadOf` rewrite with `uploadpack.allowFilter=true`, commit a new catalog (root case: with a second icon in a nested directory) plus `plugins/alpha/dist/index.js`, delete that blob's object, assert that `git clone` of the repository fails with `possible repository corruption`, and assert the refresh succeeds with the new commit, both entries and both icons. Fail on `main` (the full clone needs the missing blob). - New `reads the catalog when %s` cases (POSIX): `marketplace.json`, the subdirectory, an icon file, and the `icons` directory each a symlink to another path in the repository. The first three failed with the sparse checkout before the symlink check (`ENOENT … marketplace.json`, `not a directory in the repository`, icon dropped with a warning); all four match `main`. - Existing `reads the selected catalog commit for ref %s` cases still pass, including `origin/catalog-next`, which `ls-remote` cannot resolve and which now exercises the full-clone fallback, and `catalog-release`, an annotated tag that `resolveGitRef` peels. - `pnpm exec turbo run test --filter=@bb/server -- test/services/plugin-catalog/`: 171 passed (9 files). `test/services/plugins/plugin-install.test.ts` and `plugin-update.test.ts`: 104 passed. `turbo run typecheck --filter=@bb/server`: clean. `oxlint` on the touched files reports only the `node:fs/promises` import restriction already present on `main`. - Real-world, through `createPluginCatalogService` against the marketplace monorepo in #8127 (89 entries, 39 icons stored, identical warnings before and after): `addMarketplace` 87.05 s → 3.54 s; `refreshMarketplaces` with the ref unchanged 87.72 s → 0.75 s. Fixes #8127 > AGENT GENERATED --------- Co-authored-by: Michael Yong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
pushed a commit
that referenced
this pull request
Nov 25, 2026
) ## Human comments ## What was wrong After #7911, `cloneGitCommit` in `apps/server/src/services/plugins/managed-plugin-artifacts.ts` fetches a single commit but still checks out — and, where the server supports it, downloads — the commit's **whole** tree, even when the install selects one plugin out of a monorepo (`--subdirectory <path>` or a `.bb/plugins.json` collection entry). The selected directory is only picked after the full tree is on disk (`resolveSelectedSubdirectory` → `pluginRootDir`). For a marketplace monorepo with many plugins and sizeable unrelated content, the working-tree write (and blob download) dominates install time: #8115 measures 1:26 → 10 s and 23 s → 7 s for two marketplace plugins. Fixes #8115. Supersedes #7917, which was opened stacked on #7911 before it merged and cannot be reopened after the rebase. ## What changed - `managed-plugin-artifacts.ts`: `cloneGitCommit` takes a `GitCheckoutTarget` (a selection to resolve, or an installed plugin's recorded subdirectory) and returns the resolved subdirectory, replacing the callers' `resolveSelectedSubdirectory` step. For a subdirectory or entry selection the shallow path now: adds the URL as the `origin` remote, fetches with `--filter=blob:none` so a partial clone can lazily fetch the blobs the checkout needs, sets a cone-mode sparse checkout of the selected directory (or of `.bb` for an entry, then `sparse-checkout add`s the directory the manifest names after reading it), and checks out `FETCH_HEAD`. Cone mode keeps repository-root files, so a root `package.json`/README is still present. The root selection and the full-clone fallback are unchanged. Servers that do not advertise partial clone ignore `--filter` with a warning; the sparse working tree still applies. - Fallbacks to the full tree at checkout time, so the caller sees exactly what a full clone would: cone mode refuses to `add` a path that is not a tree (a symlinked plugin directory), the resolved plugin root (or `.bb/plugins.json`) does not `realpath` inside the sparse tree, or the path contains cone-mode pattern characters. Each runs `git sparse-checkout disable`. - Fallback to the full tree at validation time. A plugin can depend on paths outside its directory that a full checkout supplied: a `bb.server` entry that is a symlink into `shared/`, or a server source importing `../../shared/module.js` (managed installs bundle out-of-root relative source). `cloneGitCommit` therefore returns a `GitCheckout` handle and keeps `.git`; the install, update (`stageGitCandidate`) and probe paths read the manifest and run `validateInstallDir` through `checkout.withFullTreeFallback(fn)`, which on failure under a sparse tree runs `git sparse-checkout disable` (blobs fetched lazily from the `origin` promisor remote on a partial clone) and retries once. Cancellation is never retried; if expanding fails, the step's own error is reported. `checkout.finish()` removes `.git` before the content hash and promotion. The assertions between the manifest read and validation (plugin id, registration, builtin shadowing) stay outside the fallback. - Links that leave the sparse tree. A plugin's `skills` directory can be a tracked symlink such as `skills -> ../../shared/skills`; skill discovery treats an unreadable skills root as no skills rather than failing, so neither the manifest read nor validation would throw and the fallback above would never run: the install would succeed with its skills silently gone. Before accepting a sparse tree, `cloneGitCommit` now walks the selected plugin root (`keepSparseCheckoutIfLinksStayInside`): a symlink that does not resolve, or resolves to a directory outside the plugin root (cone mode writes only the files of directories outside the selection, so such a directory is incomplete), disables the sparse checkout before anything reads the tree. Links to files that resolve stay. - `install-sources.ts` `promoteGitPluginArtifact`: a shared `<repo>/<commit>` checkout created by a sparse install lacks whatever that plugin did not need, and promotion into an existing checkout moved only the plugin root. That left no shared directories for a later plugin's rebuild from source (after an SDK change), and a repository-root symlink such as `alias -> plugins`, which cone mode writes without its target, stayed dangling, so promoting `alias/alpha` failed in `mkdir` with `ENOENT` on every retry. Promotion now first adopts every entry of the staging tree the checkout lacks (`adoptMissingEntries`), merging directories present in both and leaving the roots of plugins already installed from the checkout untouched (`installedRoots`, from `listPluginArtifactsAtOrUnderPath`; installs delete `.npmrc`/`.yarnrc*` from a plugin root, so merging into one would change its content hash), then promotes the plugin root at its real path so a symlinked plugin directory resolves to it. The protected roots are matched by their real checkout-relative paths as well as the recorded ones (`protectedCheckoutRoots`): a plugin installed through a directory symlink is recorded as `alias/alpha` while adoption walks `plugins/alpha`, and a sibling's full-tree fallback would otherwise put back the files its install removed and leave its content hash stale. `promoteImmutableDir` moves aside whatever occupies the target even when hashing it fails, instead of failing the later `rename` with `ENOTDIR`. - The update path passes `row.sourceGitSubdirectory` directly and keeps not consulting the collection manifest. - No wire, CLI, or guide changes. ## How you verified - New test `checks out only the directories the selected plugin needs` (plugin-install.test.ts): installs entry `alpha`, asserts `plugins/alpha`, `.bb/plugins.json` and `README.md` are present in the shared checkout while `unrelated/` and `plugins/beta` are absent; then installs `plugins/beta` by subdirectory and asserts both plugins coexist and `unrelated/` is still absent. Fails on `main` (the whole tree is present). - New test `installs a collection entry from a server that serves partial clones`: sets `uploadpack.allowFilter=true` on the fixture repo so `--filter=blob:none` is honored and the lazy blob fetch through the `origin` promisor remote is exercised; asserts the built plugin and the absence of unselected directories. - The existing `promotes an in-repository symlinked plugin after a sibling` test caught both the cone-mode `add` refusal and the dangling-symlink promote failure during development; it passes with the fallbacks and the `promoteImmutableDir` change. - New tests for the validation-time fallback and the shared-checkout promotion, each failing without them with the quoted error: `materializes the whole commit when the selected plugin imports from outside its directory` (a sparse sibling with a committed `.npmrc` installs first; a plugin importing `../../shared/message.js` then installs, the bundle contains the shared string, `shared/message.ts` is in the checkout, and the sibling's `.npmrc` stays removed; failed with `server bundle build ... failed`), `materializes the whole commit when the selected plugin's entry is a symlink out of its directory` (failed with `manifest bb.server points at a missing file`), `installs a plugin through a symlinked directory a sibling left dangling in the shared checkout` (root `alias -> plugins`; failed with `ENOENT ... mkdir '.../alias'`), and in plugin-update.test.ts `updates a subdirectory plugin that imports from outside its directory` (failed with `ok: false`). - Second-round tests, each failing without the change: `materializes the whole commit when the selected plugin's skills are a symlink out of its directory` (after a sparse sibling; the SKILL.md resolves through the link and `readPluginManifest(...).skillNames` is `["review"]`), `leaves a plugin installed through a symlinked path untouched when a sibling expands the shared checkout` (`other/beta`, then `alias/alpha` with a committed `.npmrc`, then `plugins/gamma` whose shared import forces the full tree; `plugins/alpha/.npmrc` stays removed and alpha's content hash still matches its artifact), and in plugin-update.test.ts `updates a subdirectory plugin whose skills are a symlink out of its directory`. - `pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-install.test.ts test/services/plugins/plugin-update.test.ts`: 113 passed; the whole `test/services/plugins/` directory: all passed (the 10 `update-resolver.test.ts` failures are the same on `main` on this machine: a global git `fsmonitor--daemon.ipc` socket copied with a fixture repo). `pnpm run typecheck` in `apps/server`: clean. `oxlint` on the touched files reports only the errors already present on `main`. - Real-world timings on a marketplace monorepo, before/after this change: `plugin1` 1:26.62 → 10.409 s, `plugin2` 23.005 s → 7.434 s (table in #8115). Fixes #8115 > AGENT GENERATED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
cloneGitCommitinapps/server/src/services/plugins/managed-plugin-artifacts.tsrangit clone <url>with no depth or filter, checked out the resolved commit, and then deleted.git. Every git install, semver-range install probe, and update staging therefore downloaded the repository's entire history to use one tree. For plugins hosted in a large or long-lived repository (a marketplace monorepo with ~90 plugins in the case that prompted this) the clone dominated install time by minutes and could hit the 5-minuterunInstallCommandtimeout. Fixes #7910.What changed
managed-plugin-artifacts.ts:cloneGitCommitnow triesgit init+git fetch --depth 1 --no-tags <url> <commit>+checkout --detach FETCH_HEAD(newfetchGitCommitShallow). The commit is always a full SHA fromls-remoteresolution, and GitHub, GitLab, Bitbucket and protocol-v2 local repos serve it directly. If the fetch or checkout fails for any reason other than install cancellation, the staging dir is removed and the previous fullclone+checkout <commit>path runs unchanged, so servers that refuse unadvertised objects keep working and error messages for unreachable URLs or missing commits are the same as before. The post-checkoutrev-parse HEADverification and.gitremoval are untouched.How you verified
fetches only the resolved commit instead of the whole repository(plugin-install.test.ts): a repo carrying a ref whose object is missing.git clonerefuses it (fatal: trying to write ref ... with nonexistent object), so this test fails onmainatfab82665a3299fae8910f55d7519a3b034a03b9aand passes with the change.falls back to a full clone when the server refuses to serve the commit directly: forces git protocol v0 throughGIT_CONFIG_COUNT/KEY_0/VALUE_0(restored afterwards), asserts the direct fetch is refused withunadvertised object, then asserts the install of a non-tip pinned SHA still succeeds and records the right commit.installs a pinned commit sha via clone + checkouttest to drop the mechanism from its name.vitest run test/services/plugins/plugin-install.test.ts test/services/plugins/plugin-update.test.ts: 98 passed. The widertest/services/pluginsrun has 14 failures on this machine that are identical on untouchedmainand unrelated (Shopify-managed gitfsmonitorsocket breakscpin update-resolver.test.ts; keep-awake and provider-codex builtin builds;tsrsbinary is blocked by device policy here, so typecheck was run withtsc6 --noEmit -p apps/server/tsconfig.json: 0 errors)..gitand was still downloading after several minutes;git fetch --depth 1of that commit took 8.8 s and 82 MB.Fixes #7910