Skip to content

fix(shell): expand ~ in cd and working_directory, and lead the pipe refusal with its fix - #5724

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/shell-gh-full-access
Oct 24, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/shell-gh-full-access

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Asked to triage PRs "under ~/Work/gaia", GAIA's very first command failed with "Directory not found: ~/Work/gaia" because ~ was taken literally, and it went on to guess other paths. ~ now means your home folder in cd and in a command's working folder, as in any shell. Separately, when a | inside single quotes is refused on Windows (correctly: cmd.exe doesn't treat single quotes as quoting), the error now starts with the fix ("wrap any argument containing '|' in double quotes"), so the cut-off error line in the UI still says what to do.

Part of #5700. The rest of #5700, read-only gh commands refused in a Full access chat, is already fixed on main by #5562. It still reached the user because their desktop app was running an older agent build, which is now #5723.

Test plan

  • pytest tests/unit -k shell: 1593 passed, including new ~ tests for cd and working_directory (both fail on main)
  • python util/lint.py --black --isort: clean
  • Real machine: cd ~/Work/gaia && git log --oneline -1 (the command that failed in the user's chat) now runs and prints the latest commit
  • Eval on the next RC: tool error text changed, so watch gaia_* categories that drive shell commands on Windows
🔍 Technical details
  • _expand_home is applied in _resolve_cd_target (the real cd), _call_cwd (the pre-flight) and at the top of run_shell_command for working_directory. The install-target pre-check already used expanduser, so the pre-check and the run disagreed.
  • _ambiguous_pipe_refusal keeps its hint; only the order of the error text changed.

…efusal with its fix

`cd ~/Work/gaia` failed with "Directory not found" because ~ was taken
literally, though the pre-check beside it already expanded it. The refusal
for a '|' inside single quotes on Windows now starts with what to do, so a
truncated error line still shows it.

Part of amd#5700.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

Making ~ mean the home folder in cd and in a command's working folder is the right fix, and putting the fix first in the pipe-refusal message helps when the UI cuts the line off. One gap: commands that need a one-time approval stop working when their working folder is written with ~.

  • An approved ~ command still gets refused. The approval is saved against the folder exactly as the model typed it (~/proj), but the command now expands ~ before checking it (/home/you/proj). The two no longer match, so after the user clicks Approve, GAIA replies "needs your approval of this exact command first" and the command never runs. Commands that need a specific person to answer have the same mismatch. Fix: expand ~ where the approval key is built, so both sides compare the same path, and add a test for "approve, then run with a ~ working folder".

Real-world evidence

N/A: no evidence bundle was produced for this run. The PR description reports a manual run of cd ~/Work/gaia && git log --oneline -1 on a real machine. Everything about the approval path rests on reading the code: pytest isn't installed on this runner, so I couldn't run my repro.

🔍 Technical details

🟡 One-time and person approvals miss a ~ working directory (src/gaia/agents/tools/shell_tools.py:4530)

note_confirmed_call records _call_key(command, tool_args["working_directory"]), so the key holds the raw "~/proj". run_shell_command reassigns working_directory = _expand_home(working_directory) at the top, and later calls _take_once_approval(command, working_directory) and _take_person_approval(...) (~line 4630) with the expanded path. Because ("cmd", "~/proj") != ("cmd", "/home/u/proj"), a TIER_CONFIRM_ONCE line returns the "needs your approval of this exact command first" refusal, and a _needs_person call stays unconfirmed and can fall into _blanket_approval_refusal. confirmation_args_for_call has the same split: it compares _needs_person against the raw arguments.

The smallest fix that keeps every caller consistent is to normalise inside the key (line 416):

def _call_key(command: Any, working_directory: Any) -> Tuple[Any, Any]:
    """The identity an approval is bound to: this text, in this folder."""
    return command, _expand_home(working_directory) or None

_expand_home is defined further down the module, but it is only looked up when _call_key runs, so the order doesn't matter. For a test, add a ~ case next to test_an_approval_cannot_be_replayed in tests/unit/test_shell_prompt_adversarial.py: set HOME to repo.parent, call note_confirmed_call with working_directory="~/<repo.name>", then run the same call and assert status == "success".

Strengths

  • The pre-flight (_call_cwd), the real cd (_resolve_cd_target) and run_shell_command now expand ~ the same way, which matches the install pre-check that already used expanduser.
  • ~ is expanded before the allowed-paths check, so it can't be used to get around that check.
  • The tests set both HOME and USERPROFILE, so they behave the same on Windows.

…ll runs

The run expands ~ before checking an approval, but the approval was keyed on
the folder as typed, so an approved one-time command with a ~ working folder
was refused as unapproved.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Fixed: approvals are now keyed on the expanded folder (_call_key expands ~ too), so a one-time or person-only approval for a ~ working folder matches the run. Added the "approve, then run with a ~ working folder" test; it fails without the fix. All 1594 shell tests pass.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 24, 2026
Merged via the queue into amd:main with commit 28757d0 Oct 24, 2026
32 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/shell-gh-full-access branch October 24, 2026 20:53
kovtcharov-amd pushed a commit to kovtcharov/gaia that referenced this pull request Oct 26, 2026
…amd#5831)

Anyone who updated from a v0.25.1 release candidate to the final v0.25.1
kept the candidate's agent, so the final release's agent fixes never
reached them. On this Mac, v0.25.1 kept the rc11 build of agent 0.3.1
(`24219ae2…`) instead of the pinned build (`658361d2…`), and asking GAIA
to `cd ~/Downloads` still failed with "Directory not found:
~/Downloads", which amd#5724 fixed. `gaia init` only checked whether *a*
flagship was installed. A candidate's build carries the final version
number, so only the bytes tell them apart. Init now compares the
installed build's hash with the one the hub publishes for this machine,
and replaces and restarts the agent when they differ. The same check
replaces any build the hub no longer publishes, so a newer flagship
release is now picked up on the next `gaia init` too. If the hub can't
be reached, it keeps the working agent and says so.

## Test plan
- [x] `pytest tests/unit/test_hub_prerelease.py`:
  - a candidate's build is replaced and the agent restarted;
  - a hash that differs only in letter case counts as the same build;
  - the published build is kept;
  - an unreachable hub keeps the agent with a warning;
  - an install with no recorded hash is left alone;
  - the published hash uses the same selection as an install.
  The two replacement tests fail on main's code.
- [x] `tests/unit/test_init_command.py`,
`installer/test_init_default_profile.py`, `test_hub_*.py`: 744 passed
- [x] Live on this Mac, after installing v0.25.1 over rc11: init printed
"Replacing the installed 'gaia' agent (0.3.1+v0.25.1-rc11) with the
published build… Stopped the running 'gaia' agent". The installed hash
is now `658361d2…`, matching `binaries.lock.json`, and `cd ~/Downloads
&& pwd` in the Agent UI now prints `/Users/kalin/Downloads`.
- [x] black, isort, pylint (errors only), CI path coverage

---------

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