Skip to content

fix(shell): tell the model the shell rules, read git -C correctly, and stop throttling reads - #3909

Merged
kovtcharov-amd merged 6 commits into
amd:mainfrom
kovtcharov:claude/fix-3737-shell-guidance
Sep 24, 2026
Merged

kovtcharov-amd merged 6 commits into
amd:mainfrom
kovtcharov:claude/fix-3737-shell-guidance

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

The shell tool refused 17% of the agent's tool calls in a 168-run Fireworks benchmark (342 of 2,001), mostly for reasons the model was never told: no &&/>/;, one command per call, and a 3-per-10-seconds burst limit that throttled ordinary reads. Each refusal cost a step and a model round trip, and throttled reads were one of the causes of runs the loop guard ended early. The tool description now states the rules, the operator refusal names the working_directory fix, git -C <path> status is read correctly, and read-only commands no longer hit the burst limit. The allowlist and the operator ban are unchanged; this is orthogonal to #3808.

git config is refused, including read-only forms like git config --get and git config --list. That was already true in the code, but the spec page listed config as an allowed git subcommand; the page is now corrected, so anyone who relied on the doc should expect the refusal. The -c, --config-env and --exec-path global options stay refused too, and the refusal now says why instead of treating the option as the git command.

Test plan

  • New tests/unit/test_shell_guidance_3737.py plus existing shell guardrail and skill binary-grant suites: 330 passed, 1 skipped
  • git -C <allowed> status allowed, git -C <outside> status refused
  • A burst of read-only commands is not throttled; non-read-only commands still are, with rate_limited and wait_time_seconds
  • gaia eval agent — runs in the self-hosted CI job once the branch is pushed to amd/gaia (tool description changes)

Fixes #3737

…d stop throttling reads

The shell tool refused 342 of 2,001 agent tool calls in a Fireworks benchmark,
mostly because nothing told the model the rules: no operators, one command
per call, use working_directory instead of cd &&. The tool description now
says so, the operator refusal points at working_directory, git's global flags
(-C, -c, --git-dir, --work-tree, --no-pager) are skipped before reading the
subcommand, and read-only allowlisted commands are exempt from the
3-per-10-seconds burst limit while the per-minute cap stays.

Fixes amd#3737
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents labels Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This makes the shell tool explain its own rules, stops git -C <dir> status from being misread as a -C command, and lets a burst of ordinary reads through the 10-second throttle. The guardrails themselves are unchanged, the new -C/--git-dir/--work-tree paths get the same allowed-paths check the working_directory argument gets, and an unrecognised git global option is refused rather than skipped — that's the right direction on all three.

Three things to settle before merge:

  • The new "here's what you can run" list can talk the model out of commands a skill just granted it. The GitHub-triage skill grants gh and tells the model to run it through this tool; the coding skill grants pytest. The tool now presents a closed list that names neither, and explicitly calls python/pip blocked. A model that believes the tool over the skill will stop trying. One sentence saying a loaded skill can grant extra commands fixes it.
  • The eval hasn't run. This changes a tool description the model reads on every turn, which is exactly the case the project requires an agent eval for, and the test plan marks it pending. Unit tests gate the parsing; only the eval shows whether the new wording actually reduces refusals rather than trading one confusion for another.
  • The spec page still describes the old git parsing — the page walks through reading the subcommand straight out of the second token, which is the behaviour this PR replaced. It also says nothing about global-flag handling or the refused config/exec-path options.

Worth a thought, not a blocker: the burst exemption doesn't raise the ceiling of 10 commands a minute, so a read-heavy orientation phase now reaches that cap in seconds instead of half a minute, and the refusal it gets carries a much longer wait. Whether that's a net win depends on which of the two windows the benchmark refusals actually came from — worth confirming against the run that motivated the change.

Real-world evidence

