#6362: fix(memory): add ignore patterns to chokidar file watcher
agents
size: S
experienced-contributor
Cluster:
Skill Enhancements and Fixes
## Summary
Adds `ignorePaths` config option to memorySearch that prevents chokidar from watching non-document directories.
## Problem
When `memorySearch.extraPaths` points to a directory containing large non-document subtrees (e.g., Python `.venv` with PyTorch, `node_modules`, `.git`), chokidar opens a file descriptor for **every file and directory** in the tree — even though only `.md` files are ever indexed.
This causes the gateway process to exhaust its file descriptor limit and produce:
```
spawn EBADF
Error: EMFILE: too many open files
```
## Solution
1. Add `ignorePaths` array to memorySearch config (zod schema, types, etc)
2. Add default ignore patterns: `node_modules`, `.git`, `.venv`, `venv`, `.env`, `__pycache__`, `.tox`, `dist`, `build`, `.next`, `.nuxt`, `target`, `.cargo`
3. Pass `ignored` option to chokidar.watch()
4. Update `listMemoryFiles()` and `walkDir()` to respect ignore patterns
## Config Example
```json
{
"agents": {
"defaults": {
"memorySearch": {
"extraPaths": ["/large/project"],
"ignorePaths": ["**/custom_ignore/**"]
}
}
}
}
```
## Testing
Added test for `listMemoryFiles()` with ignorePaths.
Closes #5827
Re-opens fix from #6146 (incorrectly closed by triage bot)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds an `ignorePaths` option to `memorySearch` and wires it through config/schema/types, then uses it to reduce file watcher scope (via chokidar’s `ignored` option) and to skip ignored directories when enumerating memory markdown files.
Main concern: `ignorePaths` is documented and surfaced as “glob patterns”, but `listMemoryFiles()` only implements a narrow subset (extracting literal dir names from patterns like `**/dirname/**`). Since chokidar applies full glob semantics, certain ignore patterns can lead to watch/index mismatches or silently not be honored during indexing.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge, but the ignorePaths behavior is inconsistent and may surprise users.
- The change is localized and addresses a real resource issue, but the new ignorePaths setting is described as glob patterns while indexing only supports a narrow pattern shape, and chokidar uses full glob semantics—creating potential watch/index divergence and confusing configs.
- src/memory/internal.ts, src/memory/manager.ts, src/agents/memory-search.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16112: fix: add error handler to memory file watcher to prevent crashes
by MisterGuy420 · 2026-02-14
75.5%
#6777: fix(skills): ignore Python venvs and caches in skills watcher
by kirkluokun · 2026-02-02
74.4%
#2884: fix: Create memory directory and symlink identity files during work...
by webdevtodayjason · 2026-01-27
74.3%
#8291: Fix: Add Python virtual environment ignore patterns to skills watcher
by vishaltandale00 · 2026-02-03
74.0%
#4386: fix(memory): persist dirty flag to prevent false positive on status
by Iamadig · 2026-01-30
73.8%
#21217: fix: memory prune command to prevent unbounded MEMORY.md growth
by theognis1002 · 2026-02-19
73.7%
#23566: Gateway:expose memory/*.md in agents.files RPC
by SepehrShapouri · 2026-02-22
73.4%
#11179: fix(memory): replace confusing "No API key" errors in memory tools ...
by liuxiaopai-ai · 2026-02-07
73.3%
#11761: fix(gateway): expose memory/ directory files in agents.files RPC
by advaitpaliwal · 2026-02-08
73.2%
#12939: fix(memory): strip null bytes from workspace paths causing ENOTDIR
by omair445 · 2026-02-09
72.1%