Repository navigation
Implement arbitrary filesystem Markdown links - #14
Merged
SawyerHood merged 1 commit intoMay 16, 2026
Merged
SawyerHood merged 1 commit into
SawyerHood merged 1 commit into
Conversation
SawyerHood
marked this pull request as ready for review
May 16, 2026 00:11
brsbl
added a commit
that referenced
this pull request
Oct 5, 2026
## Human comments
## What was wrong
The Plugin Guide only existed inside bb as the `plugin-api-docs` plugin,
so the upcoming plugins blog post had no public page to link to and
couldn't embed it.
## What changed
- **`/plugin-guide` on getbb.app**
(`apps/web/src/routes/plugin-guide.tsx`): renders the Guide's
`ProductMap` straight from `plugins/plugin-api-docs/src`. The current
slide syncs to `?slide=` (replace navigation, so reload and shared links
open the same map). Plugin names in "Used by" link to that plugin's
source on GitHub (`github.com/get-bb/bb/tree/main/plugins/<dir>`), which
exists for every built-in. Their icons come from
`first-party-plugins.json`, or from the plugin's own SVG logo, read
through its manifest's `bb.branding.icon`, for the five built-ins that
ship one. "Copy for agent" copies a self-contained prompt: what to
build, the surface's SDK symbols, the bb-plugin-authoring skill, and a
link back to the slide. The in-app button copies a mention that only
resolves inside bb. The Guide is client-only and lazy-loaded
(`ClientOnly` + `React.lazy`), because its mobile/desktop layout reads
`matchMedia` on first render and would otherwise mismatch on hydration.
- **The plugin stays forkable.** The Guide's three `@/` imports resolve
through the web's existing `@/` alias to modules the web owns. This is
the same contract a fork uses: `@/` means "the host's registry items".
- `apps/web/src/components/ui/icon.tsx` and `switch.tsx` are one-line
re-exports from `@bb/shared-ui` (new workspace dependency of `@bb/web`).
- `@/lib/utils` already exists in the web; its `cn` is identical to
shared-ui's (`twMerge(clsx(inputs))`).
- No new alias or shim. A future `@/` import the web lacks fails the web
build rather than resolving to the wrong module.
- `resolveJsonModule` is on for the Guide's JSON fixtures.
- **Theme** (`apps/web/src/components/ui/theme.css`): adds the tokens
the Guide uses, copied from the app theme for light and dark: `muted`,
`timeline-accent`/`file-accent`, `border-hairline`, `border-seam`,
`surface-recessed-solid`, `surface-raised(-solid)`, `sidebar`,
`sidebar-foreground`, `sidebar-accent`, `radius-sm`,
`shadow-xs/md/lift`, `text-2xs`. It also adds `@source` lines for the
Guide and shared-ui's icon/switch. The Guide's stylesheet
(`plugin-guide/plugin-guide.css`) loads only on `/plugin-guide` and on
posts that embed it.
- **Landing CSS can coexist with Tailwind**: `landing.css`'s
`*`/`a`/`code` reset moves into `@layer landing-reset`. Unlayered, it
beat every Tailwind utility (e.g. all `p-*`/`m-*`) on pages that load
both. Pages that load only `landing.css` behave the same.
- **Blog directive** (`apps/web/src/blog/parse-post.ts`,
`post-body.tsx`): a line `component:plugin-guide` or
`component:plugin-guide:<slide-id>` becomes a `{kind:"component",
name:"plugin-guide", slide?}` block. It renders the full carousel
(opening on the app-window "anatomy" slide by default) with an "Open the
full Guide" link. `.post-body` `h2/h3/p/ul/li/li::before/strong/code`
rules now skip `.post-embed` descendants through
`:where(:not(.post-embed *))`. They don't leak into the embed, and their
specificity is unchanged, so existing overrides (lede, ordered lists,
quotes, tweet text) still win.
- **Top-nav Plugins menu** (`apps/web/src/landing/site-chrome.tsx`,
`landing.css`): "Plugins" becomes a dropdown with Marketplace and Plugin
Guide. It uses the same `<details>`/`<summary>` disclosure as the
marketplace category picker. Escape closes it and returns focus;
clicking or tabbing outside closes it. The page you are on is marked
with `aria-current`, and "Plugins" is highlighted on both pages.
- **Discoverability**: a "Plugin Guide" link in the shared site footer,
which appears on the home page, blog, changelog, privacy page,
marketplace and the Guide itself. Also a sitemap entry and a canonical
URL (`https://getbb.app/plugin-guide`, so `?slide=` links count as one
page) for `/plugin-guide`, plus links from `PLUGIN_OVERVIEW.md` and the
`bb-plugin-authoring` skill.
- **Rebuild triggers**: `@bb/web#build`/`#typecheck` inputs and the
`deploy-web.yml` paths now include `plugins/plugin-api-docs/src/**` and
`packages/shared-ui/src/**`.
- **Guide fixture fixes** (`wireframes.tsx`, `product-map.tsx`; also
shown in the in-app Guide):
- Every mobile fixture uses one phone-shaped frame (9:19, same gutter,
390px column), so the slides no longer vary between 362 and 766px tall.
- The + menu, @ typeahead and inline-action popup open from their own
controls, above both the control and its number badge, so neither is
covered.
- On mobile the command palette is a bottom sheet with a drag handle,
matching the app's responsive drawer.
- New-thread actions and the sidebar "Your panel" highlight line up with
their sibling rows.
- The side-panel file tab truncates instead of running into the + and
panel icons.
- On getbb.app, phone-width viewers see only the mobile layout, and the
desktop toggle stays visible but disabled and the slide title and blurb
above the tabs are dropped to save space
(`mobileOnlyOnCompactViewport`). The in-app Guide keeps both its desktop
toggle and its slide header on phones.
- **SDK coverage:**
- Six `*Area.member` names that aren't public exports now use their
importable `PluginBbSdk.*` paths.
- 37 uncovered public exports were added to their cards (for example
`experimental_defineHostEntry`, `defineRpcContract`, `useSettings`,
`BbNavigate.openThreadPanel`, and the testing loaders).
- A new **Provider bridges** backend card covers the `./provider-bridge`
entry points.
- **bb mark in slide titles:** "The bb app window" shows the vector bb
mark (`assets/bb-logo.svg`, inverted in dark mode like the app's
`BbLogo`) instead of italic text. `ProductMap` takes an optional
`brandMark`; without it, the in-app Guide keeps the italic text.
- **Card copy and Used by refresh**
(`plugins/plugin-api-docs/src/surfaces.ts`, `first-party-plugins.json`).
This also changes the in-app Guide.
- **Leads:** every card leads with one of five verbs: **Add** (your UI
inside bb), **Replace** (a bb region or renderer), **Run** (code with no
UI), **Provide** (agents, environments, machines, server access, AI
services) or **Use** (platform building blocks).
- **Length:** each card has 2–4 short bullets that say what a plugin
gets. SDK names and edge-case rules moved out of the visible copy. The
agent reference still carries every symbol. Total copy went from about
6,500 to about 2,000 words.
- **Template test:** `surfaces.test.ts` now enforces the shape: lead
verb, at most 4 bullets, at most 100 characters each, no SDK
identifiers.
- **Used by:** every row was rebuilt from built-in plugin source, and
six missing plugins were added to `first-party-plugins.json`: Agent
Annotations, bb account, BB guide, PDF preview, Theme Preview, Thread
list. Seven surfaces have no built-in user yet, so their row is hidden.
### Screenshots (after; new page)
Card with "Used by" and "Copy for agent" (copied state):

