fix(terminal): guard os.getcwd() against deleted CWD in _get_env_config - #33377
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(terminal): guard os.getcwd() against deleted CWD in _get_env_config#33377liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
When the process's current working directory is deleted (e.g. tmpfs cleanup on Arch Linux), os.getcwd() raises FileNotFoundError. The cleanup thread calls _get_env_config() every 60 seconds, so this error repeats indefinitely in errors.log even though the exception is caught. Wrap os.getcwd() in a try/except and fall back to the home directory. Add regression tests covering both FileNotFoundError and OSError. Fixes NousResearch#33367
Collaborator
This was referenced May 27, 2026
Closed
1 task
Contributor
|
Thanks for the focused report and regression coverage. This is now implemented on
The current implementation also routes the Docker cwd-passthrough and debug-config call sites through the same helper. |
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.
What does this PR do?
_get_env_config()callsos.getcwd()unconditionally for thelocalbackend. When the process's current working directory has been deleted (common on Arch Linux where/tmpis tmpfs and stale namespaces are reaped aggressively), this raisesFileNotFoundError.The cleanup thread calls
_get_env_config()every 60 seconds. Although the exception is caught by the thread'sexcept Exceptionhandler, it logs a full traceback toerrors.logon every tick — creating a recurring, noisy warning that never resolves.Related Issue
Fixes #33367
Type of Change
Changes Made
tools/terminal_tool.py: Guardos.getcwd()against deleted CWDtests/tools/test_terminal_cleanup_cwd.py: Regression tests forFileNotFoundErrorandOSErrorHow to Test
pytest tests/ -q— all tests should passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture and workflows — or N/ACode Intelligence
Function:tools/terminal_tool.py:_get_env_config(callers: 10+ including terminal_tool, file_tools, code_execution_tool, cleanup_thread_worker, prompt_builder)os.getcwd()is also called at line 978 (docker CWD passthrough) but only whenenv_type == "docker", which is not the affected code path