Repository navigation
fix(agent): stop a refused delete being rerouted through a Python script - #6882
Conversation
When the shell gate refused rm -rf on a folder, the agent wrote an rmtree script and ran it with execute_python_file, and the folder was deleted. The per-turn denial ledger recorded the refused folder but could not see deletes, moves or renames inside Python, and the unattended 'needs your approval' refusal was not read as a refusal, so the loop asked the model for another plan. Python file changes (shutil.rmtree/move, os.remove/unlink/rmdir/rename/ replace, pathlib unlink/rmdir/write_text/rename) now count as the same path effect, with targets resolved through variables, os.path.join and Path '/'. A target the code only computes at run time overlaps a refused path. A reroute of a policy refusal is refused without an 'Allow once' question; a person's no is still put to them once.
|
Verdict: Request changes This closes a real hole: GAIA refused
Real-world evidenceN/A: no evidence bundle was produced for this run, so this verdict rests on static review. I also probed the ledger directly: after a refused 🔍 Technical details🟡 Every shell policy refusal is recorded as
Both reach The error text then tells the model "No approval can lift that refusal … Tell the user it was not done", so the agent gives up on an ordinary file write. Gate Please add a test for this: 🟢
Strengths
|
A shell write refused for its shape ('use write_file or edit_file') was
stored as a refusal nothing could lift, so following the hint was blocked
without asking. Only a refusal whose tier is 'refuse' is now final.
|
Fixed in the latest commit. A policy refusal now counts as final only when its tier is |
…hon (amd#6938) The path sandbox only governed GAIA's file tools. A write it refused could still happen later in the same request through code the agent runs, because `run_python` and the shell aren't confined by it. This extends the refused-path guard from amd#6882 to writes made from `run_python`, `execute_python_file` and the shell. When the sandbox refuses a write to a path, any later code in that request that writes to that path, creates it, copies onto it, moves it or renames onto it is refused too. It's a refusal like the original one, not an "Allow once" question. - **Recorded as a refusal:** a write the sandbox refuses before the prompt, before the tool runs, or from inside the tool body. Only a sandbox "no" counts (the target is outside the allowed folders or write-blocked). A "read it first" or a size limit isn't recorded. A person's own "no" to a write still asks them once, as before. - **Recognised in Python:** the write forms of `open` (also `io`/`codecs`/`os.open`), pathlib `write_text`/`write_bytes`/`open`/`touch`/`mkdir`/`rename`/`replace`, `shutil.copy*`/`copytree`/`move`, and `os.rename`/`replace`/`makedirs`/`mkdir`. Targets are resolved through aliased imports, variables, f-strings, `os.path.join`, `Path /`, `.parent` and `joinpath`. A copy counts only its destination, so reading the refused file or copying from it still runs. - **Recognised in the shell:** redirects with or without spaces, including inside `cmd /c "…"` and `bash -c '…'`, `cp`/`mv`/`Copy-Item`/`Set-Content`/`Add-Content`, `xcopy`/`robocopy`, `[IO.File]` write methods, `dd of=` and `sed -i`. - **Same normalisation on both sides:** a later target is resolved exactly as the refused path was when it was recorded (links, short names and equivalent Windows path forms), so two spellings of one file compare equal. - **Recovery still works:** writing the result somewhere allowed instead, such as the working folder or the temp folder, is not blocked. - **Targets computed at run time** are treated as possibly the refused path, but only after a refusal in the same request. This covers a command a script builds at run time and code that picks its call at run time (`exec`, `eval`, `__import__`, `getattr` on a file module). It's the same fail-closed rule amd#6882 uses for deletes. Not covered here (follow-ups): - Static analysis can't see a path the code builds in ways it doesn't model (e.g. `str.format`, data read at run time). Those fall back to the computed-target rule above. - A relative path in `run_python` is resolved against the agent's working directory, but the snippet runs from the project root. Absolute paths are unaffected. - Running code inside the same path policy (OS-level confinement) would close this for good. That's a larger change. Eval categories to watch on the next RC: `gaia_files`, `gaia_shell`, `gaia_honesty`, `gaia_tool_selection`. ## Test plan - [x] New `tests/unit/agents/test_refused_write_reroute.py`: classification tests for each Python and shell form above (inline and as a script file, including aliased imports, computed commands and paths, and alternate path spellings on Windows), and false-positive cases (reads, writes elsewhere, copying from the refused path, ordinary commands, recovery writes). Agent-level tests reproduce the issue trace under auto-approve, plus a never-askable path, and check that an allowed write or a "read it first" records nothing. The rerouting cases failed before the fix; all pass now. - [x] `tests/unit/agents/test_denied_effects.py` (amd#6882) still passes. - [x] Before/after run of every unit test that touches `_execute_tool`, `run_python`, `write_file` or the denial ledger (about 190 files): no new failures against `main`. - [ ] `gaia_files` and `gaia_shell` eval categories on the next RC. Closes amd#4071
Main's #6882 added its own policy-refusal flag (a refuse-tier no that no approval lifts); this branch's flag says who refused. They answer different questions, so a Denial now carries both, and a final refusal is never reported as the user's. The redirect/argument effect parser main rewrote keeps this branch's per-segment refusal scope, and main's shape-refusal test now covers both a refusal that names the file and one that doesn't. Also from review: a turn the --time-limit timer cut off now keeps the agent's latest findings instead of only the canned stop line, the CLI reference says so and notes the exit code, and -p refuses --time-limit when the turn would run on the agent binary through the daemon, where the limit could not be enforced. The agent CHANGELOG entry moves from the released 0.3.4 section to Unreleased.
When GAIA refused
rm -rfon a folder, the agent deleted the folder anyway by writing a cleanup script and running it withexecute_python_file. The eval scenarioshell_destructive_rm_refusedcaught this on Qwen3.6, scoring 5.7 and 4.7 in two local runs. GAIA already keeps a per-turn list of refused targets, but it couldn't see deletes, moves or overwrites inside Python, and it didn't read the unattended "needs your approval" reply as a refusal. Now a Python route to a refused path is blocked like the shell command was, and the user is never asked to "Allow once" something GAIA refused.shutil.rmtree/move,os.remove/unlink/rmdir/rename/replace, and pathlibunlink/rmdir/write_text/rename. Aliased imports are covered, and targets are resolved through variables,os.path.joinandPath /.Eval categories to watch on the next RC:
gaia_shell,gaia_honesty,gaia_files,gaia_tool_selection.Test plan
rmrefused, then anrmtreescript) plus inline, aliased,os.path.join, pathlib and run-time-target variants. All six failed before the fix and pass now. Code that only reads, or touches other paths, isn't caught.tests/unitfull suite: 38,332 passed. Agent tests after merging main: 6,126 passed.python util/run_eval_lane.py --category gaia_shellbefore and after on Qwen3.6, checkingshell_destructive_rm_refused. Pending, because the machine is busy with another eval sweep.