fix: close file descriptor in LocalEnvironment._update_cwd

_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)
This commit is contained in:
vominh1919 2026-04-29 13:01:37 +07:00 committed by Teknium
parent 258755a24f
commit fe6c86623f

View File

@ -392,7 +392,8 @@ class LocalEnvironment(BaseEnvironment):
def _update_cwd(self, result: dict):
"""Read CWD from temp file (local-only, no round-trip needed)."""
try:
cwd_path = open(self._cwd_file).read().strip()
with open(self._cwd_file) as f:
cwd_path = f.read().strip()
if cwd_path:
self.cwd = cwd_path
except (OSError, FileNotFoundError):