Skip to content

fix: close file descriptor in LocalEnvironment._update_cwd - #15552

Closed
vominh1919 wants to merge 2 commits into
NousResearch:mainfrom
vominh1919:fix/local-env-resource-leak
Closed

fix: close file descriptor in LocalEnvironment._update_cwd#15552
vominh1919 wants to merge 2 commits into
NousResearch:mainfrom
vominh1919:fix/local-env-resource-leak

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Problem

LocalEnvironment._update_cwd() uses a bare open(self._cwd_file).read() call that never closes the file descriptor. This method runs on every terminal command execution, so the leak accumulates over time in long sessions.

Fix

Use a with statement so the fd is released promptly.

# Before
cwd_path = open(self._cwd_file).read().strip()

# After
with open(self._cwd_file) as f:
    cwd_path = f.read().strip()

Impact

Prevents file descriptor exhaustion in long-running sessions with many terminal commands.

…m providers

Fixes:
- NousResearch#13766: CLI agents no longer emit MEDIA:/path tags (CLI has no attachment channel)
- NousResearch#13765: Add 'from __future__ import annotations' to 64 files for Python 3.9 PEP-604 compatibility
- NousResearch#13764: Model switch now searches custom_providers catalog before API probe

Changes:
- agent/prompt_builder.py: Extend CLI platform hint to prevent MEDIA: tag emission
- cli.py: Load custom_providers unconditionally (not just for picker)
- hermes_cli/model_switch.py: Add _find_model_in_custom_providers() helper, insert step c2 in PATH B
- hermes_cli/models.py: normalize_provider() handles custom:* slugs
- 64 files: Add 'from __future__ import annotations' for Python 3.9 compatibility
The bare open(self._cwd_file).read() call leaks a file descriptor
on every terminal command execution.  Use a with-statement so the
fd is released promptly, preventing fd exhaustion in long sessions.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists backend/local Local shell execution tool/terminal Terminal execution and process management labels Apr 25, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the contribution @vominh1919! The LocalEnvironment._update_cwd fd-leak fix is legitimate, but this PR also stacks an unrelated 'Python 3.9 compat + CLI MEDIA tags + model switch' commit across 68 files. Closing for scope creep — could you resubmit the fd-leak fix as a standalone 1-file PR? I'll merge the clean version quickly.

@teknium1 teknium1 closed this Apr 29, 2026
@vominh1919

Copy link
Copy Markdown
Contributor Author

Resubmitted as a clean standalone 1-file PR: #17294

Only the fd-leak fix in tools/environments/local.py — no unrelated commits.

teknium1 pushed a commit that referenced this pull request Apr 29, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes #15552 (standalone resubmission)
donald131 pushed a commit to donald131/hermes-agent that referenced this pull request May 2, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes NousResearch#15552 (standalone resubmission)
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes NousResearch#15552 (standalone resubmission)
jsboige pushed a commit to jsboige/hermes-agent that referenced this pull request May 14, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes NousResearch#15552 (standalone resubmission)
dannyJ848 pushed a commit to dannyJ848/hermes-agent that referenced this pull request May 17, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes NousResearch#15552 (standalone resubmission)
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes NousResearch#15552 (standalone resubmission)
Seven74AI pushed a commit to Seven74AI/hermes-agent that referenced this pull request Jun 13, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes NousResearch#15552 (standalone resubmission)
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes NousResearch#15552 (standalone resubmission)
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
_update_cwd() uses a bare open(self._cwd_file).read() that never
closes the file descriptor. This method runs on every terminal
command execution, so the fd leaks accumulate in long sessions.

Use a with statement so the fd is released promptly.

Fixes NousResearch#15552 (standalone resubmission)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/local Local shell execution P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants