Skip to content

fix(agent): offer the shell whenever the session works in a code repository - #4076

Closed
kovtcharov wants to merge 2 commits into
amd:mainfrom
kovtcharov:fix/shell-tool-in-code-repos
Closed

kovtcharov wants to merge 2 commits into
amd:mainfrom
kovtcharov:fix/shell-tool-in-code-repos

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

The flagship worked real repositories without a shell. The tool loader showed run_shell_command only when a request sounded like a shell request, and coding requests usually don't ("skip gfx90a tests on PRs unless labeled"). On four TheRock CI-fix tasks it never got the shell, and 181 of its 276 tool calls were run_python wrapping a single grep or sed. Claude Code took about 20 shell calls per task; GAIA took 65–96 calls. Now, when the session's project is a code repository, the shell is offered on every turn. Outside a repository nothing changes, and the shell still asks for approval as before.

Why not just make the shell always-on everywhere: its schema is about 160 tokens on every call, and most flagship sessions (documents, email, chat) have no use for a shell. Tying it to the workspace spends those tokens only where they pay off. It's decided once, when the agent is built, so the prompt prefix stays cache-stable from turn 1. The project map already tells the model which commands run_shell_command accepts in a repo. Until now that tool often wasn't offered.

Test plan

  • New hub/agents/gaia/python/tests/test_shell_in_code_repos.py: with an embedder that matches nothing, a first turn in a .git workspace (explicit root or found from cwd) sends run_shell_command in the native tools= list. A non-repo workspace doesn't. The two repo cases fail on main.
  • Tool-loader, bundle, dynamic-tool, project-map and hub/agents/gaia/python/tests suites: no new failures versus main. The failures that remain also fail on main: 4 in test_tool_loader_token_budget.py, plus 3 in test_full_tool_bundles.py/test_gaia_agent.py caused by search_documentation being absent in this env.
  • gaia eval agent --category tool_selection compared against the committed baseline

…sitory

Coding tasks in a repository ran without a shell, because the flagship's tool
loader admitted run_shell_command only when the request's wording was close to
the tool's description. "Skip gfx90a tests on PRs unless labeled" is not, so
every grep and sed went through run_python, one command per call.

Shell availability now follows the working context: when the session's project
root (the one the project map already resolves) is a code repository,
run_shell_command joins CORE for the life of the loader. It is fixed at
construction, so the offered prefix is stable from the first turn. Outside a
repository selection is unchanged, and the shell's approval gate is untouched.
@github-actions

Copy link
Copy Markdown
Contributor

Request changes

This makes the flagship offer run_shell_command on every turn when the session's project is a code repository, instead of only when the request happens to sound shell-shaped. The design is the right one — a small overridable hook on the base agent, the decision taken once at build time so the prompt prefix stays cache-stable, and a real test that asserts the tool list actually sent to the model. Two things should land before merge.

The agent eval hasn't been run. This changes the tool schema the model sees, which is exactly the surface the project requires an eval for, and the test plan's eval item is still unchecked. Unit tests prove the tool is offered; they say nothing about whether the model uses it well, or whether the extra always-on tool crowds out something else. Run the tool-selection category against the committed baseline and paste the comparison.

The release note promises this for a path nobody has shown it working on. The changelog entry ships in the npm package, where the agent runs as a long-lived background sidecar and the "project" is taken from whatever directory that background process was first started in — not from where the user is working. Started once from a home directory, it never sees a repository, and the shell never turns on. Please confirm with a real terminal-UI session inside a repo that the shell is genuinely offered, or soften the note to describe the case it actually covers.

Real-world evidence

N/A — no evidence bundle was produced for this run, so the verdict rests on static review alone. The PR description carries strong before-state measurements (four TheRock CI-fix tasks; 181 of 276 tool calls wrapping a single grep or sed in run_python), but no after-state artifact: no eval comparison, and no session transcript or terminal-UI capture showing the shell being offered and used. Since the shipped surface is the packaged agent, that after-state is the evidence worth adding — it is the same gap as the second blocking point above.

🔍 Technical details

🟡 Important

Eval required for a tool-schema change (hub/agents/gaia/python/gaia_agent/agent.py:336)

_workspace_core_tools changes the native tools= payload for every repo session. Per CLAUDE.md → "Run agent evals when changing LLM-affecting code paths", tool registration / the JSON tool schema sent to Lemonade is on the must-eval list. The test plan's third item is unchecked:

python -m gaia.ui.server --port 4200 --host 127.0.0.1   # terminal 1
gaia eval agent --category tool_selection                # terminal 2, serially
gaia eval agent --compare \
  tests/fixtures/eval_baselines/<model>/scorecard_tool_selection.json \
  <printed-output-path>/scorecard.json

Note the always-on set grows from 16 to 17 in a repo, and CORE counts against max_tools (tool_loader.py:337), so GaiaAgentConfig.dynamic_tools_max = 28 leaves 11 dynamic slots instead of 12. That is a fine trade, but it is a behavioural change the eval is the only thing that measures.

