Skip to content

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

Merged
teknium1 merged 1 commit into
NousResearch:mainfrom
vominh1919:fix/local-env-fd-leak
Apr 29, 2026
Merged

fix: close file descriptor in LocalEnvironment._update_cwd#17300
teknium1 merged 1 commit into
NousResearch:mainfrom
vominh1919:fix/local-env-fd-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 fd leaks accumulate 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.


Standalone resubmission of the fd-leak fix from #15552 (1 file, 2 lines changed).

_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)
@vominh1919

Copy link
Copy Markdown
Contributor Author

@teknium1 please check Sir

@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 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #8112 — same fd leak fix in LocalEnvironment._update_cwd(). Also a resubmission of closed #15552.

@vominh1919

Copy link
Copy Markdown
Contributor Author

Likely duplicate of #8112 — same fd leak fix in LocalEnvironment._update_cwd(). Also a resubmission of closed #15552.

I resubmission of #15552

@teknium1
teknium1 merged commit fe6c866 into NousResearch:main Apr 29, 2026
5 of 7 checks passed
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