Skip to content

fix(file-tree): bound recursive project traversal - #1083

Open
dongwook-chan wants to merge 2 commits into
siteboon:mainfrom
dongwook-chan:fix/bound-file-tree-traversal
Open

fix(file-tree): bound recursive project traversal#1083
dongwook-chan wants to merge 2 commits into
siteboon:mainfrom
dongwook-chan:fix/bound-file-tree-traversal

Conversation

@dongwook-chan

@dongwook-chan dongwook-chan commented Aug 1, 2026

Copy link
Copy Markdown

Fixes #1082.

Follow-up to #1074, which prevents recursion into forbidden system paths but intentionally leaves ordinary large project roots for a separate change.

Problem

buildFileTree walks project roots to depth 10 with no total node budget. Its recursive Promise.all structure creates and retains the pending work and completed subtrees until the root resolves. A broad but valid root such as a populated home directory can therefore consume several gigabytes of heap, starve other API requests, and eventually crash-loop the server.

Fix

  • Cap each complete file-tree build at 10,000 visible entries.
  • Share one remaining-entry budget across every recursive branch.
  • Walk branches sequentially so traversal does not materialize every pending subtree up front.
  • Fail oversized trees with a controlled HTTP 413 FILE_TREE_TOO_LARGE error that tells users to choose a narrower root or add ignore rules.
  • Cover both an oversized single directory and a limit exceeded cumulatively across nested directories.

The limit is checked after ignore filtering, so generated directories and .gitignore exclusions do not consume the budget.

Verification

  • npx tsx --tsconfig server/tsconfig.json --test server/modules/file-tree/tests/file-tree.service.test.ts server/modules/file-tree/tests/file-tree.routes.test.ts — 11 passed
  • npm run build — passed
  • npm run typecheck — passed
  • npm run lint — passed with 0 errors; existing repository warnings remain

Summary by CodeRabbit

  • Bug Fixes
    • Added protection against excessively large file trees.
    • File-tree requests exceeding 10,000 entries now return a clear error with HTTP status 413.
    • Improved traversal handling for nested directories to prevent excessive resource usage.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9008ce68-d0a6-4928-b031-933174367ea8

📥 Commits

Reviewing files that changed from the base of the PR and between c2408f0 and 8851c1b.

📒 Files selected for processing (2)
  • server/modules/file-tree/file-tree.service.ts
  • server/modules/file-tree/tests/file-tree.service.test.ts

📝 Walkthrough

Walkthrough

File-tree traversal now enforces a shared 10,000-entry limit, processes recursive branches sequentially, and raises FILE_TREE_TOO_LARGE with HTTP 413 when the limit is exceeded. Tests cover flat and nested oversized trees.

Changes

File-tree entry budget

Layer / File(s) Summary
Shared traversal budget and sequential processing
server/modules/file-tree/file-tree.service.ts
buildFileTree shares a 10,000-entry budget across recursion, processes entries sequentially, and throws FILE_TREE_TOO_LARGE with status 413 when exceeded.
Oversized-tree validation
server/modules/file-tree/tests/file-tree.service.test.ts
Tests cover rejection of directories with 10,001 entries and nested trees with 10,002 combined entries.

Possibly related PRs

  • siteboon/claudecodeui#1074: Both changes modify buildFileTree traversal. This PR adds an entry limit, while the related PR adds forbidden-path pruning.

Suggested reviewers: blackmammoth

Poem

I’m a rabbit counting files in a row,
Ten thousand hops is all I know.
Beyond that gate, the branches pause,
A tidy error guards the cause.
Nested paths now share the score.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the bounded recursive file-tree traversal change.
Linked Issues check ✅ Passed The changes satisfy #1082 by enforcing a global entry budget, sequentializing traversal, returning HTTP 413, and adding regression tests.
Out of Scope Changes check ✅ Passed The changes are limited to file-tree traversal safeguards and focused regression tests required by #1082.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Unbounded file-tree traversal can exhaust the server heap for broad project roots

2 participants