The daemon path may never resolve a repository root (hub/agents/gaia/python/gaia_agent/agent.py:343)

_project_map_root() falls back to resolve_project_root(None), which walks up from Path.cwd(). For the frozen sidecar the daemon sets no cwd (src/gaia/daemon/sidecars/manager.py:353 sets it only on the dev branch; _spawn_process merges env but never a cwd), so the sidecar inherits the daemon's cwd — and the daemon is one machine-wide, long-lived process. If it was first started from ~, resolve_project_root returns None and this hook returns the empty set for every session, including ones the user opens from a repo. The hub/agents/gaia/npm/CHANGELOG.md entry promises the behaviour for exactly that package. This is pre-existing for the project map, but the changelog is what turns it into a user-facing promise. A TUI session run from a repo, showing run_shell_command in the offered set, would settle it either way.

🟢 Minor

The project map can still name a tool the loader isn't offering (src/gaia/agents/base/project_map.py:687)

get_project_map_system_prompt computes has_shell_tool from _tools_registry — the full registry — not from the active filter. With an explicit project_root pointing at a non-repo directory (the explicit_root=True case your own test covers), the map still renders run_shell_command accepts: … on a turn where the loader did not offer the tool. That is the failure the has_shell_tool parameter exists to prevent ("naming a tool it does not have buys a guaranteed failed call"). Pre-existing, and this PR narrows it rather than widening it — but reading _active_tool_filter when one is set would close it.

Non-repo test depends on the temp directory's ancestry (hub/agents/gaia/python/tests/test_shell_in_code_repos.py:186)

The explicit_root=False variant asserts "no repository" by chdir-ing into tmp_path and relying on the upward walk finding no VCS directory or manifest before it hits $HOME or /. On a runner whose TMPDIR sits under a checkout, that walk finds a repository and the assertion flips. Setting GAIA_PROJECT_ROOT to tmp_path (or asserting the resolved root is None first) would make it deterministic; the explicit_root=True variant is already safe.

Strengths

  • The extension point is the right shape: the base returns frozenset() and folds it in with profile_config.core | …, so every existing ChatAgent profile stays byte-identical and only the flagship opts in. No flag, no branch in the loader.
  • Resolving the set once at loader-build time (rather than per turn) is what keeps the offered prefix stable from turn 1 — and it reuses the already-cached _project_map_root(), so the map, the code index, and tool availability can never describe different trees.
  • The test asserts the real surface — the names in _openai_tools — with an embedder that scores everything at zero, so a pass genuinely means "CORE plus the workspace" rather than "semantic selection happened to help". The negative case also checks run_python is present and execute_python_file is not, which rules out the full-registry fallback masking a pass.
  • is_code_repository was reused rather than re-derived, so the predicate the project map renders and the predicate that gates the shell cannot drift apart.

An explicit project root pointing at a non-repository directory still rendered
"run_shell_command accepts: ..." in the project map, because the map asked the
tool registry whether the agent owns the shell rather than the per-turn filter
whether it was offered. That is the guaranteed failed call has_shell_tool
exists to prevent.

Also makes the negative shell test deterministic. It asserted "no repository"
by chdir-ing into tmp_path and trusting the upward walk to find nothing before
$HOME — on a runner whose TMPDIR sits under a checkout the walk finds a
repository and the assertion flips. The no-project case now stubs the root; the
non-repository case covers both ways a root is supplied.

The npm CHANGELOG promised the behaviour without saying which root it follows.
A sidecar's working directory is the daemon's, not the user's, so the entry now
names GAIA_PROJECT_ROOT the way SKILL.md section 11 already does.
@github-actions github-actions Bot added tests Test changes agents labels Sep 22, 2026
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Three of the four review findings held up and are fixed on the branch; the fourth is the eval, which I can't run here.

  • The project map named a shell the turn hadn't been given. It read the agent's whole tool registry, so on a turn where the dynamic loader narrowed the tools it still printed run_shell_command usage — inviting exactly the failed call the map's shell section exists to prevent. It now reads the per-turn selection.
  • A test could pass or fail depending on where the runner puts its temp directory. The "no project root" case walked upward from a temp path; under a checkout it found that repository and quietly asserted the opposite of its name. Split into a stubbed-root case and an explicit-root case, both deterministic.
  • The npm changelog over-promised. It read as though the shell turns itself on inside any repository, but a daemon-managed sidecar never inherits your repository as its working directory, so without being told it resolves no root and nothing changes. The entry now names GAIA_PROJECT_ROOT / GaiaAgentConfig(project_root=...), matching what SKILL §11 and SPEC already say. Re-plumbing the daemon's cwd is out of scope for this PR.

Still outstanding: the agent eval. This change alters which tools the model is offered and what the system prompt says about them, so it needs a gaia eval agent run against the committed baseline before merge — that has to happen on the maintainer's hardware.

