Repository navigation
Conversation
derivePluginId accepted "npm", "cache", "runtime" and "snapshots", so a package such as bb-plugin-npm installed and wrote its data.db, logs/ and secrets/ into the folders core keeps its npm package store, artifact cache, server build cache and state snapshots in. The names now live in one list, CORE_PLUGIN_DIRECTORIES in @bb/domain, which core's folder code builds its paths from and derivePluginId checks, so every install source, manifest load, scaffold and build refuses them. An existing install with such an id loads as an error with the reason and can still be removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…that-collide-with-core-folders-thr_6nsuqsi98j
server-archive kept its own list of core folders under plugins/ (npm, cache, snapshots) and was missing runtime, so archives treated plugins/runtime as a plugin and recorded its server/ and host/ children as separate plugin roots. The list now comes from CORE_PLUGIN_DIRECTORIES, so plugins/runtime is one server-owned tree. The archived files are the same; server-moved.json now records plugins/runtime as one root, which an older daemon rejects, hence the protocol bump to 275. Markers an older bb wrote with plugins/runtime/server and plugins/runtime/host still read. pending-boot.ts also builds its snapshots path from the shared list. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/reject-plugin-ids-that-collide-with-core-folders-thr_6nsuqsi98j
branch
November 20, 2026 19:13
ymichael
added a commit
that referenced
this pull request
Nov 21, 2026
…irectory() (#7957) ## Human comments ## What was wrong bb already gives every plugin `<dataDir>/plugins/<id>/`, but a plugin had no way to get a path inside it for its own files. So plugins built the path themselves from `bb.server.experimental_dataDir`, even though that member's JSDoc said it was not a place to write. Account Pool wrote its account credentials and machine tokens into core's `secrets/` folder (`secrets/accounts`), next to core's secret-setting files. In a 503-repo community corpus, 32 repos use `experimental_dataDir` and about 22 of them write their own files under `plugins/<id>/`, two of them into `secrets/` as well. Core built the same folder by hand in three more places (`data.db` in `bb.storage.database()`, `logs/`, `secrets/`), plus the update-snapshot code. ## What changed - **New SDK member:** `bb.storage.experimental_directory(): string` (`packages/plugin-sdk/src/backend-contract.ts`). It returns `<dataDir>/plugins/<id>/files` and creates it with mode 0700 when it is missing. It is a method, not a field, because it creates the folder, the same way `database()` does. - **One resolver:** `pluginDirectory(dataDir, id, part)` (`apps/server/src/services/plugins/plugin-directory.ts`, part = `data.db | logs | secrets | files`). It replaces the hand-written joins in `plugin-api.ts` (`database()`), `plugin-log.ts`, `plugin-settings.ts`, `plugin-service.ts` (uninstall, HTTP token) and `plugin-state-snapshot.ts`, and the new method uses it too. Plugin ids that would collide with core's folders are already refused by `derivePluginId` (#7887). - **Lifetime:** uninstall deletes `files/` along with `secrets/`, as Michael decided. `data.db` and `logs/` keep their current lifetime and survive uninstall. Update snapshots now copy `files/`, and rollback restores it, the same as `data.db` and `secrets/`. Without that, Account Pool's credentials would go from rolled-back to not rolled-back just by moving folders. A snapshot taken before this change has no `files/` copy, so restoring it removes the folder: the plugin goes back to the state it had then. No schema change; the snapshot's copy sits at `<snapshotPath>/files`. - **Snapshot copies are clones.** `files/` and `secrets/` are cloned into the snapshot and back on rollback (`cloneTree` in `plugin-state-snapshot.ts`). On macOS this runs `/bin/cp -cRp`, which uses clonefile(2) and falls back to a plain copy on other filesystems. Elsewhere it uses `fs.cp(..., { recursive: true, mode: COPYFILE_FICLONE })`, which reflinks on btrfs/XFS and otherwise copies. `fs.cp` with `COPYFILE_FICLONE` can't clone on macOS: Node 22.23 / libuv 1.51 clones only through Linux's `FICLONE` ioctl, so on APFS it quietly copies every byte (measured below), and `COPYFILE_FICLONE_FORCE` fails with `ENOSYS`. - **`experimental_dataDir` JSDoc** now says read-only: use it to migrate off files bb used to manage or to compare paths, and never write under it. - **Account Pool** keeps credentials and machine tokens in `files/accounts`. On load it moves `secrets/accounts` there once (`moveAccountSecretFiles` in `store.ts`). Each file is moved with `rename`, so modes and contents don't change. Files with the same name are replaced by the copy from `secrets/` (only an older Account Pool writes there). Then the empty folder is removed. A second run finds nothing to move. Its `bbPluginSdk` range is now `>=0.6.177`. - **Fake plugin host** (`@get-bb/plugin-sdk/testing`) implements the method as a `files` folder in its temp storage root. - **Uninstall wording** now says "settings, secrets, stored files, and schedules" in the CLI `plugin remove` help and pinned-update hint, the app's remove/uninstall confirmation, the server's removal log lines and `bb-guide-plugins.md`. - **Docs:** `docs/api_to_audit.md` has a new `bb.storage.experimental_directory()` entry and a rewritten `experimental_dataDir` entry (callers, corpus count). The Plugin Guide storage card gets a bullet (the member is on `PluginStorage`, which is already in its `apiSymbols`). The bb-plugin-authoring skill covers it in `backend-foundation.md` (`bb.storage`, `bb.server`) and `quickstart.md` (on-disk state). `docs/configuration.md` gives Account Pool's new path. - Plugin SDK 0.6.176 → 0.6.177. No wire change, no DB migration. Community callers that can move to `bb.storage.experimental_directory()` (not edited here): OXI-717/bb-plugins account-pool-balanced (request journal), nfour/bb-plugins bb-plugin-performance (`metrics/`), architawr/bb-plugin-diagram-fences (`engines/`), ComicBit/bb-plugin-nudger (`exports/`), sajov/bb-plugins bb-plugin-recall (`mirror/`, hardcoded id), g4f4r0/bb-plugins voice-tools (writes into core's `secrets/`), smsunarto/bb-plugins agent-instructions (catalog publish), patleeman/bb-plugins bb-plugin-ds4 (guesses `homedir()/.bb`). ## How you verified Tests (each fails on origin/main): - `plugins/account-pool/src/server.test.ts`, "moves account and machine-token files out of secrets/accounts once and fails over across them". It seeds 3 accounts and a machine token in `secrets/accounts`, loads the plugin and then reloads it. It checks that the folder moved with contents and modes (0600, dir 0700) unchanged and didn't change on reload, that the old machine token still authenticates, and that a 429 on the first account fails over to the second. With Account Pool's old path code: `promise resolved "undefined" instead of rejecting` (`secrets/accounts` still there). - `apps/server/test/services/plugins/plugin-settings-storage.test.ts`, "creates the plugin's files directory, keeps it across reloads, and deletes only it on remove". It uses a real path-installed plugin through `createPluginService`. - `apps/server/test/services/plugins/plugin-state-snapshot.test.ts`: the restore test now changes and adds files in `files/` after the snapshot. Without the snapshot change: `expected 'changed-file' to be 'original-file'`. - Existing Account Pool tests now read secrets from `files/accounts`. Live, with `pnpm start:worktree` (clean env), the source CLI and a fake Anthropic upstream that returns 429 for `sk-one`: 1. On origin/main: enabled Account Pool, added API-key accounts `sk-one`, `sk-two`, `sk-three`, and minted a machine token. All 4 files were 0600 in `secrets/accounts`. A request failed over from `sk-one` to `sk-two` (HTTP 200). 2. Stopped the server, checked out this branch, started it again on the same data dir. `secrets/accounts` was gone. `files/accounts` held the same 4 files, mode 0600, in a 0700 folder. The 3 account files were byte-identical. The token file differed only in `lastUsedAt` (the main server wrote it at shutdown; same value and `mintedAt`). `bb pool status` listed 3 accounts and the machine token. The old token authenticated, and the request went to `sk-two` (sk-one was still remembered as exhausted). 3. Restarted again: every file byte-identical with the same modes. 4. Made the upstream also reject `sk-two`: the request failed over to `sk-three` (HTTP 200). 5. Path plugin calling `bb.storage.experimental_directory()`: `plugins/filer/files/note.txt` was created. `bb plugin remove filer` deleted `files/` and kept `data.db` and `logs/`. `bb plugin remove --help` shows the new wording. Snapshot cost (macOS 27.2, APFS, on a dedicated APFS disk image holding only this dev data dir, so `df` sees nothing else). A `git:` plugin from a local repo tracking `main`, with a 498 MB `files/`: 4 × 100 MB random files plus 5,000 × 20 KB files in 50 folders. Each run is one `bb plugin update` after a new commit. "Peak extra disk" is the lowest free space sampled every 50 ms during the update, compared with before it. | Copy | `files/` | Update wall time | Peak extra disk | Extra disk after | | --- | --- | --- | --- | --- | | this branch, `cp -cRp` | empty | 34.6 s | — | 0 MB | | main-style `fs.cp` | 498 MB | 35.0 s, 32.8 s | 548 MB, 548 MB | 0 MB | | this branch, `cp -cRp` | 498 MB | 35.8 s, 33.7 s | 1 MB, 1 MB | 0 MB | | `fs.cp` + `COPYFILE_FICLONE` (first try) | 498 MB | 45.9 s, 42.1 s | 548 MB (sampled on the second run only) | 0 MB | The copy step on its own, warm cache, 3 runs: `fs.cp` 2.14 / 1.96 / 2.06 s and +548 MB each time; `cp -cRp` 0.91 / 0.68 / 0.64 s and +1 MB. Update wall time hardly moves because the 30 s activation stabilization window dominates it. A rollback restores with the same clone, so it pays the same again. btrfs/XFS reflinks were not measured; CI runs the Linux `fs.cp` path in the snapshot tests. Disk use across updates: a successful update deletes its snapshot as soon as the new version passes the stabilization window (`plugin-activation.ts`), so nothing builds up. That is why "after" is 0 in every row; the cost is the peak during the update. A rolled-back update keeps its snapshot (status `restored`) until it is 7 days old (`retainedUntil`) or the server restarts (the boot GC drops snapshots from earlier processes unless a rollback is unfinished). There is no per-plugin count cap. So on a filesystem without clones, every rolled-back update adds one full copy of `files/` for up to 7 days. That is an audit question in `docs/api_to_audit.md`; this PR adds no pruning. Commands (output in thread storage): - `pnpm exec turbo run typecheck lint` for `@bb/server`, `@get-bb/plugin-sdk`, `bb-plugin-account-pool`, `@bb/app`, `@bb/cli`, `@bb/templates`, `@bb/domain`, `bb-plugin-plugin-api-docs`, `bb-plugin-bb-guide` - `lint:type-aware` for `@bb/server`, `bb-plugin-account-pool`, `@get-bb/plugin-sdk` - `turbo run test` for `@get-bb/plugin-sdk`, `bb-plugin-account-pool` (395), `@bb/cli`, `@bb/templates`, `@bb/domain`, `bb-plugin-plugin-api-docs`, `bb-plugin-bb-guide` - `@bb/server` `test/services/plugins` (624), `@bb/app` `ToolsView.plugin-detail.test.tsx` - Re-ran typecheck/lint and the Account Pool and server plugin suites after rebasing on 4e45c9b. Not done: - Downgrade: if bb is downgraded after this change, Account Pool's credentials stay in `files/accounts`. The older Account Pool reads `secrets/accounts`, finds nothing, and the pool has accounts without credentials until they are added again or the folder is moved back by hand. - Account Pool is a builtin, and `bb plugin remove account-pool` is refused (HTTP 409), so the uninstall rule never deletes its credentials. Disabling it keeps them, as before. - Automations still builds its folder from the `data.db` path, and core's legacy-automations export writes `plugins/automations/import`. Both were left as they are because they aren't in this gap. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED --------- 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
derivePluginIdwas the only check on plugin ids, and it only checked the format. Core keeps four folders under<dataDir>/plugins/(npm,cache,runtime,snapshots), each named with a string literal in its own file, and nothing linked those names to the id rules. So a package namedbb-plugin-npminstalled as pluginnpm, and itsdata.db,logs/andsecrets/went into core's npm package store.bb-plugin-runtimelikewise wrote its files next to core's server build cache inplugins/runtime/server.What changed
packages/domain/src/plugin-id.ts: addedCORE_PLUGIN_DIRECTORIES(npm,cache,runtime,snapshots).derivePluginIdnow throws for those ids:package name "bb-plugin-npm" gives plugin id "npm", which bb reserves for its own folders under plugins/; rename the package. Every install source (path, git, npm, catalog), manifest load,bb plugin newand plugin build goes throughderivePluginId, so they all refuse these ids.install-sources.ts,managed-plugin-artifacts.ts,mutable-plugin-artifacts.ts,plugin-server-cache.ts,plugin-artifact-gc.ts,plugin-state-snapshot.ts.errorwith the reason after upgrade. The server keeps running, andbb plugin removestill works.quickstart.mdlists the reserved ids.pluginIdSchemais unchanged on purpose. Stored turn events (originPluginId) and queued-message wait rows are parsed with it, so tightening it could make existing rows unreadable.Community impact: none. No package name in a 503-repo community plugin corpus (1711 names), or in the getbb.app marketplace v1 or v2 catalogs, derives one of these ids.
Server archives
packages/server-archive/src/server-owned-paths.tskept its own copy of the list (npm,cache,snapshots) and was missingruntime, so archives treatedplugins/runtimeas a plugin and recordedplugins/runtime/serverandplugins/runtime/hostas separate plugin roots. It now builds the set fromCORE_PLUGIN_DIRECTORIES, soplugins/runtimeis one server-owned tree. The archived files are unchanged.server-moved.jsonnow recordsplugins/runtimeas one root, which an older daemon'sisServerOwnedPathrejects, soHOST_DAEMON_PROTOCOL_VERSIONgoes to 275. Markers an older bb wrote with the per-child roots still read (covered by a newmarkers.test.tscase).apps/server/src/services/server-move/pending-boot.tsbuilds its snapshots path from the shared list too.toolchain-prefix is not reserved. Toolchain folders are namedtoolchain-<versions with dots>, andderivePluginIdturns dots into dashes, so no plugin id can equal one.How you verified
pnpm start:worktreeand the source CLI.bb plugin install --yes path:.../bb-plugin-npmandpath:.../bb-plugin-runtimeboth installed and ran, and they createdplugins/npm/{data.db,logs/}andplugins/runtime/{data.db,logs/}next toruntime/server/<hash>.npm:@acme/[email protected], exit 1 with the reserved-id message.bb plugin new snapshotsis refused before writing anything.plugins/npmorplugins/runtime.errorwith the reason. The server stays up, andbb plugin removeremoves them.srcis reverted to origin/main):apps/server/test/helpers/core-plugin-folders.tsis a check for the whole bug class. After a real npm install (plugin-install.test.ts) and a real git update that writes a snapshot (plugin-update.test.ts), it asserts that no package name can derive any folder core created underplugins/. A future core folder added without updating the list also fails it.plugin-install.test.ts: path installs of each reserved id are refused, with no registration and no logs folder. The npm source is refused before install.packages/domain/test/plugin-id.test.ts: plain, scoped and uppercase names are refused for each reserved id, and near misses (npm-tools,my-cache,toolchain-0.28.1) still derive.turbo run test typecheck lintfor@bb/server-archiveand@bb/host-daemon-contract,@bb/servertest/server-moveand@bb/host-daemonsrc/server-movesuites; the new inventory assertion fails with the old archive list.pnpm exec turbo run test --filter=@bb/domain --filter=@bb/cli --filter=@bb/templates --filter=@bb/plugin-build --filter=bb-plugin-bb-guide, both server test files,turbo run typecheck,lintandlint:type-awarefor@bb/server,@bb/domainandbb-plugin-bb-guide, andoxfmt --check.🤖 Generated with Claude Code