N/A — no evidence bundle was produced for this PR, and I could not execute the suite here (pytest isn't installed in this review environment), so the verdict rests on static review plus the test plan's own report of 330 passed / 1 skipped. The surface that matters for a tool-description change is gaia eval agent, which the description marks as pending on a combined retest branch. Nothing in the PR demonstrates the agent's refusal rate actually moved.

🔍 Technical details

🟡 Important

1. Tool description contradicts active skill grants (shell_tools.py:1026)

The docstring presents a closed allowlist ("Only read-only commands run without approval: ls, cat, …") and names python/pip as blocked. But hub/skills/github-triage/SKILL.md:10 grants shell:execute:gh and :24 instructs "Run every GitHub command through run_shell_command"; hub/skills/coding/SKILL.md:10 grants shell:execute:pytest. Neither appears in the list, and skill_grant_covers_call runs them without a prompt. The description is the thing the model reads every turn, so it wins ties against the skill body.

            - To run a Python script use execute_python_file; to change files use
              edit_file or write_file — when those tools are available.
            - A loaded skill may grant extra commands (e.g. gh, pytest). If a
              skill tells you to run one, run it — the grant covers it.

2. Agent eval not run for a tool-docstring change

CLAUDE.md lists "tool docstrings" among the surfaces that require gaia eval agent against the committed baseline before merge, and the test plan's eval box is unchecked. The docstring grew from two lines to a twelve-line rules block on a tool the flagship agent loads by default — worth a --category run and a --compare against tests/fixtures/eval_baselines/…/scorecard_*.json before this lands, even if the combined retest branch is where it ultimately runs.

3. Spec page documents the replaced git logic (docs/spec/shell-tools-mixin.mdx:240-255)

The "Git Command Filtering" block still shows git_subcmd = cmd_parts[1].lower() — the exact line _resolve_git_subcommand replaced — and the run_shell_command docstring reproduced at :141-180 predates the new rules text. Per CLAUDE.md, a functional change updates every doc that describes it; only the rate-limit bullet was touched. While there, that block lists config as a safe git subcommand, which SAFE_GIT_COMMANDS does not (pre-existing drift, cheap to fix in the same pass).

🟢 Minor

4. The cd hint can propose a command that is also refused (shell_tools.py:156)

_cd_chain_hint is attached to every refusal the text earns, not just operator refusals, and it echoes everything after the first && verbatim. cd /repo && rm x yields "call again with command='rm x'", and cd /a && ls && pwd yields a command that still contains &&. Both send the model into a second guaranteed refusal. Cheapest fix: emit the hint only when _shell_command_refusal(rest) comes back clean.

5. "Read-only" is really "allowlisted" (shell_tools.py:698)

_is_read_only_command accepts any segment whose base is in ALLOWED_COMMANDS, which includes cd and sysctl — and sysctl -w writes kernel parameters with no argument check in _validate_command. The blast radius is bounded (the per-minute cap still applies, so the DoS ceiling is unchanged), but the docstring's claim is wider than the check. Either say "allowlisted" or gate the exemption on a narrower read set.

6. Unattached short-option form gets a confusing refusal

git -C/tmp status is valid git, but the walk sees -C/tmp as an unrecognised global option and reports "the subcommand behind it cannot be identified". Fail-closed, so not a security issue — just a refusal the model can't act on. Low priority.

Strengths

  • The -C sandbox escape is closed properly: _git_path_flag_values resolves paths the way git does (each -C rebasing the next, --git-dir/--work-tree relative to the last -C), and test_relative_dash_c_escape_is_refused_without_the_arg_scan covers the host that lacks the argument scan — the case where the check actually carries weight rather than being redundant with the existing traversal guard.
  • Unknown git global options are refused rather than stepped over, with the CWE-184 reasoning written down at shell_tools.py:127. That's the correct default for a future git release adding a value-taking flag.
  • _is_read_only_command reuses _shell_command_refusal rather than growing a second parser, so the burst exemption can't drift from the policy it claims to mirror.
  • The test file is genuinely behavioural — it asserts the description contains the rules, that non-read-only commands are still burst-limited, and that reads still hit the per-minute cap. That last one is the test most people would have skipped.

…refused

The shell tool's new rules block read as a closed list, so the model could talk
itself out of a `gh` or `pytest` command a loaded skill had just granted it —
the description is what it reads every turn, and it beats the skill body on a
tie. It now says a skill grant widens the list. The `cd DIR && ...` hint also
stopped proposing commands that are themselves refused: `cd /repo && rm x` used
to answer with "call again with command='rm x'", buying a second refusal.

Also renames the burst-limit exemption from "read-only" to "allowlisted" —
ALLOWED_COMMANDS carries `cd` and `sysctl`, which are not reads — and brings
docs/spec/shell-tools-mixin.mdx back in line with the code: the git filtering
section still showed the `cmd_parts[1]` parse that `_resolve_git_subcommand`
replaced, listed `config` as a safe subcommand it never was, and reproduced the
pre-rules tool docstring.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

Three distinct bugs are fixed here — git -C DIR status was refused because -C was mistaken for the subcommand; git config (which can write core.pager and execute arbitrary commands) was in the allowlist and should never have been; and a burst of read-only ls/cat calls hit the 3-per-10s cap and throttled the agent. All three are correctly addressed, with 256 lines of tests covering each path.

One behavior change to be aware of: git config is no longer allowed, including git config --get. Agents that used it to read config values will now get refused. This is the right security call — git config without exhaustive flag inspection is a privilege-escalation vector — but the PR description should mention it explicitly for any operators whose agents relied on it.

The _resolve_git_subcommand unknown-flag-refusal strategy (rather than silently skipping unrecognised global flags) is the correct defense against CWE-184 incomplete-allowlisting, and is worth keeping.

No correctness, security, or architecture issues found.

🔍 Technical details

_resolve_git_subcommand / _git_path_flag_values correctness

  • Chained -C chains (git -C a -C b status) resolve correctly: each -C updates base before the next is resolved.
  • --namespace is in GIT_GLOBAL_FLAGS_WITH_VALUE but not _GIT_PATH_FLAGS — correct; it's not a filesystem path.
  • git with no subcommand (len ≤ 1) still passes _validate_command due to the pre-existing if len(cmd_parts) > 1: guard; both old and new code share this gap, and git alone just prints help, so no new risk.

_is_allowlisted_command double-validation

run_shell_command calls _is_allowlisted_command (which calls _shell_command_refusal internally) and then calls _validate_shell_command (which calls it again). This is a minor redundancy, not a bug.

Spec / implementation consistency

The spec shows git_subcmd not in SAFE_GIT_COMMANDS | GIT_TERMINAL_FLAGS (set union); the implementation uses and git_subcmd not in GIT_TERMINAL_FLAGS (two not in checks). These are logically equivalent — no discrepancy.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

The PR description now spells out that git config is refused, --get and --list included. This PR doesn't change that: the code already refused it before this PR. The old spec page was wrong to list config as allowed, and this PR corrects the page, so there's no code change. The eval runs in the self-hosted CI job once a maintainer pushes the branch to amd/gaia.

🔍 Technical details
  • git config behaviour: probed _validate_shell_command on unmodified origin/main and on this branch. git config --get user.name, git config user.name and git config --list return the same refusal on both ("Git command 'config' is not allowed"). config isn't in SAFE_GIT_COMMANDS on main or at the merge base, only in the old docs/spec/shell-tools-mixin.mdx list. The one visible difference is git -c …: main refused it as "Git command '-c' is not allowed", and this branch refuses it via GIT_FORBIDDEN_GLOBAL_FLAGS with the reason. PR body updated to say this.
  • Eval: not run here. It needs the self-hosted CI job, so the box stays unticked (wording updated).
  • Tests: test_shell_guidance_3737.py, test_shell_guardrails.py, test_skill_binary_grants.py: 333 passed, 1 skipped on the current head (2d5fa596).

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Merged main — and most of this PR turned out to be superseded, so the merge shrank it a lot. Please re-read before merging; the scope is no longer what the description says.

#4049 landed a better version of this PR's headline change: the shell tool now allows &&, ||, ; and cd <dir> && cmd, and its description already tells the model so. This branch's description said the opposite ("no shell operators, one command per call") — shipping it as-is would have told the model a rule that is no longer true. Same story for the burst limit: main now waits out the window instead of refusing, which solves the throttled-reads problem a different way.

What survives is the git -C fix, and it is still worth having: on main, git -C /repo status is refused because -C gets read as the git subcommand, so a legitimate read fails. That part is merged, wired in, and green (417 tests across the shell suites).

Suggested next step: retitle/re-describe this as the git -C fix, or close it and let the remaining gap ride on its own issue.

🔍 Technical details

Conflicts were 7 regions in src/gaia/agents/tools/shell_tools.py plus one in docs/spec/shell-tools-mixin.mdx. Resolved by taking main's side everywhere the two disagreed, keeping only the branch-only additions main lacks.

Kept:

  • GIT_GLOBAL_FLAGS_WITH_VALUE / _GIT_PATH_FLAGS / _git_path_flag_values / _git_path_refusal — the global-flag walk and the allowed-paths check on -C, --git-dir, --work-tree.
  • Rewired _git_path_refusal into main's per-step loop next to _path_traversal_refusal, so it now uses each step's own cwd. That is stricter than the branch's original single-cwd call: cd a && git -C b status resolves b against a, the way git does.

Dropped as superseded:

  • _CD_CHAIN / _cd_chain_hint — main's hints now recommend cd <dir> && cmd; the branch's hint argued against it.
  • The run_shell_command docstring rewrite and its doc-page copy — main's is newer and permits the operators.
  • _check_rate_limit(allowlisted=...) and _is_allowlisted_command — replaced by main's _pace_rate_limit. _is_allowlisted_command would also have been broken after the merge: it unpacked _shell_command_refusal as segments, which main changed to steps.
  • The matching doc hunks in shell-tools-mixin.mdx (burst-exemption rows), so the spec matches the code.
  • TestTheDescriptionStatesTheRules, TestOperatorRefusalNamesWorkingDirectory, TestAllowlistedCommandsSkipTheBurstLimit in test_shell_guidance_3737.py — 25 of them asserted behavior main deliberately reversed. TestGitGlobalFlags (13 tests) remains.

One pre-existing bug fixed while trimming: the tests interpolated bare tmp_path into the command string, and shlex.split ate the Windows separators, so test_dash_c_inside_allowed_paths_runs failed and the negative cases passed for the wrong reason. Now shlex.quote-d.

Plain merge commits, no rebase or force-push.

`git -C/tmp status` is valid git, but the global-option walk matches whole
tokens, so it came back as "global option '-C/tmp' is not recognized" — a
refusal naming a flag nobody wrote, with nothing to change. It now names the
spaced form (`-C /tmp`) when the two-character prefix is a known value-taking
flag, and gives the real reason when the prefix is a forbidden one
(`-ccore.pager=evil`). A genuinely unknown option still reads as before.

The attached form stays refused rather than parsed: the `-C` allowed-paths
sandbox runs its own scan over the same tokens, and teaching two parsers to
split a token identically is how that sandbox springs a leak.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Two of the three follow-up nits were already fixed on the branch; the third is fixed in the commit I just pushed.

  • Already done: the cd DIR && ... hint no longer proposes a command that is itself refused, and the burst-limit exemption is named for what it actually checks (an allowlist, which carries a couple of non-reads) rather than "read-only".
  • Just fixed: git -C/tmp status — valid git, since a short option may carry its value attached — was refused with "global option -C/tmp is not recognized", naming a flag nobody wrote and leaving the caller nothing to change. It now says to write the value as a separate word, and an attached forbidden option gets the real reason instead of a shrug. A genuinely unknown option reads as before.

The attached form stays refused rather than parsed, deliberately: the -C allowed-paths sandbox scans the same tokens with its own parser, and two parsers that have to split a token identically is how that sandbox springs a leak. A refusal that tells you the fix costs one turn; a sandbox gap costs more.

🔍 Technical details
  • src/gaia/agents/tools/shell_tools.py — new _unrecognized_git_option_error(name), called from _resolve_git_subcommand's fall-through. It checks name[:2] against GIT_FORBIDDEN_GLOBAL_FLAGS first (so -ccore.fsmonitor=evil reports the -c reason), then GIT_GLOBAL_FLAGS_WITH_VALUE (so -C/tmp gets write '-C /tmp'), then falls back to the original text. Exact-token matches are handled earlier in the walk and never reach it.
  • _git_path_flag_values is untouched — that is the parser the -C sandbox check uses, and it is the reason the attached form is not being taught to split.
  • Three tests added to TestGitGlobalFlags in tests/unit/test_shell_guidance_3737.py, one per branch. python -m pytest tests/unit/test_shell_guardrails.py tests/unit/test_shell_guidance_3737.py tests/unit/test_skill_binary_grants.py -q → 420 passed.
  • The commit is a cherry-pick onto the branch's current tip, which had picked up a merge from main since the review.

Left behind when the callback path was removed; pylint W0611 and flake8
F401 both flag it, which reds the Code Quality gate.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 24, 2026
Merged via the queue into amd:main with commit 68162fe Sep 24, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(shell): the shell tool wastes 16% of the agent's steps on avoidable refusals

2 participants