Skip to content

terminal-suggest: avoid locking PATH directories on Windows (#349080) - #349095

Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix/issue-349080-windows-terminal-suggest-path-watcher
Open

MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix/issue-349080-windows-terminal-suggest-path-watcher

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Summary

On Windows, watchPathDirectories() in extensions/terminal-suggest/src/terminalSuggestMain.ts creates long-lived filesystem watchers across every directory listed in PATH. On Windows NTFS, file system watchers open directory handles (CreateFileW with FILE_LIST_DIRECTORY), which prevents renaming or deleting the watched directory and any parent directory in its hierarchy (MoveFileExW fails with ERROR_ACCESS_DENIED (5) or EBUSY).

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

Solution

  1. Omit Persistent Watchers on Windows: Skip createFileSystemWatcher registration for PATH directories on Windows in watchPathDirectories().
  2. On-Demand mtime Invalidation: In PathExecutableCache, validate directory mtimeMs on demand when querying executables on Windows. A 2-second rate-limit threshold ensures that rapid typing does not cause repeated stat calls while picking up newly added, modified, or replaced executables without holding persistent directory handles.
  3. Graceful Handling of Missing / Replaced Roots: When an installer unlinks or replaces a PATH directory, the cache automatically purges the stale entry without keeping handles open.

Fixes #349080
Ref #331457

…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
Copilot AI balanced review requested due to automatic review settings November 18, 2026 16:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

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

No deployments
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.

Windows terminal-suggest PATH watcher blocks renaming the parent of a PATH directory

4 participants