Repository navigation
Check out only the selected plugin's directories for git installs - #8116
Merged
Merged
Conversation
This was referenced Nov 24, 2026
Installing a plugin from a subdirectory or a collection entry of a git repository materialized the whole tree of the resolved commit even though only one plugin directory was used. For monorepos with many plugins or large unrelated content this dominated the working-tree write and, with a partial-clone capable server, the download. cloneGitCommit now takes the checkout target. For a subdirectory or entry selection it fetches with --filter=blob:none from a named origin remote (so the partial clone can lazily fetch the blobs the checkout needs), configures a cone-mode sparse checkout of the selected directory (or of .bb for an entry, then adds the directory the collection manifest names after reading it), and returns a checkout handle with the resolved subdirectory, replacing the callers' resolveSelectedSubdirectory step. The root selection and the full clone fallback are unchanged. Servers that do not advertise filters ignore --filter with a warning; the sparse working tree still applies. Cone mode refuses to add a path that is not a tree (a symlinked plugin directory) and a symlinked plugin cannot resolve inside a sparse tree, so in both cases the sparse checkout is disabled and the whole commit is materialized as before. A plugin can also depend on paths outside its directory that a full checkout supplied: a bb.server entry that is a symlink into a shared directory, or a server source that imports ../../shared/module.js, which managed installs bundle. The checkout handle therefore keeps .git, and the install, update and probe paths read the manifest and validate the install through withFullTreeFallback: when a step fails on a sparse tree, the handle runs git sparse-checkout disable, which writes the rest of the commit (fetching blobs lazily from the promisor remote on a partial clone), and runs the step again. Cancellation is never retried, and a failure to expand the tree reports the step's own error. finish() removes .git once the tree is final, before the content hash and the promotion. A shared <repo>/<commit> checkout that a sparse install created lacks whatever that plugin did not need. Promotion into an existing checkout moved only the plugin root, so a later plugin that needed the whole tree would have no shared directories for a 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 for that commit. promoteGitPluginArtifact now first adopts every entry of the staging tree the checkout lacks, merging directories present in both and leaving the roots of plugins already installed from the checkout untouched (an install removes .npmrc and .yarnrc files from a plugin root, so merging would change their content hashes), then promotes the plugin root at its real path, so a symlinked plugin directory resolves to it in the checkout. promoteImmutableDir moves whatever occupies the target aside even when hashing it fails, instead of failing the later rename with ENOTDIR. The update path passes the installed plugin's recorded subdirectory directly and keeps not consulting the collection manifest.
afn
force-pushed
the
sparse-plugin-git-checkout
branch
from
November 24, 2026 21:45
8ee92ab to
30850aa
Compare
…talled roots by real path A plugin's skills directory can be a tracked symlink out of its own directory, such as skills -> ../../shared/skills. The sparse checkout left the link dangling, and skill discovery treats an unreadable skills root as no skills rather than failing, so neither the manifest read nor validation threw and the fallback to the whole commit never ran: the install succeeded with its skills silently gone, and so did an update. cloneGitCommit now walks the selected plugin root before accepting a sparse tree. A symlink that does not resolve, or that 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 outside the root stay, since a file that resolves is whole. Promotion into an existing shared checkout left alone the roots of the plugins installed from it, comparing the recorded paths. A plugin installed through a directory symlink is recorded by that path (alias/alpha) while adoption walks the real tree (plugins/alpha), so a later sibling's full-tree fallback could put back the .npmrc and .yarnrc files its install had removed and leave its content hash stale. promoteGitPluginArtifact now protects each installed root by its real checkout-relative path as well as the recorded one. Tests: a plugin whose skills are a symlink out of its directory installs with the skill present after a sparse sibling, and such a plugin updates; a plugin installed through alias/alpha keeps its contents and content hash when a sibling's install expands the shared checkout. Each failed before this change.
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]>
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
After #7911,
cloneGitCommitinapps/server/src/services/plugins/managed-plugin-artifacts.tsfetches 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.jsoncollection 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:cloneGitCommittakes aGitCheckoutTarget(a selection to resolve, or an installed plugin's recorded subdirectory) and returns the resolved subdirectory, replacing the callers'resolveSelectedSubdirectorystep. For a subdirectory or entry selection the shallow path now: adds the URL as theoriginremote, fetches with--filter=blob:noneso a partial clone can lazily fetch the blobs the checkout needs, sets a cone-mode sparse checkout of the selected directory (or of.bbfor an entry, thensparse-checkout adds the directory the manifest names after reading it), and checks outFETCH_HEAD. Cone mode keeps repository-root files, so a rootpackage.json/README is still present. The root selection and the full-clone fallback are unchanged. Servers that do not advertise partial clone ignore--filterwith a warning; the sparse working tree still applies.adda path that is not a tree (a symlinked plugin directory), the resolved plugin root (or.bb/plugins.json) does notrealpathinside the sparse tree, or the path contains cone-mode pattern characters. Each runsgit sparse-checkout disable.bb.serverentry that is a symlink intoshared/, or a server source importing../../shared/module.js(managed installs bundle out-of-root relative source).cloneGitCommittherefore returns aGitCheckouthandle and keeps.git; the install, update (stageGitCandidate) and probe paths read the manifest and runvalidateInstallDirthroughcheckout.withFullTreeFallback(fn), which on failure under a sparse tree runsgit sparse-checkout disable(blobs fetched lazily from theoriginpromisor 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.gitbefore the content hash and promotion. The assertions between the manifest read and validation (plugin id, registration, builtin shadowing) stay outside the fallback.skillsdirectory can be a tracked symlink such asskills -> ../../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,cloneGitCommitnow 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.tspromoteGitPluginArtifact: 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 asalias -> plugins, which cone mode writes without its target, stayed dangling, so promotingalias/alphafailed inmkdirwithENOENTon 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, fromlistPluginArtifactsAtOrUnderPath; 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 asalias/alphawhile adoption walksplugins/alpha, and a sibling's full-tree fallback would otherwise put back the files its install removed and leave its content hash stale.promoteImmutableDirmoves aside whatever occupies the target even when hashing it fails, instead of failing the laterrenamewithENOTDIR.row.sourceGitSubdirectorydirectly and keeps not consulting the collection manifest.How you verified
checks out only the directories the selected plugin needs(plugin-install.test.ts): installs entryalpha, assertsplugins/alpha,.bb/plugins.jsonandREADME.mdare present in the shared checkout whileunrelated/andplugins/betaare absent; then installsplugins/betaby subdirectory and asserts both plugins coexist andunrelated/is still absent. Fails onmain(the whole tree is present).installs a collection entry from a server that serves partial clones: setsuploadpack.allowFilter=trueon the fixture repo so--filter=blob:noneis honored and the lazy blob fetch through theoriginpromisor remote is exercised; asserts the built plugin and the absence of unselected directories.promotes an in-repository symlinked plugin after a siblingtest caught both the cone-modeaddrefusal and the dangling-symlink promote failure during development; it passes with the fallbacks and thepromoteImmutableDirchange.materializes the whole commit when the selected plugin imports from outside its directory(a sparse sibling with a committed.npmrcinstalls first; a plugin importing../../shared/message.jsthen installs, the bundle contains the shared string,shared/message.tsis in the checkout, and the sibling's.npmrcstays removed; failed withserver bundle build ... failed),materializes the whole commit when the selected plugin's entry is a symlink out of its directory(failed withmanifest bb.server points at a missing file),installs a plugin through a symlinked directory a sibling left dangling in the shared checkout(rootalias -> plugins; failed withENOENT ... mkdir '.../alias'), and in plugin-update.test.tsupdates a subdirectory plugin that imports from outside its directory(failed withok: false).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 andreadPluginManifest(...).skillNamesis["review"]),leaves a plugin installed through a symlinked path untouched when a sibling expands the shared checkout(other/beta, thenalias/alphawith a committed.npmrc, thenplugins/gammawhose shared import forces the full tree;plugins/alpha/.npmrcstays removed and alpha's content hash still matches its artifact), and in plugin-update.test.tsupdates 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 wholetest/services/plugins/directory: all passed (the 10update-resolver.test.tsfailures are the same onmainon this machine: a global gitfsmonitor--daemon.ipcsocket copied with a fixture repo).pnpm run typecheckinapps/server: clean.oxlinton the touched files reports only the errors already present onmain.plugin11:26.62 → 10.409 s,plugin223.005 s → 7.434 s (table in Plugin git installs check out the whole repository tree when only one subdirectory is selected #8115).Fixes #8115