#8869: fix: prevent file descriptor leak from Python venv directories in skills
agents
stale
Cluster:
Skill Enhancements and Fixes
## Summary
Fixes a critical file descriptor leak that occurs when skills contain Python virtual environments. The gateway was accumulating 36,000+ file descriptors and eventually failing with \`spawn EBADF\` errors.
Fixes https://github.com/openclaw/openclaw/issues/8721#issuecomment-3846458925
Fixes https://github.com/openclaw/openclaw/issues/2532
Fixes https://github.com/openclaw/openclaw/issues/9481
## Root Cause
The chokidar file watcher in \`src/agents/skills/refresh.ts\` monitors all skills directories for changes, but was not ignoring Python virtual environment directories (\`venv/\`, \`.venv/\`, \`__pycache__/\`, \`site-packages/\`). Chokidar keeps file descriptors open for all monitored files, causing massive FD accumulation when skills contain Python packages.
## Changes
### 1. Chokidar watcher fix (critical)
- Add Python venv directories to \`DEFAULT_SKILLS_WATCH_IGNORED\` in \`src/agents/skills/refresh.ts\`
- Prevents the file watcher from monitoring tens of thousands of Python package files
- **This fix resolves the FD leak and spawn errors**
### Pattern Details
The fix adds these regex patterns to ignore:
- \`/(^|[\\/])venv([\\/]|$)/\` - Standard virtual environment directory
- \`/(^|[\\/])\.venv([\\/]|$)/\` - Hidden virtual environment directory
- \`/(^|[\\/])__pycache__([\\/]|$)/\` - Python compiled bytecode cache
- \`/(^|[\\/])site-packages([\\/]|$)/\` - Installed Python packages
## Testing
### Before fix:
- Gateway FD count: 36,644
- Skills files held open: 141
- Result: \`spawn EBADF\` errors on command execution
### After fix:
- Gateway FD count: 52
- Skills files held open: 0
- Result: No spawn errors, normal operation
### Validation Results
- ✅ pnpm lint: Passed (0 warnings, 0 errors)
- ✅ pnpm tsgo: Passed (TypeScript type checking)
- ✅ Code follows existing patterns and style guidelines
## Submission Checklist
- [x] Clear problem statement (FD leak causing EBADF errors)
- [x] Focused scope (single file change, 4 lines added)
- [x] Documented behavior changes (before/after FD counts shown)
- [x] Test results provided (FD count reduction verified)
- [x] Manual testing steps included (can be verified by observing FD counts)
- [x] Supporting evidence (related GitHub issues with detailed symptoms)
- [x] Research completed (root cause identified in chokidar configuration)
- [x] Validation commands passed (lint, TypeScript checks)
## Implementation Notes
The fix is minimal and non-breaking:
- Only modifies the ignore patterns for the file watcher
- Doesn't change any logic or behavior except reducing monitored files
- Follows existing pattern convention in the codebase
- Compatible with all platforms (regex patterns use cross-platform separators)
---
🤖 Generated with Claude Code
Model usage: Haiku 4.5 (analysis and validation)
Effort level: Low (straightforward, focused fix)
Most Similar PRs
#8291: Fix: Add Python virtual environment ignore patterns to skills watcher
by vishaltandale00 · 2026-02-03
79.3%
#14023: fix: filter skills watcher to relevant file types to prevent FD exh...
by funmerlin · 2026-02-11
77.6%
#9595: fix(skills): ignore .venv, __pycache__, and .openclaw to prevent FD...
by amoghacloud · 2026-02-05
74.7%
#6777: fix(skills): ignore Python venvs and caches in skills watcher
by kirkluokun · 2026-02-02
73.5%
#9925: docs: warn about Python venv placement in skill directories
by kj9kj9qv4m-bit · 2026-02-05
72.1%
#10016: fix: prevent FD exhaustion from skill watcher scanning artifact trees
by oldeucryptoboi · 2026-02-06
71.2%
#21883: fix: guard against undefined snapshot.skills in applySkillEnvOverride…
by felipedamacenoteodoro · 2026-02-20
68.1%
#16654: fix: refresh skills snapshot when managed skills change
by PhineasFleabottom · 2026-02-15
68.1%
#11250: fix: expand skills watcher ignore list and improve session repair l...
by zhangzhefang-github · 2026-02-07
67.5%
#22467: fix: failure while installing skills
by vivganes · 2026-02-21
67.1%