Skip to content

Cap workspace status file lists and report the total count - #5494

Merged
ymichael merged 2 commits into
mainfrom
t3code/fix-issue-5331
Oct 14, 2026
Merged

ymichael merged 2 commits into
mainfrom
t3code/fix-issue-5331

Conversation

@ymichael

@ymichael ymichael commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Workspace.getStatus ran git status --untracked-files=all and returned every entry in workingTree.files. A worktree with ~7,000 untracked QA artifacts therefore produced a ~1.5 MB status payload. That payload went daemon → server → app on every watcher-driven refetch, causing event-loop stalls and UI lag (#5331). The earlier guardrails each bounded something else: #1496 bounded git/process work, #1607 bounded line-stat enrichment (maxUntrackedLineStat*), and #1783 bounded only the prompt banner's render. The secondary panel's changed-files list still rendered every file once expanded. #1783 named the missing piece as follow-up work: "bound workingTree.files at the server with a truncation signal". This PR is that follow-up.

What changed

  • Domain (WorkspaceChangeStats): new required fileCount, the true total of changed files. files may now be a leading slice; the list was truncated exactly when files.length < fileCount. This applies to both workingTree and mergeBase.
  • Wire: workspace.status takes a required maxFiles. HOST_DAEMON_PROTOCOL_VERSION 234 → 235.
  • Server: owns the limit via WORKSPACE_STATUS_MAX_FILES = 200, matching the row cap the app already used.
  • host-workspace: getStatus slices the porcelain entries and merge-base files to maxFiles. Git's porcelain output lists tracked changes before untracked ones, so real edits survive the cap. Totals and line stats are still computed from the full set.
  • App: counts, pills and summaries use fileCount. WorkspaceChangesList and the secondary panel's ChangedFilesList show "N more files not shown" from the true total. The client-side 200-row slice is removed in favor of the server limit.
  • CLI: bb environment status and bb thread show print fileCount. The CLI guide template documents the 200-entry limit and fileCount.
  • Plugin SDK: bumped @get-bb/plugin-sdk 0.6.43 → 0.6.44 because the bundled declarations now include fileCount. Nothing is removed or renamed. The visible change for SDK and plugin consumers of environments.status() (bb.sdk.environments.status() for plugins): files is now at most 200 entries instead of the complete list. Code that used files.length as the count, or searched files for a path, should use fileCount and must not assume a path missing from files is unchanged. Code that builds a WorkspaceStatus object by hand must add fileCount. No in-repo plugin calls environments.status().
  • Two limits: the new 200-file status limit is separate from the existing 500-file diff limit (WORKSPACE_DIFF_MAX_FILES, Bound untracked status and diff work #1496/Restore bounded rich untracked status and diffs #1607). Status is refetched automatically whenever the worktree changes, so it stays smaller and matches the app's existing 200-row display limit from Cap the prompt banner changed-files list and lazy-mount collapsed bodies #1783. The diff panel loads only when the user opens it.
  • Not addressed: how often status is refetched under FSEvents churn. Each refetch is now small, but a busy worktree still triggers frequent git status scans.

How you verified

  • New host-workspace tests:
    • caps working-tree files with tracked edits listed first, including a limit smaller than the number of tracked edits
    • uncapped calls still return every file
    • caps merge-base files while reporting the total
    • rejects maxFiles: 0
  • Reproduced the issue's scenario (19 tracked edits + 7,000 untracked files) against Workspace.getStatus: 602,433 bytes / 7,019 entries uncapped → 17,082 bytes / 200 entries capped, with all 19 tracked edits listed and fileCount: 7019.
  • pnpm exec turbo run typecheck --filter=@bb/domain... --filter=...@bb/domain: passed.
  • pnpm exec turbo run test for @bb/app (5,761), @bb/server (3,473), @bb/cli, @bb/host-daemon, @bb/host-workspace, @bb/domain, @bb/templates: all passed.
  • @bb/host-daemon-contract: all pass except payload-size.test.ts, which is unrelated to this change. Its JSON byte counts match exactly and only the gzip sizes differ. That points to local Node 22.23 vs the pinned 22.19 (zlib).
  • oxfmt --check on changed files and turbo run lint: clean.
  • node packages/plugin-sdk/scripts/check-npm-version-guard.mjs: passes at 0.6.44 (fails at 0.6.43 because the published declaration files changed).
  • Manually checked on pnpm start:worktree with the issue's scenario: the prompt banner shows "Uncommitted · 7019 files", lists the 19 tracked edits first, and ends with "6,819 more files not shown". bb environment status --json returns 30 KB with fileCount: 7019.

Fixes #5331

🤖 Generated with Claude Code

AGENT GENERATED

ymichael and others added 2 commits October 14, 2026 10:15
Workspace status listed every changed path, so a worktree with thousands
of untracked files produced a 1.5 MB status payload on every refetch.
The server now sets a 200-file limit on the workspace.status command;
working-tree and merge-base stats carry fileCount with the true total,
and the app and CLI derive counts and "N more files not shown" from it.

Fixes #5331

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit efb7d12 into main Oct 14, 2026
47 of 48 checks passed
@ymichael
ymichael deleted the t3code/fix-issue-5331 branch October 14, 2026 17:30
ymichael added a commit that referenced this pull request Oct 14, 2026
…M-free tests out of jsdom (#5261)

## Human comments

## What was wrong

Test time went to repeated setup, not to the tests themselves. Server
tests ran all migrations against a fresh `:memory:` database per test,
even though a cached-template helper already existed: 607 `migrate`
calls and about 58 s of CPU per `@bb/server` run, at about 80 ms each
against 0.4 ms to deserialize a template. Small helpers were copied per
file (`makeTempDir` ×45, `initRepo` ×9, `LocationProbe` ×12, `deferred`
and `jsonResponse` copies), `react-resizable-panels` was mocked 9 times,
and the two `ThreadDetailPromptArea` test files duplicated 21 module
mocks. A handful of tests (listed below) asserted guide prose or
restated the implementation.

In the app and plugins, every jsdom test file pays about 3.8 s of fixed
cost (environment 1.7 s, imports 1.4 s, setup 0.3 s) before 0.44 s of
tests. A mutation audit of all 496 jsdom files found most of them are
the only guard on DOM behavior (keyboard, IME and focus paths, portals,
observers, iframe sandboxes, stale-response races tied to fix commits),
but about 100 ran in jsdom for logic that needs no DOM, 14 duplicated
stronger tests, about 50 passed for the wrong reason, and about 110
restated inventories, class tokens or library behavior.

## What changed

Eight original commits plus rebase integration fixes. Commits 1–6 touch
test code and test support only. Commits 7–8 also change production
code, but only to extract logic into functions the component or hook
still calls (behavior-preserving, reviewed for parity below).

1. **One migrated template database.** `@bb/db/testing` exports
`createMigratedConnection()` and `prepareMigratedConnectionTemplate()`.
The db and server `globalSetup` build the template once and hand it to
workers through `BB_TEST_MIGRATED_DB_TEMPLATE`, so isolated files
deserialize instead of re-migrating. Full-schema setup sites in
apps/server and packages/scripts use it. A guard test in apps/server
fails on new `migrate(` calls in its tests. Three files keep raw
`migrate` on purpose: an empty pre-migration schema, child-process
scripts, and a 0117 backfill replay that reads `migrate`'s TEMP table.
Still a real SQLite database built by the real migrations.
2. **Shared small helpers.** `@bb/test-helpers` gains
`makeTempDir`/`makeTempDirSync` (cleanup through `onTestFinished`, with
the Windows retry budget from #4776) and `initRepo`. Local `deferred`
copies use `createDeferredPromise`, and `jsonResponse` copies use
`Response.json`. apps/app gets one `LocationProbe`, two shared
`react-resizable-panels` modules (real browser build, layout stub) and
one shared question-shortcut `system-queries` mock.
`plugins/theme-preview/server.test.ts` uses the SDK fake host instead of
8 `as unknown as BbPluginApi` casts. `@/lib/sdk` and `system-queries`
factories were not added: 57 of 61 and 31 of 35 blocks are distinct, so
a factory would only move code. Plugins keep local copies (forkable
rule).
3. **Shared `ThreadDetailPromptArea` harness**
(`apps/app/src/test/thread-detail-prompt-area-harness.tsx`). The two
"every atom returns 40" jotai mocks became a store with
`secondaryPanelWidthPercentAtom` set. Changing it to 33 fails 2 and 1
tests, so the store is load-bearing.
4. **Evidence-backed deletions**, each checked against the test-audit
skill and with mutation checks:
- Deleted: prose-matching tests in `plugin-authoring-docs.test.ts` (4)
and `submit-a-plugin.test.ts` (4), and
`create-via-prompt-examples.test.ts`, which built its expectations with
the same `map` the code uses (`getCreateExamples` is now un-exported).
- Trimmed: colour and size class assertions in
`SecondaryPanelTabStrip.test.ts`. Visibility, no-drag and touch-target
assertions stay.
- Replaced: `MachineLabel.test.tsx` now covers an ephemeral host whose
provider is not loaded instead of the trivial persistent branch.
- Kept after the mutation check showed they were the only guard:
`route-loading-skeleton.test.tsx`, the
release-approval/`--ignore-scripts` skill test, and the changelog footer
colour pair.
5. **`pnpm exec turbo run bench`** runs the three opt-in benchmarks
(sidebar, composer paste, watcher recovery), documented in
`docs/debugging-and-qa.md`. Per-file jsdom cost was measured; no config
change (below).

6. **`createMemoryStorage()`** in `@bb/test-helpers`, for node tests
that only need `localStorage`/`sessionStorage`.
7. **Move DOM-free tests out of jsdom and delete duplicated ones.**
jsdom test files go from 496 to 403.
   - Pragma only: files that pass unchanged in node drop the jsdom line.
- Storage only: node tests stub storage with `createMemoryStorage()`
(plugins keep a local copy).
- TanStack Query hooks with no DOM assertions: option factories are
exported and driven with `QueryObserver`/`MutationObserver` on a
`QueryClient`.
- Pure logic inside components and hooks is extracted into functions the
component still calls and table-tested in node; hooks that only need
React render through `renderHookStatically` (`renderToStaticMarkup`).
   - Partial files are split; DOM-needing cases stay in jsdom.
- 14 files deleted where every catch is also caught elsewhere, the test
covers story-only code, or it passes for an unrelated reason; a single
unique catch moves into the stronger owner's test.
- `sidebar.bench.test.tsx` leaves the default include (`bench` still
runs it). `plugin-scaffold-external.test.ts` declares the node
environment, since a template literal containing the jsdom pragma was
selecting jsdom. theme-preview declares the SDK test host's optional
peers (`better-sqlite3`, `cron-parser`, `hono`) now that its server test
uses the fake host, so its fork installs them.
- Kept in jsdom on purpose: `useThreadSecondaryPanelVisibility` (moving
it changed callback identities), `root-compose-selection`
(`atomWithStorage` only hydrates on mount) and plugin-api-tester's smoke
test (the plugin fork check runs `npm test` in every forkable plugin).
8. **Fix tests that passed for the wrong reason and trim junk.** About
50 tests now fail when their named guard is removed. Examples:
`MarketplacesSettingsSection` asserted no "Remove BB Official" button
against a fixture named "BB Community", so nothing guarded removing the
official marketplace. scheduled-send "stays closed in another composer"
passed because the second composer's empty draft closed the dialog
anyway. Others include clipboard "desktop clipboard first",
detail-page-recipes' code-fence split, the plugin install/update
"reports once" checks, ThreadDetailHeader's edit-time pane drag and
SidebarVisibilityControls' #4245 overlap. Three tests whose guard cannot
be observed at that boundary are deleted. About 110 junk tests are
trimmed.

Net vs main after the October 14 rebase: 572 files, +13.6k / −19.0k.

## How you verified

Local timings, one package at a time (`turbo run test --filter=<pkg>
--only --force -- --reporter=json`), 16-core macOS shared with other
threads (load 10–16):

| Package | Wall | Vitest `tests` sum |
| --- | ---: | ---: |
| @bb/server | 106.6s → 91.6s | 532.0s → 398.3s |
| @bb/app | 63.5s → 67.4s | 177.7s → 190.1s |
| @bb/db | 5.0s → 6.7s | 20.0s → 19.8s |
| @bb/host-daemon | 30.8s → 31.0s | 72.7s → 85.6s |
| @bb/cli | 13.4s → 9.0s | 40.4s → 35.4s |
| @bb/scripts | 18.6s → 18.2s | 31.0s → 31.8s |

Only the server change is outside noise. `migrate` calls per server run
went from 607 to 24, and migrate CPU from 58 s to about 2 s. The 51
converted server files went from 201 s to 109 s summed. Largest drops:
plugin-catalog-service 13.1 → 1.6 s, third-party-marketplaces 6.3 → 1.2
s.

Per-file jsdom cost (402 isolated files, medians): environment 1.66 s,
import 1.42 s, setup file 0.30 s, tests 0.44 s. `vmForks` was slower on
an 80-file sample (13.2–14.3 s vs 10.8–11.1 s) and failed 6 tests. The
Vite deps optimizer gave no gain and broke 2 `importOriginal` mocks.
Neither was adopted.

Checks: `pnpm exec turbo run lint typecheck test
--filter='...[origin/main]'` after rebasing onto current main: 246 of
247 tasks passed. The failure was `PluginSettings.test.tsx` "autosaves
the latest text value on blur" at load ~22. That test body is unchanged;
the file only swapped its local `deferred` for `createDeferredPromise`
in other tests. It has failed once in each full parallel run, and a
standalone `turbo run test --filter=@bb/app --only --force` rerun passed
(594 files, 5568 tests). The same test passed 8/8 alone and 9/9 under
parallel stress on the base commit.

**jsdom audit and cleanup (commits 7–8).** Audit method per file: read
against the test-audit skill, 2–4 realistic mutations of the code under
test, then which other test files fail on the same mutation; about 1,500
mutations over 496 files. For every moved file, each unique catch the
audit recorded was re-applied: the moved test fails with it and passes
without it. Every fix in commit 8 was proven the same way (fails with
the mutation, passes after revert).

Behavior parity: three independent reviews read every production diff
(82 files) against the old code. No user-visible change. Fixed from the
review: an attachment-failure check that had moved one React tick
earlier, two no-op state updates while a panel is closed or a folder
chain is empty, merged panel-opener callbacks (reverted, see above), and
test-only exports (moved into their own modules with production
importers, or reached through public hooks). A dead
`useUiPreferencesReady`/`isUiPreferencesReady` pair with no production
caller is deleted.

Known coverage losses: thin hook wiring that now only forwards to
extracted functions (thread-list held read status effect and reveal atom
setters, a tasks scheduler null-check, the mobile recents collapsed-id
filter, the timeline panel's background-agent count). One new React
Compiler warning (not error) in `plugins/tasks/shell/data.ts`, next to
five existing ones.

Timing, before (0da6f19) vs after, back to back, two rounds, load
15–19:

| Package | Wall | Vitest file-time sum | Files / tests |
| --- | ---: | ---: | --- |
| @bb/app | 71 / 73 s → 61 / 66 s | 202 / 204 s → 179 / 195 s | 605 /
5711 → 602 / 5634 |
| bb-plugin-tasks | 6 / 7 s → 5 / 8 s | 17 / 21 s → 15 / 21 s | 40 / 412
→ 37 / 409 |
| bb-plugin-thread-list | 4 / 5 s → 5 / 4 s | 11 / 13 s → 11 / 12 s | 37
/ 451 → 35 / 444 |

Final checks: `pnpm exec turbo run lint typecheck test
--filter='...[origin/main]'` passed every package except `@bb/app`,
which failed on a fixup the rebase had dropped; after restoring it,
`turbo run lint typecheck test --filter=@bb/app` passed (7/7).

`PluginSettings.test.tsx` "autosaves the latest text value on blur"
fails occasionally under heavy parallel load. Its test and component are
unchanged from main except the `deferred` helper swap in other tests of
the file. Interleaved stress runs: 0/18 failures on main, 0/18 on this
branch.

Windows shard timings were not measured locally; compare them on this
PR's CI run.

October 14 rebase: updated onto `origin/main` at `efb7d12f2f` (#5494).
Conflict resolutions preserve shared temp-directory cleanup retries,
mobile queue defaults, project-specific model catalog caching,
title-mention regressions, inline-vis preview helpers, and the Plugin
Guide code-fence surface. The new HTML-preview routing regression stays
in a separate jsdom file; Markdown image routing stays in Node. The new
status-cap tests use the shared repository fixture, and
`WorkspaceChangesList` retains main's server-provided total count and
omitted-file coverage.

Rebase verification: `pnpm exec turbo run lint typecheck test
--filter=@bb/app --filter=@bb/host-workspace
--filter=bb-plugin-inline-vis --filter=bb-plugin-plugin-api-docs` passed
lint/typechecks and the host-workspace (161 tests), inline-vis (50
tests), and Plugin Guide (72 tests) suites. The full app run passed
5,691 tests and exposed one HTML-preview static-render failure; after
moving that test to jsdom, both preview files passed (6 tests), and app
lint/typecheck passed. After including #5494, the workspace list/summary
tests passed (10 tests), the host-workspace suite and typecheck passed
again, and app typecheck passed. `git diff --check` passed.

> AGENT GENERATED

---------

Co-authored-by: qa <qa@x>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thousands of untracked files in a worktree make its threads laggy (1.5 MB status payload)

1 participant