🔍 Technical details
  • src/gaia/agents/base/project_map.py — has_shell_tool now comes from a _shell_tool_offered() helper that prefers _active_tool_filter and falls back to _tools_registry when no filter is set. Two tests in tests/unit/test_project_map.py cover both directions of the filter.
  • hub/agents/gaia/python/tests/test_shell_in_code_repos.py — the explicit_root=False parametrization is replaced by test_no_project_at_all_earns_no_shell, which monkeypatches GaiaAgent._project_map_root to return None (resolve_project_root has its own tests), plus a config/env parametrized case for a real non-repository root. Both assert run_python is present and execute_python_file is not, so a full-registry fallback can't masquerade as a pass.
  • The changelog claim: SidecarManager._resolve_argv returns {} as the Popen kwargs in user mode (only --dev-src-dir sets a cwd), and _spawn_process merges env but never a working directory. The npm spawnSidecar path does inherit the Node caller's cwd, which is why the claim was half-true rather than wrong.
  • Eval command for whoever runs it: gaia eval agent --category rag_quality --agent-type doc, then gaia eval agent --compare tests/fixtures/eval_baselines/<model>/scorecard_rag_quality.json <run-dir>/scorecard.json.

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Replicated as #4376 on a branch we can push to — fork push access (kovtcharov/gaia) was revoked mid-review, so this PR could no longer be refreshed against main. Same content, rebased onto current main (one import conflict: main renamed skill_discovery to skill_catalog, so the new is_code_repository import was folded into main's version). The three fixed review findings are all carried over and verified; the agent eval remains the one outstanding pre-merge gate, and #4376 documents how far I got with it. Closing in favor of the replacement.

kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 28, 2026
…sitory (amd#4376)

Replicates amd#4076 (kovtcharov/gaia fork, push access blocked) onto a
branch this session can push to. No content changes beyond conflict
resolution against current main.

The flagship worked real repositories without a shell. The tool loader
showed `run_shell_command` only when a request sounded like a shell
request, and coding requests usually don't ("skip gfx90a tests on PRs
unless labeled"). On four TheRock CI-fix tasks it never got the shell,
and 181 of its 276 tool calls were `run_python` wrapping a single `grep`
or `sed`. Claude Code took about 20 shell calls per task; GAIA took
65–96 calls. Now, when the session's project is a code repository, the
shell is offered on every turn. Outside a repository nothing changes,
and the shell still asks for approval as before.

**Why not just make the shell always-on everywhere:** its schema is
about 160 tokens on every call, and most flagship sessions (documents,
email, chat) have no use for a shell. Tying it to the workspace spends
those tokens only where they pay off. It's decided once, when the agent
is built, so the prompt prefix stays cache-stable from turn 1.

## Review status carried over

The original review raised four findings. Three were fixed on the branch
and I verified each is present in this replication:

- The project map no longer names a shell the turn didn't offer —
`_shell_tool_offered()` reads `_active_tool_filter` and falls back to
the registry.
- The non-deterministic "no project root" test was split into a
stubbed-root case and an explicit-root case.
- The npm changelog now names `GAIA_PROJECT_ROOT` /
`GaiaAgentConfig(project_root=...)` instead of implying the shell turns
itself on in any repository.

The fourth — **the agent eval — is still outstanding and remains a
pre-merge gate for a maintainer.** See the note below for how far I got.

## Test plan

- [x] `python -m pytest
hub/agents/gaia/python/tests/test_shell_in_code_repos.py
tests/unit/test_project_map.py -q` — 91 passed
- [x] `python -m pytest hub/agents/gaia/python/tests/ -q` — 507 passed,
0 failed
- [x] `python -m pytest tests/unit/ -k "tool_loader or full_tool_bundles
or dynamic_tool or project_map"` — 191 passed, 2 failed; both failures
(`test_harness_runs_and_pins_baseline`,
`test_token_baseline_when_tiktoken_available`) reproduce identically on
a clean `main` checkout
- [x] `python util/lint.py --black --isort` clean
- [ ] `gaia eval agent --category tool_selection` — **could not run
here**, see below

> [!IMPORTANT]
> **The agent eval still needs to run on maintainer hardware, and this
is a tool-schema change, so it is required before merge.**
>
> I did attempt it rather than skipping it. Lemonade and the Claude
judge both work on this machine, and a scenario completes end-to-end
(`known_path_read` PASS 9.8/10). But the eval only runs against *this*
checkout if `PYTHONPATH` is pinned to it — otherwise the installed
`gaia` resolves to an unrelated worktree and measures the wrong code.
With the path correctly pinned, every scenario returns `INFRA_ERROR`
because the eval's MCP bridge cannot start:
`src/gaia/mcp/servers/agent_ui_mcp.py:282` does `from mcp.server import
MCPServer`, but the installed `mcp` package exports `Server`, not
`MCPServer`. That file is untouched by this PR and the same import is on
current `main`, so the eval is blocked by a pre-existing
incompatibility, not by this change.

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants