Agent Host file monitor watches session roots recursively, ignoring files.watcherExclude
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
VS Code 1.136.0, Linux x64, remote (tunnel + `serve-web`). Workspace folder is a large home directory.
`AgentHostFileMonitorService` takes its own recursive watch on agent session roots and never consults `files.watcherExclude`.
`out/vs/platform/agentHost/node/agentHostMain.js`:
```js
NM = Object.freeze(["**/.git","**/.git/lfs/**","**/.git/logs/**","**/.git/objects/**",
"**/.git/subtree-cache/**","**/.git/**/*.lock","**/.git/**/FETCH_HEAD",
"**/.git/**/fsmonitor--daemon/**","**/*.watchman-cookie-*"]);
_ensureRootWatcher(e, t) {
let o = this._fileMonitorService.acquire(t, () => this._onRootChanged(e),
{ excludes: NM, debounceMs: 750 });
}
```
The call site passes `excludes: NM` explicitly, so user configuration cannot apply.
**Observed.** With ~20 patterns in `files.watcherExclude`, the workbench watcher settles at ~13,200 inotify watches. With an agent session open on the same folder, the `--type=fileWatcher` process holds **193,018**; the tree contains 194,468 directories. Of 194,066 directories walked, exactly 1,138 were not watched and all of them were `.git` subtrees — confirming `NM` is the exclude set in force. `node_modules` was fully watched despite `**/node_modules/**` being configured, and despite `**/node_modules/*/**` being a shipped default of `files.watcherExclude`.
**Impact.** `max_user_watches` on this machine is 506,479, so this only cost memory. At the common defaults (8,192 / 65,536) the request exceeds the limit and breaks file watching for the whole window; `onDidWatchError` only emits a warning. The entry is refcounted, so it presents as an intermittent, self-resolving spike, which makes it hard to attribute.
**Expected.** Merge `files.watcherExclude` for the folder with the agent host's git-specific patterns.
**Workaround.** `"chat.agentHost.claudeAgent.enabled": false` — verified to remove the provider and hold the watcher at 13,244 from a cold start.
Contributor guide
Assessment
This issue has not been assessed yet.