Skip to content

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

Merged
kovtcharov-amd merged 5 commits into
mainfrom
replicate/shell-in-code-repos-4076
Sep 28, 2026
Merged

kovtcharov-amd merged 5 commits into
mainfrom
replicate/shell-in-code-repos-4076

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Replicates #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

  • python -m pytest hub/agents/gaia/python/tests/test_shell_in_code_repos.py tests/unit/test_project_map.py -q — 91 passed
  • python -m pytest hub/agents/gaia/python/tests/ -q — 507 passed, 0 failed
  • 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
  • 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.

Kalin Ovtcharov and others added 2 commits September 25, 2026 13:20
…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.
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 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
hub/agents/gaia/npm ✅ ALLOW experimental experimental 1 high body.injection.credential_request

✅ All audited skills cleared the tier they claim.

Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the skill-audit-reports artifact from this run. Offending source text is withheld from CI everywhere — reproduce it locally with gaia skill audit <dir> --show-snippets.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions — conditional on the agent eval

When the session's project resolves to a code repository, the flagship now gets the shell on every turn instead of only when the request happens to sound like one, and the project map stops advertising a shell the turn didn't actually offer. The mechanism is clean: it reuses the root the map already resolved, it's decided once at build time so the prompt prefix stays cache-stable, and the base class default keeps every other agent byte-identical.

The one thing blocking a clean merge is not in the code. This changes the tool schema the model receives, which the project requires an agent eval run for, and that run is still outstanding — the author says so plainly and shows the eval is blocked by an unrelated, pre-existing import error in the MCP bridge that also exists on main. A maintainer needs to run it on hardware (or fix that bridge import first); nothing in this diff can substitute for it.

Two smaller things worth a follow-up:

  • Inside a repository the always-on set grows by one, which quietly takes one slot away from the per-turn selection budget. The comment next to that budget still promises the old number, so the next person tuning it will be working from a stale premise.
  • The changelog tells readers to "See SKILL §11" for this behaviour, but that section only explains how the project root is chosen — it never mentions the shell. A reader who follows the pointer won't find what they were sent for.

Real-world evidence

An evidence bundle ran and is substantive. It boots the flagship sidecar from this branch: gaia agent health gaia returns healthy, the daemon starts it in dev mode, and /health, /version, /v1/gaia/version all return 200. The useful part is the live contrast on the gate itself — with the project root on a repository, a real POST /v1/gaia/query produced

[project-map] indexing /home/runner/work/gaia/gaia in the background

while the identical request against a plain directory produced zero [project-map] lines. That is the change's trigger firing where it should and staying silent where it shouldn't, on the real route. Three adjacent operations were spot-checked alongside and came back clean.

What it does not show, and says so: the actual tools= list sent to the model and the rendered run_shell_command accepts: block, both marked pending strix-halo lane — per-turn selection needs the Lemonade embedder, absent on this runner. So the last link in the chain rests on static review here. That's the expected CI-lane shape rather than a gap I'd block on, but it is the same surface the outstanding eval covers, which is why that gate matters.

🔍 Technical details

🟢 The workspace CORE tool eats a dynamic slot the budget comment still promises

GaiaAgentConfig.dynamic_tools_max = 28 is documented as "15 CORE (FULL_CORE_TOOLS) + 13 dynamic slots … Grows with CORE so the dynamic share stays 13" (hub/agents/gaia/python/gaia_agent/agent.py:181-188). In a repo session CORE is now 16, and ToolLoader.select admits CORE into self._loaded before the len(self._loaded) < self._max_tools candidate loop (src/gaia/agents/base/tool_loader.py:317-370), so the dynamic share is 12 there, not 13. A 6-member bundle still fits, so this is a tuning drift rather than a bug — but the comment is now wrong for exactly the sessions the PR targets.

Either grow the cap with the workspace set:

def _resolve_dynamic_tools_max(self) -> int:
    raw = os.getenv("GAIA_DYNAMIC_TOOLS_MAX")
    if raw is None:
        return int(self.config.dynamic_tools_max) + len(self._workspace_core_tools())
    ...

or leave the number and amend the comment to say the dynamic share is 13 outside a repository and 12 inside one. (If you take the first option, note _resolve_dynamic_tools_max lives in ChatAgent — the union point — so the addition applies to any future workspace CORE, not just the shell.)

🟢 CHANGELOG points at SKILL §11, which doesn't mention the shell

hub/agents/gaia/npm/CHANGELOG.md:95 ends with "See SKILL §11." §11 (hub/agents/gaia/npm/SKILL.md:470-489) covers the map's token cost, the background index, and how GAIA_PROJECT_ROOT / GaiaAgentConfig(project_root=...) pick the root — it never says the shell rides along. CLAUDE.md's doc-sync rule wants the behaviour stated in the docs that describe the surface. One sentence in §11 closes it, e.g. after the "no map" line:

A directory that resolves to a repository additionally makes run_shell_command always-on for the session (it stays confirmation-gated); a non-repository root leaves tool selection entirely semantic.

SPEC.md:319-325 describes the same project-map paragraph and is a reasonable second home for it.

🟢 Nothing pins the base-class default

ChatAgent._workspace_core_tools() returning frozenset() is what keeps every non-flagship profile byte-identical (hub/agents/chat/python/gaia_agent_chat/agent.py:723-729), and the union now sits in the shared base. A future subclass-wide change there would hand the doc profile a shell with no test noticing. A one-liner asserting a plain ChatAgent's loader CORE equals PROFILE_TOOL_CONFIGS[profile].core would fence that off.

