Repository navigation
fix(agents): name a directory instead of leaking a raw errno from file tools - #3891
Conversation
…e tools read_file, edit_python_file and replace_function all guard on os.path.exists(), which is true for a directory. Pointing any of them at one reached open() and surfaced IsADirectoryError as an unstructured "[Errno 21] Is a directory: ..." string, which an agent has no way to act on and just retries. Add an os.path.isdir() check right after the existence check at all three call sites, returning a message that names the problem instead. Fixes amd#3890.
|
Thanks for this — it fixes exactly what we saw in benchmark runs, where One more place has the same gap: the |
|
Good catch, confirmed the same gap in file_tools.py's read_file (open() on a directory raises IsADirectoryError into the generic except Exception, same raw errno). Pushed a matching isdir guard there plus a test, 2a3effe. |
|
Verdict: Approve with suggestions The fix is correct and complete. All four call sites that could pass a directory to One 🟢 nit: The inline comment in 🔍 Technical details
|
|
Good catch, fixed in 7f005f2. The comment cited the PR number where it meant the issue. |
… project (amd#3902) Asking the agent to run a project's test file used to fail before any test ran. `execute_python_file` ran every script from the script's own folder, so `tests/test_dates.py` doing `from toybox import dates` died with `ModuleNotFoundError: No module named 'toybox'`: the project root was neither the working directory nor on the import path. Now a script inside the agent's project directory runs from that directory, with it on `PYTHONPATH`, so project tests import the project the way they do under pytest. A script outside the project still runs from its own folder. Found in the same 168-run Fireworks benchmark as amd#3890. Models made the identical failing call over and over, and in two runs the loop guard ended a task that was already finished. The directory half of amd#3890 (`read_file` on a folder) is left to amd#3891. <details> <summary>🔍 Technical details</summary> - The project directory comes from `resolve_project_root`: the config's `project_root`, then `GAIA_PROJECT_ROOT`, then the nearest code repository at or above the working directory, never the home directory. The flagship defers to its project map's cached root, so the map and a script's working directory always name the same tree. With no project, a script runs from its own folder with the environment untouched. An existing `PYTHONPATH` is kept, after the project root. - Only flat-layout projects become importable; a `src/` layout would need `src/` on the path. - The sandbox check (`is_path_allowed`) and existence check are unchanged and still run first. - One behavior change: a project script that opens files by a path relative to its own folder now resolves them against the project root. The tool docstring says where scripts run, so the model can see this. - The docstring is part of the LLM-visible tool schema. No agent eval was run for this PR. - amd#3891 fixes `FileIOToolsMixin.read_file` but not `FileSearchToolsMixin.read_file` in `file_tools.py`, which the chat profiles also register and which still hits the raw errno. </details> ## Test plan - [x] `pytest tests/unit/test_execute_python_file_cwd.py` (9 passed): a temp project's `tests/test_x.py` doing `from pkg import mod` runs through the registered tool with return code 0 and cwd = project root, also when launched from `tests/`. Also covers the no-project case, a bad `GAIA_PROJECT_ROOT`, `PYTHONPATH` preservation, and a real `GaiaAgent` whose script cwd follows its project map after a `chdir`. - [x] Related suites pass: `tests/unit/test_chat_agent_integration.py`, `tests/unit/agents/test_tool_arg_coercion.py`, `tests/unit/agents/test_confirmation_required_tools.py`, `tests/unit/test_starter_skills.py`, the prompt-budget tests, `hub/agents/chat/python/tests` (265 passed, 15 skipped) - [ ] `gaia chat` in a project with a `tests/` folder: ask it to run one test file and confirm the imports resolve --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Ovtcharov <[email protected]>
Summary
read_file,edit_python_fileandreplace_functionall raised a rawIsADirectoryErrorwhen pointed at a directory instead of telling the model what went wrong.Why
os.path.exists()is true for a directory, so the existing-path guard at all three call sites let it through toopen(). TheIsADirectoryErrorlands in the genericexcept Exceptionhandler and comes back as"[Errno 21] Is a directory: '...'", which isn't something a model can act on, it just retries the same call. Your own comment on the issue confirmed the same shape hitsedit_python_fileandreplace_functiontoo.Linked issue
Fixes #3890
Changes
os.path.isdir()right after the existingos.path.exists()check in all three tools, returning a message that names the directory instead of the errno.browse_directory, per your comment, since it isn't registered on every agent that composes this mixin.Test plan
pytest tests/unit/test_file_io_directory_path_errors.py -v: 5 passed. Reverting just theisdircheck makes the three directory-case tests fail with the raw errno back in the message.pytest tests/unit/test_file_write_guardrails.py tests/unit/test_replace_function_spans.py tests/unit/test_file_editing_prompt.py tests/unit/test_file_access_scope.py tests/unit/agents/test_file_edit_semantics.py -v: all still pass, in the same python:3.12-slim container both times.Evidence
gaiasubcommands.Exercising it live needs an agent session against a model server, which isn't available in this environment; the tests above call the registered tool functions directly, which is the same code path a live session would hit.
Checklist
Fixes #3890).