fix(tools): guard os.getcwd() in _get_env_config against missing CWD - #33407
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(tools): guard os.getcwd() in _get_env_config against missing CWD#33407liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
When the process's current working directory is removed (e.g. by Arch Linux's aggressive tmpfs cleanup), os.getcwd() raises FileNotFoundError. The cleanup thread calls _get_env_config() every 60 seconds, so this produced a recurring warning in errors.log that never stopped. Guard both os.getcwd() call sites (local default_cwd and docker mount CWD source) with a try/except that falls back to the user's home directory when the CWD no longer exists. Fixes NousResearch#33367
Collaborator
3 tasks
Contributor
Author
|
Duplicate of #33377 (same fix for in ). Closing in favor of the earlier PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_get_env_config()intools/terminal_tool.pycallsos.getcwd()without protection. When the process's CWD is removed (e.g. by Arch Linux's aggressive tmpfs cleanup of/tmp), this raisesFileNotFoundError. The background cleanup thread calls_get_env_config()every 60 seconds, producing a recurring warning inerrors.logthat never stops — and the cleanup itself never runs, so stale environments accumulate.Fix
Guard both
os.getcwd()call sites in_get_env_config()withtry/except (FileNotFoundError, OSError), falling back toos.path.expanduser("~"):os.getcwd()→ wrapped in try/exceptos.getcwd()fallback → wrapped in try/exceptRegression test
New test file
tests/tools/test_get_env_config_cwd_fallback.pywith 5 test cases:test_local_env_getcwd_file_not_found— FileNotFoundError falls back to hometest_local_env_getcwd_os_error— OSError falls back to hometest_local_env_getcwd_normal— normal case still uses real CWDtest_local_env_terminal_cwd_overrides_fallback— explicit TERMINAL_CWD still takes precedencetest_docker_mount_cwd_getcwd_file_not_found— docker mount path doesn't crashAll 5 new tests pass. Existing
test_parse_env_var.py(12 tests) also passes.Code Intelligence
tools/terminal_tool.py:_get_env_config(callers: 4 —_cleanup_thread_worker,create_terminal_environment,create_file_environment,create_web_environment)_cleanup_thread_workercatches all exceptions at line 1242, but the FileNotFoundError clutters logs every 60s and prevents cleanup from runningFixes #33367