Agent providers card with built-in brand logos:

Top nav, before and after (`/blog`, 1440 wide):
**Before**

**After**

Plugins menu open on `/plugin-guide`:

Mobile (390 wide), before and after:
**Before**

**After**

Dark, on the marketplace:

Slide title with the bb mark, light and dark:


Mobile fixtures, one phone frame each (390 wide):




Desktop app window with "Your panel" hovered (#2) and the truncated file
tab (#14):

The + menu opening from the + button, and the @ typeahead with its badge
above it:


Site footer with the Plugin Guide link:

Plugin backend with a refreshed card:

Desktop, light (1440×900 @2x):

Desktop, dark, with a surface card open showing "Used by" links:

Mobile (390×844 @2x):

Blog post with `component:plugin-guide` (local draft, not committed):

In-app Guide on this branch (dev app), phone width: slide title and
blurb kept, desktop toggle enabled:

In-app Guide on this branch, desktop:

## How you verified
- `pnpm exec turbo run build --filter=@bb/web` passes. The client build
emits the Guide chunks, and the Guide CSS contains the new token
utilities (`bg-sidebar`, `text-2xs`, `border-border-hairline`,
`shadow-lift`, …).
- `bb plugin build plugins/plugin-api-docs` passes, and its `app.js`
still uses the host runtime `experimental_Icon`.
- Branch web app (`vite dev`) driven through `bb browser-automation`,
headless Chrome for Testing, 2× device scale:
- `/plugin-guide` at 1440×900: Guide content renders (7 slides, 68
annotation chips). Clicking a slide tab updates `?slide=composer`,
ArrowRight moves to `?slide=home`, and loading `?slide=settings` opens
"Plugin settings page". A chip opens its card, and "Used by" links point
to each plugin's GitHub source with icons. "Copy for agent" shows
"Copied", and the clipboard receives the self-contained prompt; checked
by stubbing `navigator.clipboard.writeText`. Brand logos render, masked
to the text color, on the Agent providers card.
- Dark scheme via `prefers-color-scheme`: tokens resolve correctly.
- 390×844: mobile slides ("Sidebar" → next → `?slide=app-shell-thread`),
no horizontal overflow.
- Draft post with `component:plugin-guide` and
`component:plugin-guide:composer`: two embeds at the 680px column width,
opening on "The bb app window" and "The composer". Links go to
`/plugin-guide` and `/plugin-guide?slide=composer`. Computed styles show
no `.post-body` leak (Guide `li::before` is `none`, Guide `p` is 13px),
while the post's own list keeps its markers and spacing.
- No console errors or page errors in any of these runs.
- Plugins menu, in Chrome for Testing at 2×: click opens it; outside
click closes it; Enter opens it; Tab reaches Marketplace then Plugin
Guide; Escape closes it and refocuses "Plugins"; tabbing past the last
item closes it. The current page is marked on `/plugin-guide` and
`/marketplace`. Checked at 390 px (panel stays on screen) and in dark
mode. No console errors. On `/`, the open panel paints above the hero's
"New" callout: hit-testing both rows lands on the links, and clicking
Plugin Guide navigates. The header is lifted with `position: relative;
z-index: 10` because its entrance animation fill can trap the panel's
z-index in Safari and Firefox.
- Real Safari 26.5.2 on macOS (safaridriver): home Plugins menu,
`/plugin-guide` desktop (slides, `?slide=`, all three composer menus,
brand icons, Copy for agent), and 390 and 360 widths. Dark mode wasn't
driven in Safari.
- Existing pages are unchanged. On `/`, `/blog`, both posts,
`/changelog`, `/privacy` and `/marketplace`, every element's computed
margin, padding, color, font, line height, decoration, size and
`::before` were captured, then `landing.css`/`blog.css` were swapped in
place for their `origin/main` form (reset unlayered, no embed
exclusion): 0 differences on every page. The same check flagged the lede
and `<ol>` markers on `/privacy` against an earlier revision of this PR,
which the review caught.
- Parser tests in `parse-post.test.ts` (directive with and without
slide; near-misses stay paragraphs) and the sitemap test run in CI.
- In-app Guide, branch dev app (`pnpm dev`, `plugin-api-docs` enabled),
Chrome for Testing at 2×: at 1440×900 the slide header (italic *bb*,
blurb) and toggle are unchanged; at 390×844 the slide title and blurb
still show, the desktop toggle stays enabled, the phone mock fits at
scale 1 and scrolls fully into view, and nothing overflows sideways. The
web keeps the compact header (title `sr-only`) and serves `<link
rel="canonical" href="https://getbb.app/plugin-guide">` in the SSR HTML.
## Follow-ups (P2, not in this PR)
- Close the Plugins menu on Escape after a mouse open. Safari doesn't
focus the summary on click, so the details-scoped key handler doesn't
fire. Use a document keydown listener. (Nav review, 4fa7844)
- Drop Agent Annotations from "Draft prompt highlighting". It only uses
`replace` and `onSubmitted`, never highlighting. (Card review,
1f09afd)
- Reword the app-wide scripts bullet "Clean up automatically when the
window reloads". bb runs the returned disposer on unmount, which also
happens on plugin reload and disable. (Card review)
- Read `.bb` from the default JSON import in the web brand-icon glob, so
a future plugin manifest without `bb` can't break the web build. (Card
review)
- #4936 (draft, stacked on #4608) switches "Used by" links to the
built-in marketplace pages, falling back to GitHub for built-ins #4608
leaves unlisted.
- Validate `component:plugin-guide:<slide>` ids at parse time. Right now
a typo opens the first slide and the "Open the full Guide" link carries
the bad id (Codex review).
- Add `packages/shared-ui/package.json`, `plugins/*/package.json`,
`plugins/*/icons/*.svg` and `plugins/*/*.svg` to the
`@bb/web#build`/`#typecheck` inputs, and the same plus
`assets/bb-logo.svg` and `pnpm-lock.yaml` to the deploy-web paths. The
brand-icon glob reads every plugin manifest and SVG, so a manifest or
icon change alone neither rebuilds nor redeploys the site. (Slop Cop
architecture, code quality)
- Scan shared-ui's `motion.ts` with Tailwind `@source`. The switch's
transition classes currently survive only because the web's `motion.ts`
has the same string.
- Document, or test, the `@/` modules the web supplies to the Guide
(icon, switch, lib/utils). Today a new `@/` import in the Guide fails
the web build with an error that points at web paths.
- Stop the Guide stylesheet from overriding landing tokens on
`/plugin-guide` and posts that embed it: `theme.css` loads after
`landing.css` and replaces `--font-sans` (drops the size-matched Inter
fallback), `--font-mono` (Fira Code, never loaded on the web),
`--border`, `--state-hover` and `--surface-recessed`. Scope the app
values to the Guide or re-assert landing's after the import. (Slop Cop
architecture, code quality)
- Size the web `PhoneFixture` against
`document.documentElement.clientHeight` instead of `window.innerHeight`,
so collapsing mobile browser toolbars don't rescale the phone mock and
shift the page while scrolling. (Slop Cop performance)
- Build the web "Copy for agent" context from
`pluginSurfaceAgentContext` instead of copied lines, with a web test.
(Slop Cop architecture)
- Test that every theme token the Guide uses is defined in the web
`theme.css`, and that every "Used by" display name resolves to exactly
one plugin manifest. (Slop Cop architecture, code quality)
- Add `resolve.dedupe: ["react", "react-dom"]` to the web Vite config,
and move the Guide's `@source` lines from the shared `theme.css` into
`plugin-guide.css`. (Slop Cop architecture)
BB-Thread: [Public Plugin Guide on
getbb.app](https://brsbl.getbb.app/projects/proj_khiw2za95v/threads/thr_ptdzpsxqum)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
> AGENT GENERATED
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 5, 2026
## Human comments ## What was wrong A storage scan finds worktrees created outside bb. To do that, the server called the host's `listGitWorktrees` with only the repository paths. The host ran `git status` (plus `rev-list` for detached HEADs) on **every** linked worktree, and the server then threw away the ones bb owns: live environment paths and project sources. On `~/Projects/bb` that's 127 `git status` runs per scan, and 42 of them were for worktrees the caller ignored. This is finding #14 from the Nov 4 hot-path overreach audit. Two parts of that finding didn't hold or are out of scope here: - The audit said the scan rewrites index files. It doesn't: the host already runs git with `GIT_OPTIONAL_LOCKS=0`. - The `hosts` thread paging is a separate mechanism and is not touched. ## What changed - `plugins/storage-retention/src/host-contract.ts`: `listGitWorktrees` input gains `ownedPaths`. - `plugins/storage-retention/src/git-worktrees.ts`: the host skips any linked worktree whose normalized path exactly equals an owned path, *before* inspecting it. The host bundle's SDK runtime has no host-path comparison helper, and adding one would change plugin-build/SDK, so the host uses exact matching. An exact match can only skip paths the server also treats as owned. - `plugins/storage-retention/src/storage.ts`: the server sends its owned path list and keeps its comparison-key `ownedByBb` filter as the authority. A textual mismatch (different case, for example) costs only the old extra `git status`; it can never hide an external worktree. Users see the same external-worktree list; scans just do less work. This RPC is plugin-internal, and the server builds and ships the host bundle alongside it, so there is no `HOST_DAEMON_PROTOCOL_VERSION` bump and no plugin SDK change. ## How you verified **Real data.** I ran `listGitWorktrees` from main and from this branch directly against `~/Projects/bb` (4.4k branches, 128 worktrees), interleaved over 5 pairs. The owned paths came from the live `~/.bb/bb.db` (opened read-only; 61 environment and source paths, 42 of them worktrees of this repo). A `git` shim on PATH counted spawns. Load average was 26–55 throughout (other threads' benchmarks were running), so treat wall times as noisy and spawn counts as exact. | | `git status` / scan | `rev-list` / scan | wall time per scan, sorted (ms) | median | |---|---|---|---|---| | main | 127–128 | 10 | 25977, 27250, 40327, 40629, 47682 | 40.3 s | | branch | 85–86 | 10 | 16815, 17428, 20792, 34563, 42211 | 20.8 s | In every pair, both versions produced the same set of external worktrees. I re-ran 3 more interleaved pairs after the exact-match revision, at a quieter load of 4–10. `git status` dropped from 127 to 85 per scan (the same 42 owned worktrees skipped), the external sets were identical, and wall time went from 13195/13293/12592 ms to 8986/9530/9082 ms (median **13.2 s → 9.1 s**). **Tests.** The existing real-git scan test in `storage.test.ts` now also checks that the host returns only the four external worktrees and never the bb-owned `managed` one. With the host filter disabled it fails (`expected [ …(5) ] to deeply equal [ …(4) ]`). - `pnpm exec turbo run prepare:bundled typecheck lint --filter=bb-plugin-bb--storage-retention`: pass (`prepare:bundled` is the host-bundle build that failed in CI on the first revision) - `vitest run src/storage.test.ts`: 33/33 pass CI runs the full suites. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 5, 2026
…folders out of it (#7099) ## Human comments ## What was wrong Follow-up to #7072 for finding #14 of the Nov 4 hot-path overreach audit. The storage-retention plugin read **every thread** (`threads.list` paged 500 at a time, about 4,500 rows here) in three places: - the report behind the `hosts` / `host` RPCs (rendered on every Storage page refresh), - `startScan`, - `retryWorktreeCleanup`. The threads it actually uses are a much smaller set: - threads named by the machine's thread-storage entries (and large files), - threads in *retired* environments, used to decide whether a leftover worktree is still occupied, - threads linked to external worktrees and `.bb-dev` entries, found by environment path or by a thread ID encoded in the path. Most of those storage entries are **empty folders**. On this machine 1,546 of the 1,844 folders in `~/.bb/thread-storage` hold nothing. 1,157 were emptied when their thread was archived: "Delete storage on archive" discards the contents and recreates the folder (`recreate: true`). Another 350 were created at thread start and never written to. On the other two machines, 118 of 122 and 20 of 43 entries are 0 bytes. The report still looked up each of their threads, and it counted the folders as storage: 1,844 "threads with storage" here, where only 298 hold anything. On this machine the live server logged `POST /api/v1/plugins/bb--storage-retention/rpc/hosts` at **1,821 ms**. Its 500-row `GET /api/v1/threads` pages take a median of 174 ms each (32 slow-request samples in `server.19x/20x.log`). ## What changed `plugins/storage-retention/src/storage.ts`, `sdk-data.ts`: - **Report:** reads storage-entry, large-file and path-encoded threads by ID with `threads.list({ threadIds })` (existing 200-ID chunks). It reads threads in retired environments and in environments matching linked paths with `threads.list({ environmentId })`, one indexed call per environment. Everything downstream (classification, leftover detection, linked threads) runs unchanged over that set. - **Scan and cleanup retry:** read only threads in retired environments (`readLeftoverEnvironments`). They don't page any more. - The environment-only half of `leftoverEnvironments` became `retiredEnvironments`. `linkedThreads` takes a precomputed `threadLink` (environment IDs plus encoded thread ID). With the thread list gone, the report context shared across hosts now only shares `projects.list`. **Empty folders** (second commit): - The host scan (`disk-usage.ts`) flags each per-child directory that has no entries (`empty`), with one `opendir` + `read` per folder. It's a real emptiness check, not "0 bytes", because `du` reports an empty folder as 4 KiB on Linux. - The report, **Remove orphans** and **Clear archived files** skip empty entries. They aren't looked up, counted, offered for clearing, or labelled orphans. The cleanup actions' counts now match what the report shows. - Empty entries stay in the cached scan. Archive cleanup uses the scan to find the machine for a thread without an environment (`clearThreadStorage`). Dropping them would send those threads into its hourly "location unavailable" retry; 187 such threads have empty folders here. - Scans cached before this change have no `empty` flag. They read as non-empty, so the report is unchanged until the machine is rescanned. - `linkedThreads` sorts newest first (`createdAt`, then `id`) instead of following read order. That's the order main produced for this data, and it no longer changes with which read returned a thread. - The host contract's `measure` children gain a required `empty` field. The host worker ships in the same plugin bundle, as with #7072's `ownedPaths`. **No SDK change.** `threads.list` already has both targeted filters (`threadIds`, `environmentId`). The per-environment calls cover only retired worktrees awaiting teardown plus linked paths: 2 + a few on this machine, each an indexed `threads_environment_archived_deleted_idx` lookup. An `environmentIds` list filter would save a handful of sub-millisecond calls, which isn't worth an SDK bump. ## How you verified **Benchmark, real data.** I ran the plugin's actual `createStorage(...).hosts()` code from `origin/main`, from this PR's first commit (54d913c), and from the PR head. The fake SDK's `threads.list` / `environments.list` / `projects.list` call the server's own route functions (`listThreadsWithPendingInteractionState` + `toThreadListEntryResponses`, `listEnvironments` + `toEnvironmentResponses`) against the live `~/.bb/bb.db` **opened read-only**. Each response gets a JSON round trip. For input, I rescanned this machine's real `~/.bb/thread-storage` (32 GB, 1,844 folders) with each version's own `measureDiskUsage`. That's read-only: `du` plus one directory read per folder. The other two machines use the plugin's cached scans (122 / 43 entries), which have no `empty` flag. Medians of 9 runs, 3 alternating rounds: | `hosts()` | main | first commit | PR head | |---|---|---|---| | total | 197.9 / 200.6 / 197.0 ms | 71.2 / 71.9 / 70.8 ms | **25.4 / 25.8 / 25.5 ms** | | inside `threads.list` | 185 ms | 63 ms | 20 ms | | `threads.list` calls | 10 (full paging) | 24 | 16 | | thread rows served | 4,521 | 2,023 | **485** | | scan/retry thread read (2 retired envs) | 176 ms, 4,513 rows | 0.6 ms, 2 rows | 0.6 ms, 2 rows | Of the 485 rows, 298 are this machine's non-empty folders and 165 are the other two machines' cached entries. The rest are threads in retired or linked environments. **Scan time is unchanged:** 10.1 / 9.7 s for main's scanner and 9.9 / 10.3 s for the PR's over the same folder. The emptiness check is lost in `du`'s noise. Both find 1,844 entries, and the PR flags 1,546 empty, exactly the folders `du` measures at 0 bytes on this Mac. **Reports:** - main and the first commit: byte-identical for all 3 machines. - main and the PR head on a scan cached before this change (no `empty` flag): byte-identical. - main and the PR head on the fresh scan: the other two machines are byte-identical. On this machine every byte total is identical (active, archived, orphan, leftover, hidden, clearable, large files), and so are `largestThreads`, leftover and external worktrees, developer storage, and linked threads. Only the counts that included empty folders change: | this machine | main | PR head | |---|---|---| | threads with storage | 1,844 | 298 | | archived threads with storage | 1,805 | 271 | | archived files to clear (threads) | 1,651 | 209 | | hidden threads, active / archived | 4 / 20 | 0 / 0 | The harness has no HTTP hop and the server isn't under load, so absolute times are lower than live. Thread rows served for the report drop 89% (4,521 → 485). On the live server that should take the logged ~1.8 s to a few hundred milliseconds. That's an estimate; I didn't measure it on the live server. **Tests** (`pnpm exec turbo run test typecheck lint --filter=bb-plugin-bb--storage-retention`, 88 passing): - I replaced the test that pinned the old "one full thread listing for every host" design. In the new test, `threads.list` **throws on an unfiltered call** and honours the `threadIds` / `environmentId` filters. Real temp folders back the storage root: a folder with a file, an empty folder for an archived thread, and an empty folder with no thread. It checks four things: - the report counts only the non-empty folder; - neither empty folder is counted as archived or orphan; - `threadIds` lookups ask for only `thr_kept`; - a retired worktree held by an unarchived thread, which only the environment read finds, isn't reported as leftover. - In "never clears thread storage that holds a workspace", the archived thread already cleared on archive no longer shows as "archived files to clear". **Clear archived files** now reports 0 cleared, matching the report. - `disk-usage.test.ts` adds an empty folder to the per-child test, which runs against real `du`, `du` with one child per batch, and the walker. It expects `empty: true` for that folder and `empty: false` for folders and files with content. - **Mutation checks:** - `readThreadsInEnvironments` reading nothing fails the new test (`env_busy` reported). - Dropping the report's empty filter fails 2 tests. - Dropping the filter in `discard` fails the Clear-archived-files assertion. - I dropped the `threads.list` call-count assertion from the reconnect-rescan test. `scannedHostIds` already asserts that only the reconnected machine is rescanned. **Left out** - The ~300 non-empty storage-entry reads stay. The report classifies every non-empty entry (active, archived, hidden, clearable, orphan), so it needs each of those threads. - Empty folders aren't deleted. They take almost no space, and "Delete storage on archive" still recreates the folder on purpose. Whether it should stop recreating it is a separate question. - The other two machines' counts update on their next scan. - `readEnvironments` still pages environments per host. That route already leaves out destroyed environments (~60 rows here, 1.5 ms). - The retention-policy sweep (`service.ts` `candidates`) still pages every thread. It selects threads by age across all projects, which is a different query and not this finding. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
pushed a commit
that referenced
this pull request
Nov 25, 2026
…lability read (#8187) ## Human comments ## What was wrong A nested bb whose Account Pooler proxies to a parent pool decides per turn whether it can route through the parent, using `ParentAvailability` in `plugins/account-pool/src/parent-pool.ts`. `load()` gives the parent's `/availability` 2 s, and on any error or non-OK status returns `UNAVAILABLE_POOL`. `get()` caches that result for the full 30 s TTL, the same as a good answer. So one slow read from a busy parent takes the child off the pool for 30 s, and every turn that starts in that window runs with no pool credentials. On a child with no Claude login of its own, Claude Code answers `Not logged in · Please run /login` and Provider Retry skips the turn as not retryable. On one child this happened three times in a day, each time the parent's host was under heavy load. ## What changed - `plugins/account-pool/src/parent-pool.ts`: `ParentAvailability` remembers the last good availability. - A failed read keeps serving it, and the next read is tried after 5 s instead of 30 s. - Once reads have failed for 60 s in a row, the parent is reported unavailable and that answer is cached for the normal TTL, as before. A parent that has never answered is reported unavailable, and the read is retried after 5 s. - The read timeout goes from 2 s to 5 s. - `plugins/account-pool/src/parent-pool.test.ts`: three cases, all of which fail on `main`: - one failed read keeps the last good value and retries after 5 s; - a parent that stays down is reported unavailable after 60 s, then cached for the TTL; - a failed first read is retried after 5 s. - No wire, CLI or doc changes. ## How you verified - New tests on `main`'s `parent-pool.ts`: the 3 new tests fail with `expected { claude: false, codex: false } to deeply equal { claude: true, codex: false }`, and the other 13 pass. With the change: 16/16. - After the final commit: `pnpm exec turbo run typecheck lint test --filter=bb-plugin-account-pool --force` passed 10/10 tasks, with 14 test files and 402 tests passing. Lint reported 3 warnings, all in `app.tsx`, which this PR does not touch. `pnpm exec turbo run lint:type-aware --filter=bb-plugin-account-pool --force` passed 7/7 tasks with 0 warnings. `pnpm exec turbo run prepare:bundled --filter=bb-plugin-account-pool` passed 7/7 tasks. `oxfmt --check` passes on both files. - Standalone reproduction with real HTTP and the real clock. `ParentAvailability` uses the real `fetch` and the shipped TTL and timeouts against a local HTTP parent, and one `get()` per second stands in for a turn start. `main` and this branch ran side by side. One slow answer (request #2 answers in 8 s, then normal), on `main`: ``` [ 0.0s] parent: request #1 -> 200 {claude:true} [ 0.1s] child: turn start -> ROUTED (claude via parent pool) [ 30.2s] parent: request #2 answering in 8s [ 32.2s] child: warn could not read parent availability: The operation was aborted due to timeout [ 32.2s] child: turn start -> NOT ROUTED (turn runs with no login) after waiting 2003ms [ 62.3s] parent: request #3 -> 200 {claude:true} [ 62.3s] child: turn start -> ROUTED (claude via parent pool) summary: 43 turn starts routed, 30 not routed, 3 parent requests ``` With the change: ``` [ 0.0s] parent: request #1 -> 200 {claude:true} [ 0.1s] child: turn start -> ROUTED (claude via parent pool) [ 30.2s] parent: request #2 answering in 8s [ 35.2s] child: warn could not read parent availability: The operation was aborted due to timeout [ 35.2s] child: turn start -> ROUTED (claude via parent pool) after waiting 5003ms [ 40.2s] parent: request #3 -> 200 {claude:true} [ 70.4s] parent: request #4 -> 200 {claude:true} summary: 70 turn starts routed, 0 not routed, 4 parent requests ``` A parent that stays down (503 from 25 s on), on `main`: ``` [ 0.0s] parent: request #1 -> 200 {claude:true} [ 0.1s] child: turn start -> ROUTED (claude via parent pool) [ 30.2s] parent: request #2 -> 503 (down) [ 30.2s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 30.2s] child: turn start -> NOT ROUTED (turn runs with no login) [ 60.4s] parent: request #3 -> 503 (down) [ 60.4s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 90.5s] parent: request #4 -> 503 (down) [ 90.5s] child: warn could not read parent availability: parent availability returned HTTP 503 [120.7s] parent: request #5 -> 503 (down) [120.7s] child: warn could not read parent availability: parent availability returned HTTP 503 summary: 30 turn starts routed, 100 not routed, 5 parent requests ``` With the change, the child keeps routing for 60 s after the first failure, then reports the parent unavailable and goes back to reading every 30 s: ``` [ 0.0s] parent: request #1 -> 200 {claude:true} [ 0.1s] child: turn start -> ROUTED (claude via parent pool) [ 30.2s] parent: request #2 -> 503 (down) [ 30.2s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 35.2s] parent: request #3 -> 503 (down) [ 35.2s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 40.2s] parent: request #4 -> 503 (down) [ 40.2s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 45.3s] parent: request #5 -> 503 (down) [ 45.3s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 50.3s] parent: request #6 -> 503 (down) [ 50.3s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 55.3s] parent: request #7 -> 503 (down) [ 55.3s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 60.3s] parent: request #8 -> 503 (down) [ 60.3s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 65.3s] parent: request #9 -> 503 (down) [ 65.3s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 70.3s] parent: request #10 -> 503 (down) [ 70.3s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 75.3s] parent: request #11 -> 503 (down) [ 75.3s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 80.3s] parent: request #12 -> 503 (down) [ 80.3s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 85.4s] parent: request #13 -> 503 (down) [ 85.4s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 90.4s] parent: request #14 -> 503 (down) [ 90.4s] child: warn could not read parent availability: parent availability returned HTTP 503 [ 90.4s] child: turn start -> NOT ROUTED (turn runs with no login) [120.5s] parent: request #15 -> 503 (down) [120.5s] child: warn could not read parent availability: parent availability returned HTTP 503 summary: 90 turn starts routed, 40 not routed, 15 parent requests ``` <details><summary>repro.mts (run from the repo root as <code>node_modules/.bin/tsx repro.mts $PWD/plugins/account-pool/src/parent-pool.ts slow-once|down</code>)</summary> ```ts import { createServer } from "node:http"; import type { AddressInfo } from "node:net"; const [modulePath, scenario] = process.argv.slice(2) as [string, "slow-once" | "down"]; const { ParentAvailability } = await import(modulePath); const TOKEN = "vqMIj4xUiI3PyvKS2SllSKHsOfxLF_sAZwzNAAvV9TQ"; const started = Date.now(); const t = () => ((Date.now() - started) / 1000).toFixed(1).padStart(5); let request = 0; const server = createServer((req, res) => { request += 1; const n = request; const elapsed = (Date.now() - started) / 1000; if (req.headers["x-bb-account-pool-token"] !== TOKEN) { res.writeHead(401).end(); return; } const answer = () => { res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify({ claude: true, codex: false })); }; if (scenario === "slow-once" && n === 2) { console.log(`[${t()}s] parent: request #${n} answering in 8s`); setTimeout(() => { if (!res.destroyed) answer(); }, 8_000); return; } if (scenario === "down" && elapsed > 25) { console.log(`[${t()}s] parent: request #${n} -> 503 (down)`); res.writeHead(503).end(); return; } console.log(`[${t()}s] parent: request #${n} -> 200 {claude:true}`); answer(); }); await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve)); const { port } = server.address() as AddressInfo; const availability = new ParentAvailability({ parent: { baseUrl: `http://127.0.0.1:${port}/api/v1/plugins/account-pool/http`, token: TOKEN }, fetch, now: Date.now, onError: (error: unknown) => console.log(`[${t()}s] child: warn could not read parent availability: ${error instanceof Error ? error.message : String(error)}`), }); const durationS = scenario === "slow-once" ? 75 : 130; let last: string | null = null; let routed = 0; let unrouted = 0; while ((Date.now() - started) / 1000 < durationS) { const before = Date.now(); const value = await availability.get(); const waited = Date.now() - before; if (value.claude) routed += 1; else unrouted += 1; const state = value.claude ? "ROUTED (claude via parent pool)" : "NOT ROUTED (turn runs with no login)"; if (state !== last || waited > 500) { console.log(`[${t()}s] child: turn start -> ${state}${waited > 500 ? ` after waiting ${waited}ms` : ""}`); last = state; } await new Promise((r) => setTimeout(r, 1_000)); } console.log(`summary: ${routed} turn starts routed, ${unrouted} not routed, ${request} parent requests`); server.close(); process.exit(0); ``` </details> - **Not checked:** an isolated nested bb against a slow parent bb end to end. The reproduction drives the same class the server constructs, with the same options except `onError`. Fixes #8188 > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) 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.
Summary
host.read_fileto omitrootPathfor explicit disk reads while still requiringrootPathfor git-ref reads.Validation
NODE_OPTIONS=--no-experimental-webstorage pnpm exec turbo run test --filter=@bb/host-daemon-contract --filter=@bb/host-daemon --filter=@bb/server-contract --filter=@bb/server --filter=@bb/app@bb/host-daemon-contract: 2 files, 26 tests passed@bb/host-daemon: 27 files, 264 tests passed@bb/server-contract: 1 file, 11 tests passed@bb/server: 76 files, 764 tests passed, 4 skipped@bb/app: 80 files, 491 tests passedpnpm exec turbo run typecheck --filter=@bb/host-daemon-contract --filter=@bb/host-daemon --filter=@bb/server-contract --filter=@bb/server --filter=@bb/appgit diff --checkSecurity / Product Notes
open in editorremains gated to local-host thread environments.