From fe6c86623fabf023040d0bc3b0f1a98561abcbb8 Mon Sep 17 00:00:00 2001 From: vominh1919 Date: Wed, 29 Apr 2026 13:01:37 +0700 Subject: [PATCH] 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) --- tools/environments/local.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/environments/local.py b/tools/environments/local.py index 1029545f..448fe024 100644 --- a/tools/environments/local.py +++ b/tools/environments/local.py @@ -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):