Things I checked that are fine

  • ProfileToolConfig.core is a FrozenSet[str] (tool_bundles.py:537), so | is well-typed; ToolLoader takes Sequence[str] and re-freezes.
  • validate_registry can't trip on the new CORE member: register_shell_tools() runs for every profile, including the early-return chat one (gaia_agent_chat/agent.py:1510-1516).
  • get_project_map_system_prompt is already in Agent.VOLATILE_PROMPT_FRAGMENTS (src/gaia/agents/base/agent.py:1116), so making its text per-turn-variable does not move a now-churning fragment into the cached static head.
  • _apply_tool_filter sets _active_tool_filter before recomposing the prompt (agent.py:1953-1962), so _shell_tool_offered() always reads this turn's filter, and an empty-list filter correctly reads as "nothing offered" rather than falling back to the registry.
  • Building the loader in __init__ now resolves _project_map_root() at construction instead of first turn. self.config is already set by then (gaia_agent_chat/agent.py:322 vs :475), so the explicit root is honoured. Side effect worth knowing: a misconfigured GAIA_PROJECT_ROOT now raises from the constructor rather than the first turn — louder and earlier, consistent with the fail-loudly rule, but it will surface as a sidecar boot failure rather than a turn error.
  • The new tests hold up: the embedder stub scores everything zero, and _assert_selection_ran_without_the_shell asserting run_python present / execute_python_file absent is a genuine guard against the full-registry fallback silently passing the negative cases. Stubbing _project_map_root in the "no project at all" case instead of relying on where TMPDIR sits is the right call.

Strengths

  • The fix is at the right altitude: a _workspace_core_tools() hook on the base class with an empty default, overridden only by the flagship. No branching in the loader, no new config surface, and zero behaviour change for every other agent.
  • The second commit is the better half. Making the project map report what the turn offered rather than what the registry owns removes a guaranteed-failed-tool-call class that the dynamic loader had quietly reintroduced — and it's covered both ways.
  • The changelog entry leads with the user-visible outcome and names the GAIA_PROJECT_ROOT caveat, which is the non-obvious part for a sidecar integrator.

Resolves the changelog conflict between this branch's "shell, always on
inside a code repository" entry and main's "sleep, always on" entry by
keeping both as separate bullets.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (the branch had drifted into a real conflict) and picked up the two review nits while resolving it — merge is clean now, but the eval gate is still open.

  • Merge conflict: only the npm CHANGELOG collided (this PR's shell entry vs. main's new sleep entry) — kept both as separate bullets, nothing else needed manual resolution.
  • Dynamic-tools budget: _resolve_dynamic_tools_max() now grows the cap by len(_workspace_core_tools()), so the shell riding along in a repo session no longer quietly shrinks the per-turn selection budget. Comment next to dynamic_tools_max updated to explain both growth paths (bump the literal for FULL_CORE_TOOLS, automatic for per-session workspace tools).
  • SKILL/SPEC §11 pointer: added a sentence to both docs saying the same repository check also makes the shell always-on, so a reader following "See SKILL §11" actually finds it.

On the eval: mcp.server.MCPServer is genuinely missing from the installed mcp 1.27.0 (it moved to mcp.server.mcpserver.MCPServer upstream) — confirmed with a local, uncommitted shim, which got the MCP bridge itself starting. But gaia eval agent --category tool_selection still can't produce a scored run in this environment: the backend's AgentRegistry refuses to instantiate agent_type='gaia' in-process ("runs out-of-process as a daemon sidecar"), and a fresh Agent UI backend couldn't reach the local Lemonade Server either. Both are environment/architecture issues, not this diff — but they mean the eval still needs to happen against a proper harness before merge, same as the PR description already says.

Full tool suite (hub/agents/gaia/python/tests/, 536 tests) and lint pass clean on the rebased branch.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 28, 2026
Merged via the queue into main with commit d7c0655 Sep 28, 2026
39 of 44 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the replicate/shell-in-code-repos-4076 branch September 28, 2026 17:33
itomek added a commit that referenced this pull request Sep 28, 2026
One conflict: main's #4376 added `_workspace_core_tools` at the same anchor
where #4114 added `_profile_registers_tools`. Unrelated methods, both kept.

Re-verified rather than assumed after the merge: the generator still derives
94 tools (CORE 16 + 24 bundles), fast prefill is still 2,860, and the default
moved 17,652 -> 17,620, which the guide and CHANGELOG now say.

main's 4a0a069 raised the tool-description budget to 500 chars, so the
read_tool_output overage this branch inherited is gone — `util/lint.py --all`
is now fully green.
kovtcharov-amd added a commit that referenced this pull request Sep 28, 2026
…profile pins

#4038's docstring trim dropped "call it directly as a tool instead" from
run_python's no-tool-access warning, leaving only what NOT to do without
the actionable alternative -- restored within the same char budget.

Also refreshes test_tool_loader_token_budget.py's doc-profile pins: the
tool count drifted from 39 to 44 (and char/token counts with it) as
today's merges (#3122, #4021, #3335, #3791, #4376, and others) each added
or exposed a doc-profile tool. Re-measured all five values fresh rather
than estimating.
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 29, 2026
Merging main's independent amd#4376 (shell offered whenever the session
works in a repo) reintroduced an older, simpler copy of this method
right after the one this branch already had -- Python keeps only the
second definition, so it silently overrode the version that also puts
delegate_task and the session-findings ledger tool in core when
delegation is on. hub/agents/gaia/python/tests/test_delegate_wiring.py
caught it (delegate_task/session_findings missing from tool_loader._core).
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