Skip to content

fix(ui): show files a shell command deletes as deleted, with Undo - #5561

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/shell-deletes-in-changes
Oct 23, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/shell-deletes-in-changes

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

When the agent deleted a file with a shell command (del notes.txt, rm notes.txt, Remove-Item notes.txt), the turn's Changes view only said it ran a command GAIA can't track, and Undo couldn't bring the file back. Now a plain delete of named files in the workspace shows each file as deleted, with its old contents in the diff, and Undo this turn restores it. A delete GAIA can't read exactly (a wildcard, a variable, a folder, a file outside the workspace, or extra steps on the line) still shows as untracked shell work, so Undo never claims more than it has.

Relayed (desktop) chats get this once #5553 lands: the shell tool records into the same turn recorder the sidecar opens there. On main today, relayed turns record nothing at all, shell or otherwise.

Test plan

  • pytest tests/unit/test_shell_undo_marks.py: del/rm of a workspace file shows as deleted by run_shell_command, with no untracked entry, its old text in the diff, and restore_turn puts it back. del *.txt stays untracked with no files. Deleting a file outside the allowed paths stays untracked and isn't recorded as restorable. A copy that fails leaves the file and doesn't run the command.
  • pytest tests/unit/agents/test_shell_deletes.py: which delete forms are read (cmd, sh, PowerShell) and which are left as unknown.
  • On top of fix(ui): show a relayed agent's file changes in Outputs, Changes and Undo #5553's branch, a stand-in sidecar agent that runs the real shell tool with del notes.txt under changes_turn_id: the relayed turn lists the file as deleted, with no untracked work, and Undo restores it. This was a local check only, not added here, because it depends on fix(ui): show a relayed agent's file changes in Outputs, Changes and Undo #5553.
  • pytest tests/unit/test_shell_*.py tests/unit/chat tests/unit/agents -n 4: 7688 passed. There was 1 setup error from a thread left running by an earlier test (test_step_timing), and that test passes when run alone. origin/main also had 1 setup error in the same run, in a different test (test_email_phishing_guard).
  • python util/lint.py --black --isort --pylint --flake8
🔍 Technical details
  • Approach: parse the delete, not diff the tree. A before/after file list can show that a file vanished, but it has no copy of the contents to restore. Copying the whole tree before every command would be unbounded.
  • shell_deletes.split_exact splits a step the way cmd.exe or sh will hand it to the program. It returns None for anything that could expand or re-split: %, ^, !, *, ?, $, backticks, ~, redirections, cmd's ,;= name separators, or single quotes under cmd. delete_operands reads del/erase (/f, /q), rm (-f, -v, --), unlink, and powershell/pwsh running one Remove-Item statement (-Path/-LiteralPath/positional, -Force, -Confirm:$false). Recursive flags, /s, /p, -i, drive-relative paths, ADS/device paths and names Windows trims are all refused.
  • ShellToolsMixin._snapshot_shell_deletes runs where note_untracked("shell", …) used to, after the cancel check and before anything spawns. It calls before_change(path, "run_shell_command") for each operand that is a regular file (not a link), at most 64 MiB, outside credential folders, and inside _path_allowed(..., prompt_user=False). The untracked note is skipped only when every step is a cd or a fully copied delete. A SnapshotError returns NOT_EXECUTED, the same rule the file tools follow.
  • The one-time-approval path (raw shell text) is unchanged. Destructive lines are never offered there anyway.
  • Deletes in the existing turn ledger already come through as change: "deleted" with a diff, and the webui already renders that, so there's no frontend change.

A file the agent removed with `del notes.txt`, `rm notes.txt` or
`Remove-Item notes.txt` showed in Changes only as untracked shell work, so
Undo could not bring it back. The shell tool now reads plain deletes with
literal operands, copies each named workspace file before the command runs,
and records it in the turn like the file tools do. A delete it cannot read
exactly (wildcards, variables, recursion, folders, files outside the allowed
paths, several statements) keeps the untracked label.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

When the agent deletes a named workspace file with a plain shell command (del, rm, unlink, Remove-Item), GAIA now copies the file first, so the turn shows it as deleted with a diff and Undo can bring it back. The parser is deliberately conservative: anything it can't read exactly (wildcards, variables, recursion, folders, files outside the workspace, chained statements) still counts as untracked shell work. If the copy fails, the command doesn't run. I found no blocking bugs.

  • Evidence gap (nudge, not a blocker): the Changes view and Undo are user-visible, but the PR shows only unit tests and describes a local relayed-turn check in prose. Attach the real turn listing (or an Agent UI screenshot) showing a del notes.txt turn as "deleted" and restored by Undo.
  • One small parser edge: for del "a""b", the parser reads two files where cmd.exe may see one. Refusing quotes that touch other text would close it.

Real-world evidence

