Repository navigation
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
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 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 sparse sibling checkout leaves such a symlink dangling in the shared cache directory; promoteImmutableDir now 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. Stacked on "Fetch only the resolved commit for git plugin installs".
|
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. Linked issue. Every pull request must close an open issue in this repository. The issue keeps the problem tracked even if this pull request closes or we take a different approach. Open an issue for the change, or find an existing one, and add See CONTRIBUTING.md for details. |
|
Leaving this closed for now: #7911 removes the history download, which is most of the cost. Sparse checkout adds four fallback paths and changes shared cache promotion for a smaller remaining saving. Happy to revisit it as a separate issue with measurements. |
|
Sounds good. Thanks @ymichael for the quick turnaround on merging the other PR! Hopefully that takes care of the biggest bottleneck, but I’ll reopen this with benchmarks if it seems like it will make a significant difference. |
) ## 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
Human comments
What was wrong
Stacked on #7911 (
shallow-plugin-git-fetch); only the last commit is new here. 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 or large unrelated content, the working-tree write and blob download dominate what remains of the install time. Refs #7910.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.install-sources.tspromoteImmutableDir: a sparse sibling checkout leaves a symlinked plugin entry dangling in the shared<repo>/<commit>cache dir. Hashing it threw, which skipped the move-aside and made the laterrenamefail withENOTDIR. The hash comparison and the move-aside are now independent.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 on the base branch (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.vitest run test/services/plugins test/services/plugin-catalog: 765 passed; the 2 failing files (plugin-authoring-docs,plugin-authoring-doc-examples) fail identically on the base branch becausepackages/plugin-sdk/bundled-typesis not built here.pnpm run typecheckinapps/server: clean.oxlinton the touched files reports only the 3 pre-existing errors present on the base branch.Fixes #