fix(dsn): limit concurrent stat() calls in project root detection (CLI-19A)#768
fix(dsn): limit concurrent stat() calls in project root detection (CLI-19A)#768
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛Init
Other
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
…I-19A) processDirectoryLevel fires up to 68 parallel stat() calls per directory level through anyExists() (VCS: 7, CI: 12, language: 30, build: 19), all sharing no concurrency limit. On macOS, this exhausts kqueue file descriptor limits for deeply nested projects, surfacing as EINVAL. Add a module-scoped pLimit(32) instance (statLimit) shared across every anyExists() call so total concurrent stat() calls are capped at 32 regardless of how many marker groups run in parallel. The shared limiter bounds total FD pressure — not per-group pressure — matching the pattern in response-cache.ts. 32 keeps VCS (7) and CI (12) marker checks fully parallel while throttling only the larger LANGUAGE_MARKERS (30) and BUILD_SYSTEM_MARKERS (19) groups. Leaves comfortable headroom under macOS's ~256 kqueue FD ceiling.
3b04a59 to
c408dc2
Compare
|
Codecov Results 📊✅ 138 passed | Total: 138 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1652 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 95.51% 95.50% -0.01%
==========================================
Files 254 254 —
Lines 36676 36678 +2
Branches 0 0 —
==========================================
+ Hits 35027 35026 -1
- Misses 1649 1652 +3
- Partials 0 0 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c408dc2. Configure here.

Summary
processDirectoryLevelfires up to 68 parallelstat()calls per directory level throughanyExists()(VCS: 7, CI: 12, language: 30, build: 19) with no concurrency limitEINVAL(CLI-19A)pLimit(32)instance (statLimit) shared across everyanyExists()callApproach
The shared limiter bounds total FD pressure across all marker groups, not per-group pressure — so 4 parallel
anyExists()groups still share a single 32-slot budget. Matches the pattern inresponse-cache.ts(const cacheIO = pLimit(CACHE_IO_CONCURRENCY)).32 keeps VCS (7) and CI (12) marker checks fully parallel while throttling only the larger
LANGUAGE_MARKERS(30) andBUILD_SYSTEM_MARKERS(19) groups, staying well under macOS's ~256 kqueue FD ceiling.Changes
src/lib/dsn/project-root.ts— addSTAT_CONCURRENCY = 32exported constant + sharedstatLimit, wrappathExistsinanyExists()with ittest/lib/dsn/project-root.test.ts— add concurrency cap test (mocksstatto track peak concurrent calls, asserts ≤STAT_CONCURRENCY) and early-exit preservation test