Repository navigation
fix(tools): run scripts from the project root so tests can import the project - #3902
Conversation
… project execute_python_file ran every script from the script's own folder, so a project test such as tests/test_dates.py failed with ModuleNotFoundError for the project's own package. In the Fireworks benchmark that produced repeated identical failures, and twice the loop guard ended a run whose task was already done. A script under the agent's project directory (config project_root, else the working directory) now runs from that directory with it prepended to PYTHONPATH. Scripts outside it still run from their own folder. The sandbox and existence checks are unchanged.
Verdict: Request changesGood catch and a real fix — running a project's test file from the project root with the root importable is exactly right, and the unit test reproduces the original Blocking issues
Real-world evidenceN/A — no evidence bundle was produced for this run, and this review lane has no pytest installed, so I could not execute the new test myself. The PR's own test plan leaves the one end-to-end item ( 🔍 Technical details🟡 Important1. p, getattr(self.config, "project_root", None) or os.getcwd()
Note 2.
Combined fix for both — treat "no project" as the old behaviour: with the helper taking ( 3. Missing eval run for an LLM-visible surface ( CLAUDE.md lists "tool docstrings, or the JSON tool schema sent to Lemonade" among the changes that require 🟢 Minor
Strengths
|
…does Running a project's test file from a subfolder still failed to import the project, and running any script from a home directory quietly changed what it could see. execute_python_file had its own project-root rule — config value, else the working directory — so starting the agent in myproj/tests/ never found myproj/, the exact case the fix targeted. It now calls the canonical resolve_project_root(), which honours GAIA_PROJECT_ROOT, ascends to the nearest enclosing repository, and answers None outside a project. None restores the old behaviour exactly: the script runs from its own folder with the environment untouched. That matters because allowed_paths defaults to the home directory, so the previous cwd fallback made $HOME the working directory and put it on PYTHONPATH, breaking relative reads next to the script and letting a stray ~/email.py shadow a stdlib module. A bad GAIA_PROJECT_ROOT now surfaces as a tool error dict instead of escaping the tool call.
|
Verdict: Approve
The implementation is well-decomposed: Tests cover all the meaningful cases: happy path from both the project root and a subdirectory, the no-project fallback, a misconfigured One nit (🟢): 🔍 Technical details
|
A script run by the flagship now has a test proving it runs in the project the project map describes, even after the process changes directory. The run-context helper also notes that only flat-layout projects become importable, since a src/ layout needs src/ on the path.
|
Both follow-ups are in. The helper's docstring now says only flat-layout projects become importable. A new test covers the flagship path: its scripts run in the project the project map describes, even after the process changes directory. 🔍 Technical detailsAll changes are in 0e75567.
Tests: The first review's eval request still stands, because the tool docstring changed. It runs in the self-hosted CI job once a maintainer pushes this branch to amd/gaia; it can't run on this machine. The live |
|
Refreshed this branch against current The update was a clean merge: nothing was resolved by hand, and no commit on this branch was rewritten. CI now runs against an up-to-date base. |
Asking the agent to run a project's test file used to fail before any test ran.
execute_python_fileran every script from the script's own folder, sotests/test_dates.pydoingfrom toybox import datesdied withModuleNotFoundError: 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 onPYTHONPATH, 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 #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 #3890 (
read_fileon a folder) is left to #3891.🔍 Technical details
resolve_project_root: the config'sproject_root, thenGAIA_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 existingPYTHONPATHis kept, after the project root.src/layout would needsrc/on the path.is_path_allowed) and existence check are unchanged and still run first.FileIOToolsMixin.read_filebut notFileSearchToolsMixin.read_fileinfile_tools.py, which the chat profiles also register and which still hits the raw errno.Test plan
pytest tests/unit/test_execute_python_file_cwd.py(9 passed): a temp project'stests/test_x.pydoingfrom pkg import modruns through the registered tool with return code 0 and cwd = project root, also when launched fromtests/. Also covers the no-project case, a badGAIA_PROJECT_ROOT,PYTHONPATHpreservation, and a realGaiaAgentwhose script cwd follows its project map after achdir.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 chatin a project with atests/folder: ask it to run one test file and confirm the imports resolve