#17409 · @BYK · opened Mar 13, 2026 at 6:44 PM UTC · last updated Mar 21, 2026 at 10:24 AM UTC
fix(opencode): limit concurrent bootstraps, async filesystem I/O, bounded dir walk
Score breakdown
Impact
Clarity
Urgency
Ease Of Review
Guidelines
Readiness
Size
Trust
Traction
Summary
This PR addresses severe server performance degradation when many projects load concurrently by limiting bootstrap concurrency, converting sync filesystem calls to async, and bounding directory walk depth. It significantly improves server responsiveness and prevents health check timeouts for users with many sidebar projects. This is a critical performance fix.
Description
Issue for this PR
Closes #17407
Type of change
- [x] Bug fix
- [ ] New feature
- [x] Refactor / code improvement
- [ ] Documentation
What does this PR do?
Three changes to reduce server event loop contention when many projects load concurrently (e.g. opening ~/Code with 17 sidebar projects):
1. Instance bootstrap concurrency limit (p-limit, N=3): Each Instance bootstrap spawns 5-7 subprocesses (git, ripgrep, parcel/watcher). With 17 concurrent bootstraps that's ~100 subprocesses overwhelming a 4-core SATA SSD system. The p-limit semaphore gates new directory bootstraps while allowing cache-hit requests through instantly. Peak subprocesses: ~100 → ~18.
2. Async Filesystem.exists and isDir:
Filesystem.exists() wrapped existsSync() in an async function — it looked async but blocked the event loop on every call. Replaced with fs.promises.access(). Same for isDir (statSync → fs.promises.stat). This lets the event loop serve health checks and API responses while directory walk-ups are in progress. Added Filesystem.existsSync() for callers that genuinely need sync behavior.
3. Bounded Filesystem.up/findUp walk depth (maxDepth=10):
Previously walked all the way to / with no limit. Added maxDepth parameter (default 10) as a safety net against degenerate deep paths.
How did you verify your code works?
- Tested with 17 sidebar projects — server stays responsive during bootstrap
- Health checks no longer timeout during concurrent bootstraps
- All existing tests pass
Screenshots / recordings
N/A — backend changes only.
Checklist
- [x] I have tested my changes locally
- [x] I have not included unrelated changes in this PR
Linked Issues
#17407 Server overwhelmed by concurrent project bootstraps when many sidebar projects exist
View issueComments
No comments.
Changed Files
bun.lock
+4−1packages/app/src/components/dialog-connect-provider.tsx
+1−1packages/app/src/components/dialog-custom-provider.tsx
+1−1packages/opencode/package.json
+1−0packages/opencode/src/cli/cmd/tui/component/dialog-provider.tsx
+1−1packages/opencode/src/project/instance.ts
+6−1packages/opencode/src/util/filesystem.ts
+19−14