Repository navigation
terminal-suggest: avoid locking PATH directories on Windows (#349080) - #349095
Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
Conversation
…t#349080) On Windows, watchPathDirectories opened persistent filesystem watchers via CreateFileW across every directory on PATH. Because Windows NTFS prohibits directory renames and unlinks while an open handle exists anywhere in the subtree, external installers and updaters (e.g. DeepSeek Harness, Git for Windows, Docker Desktop) failed with ERROR_ACCESS_DENIED (5) or EBUSY when attempting to rename the application root. Fix by: 1. Skipping persistent createFileSystemWatcher handles on Windows in watchPathDirectories. 2. Validating directory mtimes on demand in PathExecutableCache on Windows with a 2-second rate-limit, picking up added, modified, or replaced executables without keeping long-lived directory handles. 3. Automatically invalidating removed or replaced PATH directories without holding handles or pinning abandoned directory objects. Fixes microsoft#349080
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
PATH cache invalidation can indefinitely omit valid commands or suggest broken symlinks because it misses cross-directory dependencies, changes during scans, and directory replacements with unchanged timestamps.
6 open issues
Detect PATH directory replacement with unchanged mtime · New Rebuild dependent caches when PATH directories change · New Capture directory metadata before enumeration · New Validate due PATH entries concurrently and reuse negative caches · New Add Windows cache invalidation regression tests · New Test that Windows skips PATH watchers · New
Review effort: Max
| } else { | ||
| cachedEntry.lastCheckedMs = now; | ||
| const stat = await fs.stat(pathDir).catch(() => undefined); | ||
| if (stat?.isDirectory() && stat.mtimeMs === cachedEntry.mtimeMs) { |
| if (stat?.isDirectory() && stat.mtimeMs === cachedEntry.mtimeMs) { | ||
| cachedExecutables = cachedEntry.executables; | ||
| } else { | ||
| this._cachedExes.delete(pathDir); |
Comment on lines
+161
to
+162
| const stat = await fs.stat(pathDir).catch(() => undefined); | ||
| mtimeMs = stat?.mtimeMs ?? 0; |
Comment on lines
+123
to
+127
| if (now - cachedEntry.lastCheckedMs < 2000) { | ||
| cachedExecutables = cachedEntry.executables; | ||
| } else { | ||
| cachedEntry.lastCheckedMs = now; | ||
| const stat = await fs.stat(pathDir).catch(() => undefined); |
Comment on lines
+123
to
+124
| if (now - cachedEntry.lastCheckedMs < 2000) { | ||
| cachedExecutables = cachedEntry.executables; |
| } | ||
|
|
||
| async function watchPathDirectories(context: vscode.ExtensionContext, env: ITerminalEnvironment, pathExecutableCache: PathExecutableCache | undefined): Promise<void> { | ||
| if (isWindows) { |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
On Windows,
watchPathDirectories()inextensions/terminal-suggest/src/terminalSuggestMain.tscreates long-lived filesystem watchers across every directory listed inPATH. On Windows NTFS, file system watchers open directory handles (CreateFileWwithFILE_LIST_DIRECTORY), which prevents renaming or deleting the watched directory and any parent directory in its hierarchy (MoveFileExWfails withERROR_ACCESS_DENIED (5)orEBUSY).This caused external updaters and installers (such as DeepSeek Harness, Git for Windows, Docker Desktop, Python, etc.) to fail during in-place upgrades when VS Code had an integrated terminal open with shell integration active.
Root Cause
vscode.workspace.createFileSystemWatcherprevent Windows from completing directory moves/renames across the application tree.C:\$Extend\$Deleted\(as detailed in terminal-suggest: PATH is resolved once at activation, so a replaced PATH directory stops updating completions until reload #331457).Solution
createFileSystemWatcherregistration for PATH directories on Windows inwatchPathDirectories().mtimeInvalidation: InPathExecutableCache, validate directorymtimeMson demand when querying executables on Windows. A 2-second rate-limit threshold ensures that rapid typing does not cause repeatedstatcalls while picking up newly added, modified, or replaced executables without holding persistent directory handles.Fixes #349080
Ref #331457