Skip to content

fix(agents): ask before a gated shell command in a Full access desktop chat - #5562

Merged
kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:kalin/full-access-asks-gated-shell
Oct 23, 2026
Merged

kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:kalin/full-access-asks-gated-shell

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

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.py passes. 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 on origin/main too (cat/compound-line tests).
  • Manual: in the Agent UI with the flagship running as a sidecar, set a chat to Full access and ask it to delete a scratch file. A prompt appears. Deny leaves the file; Allow deletes it. git status still runs with no prompt.
  • Eval categories to watch on the next RC: gaia_tool_selection, error_recovery.
🔍 Technical details
  • Over HTTP, Full access sets auto_approve_gated_tools=True with full_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.
  • Now, when the console says a person can answer (answers_confirmations and grants_paths are True, full_access is False, it isn't in background mode, the GAIA_AUTO_APPROVE_TOOLS env var isn't set, and the handler declares asks_past_preapproval), the pre-flight records the call. confirmation_args_for_call adds the reserved NEEDS_PERSON_ARG.
  • SSEOutputHandler.confirm_tool_execution removes the marker before anything is emitted. For a marked call it skips auto-approve, which is the same pattern as the existing widens_scope exception, and it denies when answers_confirmations is False.
  • On the execution path, a call counts as confirmed only if note_confirmed_call recorded 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_tool rejects 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_condition is not marked and still refuses.
  • The sidecar's HTTP routes and schemas don't change, so the OpenAPI spec doesn't need regenerating. What changes is behaviour: under /bypass, a gated shell call on an answerable run now emits needs_confirmation. SPEC.md, SKILL.md and CHANGELOG.md in hub/agents/gaia/npm describe it.

…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.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

In a Full access desktop chat, a command that needs approval (a delete, git add) used to be refused with "turn on Full access" even though it was already on. Now it gets the normal approval prompt. The fix is narrow and fails closed: the new "a person must answer" mark is only added when a person is actually watching, the model can't add it itself, and the command only runs if the approval was given for that exact command in that exact folder. I found no correctness or security problems.

One thing to add before merge:

  • No proof from the real app yet. This changes what users see in the Agent UI, but the manual check in the Test plan (Full access chat, delete a scratch file, Deny keeps it, Allow deletes it) is still unchecked, and there's no screenshot. Please run it and attach a before/after screenshot of the prompt. The live-sidecar test covers the relay, but not what actually shows on screen.

Real-world evidence

N/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 details

Issues

  • 🟡 Missing Agent UI evidence. This change alters what users see in the Agent UI: /bypass sessions now get a needs_confirmation event where they used to get a refusal. Under the rubric that needs a Playwright run or screenshot against gaia chat --ui. test_full_access_relays_a_gated_shell_prompt_to_the_ui drives the real sidecar relay, which covers the route layer. The rendered modal, and whether the "always" choice shows up for a TIER_CONFIRM call, are still unshown.

What I checked and found sound

  • The approval is tied to the exact call. note_confirmed_call only records _person_approved when the key equals _needs_person. _take_person_approval uses it up and clears both fields on every run. The pre-flight resets both at the start of every shell call, so leftover state from a denied call or a rerouted early return can't approve a later call. A direct tool call still hits _nothing_could_have_confirmed, and test_a_direct_call_on_a_full_access_chat_never_runs_a_gated_command covers that.
  • The marker is reserved in _execute_tool (agent.py:6532). It forces one_time, so a "yes" to the earlier reroute question can't stand in for the real prompt. SSEOutputHandler.confirm_tool_execution strips it before scripted_user, grant_scope, and the emitted args. The test asserts there's no marker on the wire.
  • The marked call only skips auto-approval. An earlier "always" grant (call_is_granted) still answers it, which is correct because a person gave that grant. _a_person_answers excludes full_access, background_mode, and GAIA_AUTO_APPROVE_TOOLS. Only SSEOutputHandler declares asks_past_preapproval, so the TUI console and other consoles are untouched.
  • Docs: the claim is updated together in SPEC.md §5.5, SKILL.md, and CHANGELOG.md. README.md and the /bypass route docstring make no claim that contradicts the new behaviour, and the routes and schemas are unchanged, so no OpenAPI regeneration is needed.

Strengths

  • It reuses the existing widens_scope exception pattern for pre-approval instead of adding a parallel gate.
  • The tests cover both sides: allow and deny, the one-time line asked only once, safe commands still running unasked, and every unattended path (unwatched run, env var, direct call, marker passed by the model) still refusing.
  • The PR names the eval categories to watch (gaia_tool_selection, error_recovery) on the next RC, as required for a tool-confirmation change.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

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.

  • Unit Tests (Linux): only test_redaction_stays_fast_on_dense_escapes failed (2.01s against its time limit). That same test failed the same way on two unrelated branches this week, and it passes locally. A maintainer needs to rerun the job; my account can't rerun runs in amd/gaia.
  • Agent UI screenshot: not attached yet. It needs a model to choose the delete on a real-inference machine. The Test plan item stays unchecked until that run.
🔍 Technical details
  • Same flake elsewhere: runs 39806581829 (claude/gaia-electron-app-icons-3714ec, 2.52s) and 39678500932 (feat/eval-prompt-cache, 2.29s). Main's latest Unit Tests run (39836785127) is green.
  • Local on this branch: test_relay_tool_confirmation.py, test_shell_prompt_instead_of_refuse.py and test_stdio_hung_server.py give 311 passed. test_an_outside_path_is_named_and_approved_before_the_run was deselected because it fails on this Windows box on main as well; it passes in CI.
  • gh run rerun 39840882827 --failed returned "Must have admin rights to Repository".

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Checked live in the Agent UI: a Full access desktop chat now asks before a gated delete, and runs it only after Allow once.

Full access chat asks before del

🔍 Technical details

Build: 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 fireworks.deepseek-v4p1-flash. Asked "delete notes.txt in your documents folder with del" in Full access. The prompt showed the exact command (del "…\.gaia\documents\notes.txt") with Allow once / Deny; after Allow once the file was gone. A delete outside the chat's folders is still never offered (by design).

kovtcharov-amd pushed a commit that referenced this pull request Oct 23, 2026
…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
auto-merge was automatically disabled October 23, 2026 08:30

Head branch was pushed to by a user without write access

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Merged current main in; one conflict, and the tests pass.

  • gaia npm CHANGELOG: this PR's "Fixed" entry and main's new "A tool result keeps the tool's own status" entry both landed under Unreleased. Kept both. Neither bumps the contract, so 2.19 stands.
  • The shell, confirmation gate and SSE handler merged cleanly. Main's change to send only the model's arguments in needs_confirmation (fix(serve): send only the model's tool arguments in needs_confirmation #5645) and this PR's reserved approval marker touch separate paths, so the marker never reaches args.

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.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
Merged via the queue into amd:main with commit 2547e81 Oct 23, 2026
40 of 41 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/full-access-asks-gated-shell branch October 23, 2026 12:21
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 25, 2026
…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>
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