From 94f691caaae1d5d4e984807dc377b72bd873be3c Mon Sep 17 00:00:00 2001 From: Pratyush Singhal Date: Mon, 23 Nov 2026 16:08:31 +0530 Subject: [PATCH 1/2] fix(agents): Gemini's file tools read the task directories /app and /tmp/data gemini-cli's file tools refuse paths outside its workspace, /workspace, so a task's files under /app (as /app/handover) failed read_file with "Path not in workspace", and a binary file there never reached the model. Each run's settings now include whichever of /app and /tmp/data exist (the CLI fails to start on a missing included directory), the directories the snapshot changelog already treats as the task's. Co-Authored-By: Claude Opus 5.5 --- .../agents/agents/gemini/a2a_server.py | 4 ++-- .../agents/agents/gemini/gemini_config.py | 18 +++++++++++------- tst/unit/agents/gemini/conftest.py | 3 ++- tst/unit/agents/gemini/test_extensions.py | 13 +++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/agent_env/agents/agents/gemini/a2a_server.py b/src/agent_env/agents/agents/gemini/a2a_server.py index 622dd30bd..b03589a53 100644 --- a/src/agent_env/agents/agents/gemini/a2a_server.py +++ b/src/agent_env/agents/agents/gemini/a2a_server.py @@ -95,7 +95,7 @@ outermost, remove_settings_hooks, ) -from gemini_config import gemini_home, run_settings, user_settings_path +from gemini_config import TASK_DIRS, gemini_home, run_settings, user_settings_path from gemini_kit import ( DurableSessionRefs, FilePartMaterializeError, @@ -343,7 +343,7 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]: def _changelog_roots() -> list[str]: """The changelog's default capture roots: the writable layer a fresh agent of the image reconstructs, the CLI's state (and its transcripts) included.""" - return outermost([str(Path.home()), str(gemini_home()), GEMINI_CWD, "/app", "/tmp/data", "/usr/local", "/etc"]) + return outermost([str(Path.home()), str(gemini_home()), GEMINI_CWD, *TASK_DIRS, "/usr/local", "/etc"]) def _install_changelog_hook(command: str) -> None: diff --git a/src/agent_env/agents/agents/gemini/gemini_config.py b/src/agent_env/agents/agents/gemini/gemini_config.py index a1f324c89..a6e792075 100644 --- a/src/agent_env/agents/agents/gemini/gemini_config.py +++ b/src/agent_env/agents/agents/gemini/gemini_config.py @@ -2,8 +2,8 @@ `~/.gemini/settings.json` holds what every run shares, the changelog's hook. Each run gets settings of its own as the CLI's system settings, which override the user's: the -task's MCP servers with the turn's role header, and the turn's system prompt as a -context file named by its content. So turns running at once never share a role, and a +task's MCP servers with the turn's role header, the task directories that exist as +included directories, and the turn's system prompt as a context file named by its content. So turns running at once never share a role, and a system prompt keeps one path from turn to turn. """ from __future__ import annotations @@ -28,6 +28,9 @@ _DEFAULT_SYSTEM_SETTINGS = Path("/etc/gemini-cli/settings.json") # The CLI's context file in a workspace, which a run with a system prompt still loads beside its own. _WORKSPACE_CONTEXT_FILE = "GEMINI.md" +# Where tasks put files for the agent outside its workspace. The CLI's file tools refuse paths outside the workspace +# and its included directories, and it fails to start when an included directory is missing. +TASK_DIRS = ("/app", "/tmp/data") _prompt_files: Counter[Path] = Counter() _prompt_files_lock = threading.Lock() @@ -83,13 +86,14 @@ def run_settings(servers: Mapping[str, Mapping[str, Any]], role: str | None, **(settings.get("mcpServers") if isinstance(settings.get("mcpServers"), dict) else {}), **{settings_name(name): _server_entry(info["url"], info.get("headers"), role) for name, info in servers.items()}, } + context = dict(settings["context"]) if isinstance(settings.get("context"), dict) else {} + if task_dirs := [d for d in TASK_DIRS if os.path.isdir(d)]: + context["includeDirectories"] = list(dict.fromkeys([*(context.get("includeDirectories") or []), *task_dirs])) with ExitStack() as stack: if system_prompt: - context = stack.enter_context(_prompt_file(home, system_prompt)) - settings["context"] = { - **(settings.get("context") if isinstance(settings.get("context"), dict) else {}), - "fileName": [_WORKSPACE_CONTEXT_FILE, context.name], - } + context["fileName"] = [_WORKSPACE_CONTEXT_FILE, stack.enter_context(_prompt_file(home, system_prompt)).name] + if context: + settings["context"] = context path = runs / f"{token}.json" # It carries the MCP servers' headers. with os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), "w") as handle: diff --git a/tst/unit/agents/gemini/conftest.py b/tst/unit/agents/gemini/conftest.py index 0b94e63c0..6d2d73387 100644 --- a/tst/unit/agents/gemini/conftest.py +++ b/tst/unit/agents/gemini/conftest.py @@ -11,7 +11,7 @@ from agentenv_protocol import transfers as protocol_transfers from starlette.testclient import TestClient -from tst.unit.agents.gemini.agent import a2a_server, gemini_bridge +from tst.unit.agents.gemini.agent import a2a_server, gemini_bridge, gemini_config from tst.unit.agents.gemini.support import FakeStore, Staging @@ -34,6 +34,7 @@ def home(monkeypatch, tmp_path) -> Path: monkeypatch.setattr(a2a_server, "GEMINI_CWD", cwd) monkeypatch.setattr(a2a_server, "SKILLS_DIR", gemini_home / "skills") monkeypatch.setattr(a2a_server, "INPUTS_DIR", Path(cwd) / "inputs") + monkeypatch.setattr(gemini_config, "TASK_DIRS", ()) return root diff --git a/tst/unit/agents/gemini/test_extensions.py b/tst/unit/agents/gemini/test_extensions.py index e10b24f12..02891ddc7 100644 --- a/tst/unit/agents/gemini/test_extensions.py +++ b/tst/unit/agents/gemini/test_extensions.py @@ -129,6 +129,19 @@ def test_turns_sharing_a_system_prompt_share_its_file_until_the_last_ends(home): assert prompt.read_text() == "be brief" and not second.exists() assert not prompt.exists() and not first.exists() + +def test_a_run_includes_the_task_directories_that_exist_so_the_file_tools_read_them(monkeypatch, tmp_path, home): + app_dir, data_dir = tmp_path / "app", tmp_path / "data" + app_dir.mkdir() + monkeypatch.setattr(gemini_config, "TASK_DIRS", (str(app_dir), str(data_dir))) + + with gemini_config.run_settings({}, None, None) as path: + assert json.loads(path.read_text())["context"] == {"includeDirectories": [str(app_dir)]} + data_dir.mkdir() + with gemini_config.run_settings({}, None, "be brief") as path: + context = json.loads(path.read_text())["context"] + assert context["includeDirectories"] == [str(app_dir), str(data_dir)] and context["fileName"][0] == "GEMINI.md" + def test_a_duplicate_url_or_name_is_a_409(home, client): client.post(MCP_CONFIG_PATH, json={"url": "https://gw/a/mcp", "name": "env1"}) From 78ac167628f4472e9efe4dd627c6bb7ab8fe761b Mon Sep 17 00:00:00 2001 From: Pratyush Singhal Date: Mon, 23 Nov 2026 22:10:06 +0530 Subject: [PATCH 2/2] fix(agents): Gemini's file tools also read /tmp/file_artifacts, load_artifact's default for an agent A FileArtifact, file universe or URL that load_artifact puts in an agent without a destination_path lands in /tmp/file_artifacts, which the included directories left out, so its files still failed read_file with "Path not in workspace". The snapshot changelog keeps its own roots: they say what to rebuild of the agent's writable layer, not where tasks hand it files. Co-Authored-By: Claude Opus 5.5 --- src/agent_env/agents/agents/gemini/a2a_server.py | 4 ++-- src/agent_env/agents/agents/gemini/gemini_config.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/agent_env/agents/agents/gemini/a2a_server.py b/src/agent_env/agents/agents/gemini/a2a_server.py index b03589a53..622dd30bd 100644 --- a/src/agent_env/agents/agents/gemini/a2a_server.py +++ b/src/agent_env/agents/agents/gemini/a2a_server.py @@ -95,7 +95,7 @@ outermost, remove_settings_hooks, ) -from gemini_config import TASK_DIRS, gemini_home, run_settings, user_settings_path +from gemini_config import gemini_home, run_settings, user_settings_path from gemini_kit import ( DurableSessionRefs, FilePartMaterializeError, @@ -343,7 +343,7 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]: def _changelog_roots() -> list[str]: """The changelog's default capture roots: the writable layer a fresh agent of the image reconstructs, the CLI's state (and its transcripts) included.""" - return outermost([str(Path.home()), str(gemini_home()), GEMINI_CWD, *TASK_DIRS, "/usr/local", "/etc"]) + return outermost([str(Path.home()), str(gemini_home()), GEMINI_CWD, "/app", "/tmp/data", "/usr/local", "/etc"]) def _install_changelog_hook(command: str) -> None: diff --git a/src/agent_env/agents/agents/gemini/gemini_config.py b/src/agent_env/agents/agents/gemini/gemini_config.py index a6e792075..76f8fe3e6 100644 --- a/src/agent_env/agents/agents/gemini/gemini_config.py +++ b/src/agent_env/agents/agents/gemini/gemini_config.py @@ -3,8 +3,9 @@ `~/.gemini/settings.json` holds what every run shares, the changelog's hook. Each run gets settings of its own as the CLI's system settings, which override the user's: the task's MCP servers with the turn's role header, the task directories that exist as -included directories, and the turn's system prompt as a context file named by its content. So turns running at once never share a role, and a -system prompt keeps one path from turn to turn. +included directories, and the turn's system prompt as a context file named by its content. +So turns running at once never share a role, and a system prompt keeps one path from turn +to turn. """ from __future__ import annotations @@ -28,9 +29,10 @@ _DEFAULT_SYSTEM_SETTINGS = Path("/etc/gemini-cli/settings.json") # The CLI's context file in a workspace, which a run with a system prompt still loads beside its own. _WORKSPACE_CONTEXT_FILE = "GEMINI.md" -# Where tasks put files for the agent outside its workspace. The CLI's file tools refuse paths outside the workspace -# and its included directories, and it fails to start when an included directory is missing. -TASK_DIRS = ("/app", "/tmp/data") +# Where tasks put files for the agent outside its workspace: /tmp/file_artifacts is load_artifact's default for an +# agent. The CLI's file tools refuse paths outside the workspace and its included directories, and it fails to start +# when an included directory is missing. +TASK_DIRS = ("/app", "/tmp/data", "/tmp/file_artifacts") _prompt_files: Counter[Path] = Counter() _prompt_files_lock = threading.Lock()