Repository navigation
fix(agents): ask before a gated shell command in a Full access desktop chat - #5562
Conversation
…p chat In an Agent UI chat set to Full access, a gated shell command such as a delete or git add was refused outright, so the chat could not run it at all. The relayed sidecar keeps the shell gates on over its socket (amd#3373), and its pre-approval was not allowed to answer for them. Such a command now goes to the person watching the chat: the shell pre-flight marks the call, the confirmation handler asks about it even while tools are pre-approved, and the shell runs it only when that person approved this exact call. Safe commands still run unasked, and unattended runs (GAIA_AUTO_APPROVE_TOOLS, nobody able to answer, background) still refuse.
|
Verdict: Approve with suggestions In a Full access desktop chat, a command that needs approval (a delete, One thing to add before merge:
Real-world evidenceN/A: no evidence bundle was produced for this run, and the Agent UI flow needs a real-inference machine. I couldn't run the tests here either (pytest isn't installed on this runner). This verdict comes from reading the code only. Running the Agent UI prompt and screenshotting it is still pending (strix-halo lane or the author's manual run). 🔍 Technical detailsIssues
What I checked and found sound
Strengths
|
|
No code changes needed from the review. The one red check is a known timing flake, and the on-screen check of the prompt is still a manual step.
🔍 Technical details
|
|
Checked live in the Agent UI: a Full access desktop chat now asks before a gated delete, and runs it only after Allow once. 🔍 Technical detailsBuild: this branch merged with #5553 and #5561 on top of the integration branch; app, backend and gaia-agent binary built from one commit; fresh profile; model |
…5610) Four timing-sensitive unit tests failed 8 unrelated PRs this week (#5537, #5539, #5562, #5563, #5564, #5565, #5566, #5568) and one of main's last 11 completed runs. Each still guards the same bug, but no longer races the clock on a busy runner. Every rewritten test was checked by breaking the code: it fails on the real bug and passes 50/50 runs, including under full CPU load. The PR also keeps three tests out of the developer's real `~/.gaia`. ## Test plan - [x] `pytest tests/unit/mcp/client/test_stdio_hung_server.py tests/unit/test_file_lock.py tests/unit/test_mcp_bridge_concurrency.py tests/unit/chat/ui/test_agent_model_override.py tests/integration/test_folder_indexing.py -n 4`: 316 passed, 3 skipped - [x] The four de-flaked tests, run 50x each: 250/250 serial, and 250/250 under xdist (32 workers) with all 32 cores also running busy loops. Main's versions in that same loaded run: redaction failed 10/50. - [x] Each test fails when its bug is put back in the code (see details) - [x] `tests/integration/test_folder_indexing.py -n 4`, 5 runs: all pass. Main's version fails 7 to 9 tests per run. - [x] Test 841 passes with `GAIA_HOME` set to a temp dir. Main's version fails. - [x] Electron `npx jest`: 1098 passed. The one failure, `test_electron_chat_installer.js` (component size 103,725 > 102,400), also fails on main and is unrelated. - [ ] CI green on Linux, macOS and Windows unit lanes <details> <summary>🔍 Technical details</summary> **`test_redaction_stays_fast_on_dense_escapes`** (Linux, 2.01 to 2.03 s against a 2 s limit) - Cause: an absolute 2 s bound. Locally the worst text takes 0.19 s. On a 4-worker, coverage-traced runner it took about 10x that. - Fix: time one 1M-char text against eight 125K texts with the same total length, on the same machine. Linear code scores about 1.0 and a quadratic scan scores 8, so the test asserts < 3. It takes the best of up to three paired runs, and uses the lower of the wall-clock and CPU (`thread_time`) ratios. Contention inflates wall time, and Windows samples CPU time on ticks. The test also fails if the 1M text takes more than 15 s of CPU, which catches a per-position rescan: that is linear but takes minutes. - Break checks: a quadratic prefix copy in `_candidate_windows` (`len(text[:start].rstrip("\\"))`) gives a ratio of 5.9x and the test fails. Main's 2 s test passed that same regression locally (1.57 s). A per-anchor rescan without merging takes 56 s and hits the 15 s ceiling. **`test_children_of_an_exited_server_are_still_stopped`** (Linux) - Cause: the test slept a fixed 2 s for the child watcher. The watcher backs off (0.5, 1, 2, 4 s…), so on a slow start its next scan came after the launcher had exited and the child was never recorded. - Fix: poll until `child_pid in transport._children`, with a deadline of 3 × `_CHILD_SCAN_MAX_S`. - Break checks: never recording children fails with "never recorded". Clearing `_children` before stopping fails with "kept running". Delaying the watcher's first scan by 2.5 s reproduces the CI failure on main's test, and the new test passes. - Note for the product side: a launcher that spawns a child and exits inside a backoff window still orphans that child. Real `npx`/`uvx` launchers outlive the window. **`test_the_next_waiter_takes_the_lock_within_milliseconds`** (macOS, median 6.5 to 8.1 ms against 5 ms) - Cause: macOS stretches `sleep(0.001)` under load, and the 5 ms median left no headroom. - Fix: the test wraps `_poll_interval`, which records each interval and signals the moment the waiter starts a poll's sleep. The lock is released right then, so the whole interval stands between the waiter and the lock. - Assertions: every interval the front waiter asks for is ≤ 2 ms, and the median hand-off is < 15 ms. A 20 ms poll always waits at least 20 ms, so it fails the median even with the bound widened. - Break checks: `_NEXT_POLL_SECONDS = 0.02` or `0.1` fails the interval assertion. Sleeping `_POLL_SECONDS` directly, so `_poll_interval` is bypassed, fails the median (20.8 ms). **`test_a_dropped_idle_connection_is_logged[True]`** (Linux) - Cause: the test asserted that `"Traceback"` was absent from the stderr captured by `capsys`. The traceback in that run came from a fake Lemonade server that `test_lemonade_shared_server.py` left running on the same xdist worker (`BrokenPipeError`). - Fix: the `serve` fixture records the bridge server's own `handle_error` calls, and the test asserts that list is empty. socketserver calls `handle_error` before it closes the connection, so the check doesn't race. A plugin that writes a traceback to stderr during the test fails main's version and passes the new one. - Break check: making `log_error` also call the base `log_error`, and reverting `str(args[0])`, raises `TypeError` in the handler, and the test fails. **Isolation fixes** - `test_folder_indexing.py`: `temp_folder` now lives in `isolated_gaia_home`, a per-test fake home, so `ensure_within_home` still admits it. Parallel workers no longer share or delete `~/.gaia/test_temp`. - `test_issue_841…`: the test now sets `GAIA_HOME` itself, so an inherited value can't override the patched `Path.home`. - `tests/electron/setup.js`: `os.homedir()` points at a per-file temp dir. It is assigned rather than spied, so `jest.restoreAllMocks()` can't undo it. Setting `HOME` would not work, because Jest's sandboxed `process.env` never reaches `os.homedir()`. - The "Ignoring invalid agents section in …\.gaia\tray-config.json" log came from `crash-loop-notification.test.cjs`, which mocks `fs` with a config the validator rejects. The real file was never read, but the path now names the temp home. </details>
# Conflicts: # hub/agents/gaia/npm/CHANGELOG.md
Head branch was pushed to by a user without write access
|
Merged current main in; one conflict, and the tests pass.
Tests: this PR's tests plus the shell, confirmation, permission, relay, SSE and chat/ui suites (3728 passed, 51 skipped). Black and isort are clean. |
…efusal with its fix (amd#5724) 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 amd#5700. The rest of amd#5700, read-only `gh` commands refused in a Full access chat, is already fixed on main by amd#5562. It still reached the user because their desktop app was running an older agent build, which is now amd#5723. ## Test plan - [x] `pytest tests/unit -k shell`: 1593 passed, including new `~` tests for `cd` and `working_directory` (both fail on main) - [x] `python util/lint.py --black --isort`: clean - [x] 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 <details> <summary>🔍 Technical details</summary> - `_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. </details>

Before: a desktop (Agent UI) chat set to Full access couldn't run a delete,
git add, or any other command that needs approval. GAIA refused it and told the user to turn on Full access, which was already on. After: GAIA shows the normal approval prompt for that command (Allow once / Deny, plus "always" where it's offered) and runs it only if the user allows. Commands that never need approval still run without asking, and a command that needs approval still never runs unasked through the desktop app's agent connection.This replaces #5555, which only reworded the refusal. That case now gets a prompt, so #5555 can be closed.
Test plan
pytest tests/unit/test_shell_prompt_instead_of_refuse.py tests/unit/test_relay_tool_confirmation.pypasses. New cases cover: a Full access chat asks about a gated command and runs it only after Allow; Deny means it doesn't run; a one-time line is asked once; a safe command runs unasked; an unwatched run,GAIA_AUTO_APPROVE_TOOLS, and a direct tool call all still refuse without prompting; the model can't pass the marker itself; the live sidecar relays the prompt to the Agent UI and acts on its answer.pytest tests/unit -k "shell or permission or confirm or approval or relay" -n 4: the same 3 Windows-only failures fail onorigin/maintoo (cat/compound-line tests).git statusstill runs with no prompt.gaia_tool_selection,error_recovery.🔍 Technical details
auto_approve_gated_tools=Truewithfull_access=False, so the shell gates stay on (feat(shell): let --bypass-permissions lift the shell operator block #3373). The shell pre-flight used to refuse every gated call when the only approval on hand was blanket.answers_confirmationsandgrants_pathsare True,full_accessis False, it isn't in background mode, theGAIA_AUTO_APPROVE_TOOLSenv var isn't set, and the handler declaresasks_past_preapproval), the pre-flight records the call.confirmation_args_for_calladds the reservedNEEDS_PERSON_ARG.SSEOutputHandler.confirm_tool_executionremoves the marker before anything is emitted. For a marked call it skips auto-approve, which is the same pattern as the existingwidens_scopeexception, and it denies whenanswers_confirmationsis False.note_confirmed_callrecorded an approval for exactly that(command, working_directory). A direct tool call, or a call whose approval was auto-approved, is still refused by_nothing_could_have_confirmed._execute_toolrejects the marker if the model sends it, and treats a marked call like a one-time call, so the reroute question can't stand in for the real prompt.wait_for_conditionis not marked and still refuses./bypass, a gated shell call on an answerable run now emitsneeds_confirmation.SPEC.md,SKILL.mdandCHANGELOG.mdinhub/agents/gaia/npmdescribe it.