N/A: there is no evidence-bundle.md for this run, and pytest isn't installed on this runner, so I couldn't run the PR's tests either. The verdict rests on static review plus a direct check of the parser module on edge-case inputs (results below). The rendered Changes/Undo view is still waiting on the strix-halo lane.

🔍 Technical details

Issues

🟡 No surface evidence for the Changes/Undo behaviour. The PR changes what a turn's ledger reports (change: "deleted" + restorable). The unit tests cover the recorder, but the PR body has no captured output from the real surface. A /api/...turns response or a gaia chat --ui screenshot of a deleted-then-restored file would satisfy the rubric. This is a nudge; there is no code defect.

🟢 Adjacent quoted tokens split differently from cmd.exe (src/gaia/agents/tools/shell_deletes.py:48-61). shlex.split(posix=False) turns del "a""b" into ["\"a\"", "\"b\""] → operands a, b. cmd.exe likely hands del a single name. If a and b both exist, covered is True and nothing is noted as untracked, yet the file actually deleted was never copied. This is very contrived, but it's the one way the "Undo never claims more than it has" promise can break. A cheap guard is to refuse "" before splitting, the same way _split_ps_body already does:

    if '""' in text:
        return None
    try:
        tokens = shlex.split(text, posix=False)

🟢 # is not in _POSIX_UNSAFE (shell_deletes.py:27). In bypass mode sh treats rm a.txt #b.txt as a comment, but the parser returns ['a.txt', '#b.txt']. The result is only an extra harmless copy of #b.txt if it exists, so it's not a correctness bug. Adding # would make the parser match sh exactly.

🟢 Doc wording (docs/guides/agent-ui.mdx). On Windows, a bare Remove-Item notes.txt goes to cmd.exe, which has no such command. Only the powershell Remove-Item … form is parsed. Consider writing it as powershell Remove-Item notes.txt so readers aren't misled.

Parser checks run here (loaded the module directly):

'rm a.txt #b.txt'                              -> ['a.txt', '#b.txt']
'pwsh -c "Remove-Item a.txt" -NoExit'          -> None
'powershell Remove-Item -Path'                 -> None
'del "a""b"'                                   -> ['a', 'b']
'powershell Remove-Item -Path a.txt -Recurse'  -> None
'powershell Remove-Item a.txt -Exclude:y'      -> None

Strengths

  • It fails closed in the right places. An unreadable step keeps note_untracked, the copy happens after the cancel check and before anything spawns, and a SnapshotError returns NOT_EXECUTED, the same rule the file tools follow.
  • _restorable_delete_target reuses _path_allowed(prompt_user=False) and _protected_folder on the realpath and skips symlinks and directories. A folder del therefore can't be mistaken for a single file.
  • The tests cover both directions: what gets read, and the cases that must stay unknown on cmd, sh and PowerShell. The end-to-end recorder tests include an actual restore_turn round-trip.

del ab split into two names where the program may read one, so Undo could claim a file it never copied; a cmd line with an empty quote pair is now left untracked. An sh delete with # is left untracked too, since sh reads the rest as a comment. The guide now names the powershell form of Remove-Item, the only one GAIA reads.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Both parser edges are closed, CI is green, and the guide now names the form GAIA actually reads (powershell Remove-Item notes.txt). A cmd delete with adjacent quotes (del "a""b") and an sh delete with # now stay untracked, so Undo never claims a file it didn't copy.

The Agent UI screenshot of a deleted-then-restored file isn't attached yet. It needs a model to choose the delete on a real-inference machine. The recorder tests run a real del/rm through the shell tool and restore it with restore_turn.

🔍 Technical details
  • _split_windows returns None when the line contains "", the same guard _split_ps_body uses. # was added to _POSIX_UNSAFE.
  • New cases in test_shell_deletes.py: del "a""b", del "a""", and rm a.txt #b.txt all give None.
  • Local: test_shell_deletes.py and test_shell_undo_marks.py give 50 passed. tests/unit -k "shell or permission or confirm or setup or empty_answer or snapshot or undo" gives 2661 passed, with 3 shell tests that fail on this Windows box on main as well. Black and isort are clean.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Checked live in the Agent UI: the file deleted by del shows in Changes as deleted with its old contents, and Undo put it back byte for byte.

Changes lists the shell-deleted file

🔍 Technical details

Same live build as #5562 (with #5553 for relayed recording), Fireworks DeepSeek V4 Flash, relayed desktop chat. After the turn: "Changed 1 file · Review changes · Undo this turn"; Outputs listed notes.txt as "File deleted"; Undo restored heron notes: keep me. After-undo screenshot: https://raw.githubusercontent.com/kovtcharov/gaia/kalin/agent-ui-test-pass-evidence/agent-ui-test-pass/p2-after-undo.jpg

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
Merged via the queue into amd:main with commit 5191449 Oct 23, 2026
36 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/shell-deletes-in-changes branch October 23, 2026 07:16
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.

2 participants