Skip to content

Bound untracked status and diff work - #1496

Merged
ymichael merged 2 commits into
mainfrom
fix/bound-untracked-status-diff
Aug 13, 2026
Merged

ymichael merged 2 commits into
mainfrom
fix/bound-untracked-status-diff

Conversation

@ymichael

@ymichael ymichael commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • stop automatic workspace status from diffing every untracked file; untracked per-file counts are now unknown and aggregate totals explicitly report lineStatsComplete: false
  • batch explicit untracked diff/stat/patch work through a disposable alternate Git index, keeping Git child-process count independent of untracked file count without mutating the real index
  • enforce one server-owned 500-file ceiling for diff enumeration and legacy untracked content; tracked and untracked listings stop at the ceiling-plus-one sentinel before content stats run
  • support sparse checkouts with git add --sparse and tolerate files disappearing during alternate-index setup with bounded refresh/retry behavior
  • propagate the completeness contract through the app, CLI, daemon protocol, SDK declarations, and generated templates; bump the host daemon protocol to 119

Why

Workspace status runs on the watcher cadence. Its previous git diff --no-index --numstat call per untracked file turned repositories containing large ignored-store mistakes into thousands of child processes and event-loop stalls. Status only needs to identify those files, so it no longer reads their contents. Explicit user-requested diffs still produce exact stats and patches, but do so with bounded enumeration, bounded output buffers, and a fixed-size Git process graph.

The old 5,000-file value was inherited from the original virtualized diff implementation without a documented resource benchmark. The unified 500-file ceiling keeps the daemon's conservative numstat budget near 8 MiB and declines larger diffs before stats/content work.

Verification

  • pnpm exec turbo run typecheck (58/58 targets)
  • host-workspace tests (204/204)
  • server tests (1,471/1,471)
  • affected app, CLI, host-daemon, and host-daemon-contract suites
  • regression coverage for incomplete status totals, bounded tracked/untracked enumeration, full-diff truncation, sparse-cone files, disappearing-file races, literal paths, and preserving the real Git index

Fixes #1489

AGENT GENERATED: by GPT-5.6

@bb-slop-cop

bb-slop-cop Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am the Slop Cop. I am now reviewing this pull request for security, code quality, performance, duplication, architecture, and end-to-end behavior.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

ELI5: This PR replaces many Git processes with one shared temporary index. It also stops showing line totals when untracked file contents are not included.

I found three regressions:

  • Sparse-checkout repositories fail when an untracked file sits outside the sparse cone.
  • The 5,000-file limit applies after Git and Node collect every path. Large path lists can fail before the limit helps.
  • One untracked file that disappears can make the complete batch fail.

I left inline comments with the reproduction details and direct corrections.

The security review found no command injection, path traversal, or real-index mutation. I found no harmful duplication. A future refactor could share target-range policy across the stat, patch, and full-diff paths.

Validation passed for 198 workspace tests, 49 daemon-contract tests, 418 CLI tests, and 548 daemon tests. The affected package type check passed. All GitHub checks passed. The dev server started successfully. The UI route needed a provisioned provider thread, so direct Git-path tests covered this behavior.

I posted this as a comment review. I did not approve the pull request or use the GitHub request-changes option.

@ymichael
ymichael force-pushed the fix/bound-untracked-status-diff branch from 5c62f45 to 3905f4c Compare August 13, 2026 16:13
@ymichael
ymichael merged commit 2292db1 into main Aug 13, 2026
10 checks passed
@ymichael
ymichael deleted the fix/bound-untracked-status-diff branch August 13, 2026 16:24
budah1987 added a commit to budah1987/bb that referenced this pull request Aug 15, 2026
Brings BBamir up to date with upstream through f1dbedd.

Conflict resolutions (BBamir-preserving unless noted):
- host-workspace: re-merged workspace.ts hunk by hunk so BBamir's
  path-scoped diffs/commits, publish/update-from-target, and merge-base
  caching survive alongside upstream's bounded untracked line stats and
  abort-signal cancellation (get-bb#1496, get-bb#1607).
- app UI: skipped upstream get-bb#1559 (unified new-thread/secondary-panel
  layout) for the five views BBamir rewrote, and re-merged those files
  against pre-get-bb#1559 upstream so every other upstream fix still lands.
- ui/sidebar: kept BBamir's Command Center drawer (the mobile swipe
  subsystem stays deleted) and ported upstream's windowed-list content
  ref plus the get-bb#1261 offcanvas visibility fix.
- thread header: kept BBamir's workflow actions and project/branch
  context, added upstream's inline rename (get-bb#1453) and split-dimming
  setting (get-bb#1605).
- archive toast: kept BBamir's toast shape, adopted upstream's
  grace-period-aligned undo duration (get-bb#1016).
- composer attachments: took upstream's shared useDraftAttachmentUploads
  and folded BBamir's format validation into it, so the thread-detail
  composer gains the check too.

Also migrates the six BBamir-only plugins from @bb/plugin-sdk to
@get-bb/plugin-sdk and regenerates the bundled SDK types, templates,
and lockfile.
SawyerHood added a commit that referenced this pull request Aug 18, 2026
…ies (#1783)

## Summary

- `WorkspaceChangesList` scroll mode (the prompt banner) 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 a collapsed section no
longer carries its DOM.
- Adds `WorkspaceChangesList.test.tsx` and 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.files` at the server with
a truncation signal so no surface can render an unbounded list.

## Verification

- `WorkspaceChangesList.test.tsx` and
`ThreadPromptContextBanner.test.tsx`: 20 passed
- `pnpm exec turbo run typecheck --filter=@bb/app` passed; ESLint and
Prettier clean
- End-to-end in the dev app with a repo of 3,000 untracked files:
collapsed page has no list mounted (578 elements); expanded shows 200
rows plus `2,801 more files not shown` (1,392 elements); body is
retained and `aria-hidden` after collapse.

> AGENT GENERATED: by Claude Opus 5

Co-authored-by: Claude <[email protected]>
ymichael added a commit that referenced this pull request Oct 14, 2026
## 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]>
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.

Git status spawns one process per untracked file

1 participant