Repository navigation
Cap the prompt banner changed-files list and lazy-mount collapsed bodies - #1783
Conversation
A workspace with tens of thousands of untracked files put every path into the prompt banner's WorkspaceChangesList. One trace showed 15,701 rows in a 128px scroll box: ~65k elements, ~97k layout objects, and 320-580 ms per layout, so a click on a file row blocked the main thread for 1.4 s. The list was mounted even while the section was collapsed. - WorkspaceChangesList scroll mode now renders at most 200 rows and adds a "N more files not shown" row for the remainder. - AnimatedBody in ThreadPromptContextBanner mounts its children on the first expand and retains them afterwards, so collapsed sections cost no layout. Co-Authored-By: Claude <[email protected]>
|
🚨 SLOP COP 🚨 · I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior. |
| ); | ||
| } | ||
|
|
||
| const visibleFiles = |
There was a problem hiding this comment.
🚨 slopcop/review — This default cap also changes the Git action confirmation dialog.
ThreadGitActionDialog omits limit, so it now lists only 200 files. Its commit action still runs git add -A.
A user cannot inspect every file before the action. Please make this cap explicit and use it only in the prompt banner.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain English summary: This change limits a large changed-file list to 200 rows. It builds a collapsed section only after a user opens it.
Finding
Medium: The new default also caps the Git action confirmation dialog. That dialog still commits all workspace files with git add -A.
Users see the hidden-file count. However, they cannot inspect file names after row 200 before the action.
Please make the cap explicit. Pass it only from the prompt banner. Add a dialog test for a file after row 200.
Review notes
- Security: I found no new script injection, path traversal, or data-boundary defect.
- Quality: Several prompt cards repeat the disclosure pattern. A shared helper remains optional because
ExpandablePanelremoves its body after close. - Performance: The browser test used 251 files. The initial collapsed banner had no file list.
- Performance: Expansion showed 200 buttons and a 51-file remainder. The file click worked. The development action took 114 ms.
- Accessibility: Hidden buttons remain in the Tab order after collapse. The base commit already had this defect, so this change did not introduce it.
- Validation: The 20 changed tests passed. The 26 prompt-area tests passed. The app type check and all GitHub checks passed.
The pull request merged before this review finished. This review records the follow-up issue.
## What was wrong Two of the three surfaces in #1615 still mounted every row of a large array into a small scroll box. A scroll box clips painting, not DOM, so WebKit still styled, laid out and kept every row in memory. `CsvFilePreview` mapped its whole 500x100 parse window into `<tr><td><span>` (50,000 `td`, ~101k elements in the table, a 2-8 s main-thread block and +33 MB heap, per the [report](https://get-bb.github.io/reports/issues/1615.html)). `RemotePathBrowser` mapped every `readdir` entry into an `<li>` inside its `h-56` box (5,000 rows / 20,000 elements for a 5,000-file folder) because the daemon listing has no cap. The third surface, the prompt-banner `WorkspaceChangesList`, was already fixed on main by #1783 (200-row cap and lazy mount of collapsed bodies). ## What changed - `apps/app/src/components/secondary-panel/FilePreview.tsx`: the CSV table mounts only the body rows near the viewport with `useVirtualizer` (the pattern `DiffFilesPanel` already uses) on the existing scroll container. Spacer `<tr>`s above and below the mounted window keep the table's natural height, so the scrollbar, the sticky header row and the sticky row-number gutter behave exactly as before. Row height is a fixed 29px estimate (`leading-5` + `py-1` + border) corrected by `measureElement`. Columns are not virtualized; a mounted row still has up to 101 cells, so the bound is roughly 35-45 rows x 101 cells instead of 500 x 101. - `apps/app/src/components/dialogs/RemotePathBrowser.tsx`: the entry list mounts only the rows near the viewport, positioned absolutely inside a `ul` sized to the virtual total. The "new folder" form stays inside the same scroll box above the list; the 10-row overscan covers its height so no `scrollMargin` measurement is needed (documented in the code). - No wire, CLI or protocol change. The daemon still returns the full directory listing and full CSV file; this PR bounds the DOM, which is what the issue and report measured. Capping the listing at the daemon (the report's optional step) would change the `host.browse_directory` result shape and need a `HOST_DAEMON_PROTOCOL_VERSION` bump, so it is left out of this focused change. ## How you verified New tests (jsdom, with `offsetHeight` mocked so the virtualizer has a viewport): - `FilePreview.test.tsx` > "mounts only the CSV rows near the viewport, not the whole 500x100 window": a 600x120 CSV mounts fewer than 6,000 `td` and 14-59 rows, the first row is visible and the last is not; scrolling the box to the bottom mounts `r499c0`, unmounts `r0c0`, and the truncation note still reads "Showing the first 500 rows and 100 columns." - `RemotePathBrowser.createFolder.test.tsx` > "mounts only the entries near the viewport for a huge directory": a 5,000-entry listing mounts 8-59 `li`; scrolling to the bottom mounts `file_04999` and unmounts `file_00000`. Fail before (source files checked out from `origin/main`, tests from this branch): ``` × mounts only the entries near the viewport for a huge directory AssertionError: expected 5000 to be less than 60 × mounts only the CSV rows near the viewport, not the whole 500x100 window AssertionError: expected 50000 to be less than 6000 ``` Pass after, from the committed tree (`git status --porcelain` empty): ``` pnpm exec turbo run typecheck --filter=@bb/app -> Tasks: 3 successful, 3 total pnpm exec turbo run test --filter=@bb/app --force -> Tasks: 4 successful, 4 total Test Files 409 passed (409), Tests 3158 passed | 3 skipped (3161) ``` Manual check on my own dev instance (headless Chromium 1400x900, fixture from the report: 600x120 `data/big.csv` plus 5,000 untracked files): - CSV preview (before, from the report at the same viewport: `td: 50000`, `tableNodes: 101306`, 3.2 s to table-in-DOM): after, `td: 3401`, `tableNodes: 7176`, 34 body rows, 597 ms from Enter to table-in-DOM including the file fetch. Scroll size unchanged at 28,848x14,529 px. Scrolled to the bottom: rows 467-499 mounted, last cell `r499c0`, sticky header still at the top of the box. Scrolled to (6000, 5000): rows 198-240 mounted, sticky `#` gutter still at the left edge. - Folder browser on the 5,000-file directory (before: 5,000 `li`, 20,001 nodes in the box): after, 19 `li`, 77 nodes in the box, 108 ms; scrolled to the bottom shows `file_04982`-`file_04999`. Fixes #1615 > AGENT GENERATED: by Claude Opus 5 ## Independent verification Checked out `bb/fix-1615-bounded-lists` at `bf3a653a2` (one commit over `origin/main`, which is an ancestor; GitHub reports MERGEABLE/CLEAN) in a separate worktree with its own dev instance. Commands: ``` git fetch origin main && git fetch origin bb/fix-1615-bounded-lists && git checkout -b verify-1615-r1 FETCH_HEAD git checkout origin/main -- apps/app/src/components/secondary-panel/FilePreview.tsx apps/app/src/components/dialogs/RemotePathBrowser.tsx (cd apps/app && pnpm exec vitest run --config vitest.config.ts src/components/secondary-panel/FilePreview.test.tsx src/components/dialogs/RemotePathBrowser.createFolder.test.tsx) git checkout HEAD -- <same two files> # then the same vitest command again pnpm exec turbo run typecheck --filter=@bb/app pnpm exec turbo run test --filter=@bb/app --force ``` Fail before (PR tests against `origin/main` sources): ``` × mounts only the entries near the viewport for a huge directory AssertionError: expected 5000 to be less than 60 × mounts only the CSV rows near the viewport, not the whole 500x100 window AssertionError: expected 50000 to be less than 6000 Test Files 2 failed (2) Tests 2 failed | 26 passed (28) ``` Pass after (PR sources restored, `git status --porcelain` empty): `Test Files 2 passed (2), Tests 28 passed (28)`. `turbo typecheck --filter=@bb/app`: `Tasks: 3 successful, 3 total`. `turbo test --filter=@bb/app --force`: `Tasks: 4 successful, 4 total`, `Test Files 409 passed (409)`. Repro on the fixed branch (own dev instance, headless Chromium 1400x900 via doobie, report fixture: 600x120 `data/big.csv` committed plus 5,000 untracked files, one "Reply only with ok." codex turn to provision the workspace): - CSV preview, after pressing Enter in the secondary-panel file search: `td: 3401`, `th: 135`, `tableNodes: 7176`, 34 body rows (indexes 0-33), 995 ms Enter-to-table; scroll box 505x742, scroll size unchanged at 28,848x14,529, note "Showing the first 500 rows and 100 columns." Scrolled to the bottom: rows 467-499 mounted, last cell `r499c0`, sticky header still at the top of the box. Scrolled to (6000, 5000): rows 164-206 mounted, sticky row gutter still at the left edge. The report measured `td: 50000`, `tableNodes: 101306`, 3.2 s on main. No longer reproduces. - Add-project folder browser on the 5,000-file directory: 19 `li`, 77 nodes in the 224 px box (report on main: 5,000 `li`, 20,001 nodes), `ul` height 139,981 px. Scrolled to the bottom: 18 `li` mounted, `file_04991`-`file_04999` visible. Scrolled to the middle: `file_02500`-`file_02508` visible with the viewport fully covered. With the "New folder" form open above the list, top and bottom still show `file_00000` and `file_04999` with no gap. No longer reproduces. - Third surface in the issue (prompt-banner `WorkspaceChangesList`) confirmed already bounded on `origin/main`: `WORKSPACE_CHANGES_LIST_MAX_ROWS = 200` and `AnimatedBody` mounts children only after the first expand. The banner on my instance exposes a single "Changed files: Untracked, 5000 files" button while collapsed. CI at verification time: all required checks pass (app-1/2/3, server, packages, integration tests; Package Smoke on ubuntu and macos-15; version check). iOS simulator flows and Node compatibility smoke skipped by path filter. Residual risks (none blocking): - `RemotePathBrowser` does not pass `scrollMargin`, so the virtualizer treats the list as starting at scroll offset 0 while the box's `py-1` padding and the optional "New folder" form (28 px + 4 px margin, plus an error line) sit above it. The 10-row (280 px) overscan absorbs that offset today; a taller element above the list would need `scrollMargin`. - CSV columns are not virtualized: each mounted row still carries up to 101 cells, so a 100-column file mounts ~3.4k `td` instead of 50k. Text selection for "Add to chat" spans only mounted rows, the same limitation the virtualized code view already has. - The daemon still returns unbounded directory listings and the status route still returns every changed file on the wire; capping those needs a protocol bump and is out of scope here. > AGENT GENERATED: by Claude Opus 5 Co-authored-by: Claude <[email protected]>
## 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`, #1496/#1607). Status is refetched automatically whenever the worktree changes, so it stays smaller and matches the app's existing 200-row display limit from #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](https://claude.com/claude-code) > AGENT GENERATED --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
WorkspaceChangesListscroll mode (the prompt banner) now renders at most 200 rows and adds aN more files not shownrow for the remainder.AnimatedBodyinThreadPromptContextBannermounts its children on the first expand and retains them afterwards, so a collapsed section no longer carries its DOM.WorkspaceChangesList.test.tsxand a banner test for the lazy mount.Why
Fixes #1777.
The DevTools trace attached to #1777 (bb 0.38.0) showed one
UL class='space-y-1 overflow-auto max-h-32 ...'with 15,701 children: the prompt banner's changed-files list for a workspace with a huge untracked tree. That single list produced ~65k elements and ~97k layout objects, so every full layout cost 320–580 ms and a click on a file row blocked the main thread for 1.44 s (React re-created all rows, then two layout effects forced synchronous layout). The list was in the DOM even while the git section was collapsed.#1496 and #1607 bounded the daemon side (process count, diff content, 500-file diff ceiling) but kept every path in workspace status. This change bounds the client render. The metadata panel already caps its copy at
limit={5}.Follow-up (not in this PR): bound
workingTree.filesat the server with a truncation signal so no surface can render an unbounded list.Verification
WorkspaceChangesList.test.tsxandThreadPromptContextBanner.test.tsx: 20 passedpnpm exec turbo run typecheck --filter=@bb/apppassed; ESLint and Prettier clean2,801 more files not shown(1,392 elements); body is retained andaria-hiddenafter collapse.