Skip to content

fix(agent): run_python runs in scratch when the repo around the cwd is unapproved - #5768

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/fix-run-python-root
Oct 26, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/fix-run-python-root

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

run_python refused every snippet when the GAIA daemon had been started from inside a git checkout. The agent treated that checkout as "the project", and the user had never approved it. So asking it to parse a CSV in a folder you had approved failed with "Access denied: is not in allowed paths". Now that case runs in the agent's scratch folder, as it already does when there's no project. A project root you set explicitly and haven't approved is still refused.

Found by the ai-pc-evals 0.6.4 as-rag-malformed-files and as-data-malformed-csvs tasks, run through the Agent UI on v0.25.1-rc11.

Test plan

  • pytest tests/unit/test_run_python_tool.py: a detected but unapproved repo runs in scratch, writes nothing into the repo, and stays off PYTHONPATH; an explicit GAIA_PROJECT_ROOT that isn't allowed is still refused
  • pytest tests/unit -k "python or scratch or project or chat": only failures are ones that also fail on main (test_a_pytest_run_attaches_its_check, pip/uv installer test)

Closes #5765

…s unapproved

When the daemon was started inside a git checkout, run_python treated that
checkout as the project and refused every snippet because the user never
approved it, even snippets that only read an approved folder.

A project root guessed from the process cwd that is outside the allowed paths
is now handled like no project: the snippet runs in the scratch dir and the
root is not put on PYTHONPATH. A root the user set (GAIA_PROJECT_ROOT or
project_root config) that is not allowed is still refused.

Closes amd#5765
@github-actions github-actions Bot added the tests Test changes label Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Before this fix, run_python refused every snippet when the daemon had been started inside a git checkout the user never approved. The fix tells apart a project root the user picked (config or GAIA_PROJECT_ROOT) from one guessed from the launch folder. A guessed root that isn't approved now falls back to the scratch folder and is dropped from the import path. A root the user picked and hasn't approved is still refused. The change is small and covered by tests for both the fallback and the refusal.

One edge case is worth a look, but it doesn't block merge. If the user's chosen project root sits outside the allowed-paths scope, the snippet is refused and the error names the current folder, not the project root.

Real-world evidence

N/A: no evidence bundle was produced for this run. The change is inside the agent's run_python tool, and the Agent UI path is deferred to the strix-halo lane. The verdict rests on static review and the PR's own unit-test plan. I couldn't run the tests here because pytest isn't installed on this runner.

🔍 Technical details

Issues

🟢 A chosen root outside GAIA_ALLOWED_PATHS gets a misleading refusal (hub/agents/chat/python/gaia_agent_chat/agent.py:2090)
_project_map_root() returns None when the explicit root is outside in_env_scope. Then run_dir becomes Path.cwd(), and chosen_root is truthy, so the scratch fallback is skipped. The result is "Access denied: …", which names the cwd and not the root the user set. If the cwd is allowed, the snippet silently runs there instead of in the chosen project. Refusing is the intended policy, so consider naming the chosen root in the error when chosen_root and not project.

🟢 chosen_root is read live while project is cached at init
_project_map_root() caches the root, but os.environ.get(PROJECT_ROOT_ENV) is re-read on every call. If the env var changes mid-session, the two can disagree. This is unlikely in practice. Caching the "explicit?" flag next to the root would keep them consistent.

Strengths

  • Setting project = None on the scratch path also keeps the unapproved repo off PYTHONPATH and out of the watch list. The new test asserts both.
  • The old refusal test was renamed and pinned to an explicit GAIA_PROJECT_ROOT, so the policy is now spelled out: guessed roots fall back, chosen roots are refused.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Fixed the misleading refusal. When the project root you set is outside the allowed paths, run_python now refuses and names that root, instead of naming the current folder or quietly running there. There's a new test for it.

I left the env-var timing point alone. GAIA_PROJECT_ROOT changing mid-session isn't a supported flow, and caching it would add state for no user-visible gain.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 26, 2026
Merged via the queue into amd:main with commit 401e61f Oct 26, 2026
26 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/fix-run-python-root branch October 26, 2026 10:03
@kovtcharov-amd kovtcharov-amd mentioned this pull request Oct 26, 2026
5 of 9 tasks
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 26, 2026
## Why this matters

v0.25.2 is a bug-fix release on top of v0.25.1: setup and install no
longer stop at the first failed step, shell and file access handle
Windows paths and text encodings, the Agent UI and desktop app stop
showing misleading states, and document search, email and skills each
lose a handful of rough edges. 55 commits since v0.25.1; notes are in
`docs/releases/v0.25.2.mdx` and credit 15 outside contributors.

## Test plan

- [x] `python util/validate_release_notes.py docs/releases/v0.25.2.mdx
--tag v0.25.2` passes
- [x] `mintlify validate` (from `docs/`) passes
- [x] `python util/check_doc_links.py --internal-only`, `python
util/check_doc_versions.py` and `node
installer/version/bump-ui-version.mjs --check` pass
- [x] `python util/check_component_core_api.py --release-version 0.25.2`
passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
tests/unit/test_release_tag.py
tests/unit/test_hub_core_version_gate.py`: 156 passed
- [ ] CI green on the merge commit
- [ ] `release_train_dryrun.yml` passes on that commit before the RC tag

## Evals to re-run on the RC tag

LLM-affecting PRs merged without per-PR evals; run these on
`v0.25.2-rc1`:

- `gaia_shell` and shell/safety (amd#5794, amd#5751, amd#5768)
- `gaia_honesty` (amd#5753)
- `gaia_skills_tasks` and `gaia_skills_lifecycle` (amd#5422, amd#5755)
- `rag_retrieval` and `rag_quality` (amd#5742, amd#5754, amd#5761, amd#5817, amd#5812)
- email scenarios (amd#5767, amd#5811)
- `tool_selection` and `error_recovery` (amd#5732)
- Claude provider thinking replay (amd#5072)
- memory categories (amd#5818 merged; amd#5756 has not)

## Release checklist

- [ ] Freeze main, wait for green CI on the exact commit, pass
`release_train_dryrun.yml`, then push `v0.25.2-rc1`
- [ ] Extend the changelog if main gains commits before the tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(agent): run_python refuses every snippet when the daemon started inside an unapproved git repo

2 participants