Skip to content

fix: prevent file descriptor leak from Python venv directories in skills#8869

Closed
jverkoey wants to merge 4 commits intoopenclaw:mainfrom
ClutchEngineering:fix/python-venv-fd-leak
Closed

fix: prevent file descriptor leak from Python venv directories in skills#8869
jverkoey wants to merge 4 commits intoopenclaw:mainfrom
ClutchEngineering:fix/python-venv-fd-leak

Conversation

@jverkoey
Copy link
Copy Markdown

@jverkoey jverkoey commented Feb 4, 2026

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 #8721 (comment)
Fixes #2532
Fixes #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

  • Clear problem statement (FD leak causing EBADF errors)
  • Focused scope (single file change, 4 lines added)
  • Documented behavior changes (before/after FD counts shown)
  • Test results provided (FD count reduction verified)
  • Manual testing steps included (can be verified by observing FD counts)
  • Supporting evidence (related GitHub issues with detailed symptoms)
  • Research completed (root cause identified in chokidar configuration)
  • 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)

The chokidar file watcher was monitoring all files in skills directories,
including venv, .venv, __pycache__, and site-packages. This caused file
descriptors to be held open for thousands of Python package files.

Add these directories to DEFAULT_SKILLS_WATCH_IGNORED to prevent the
watcher from monitoring them.

This complements the pi-coding-agent patch which prevents the loader
from scanning into these directories.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jverkoey jverkoey force-pushed the fix/python-venv-fd-leak branch from 466866d to e068022 Compare February 6, 2026 05:45
@jverkoey
Copy link
Copy Markdown
Author

jverkoey commented Feb 7, 2026

@blenoski
Copy link
Copy Markdown

Adding some more info to this issue. I ran into the issue after installing the transcribe skill (audio to text) with a local model which does indeed setup a Python ".venv" in the skills directory. Confirming that adding ".venv" to the DEFAULT_SKILLS_WATCH_IGNORED fixed the issue.

@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Feb 21, 2026
@steipete
Copy link
Copy Markdown
Contributor

Closing as AI-assisted stale-fix triage.

Linked issue #2532 ("[Bug]: spawn EBADF error on all exec tool calls**") is currently closed and was closed on 2026-02-13T03:33:12Z with state reason not_planned.
Given that issue state, this fix PR is no longer needed in the active queue and is being closed as stale.

If the underlying bug is still reproducible on current main, please reopen this PR (or open a new focused fix PR) and reference both #2532 and #8869 for fast re-triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] FD Leak: skills watcher ignores .venv/, causing spawn EBADF [Bug]: spawn EBADF error on all exec tool calls**

3 participants