Repository navigation
fix(daemon): bound cwd validation per UNC route - #14967
Conversation
666b29a to
af9a353
Compare
|
Pushed two follow-ups from a review pass: Layering. Eviction interaction. The dedupe eviction added in #14966 re-probes a path whose previous probe is still in flight — deliberately, so a recovered mount is noticed instead of being pinned to a promise that can never settle. On a still-dead path each eviction wave would otherwise add another overlapping probe. The lane bounds that, which makes it a same-path argument for this change, not just the distinct-path one in the ticket. Added a test asserting peak concurrency stays at 2 across four eviction waves, and a comment recording that the eviction is only safe because the lane caps the overlap. Daemon + providers + shared: 7089 tests pass. Typecheck and lint clean. |
af9a353 to
ccd1a54
Compare
Async cwd validation dedupes by exact path but had no concurrency bound, and a dead UNC share answers `stat` in ~21s while holding one of libuv's 4 default fs threads. Four distinct paths on one unreachable server therefore starved every other async fs read in the daemon — including the cold-restore history replay running alongside them — which moves the head-of-line stall #14848 removed from the event loop into the thread pool. Adds a per-route lane of 2, reusing PrioritySemaphore and matching the per-distro lane in rate-limits/auth-filesystem-operation.ts. Keyed by the host that has to answer (WSL distro, or the `\\server` prefix) so many dead subdirectories of one share fold into one lane. Local-disk paths bypass the lane entirely: a global cap would queue a healthy local spawn behind a dead share. Moves PrioritySemaphore to src/shared. It has no imports, and reaching into src/main/daemon from src/main/providers inverted the dependency direction that already runs daemon -> providers. Note this bounds pool occupancy, which cancellation cannot: an aborted `stat` still holds its libuv thread until the OS returns. STA-4543
ccd1a54 to
a00e81c
Compare
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 4 remain after this review. 📝 WalkthroughWalkthroughAdds the shared Merge Risk: 🟡 Moderate · up to The new per-route validation cap does not apply to slash-form WSL UNC paths, so stalled validations can still exhaust filesystem workers and delay unrelated daemon work; this should be fixed before merging. The semaphore also needs basic input validation. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/providers/working-directory-validation.ts (1)
13-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense the implementation rationale comment.
Keep the non-obvious reason in one concise line. The added five-line comment is longer than necessary.
As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 53254eb2-dfb5-435b-8b65-4844d9f33ab6
📒 Files selected for processing (5)
src/main/daemon/history-reader.tssrc/main/providers/working-directory-validation.test.tssrc/main/providers/working-directory-validation.tssrc/shared/priority-semaphore.test.tssrc/shared/priority-semaphore.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 4 remain after this review.
| function uncRouteKey(cwd: string): string | null { | ||
| if (!cwd.startsWith('\\\\')) { | ||
| return null | ||
| } | ||
| const wslInfo = parseWslUncPath(cwd) | ||
| if (wslInfo) { | ||
| return `wsl:${wslInfo.distro.trim().toLowerCase()}` | ||
| } | ||
| const server = cwd.slice(2).split(/[\\/]/, 1)[0] | ||
| return `unc:${server.toLowerCase()}` |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Recognize slash-form WSL UNC paths before the backslash guard.
parseWslUncPath accepts //wsl.localhost/..., but the startsWith('\\\\') guard returns null first. Those paths bypass the lane, so distinct stalled probes can again consume all filesystem worker threads.
Normalize the prefix check after handling the WSL parser result.
Proposed fix
function uncRouteKey(cwd: string): string | null {
- if (!cwd.startsWith('\\\\')) {
- return null
- }
const wslInfo = parseWslUncPath(cwd)
if (wslInfo) {
return `wsl:${wslInfo.distro.trim().toLowerCase()}`
}
- const server = cwd.slice(2).split(/[\\/]/, 1)[0]
- return `unc:${server.toLowerCase()}`
+ const normalizedCwd = cwd.replace(/\\/g, '/')
+ if (!normalizedCwd.startsWith('//')) {
+ return null
+ }
+ const server = normalizedCwd.slice(2).split('/', 1)[0]
+ return server ? `unc:${server.toLowerCase()}` : null
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function uncRouteKey(cwd: string): string | null { | |
| if (!cwd.startsWith('\\\\')) { | |
| return null | |
| } | |
| const wslInfo = parseWslUncPath(cwd) | |
| if (wslInfo) { | |
| return `wsl:${wslInfo.distro.trim().toLowerCase()}` | |
| } | |
| const server = cwd.slice(2).split(/[\\/]/, 1)[0] | |
| return `unc:${server.toLowerCase()}` | |
| function uncRouteKey(cwd: string): string | null { | |
| const wslInfo = parseWslUncPath(cwd) | |
| if (wslInfo) { | |
| return `wsl:${wslInfo.distro.trim().toLowerCase()}` | |
| } | |
| const normalizedCwd = cwd.replace(/\\/g, '/') | |
| if (!normalizedCwd.startsWith('//')) { | |
| return null | |
| } | |
| const server = normalizedCwd.slice(2).split('/', 1)[0] | |
| return server ? `unc:${server.toLowerCase()}` : null | |
| } |
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/providers/working-directory-validation.ts (1)
13-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense the implementation rationale comment.
Keep the non-obvious reason in one concise line. The added five-line comment is longer than necessary.
As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 53254eb2-dfb5-435b-8b65-4844d9f33ab6
📒 Files selected for processing (5)
src/main/daemon/history-reader.tssrc/main/providers/working-directory-validation.test.tssrc/main/providers/working-directory-validation.tssrc/shared/priority-semaphore.test.tssrc/shared/priority-semaphore.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 4 remain after this review.
🛑 Comments failed to post (1)
src/shared/priority-semaphore.ts (1)
10-12: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reject invalid concurrency values.
A zero, negative, fractional, or non-finite value makes permit behavior invalid. Reject values that are not positive safe integers in the constructor.
Proposed fix
constructor(concurrency: number) { + if (!Number.isSafeInteger(concurrency) || concurrency < 1) { + throw new RangeError('concurrency must be a positive safe integer') + } this.available = concurrency }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.constructor(concurrency: number) { if (!Number.isSafeInteger(concurrency) || concurrency < 1) { throw new RangeError('concurrency must be a positive safe integer') } this.available = concurrency }
Async cwd validation dedupes by exact path but had no concurrency bound, and a dead UNC share answers `stat` in ~21s while holding one of libuv's 4 default fs threads. Four distinct paths on one unreachable server therefore starved every other async fs read in the daemon — including the cold-restore history replay running alongside them — which moves the head-of-line stall #14848 removed from the event loop into the thread pool. Adds a per-route lane of 2, reusing PrioritySemaphore and matching the per-distro lane in rate-limits/auth-filesystem-operation.ts. Keyed by the host that has to answer (WSL distro, or the `\\server` prefix) so many dead subdirectories of one share fold into one lane. Local-disk paths bypass the lane entirely: a global cap would queue a healthy local spawn behind a dead share. Moves PrioritySemaphore to src/shared. It has no imports, and reaching into src/main/daemon from src/main/providers inverted the dependency direction that already runs daemon -> providers. Note this bounds pool occupancy, which cancellation cannot: an aborted `stat` still holds its libuv thread until the OS returns. STA-4543
Async cwd validation dedupes by exact path but had no concurrency bound, and a dead UNC share answers `stat` in ~21s while holding one of libuv's 4 default fs threads. Four distinct paths on one unreachable server therefore starved every other async fs read in the daemon — including the cold-restore history replay running alongside them — which moves the head-of-line stall stablyai#14848 removed from the event loop into the thread pool. Adds a per-route lane of 2, reusing PrioritySemaphore and matching the per-distro lane in rate-limits/auth-filesystem-operation.ts. Keyed by the host that has to answer (WSL distro, or the `\\server` prefix) so many dead subdirectories of one share fold into one lane. Local-disk paths bypass the lane entirely: a global cap would queue a healthy local spawn behind a dead share. Moves PrioritySemaphore to src/shared. It has no imports, and reaching into src/main/daemon from src/main/providers inverted the dependency direction that already runs daemon -> providers. Note this bounds pool occupancy, which cancellation cannot: an aborted `stat` still holds its libuv thread until the OS returns. STA-4543
Follow-up hardening on #14848 (merged, not reverted).
What is actually wrong
Async cwd validation dedupes by exact path with no concurrency bound. A dead UNC share answers
statin ~21s (per #14848's own Windows 11 measurement) while holding one of libuv's 4 default fs threads (UV_THREADPOOL_SIZEis unset repo-wide). Four distinct paths on one unreachable server therefore starve every other async fs read in the daemon — includinghistory-reader.ts:251, the cold-restore replay running alongside them.That relocates the head-of-line stall #14848 removed from the event loop into the thread pool.
Fix
A per-route lane of 2, reusing the existing
PrioritySemaphoreand mirroring the per-distro lane inrate-limits/auth-filesystem-operation.ts("a few disconnected distros must not occupy libuv's entire filesystem pool").Keyed by the host that has to answer — WSL distro, or the
\\serverprefix — so many dead subdirectories of one share fold into one lane, which is what actually folds the byte-exact dedupe miss.Local-disk paths bypass the lane entirely: a global cap (the ticket's "bound by host" wording) would queue a healthy local spawn behind a dead share.
Scoping notes
statstill holds its libuv thread until the OS returns. Complementary to fix(daemon): bound cwd validation and attach-only requests on a dead share #14966, not redundant with it.Testing
New tests for the cap, lane isolation per server, and local paths bypassing a stalled queue. Daemon + providers + ipc: 5271 passed. Typecheck and lint clean.
STA-4543