Skip to content

fix(ui): stop an Agent UI turn only when it makes no progress - #5200

Merged
kovtcharov-amd merged 2 commits into
mainfrom
fix/agent-ui-no-turn-cap
Oct 16, 2026
Merged

kovtcharov-amd merged 2 commits into
mainfrom
fix/agent-ui-no-turn-cap

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Before: the Agent UI cut off every turn after 10 minutes of agent time, even while the agent was still working, and told the user "The request was stopped before it finished" as if they had pressed Stop. Long script and document tasks lost their deliverables. After: a turn runs as long as it keeps making progress. A running tool or a prompt waiting on you never counts as idle, and a silent model is still ended by the existing stall check. GAIA stops a turn only after 75 minutes with no progress, and then says so: "This turn ran for 75 minutes without progress, so GAIA stopped it. … Send "continue" to pick up where it left off." Stop keeps its own wording. API clients that don't stream had their own fixed 10-minute cap, and it now follows the same rule.

Fixes #5177. GAIA_STREAM_TIMEOUT keeps working; it now sets the no-progress window.

Test plan

  • python -m pytest tests/unit/chat/ui/test_turn_idle_limit.py tests/unit/chat/ui/test_user_input_stream_clock.py tests/unit/chat/ui/test_run_outlives_timeout.py tests/unit/chat/ui/test_stop_done_event.py tests/unit/test_stream_timeout_env.py tests/unit/agents/test_verification_scope.py. These run real turns on a fake clock: 25 minutes of steady progress, a 40-minute silent tool run, and a 40-minute permission wait are not stopped. A silent turn is stopped with the honest message, whether it stops at a step boundary or mid-generation. Stop still says "Cancelled.", the window is configurable, and a worst-case model stall ends through the stall check, not this limit.
  • In the Agent UI, run the ~11-minute script prompt from fix(ui): Agent UI ends any turn after 10 minutes of work and says the request was stopped #5177 and allow both prompts. The turn finishes, progress.log has 22 lines, and summary.txt is written.
  • python util/lint.py --black --isort

A turn was cut off after 600 s of agent time even while it was working, and
the user was told "The request was stopped before it finished", the same words
as pressing Stop. Long document and script tasks lost their deliverables.

Now a turn has no time limit while it makes progress: any agent event counts,
and a running tool or a prompt waiting on the user is never idle, since each
has its own deadline. A turn is stopped only after 75 minutes with no progress
(GAIA_STREAM_TIMEOUT, now a no-progress window), which is longer than the LLM
layer lets any single model call stay silent, so a stalled model is still ended
by the stall check. The stopped turn says which limit ended it and how to
continue; the agent is told the reason through its cancel signal, so its own
answer and history say it too. The non-streaming chat path had its own fixed
600 s cap and now follows the same rule.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents labels Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Agent UI turns are no longer cut off at 10 minutes while the agent is still working. A turn is now stopped only after 75 minutes with no progress, and the user is told why instead of seeing the generic Stop wording. Non-streaming API clients follow the same rule. The live evidence confirms both chat paths stop on a stalled backend and save the new message, and the logic looks sound. One edge case is worth a follow-up:

  • A tool call the agent rejects as a repeat stays marked "running". When the agent rejects a repeated tool call, it never closes the tool's "running" mark. For the rest of that turn the no-progress limit can't fire, so only the model-stall check can end a stuck turn. That is a backstop, not a failure, so this doesn't block merge.

Real-world evidence

From the evidence bundle (PR head 1334a224, fake Lemonade that stalls 20 s and then returns 503, GAIA_STREAM_TIMEOUT=5):

POST /api/chat/send  stream=false
{"message_id":5,"content":"This turn ran for 5 seconds without progress, so GAIA stopped it. Anything it finished before then is kept. Send \"continue\" to pick up where it left off.","sources":[],"tokens":null}
HTTP 200  elapsed 85.94s
[11:50:39] ERROR _get_chat_response | Chat turn made no progress for 5s; stopping it

POST /api/chat/send  stream=true
data: {"type": "agent_error", "content": "This turn ran for 5 seconds without progress, so GAIA stopped it. …"}
data: {"type": "answer", "content": "This turn ran for 5 seconds without progress, so GAIA stopped it. …"}
data: {"type": "done", "message_id": 7, …}
HTTP 200  elapsed 68.14s

On the base commit, the non-streaming path ignored the limit and ran for 156 s. Bad GAIA_STREAM_TIMEOUT values (abc, 0, 90000) stop the server at startup with an actionable error. In the spot checks, /api/health returned 200, the session was released (/api/chat/active was empty), and the stop message was saved to the session.

What wasn't tested:

  • The positive case. A long turn that keeps making progress and runs past the limit needs real inference, so it rests on the PR's fake-clock unit tests.
  • The Agent UI screenshot. This is pending the strix-halo lane.
  • A worker thread that never returns. The bundle notes that this holds the HTTP request and the session open indefinitely. The cause is the existing "session lock outlives the worker" wait, which this PR doesn't change, and base wasn't run with that setup.
  • The unit tests. I couldn't run them here (no pytest on this runner), so they rest on CI.
🔍 Technical details

🟡 Rejected repeat tool call leaves the tool marked as running (src/gaia/agents/base/agent.py:~10211-10243, native tool path)

  • print_tool_usage(tool_name) fires before the repeat check. On the first repeat, the loop-correction branch continues without calling pretty_print_json(..., "Tool Result") or print_tool_complete().
  • Streaming: SSEOutputHandler._tool_start_time stays set, so tool_running() returns True.
  • Non-streaming: _ActivityConsole.tool_running stays True.
  • Either way, _TurnIdleClock.idle_for(owned_wait=True, …) resets on every poll until a later tool completes. For the rest of that turn, only the LLM stall check bounds it.
  • Fix: call self.console.stop_progress() and self.console.print_tool_complete() before that continue. That also closes the dangling tool_start card in the UI. Better still, move the repeat check ahead of print_tool_usage.
  • A test that runs a repeat-rejected call followed by a silent model, and asserts the turn still stops, would pin this down.

🟢 The non-streaming path counts only print_tool_complete as a tool's end (src/gaia/ui/_chat_helpers.py, _ActivityConsole)

  • The streaming handler also clears on the tool result (pretty_print_json). Any agent path that prints a result but skips print_tool_complete would leave the non-streaming turn marked "running".
  • Clearing on pretty_print_json(_, "Tool Result") as well would match the SSE semantics.

🟢 The non-streaming worker has no deadline after the turn is stopped

  • After the turn is stopped, finally: await asyncio.wait({worker}) has no deadline, so a wedged worker holds the HTTP request open indefinitely. The evidence bundle shows exactly this.
  • This behaviour isn't new, but the fixed 600 s cap used to make it rarer.
  • Worth tracking separately, since the fix is a design call: return to the client and keep holding the lock in the background.

Strengths

  • TurnCancel subclasses threading.Event, so every existing cancel_event.set() and is_set() caller keeps working. The agent picks up the reason through getattr(cancel_event, "message", None), which leaves the plain-stop wording unchanged.
  • The tests run real turns on a fake clock and cover both directions:
    • should not stop: steady progress, a long silent tool, a long permission wait.
    • should stop: a silent turn at a step boundary or mid-generation, the user's Stop.
  • They also pin the default window above the LLM layer's maximum request budget, so a silent model is always ended by the stall check first.
  • The docs (agent-ui.mdx) were updated in step with the behaviour and the new default.

A call the repeat guard refused to run stayed marked as running, so for the
rest of the turn the Agent UI's no-progress limit could never fire, and its
tool card spun forever. The refused call now ends with a failed "not run"
result. The non-streaming activity tracker also ends a tool on its result,
the same way the SSE handler does.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Fixed the two code findings in the latest push. The third is pre-existing and left out of this PR.

  • A refused repeat call stayed marked running. Fixed. The repeat guard now closes the call with a failed "not run" result on both the legacy and native paths. The no-progress limit can fire again after a refusal, and the tool card no longer spins. A test runs both paths through a real agent loop and fails without the fix.
  • The non-streaming tracker ended a tool only on complete. Fixed. It now also ends one on its result, the same way the SSE handler does.
  • A wedged non-streaming worker holds the request open. Not changed here. The wait that keeps the session lock until the worker exits predates this PR, and changing it is a separate design call.

@kovtcharov-amd
kovtcharov-amd merged commit 3a38894 into main Oct 16, 2026
51 of 52 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/agent-ui-no-turn-cap branch October 16, 2026 13:38
kovtcharov-amd added a commit that referenced this pull request Oct 16, 2026
…mit (#5201)

The v0.25.0 release notes still say an Agent UI turn is capped at 600
seconds. Since #5200 merged, a turn runs as long as it makes progress
and stops only after 75 minutes without any. This updates that one line
so the notes match what ships.

## Test plan
- [x] `python util/validate_release_notes.py docs/releases/v0.25.0.mdx
--tag v0.25.0` passes
- [ ] Docs Validation passes on this PR
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Oct 19, 2026
…md#5382)

The Slack and Telegram bridges answer one message at a time and waited
for each answer with no deadline. If the agent went quiet while still
running, every later message on the bridge waited behind it forever. Now
a turn that makes no progress for 75 minutes is stopped. A running tool
or an approval waiting on you doesn't count as no progress, and
`GAIA_STREAM_TIMEOUT` changes the window, as in the Agent UI (amd#5200). If
the agent acknowledges the stop, the user is told and can send
"continue". If it doesn't, the agent is restarted: the user is told the
conversation was reset, and anyone else it was talking to sees a note on
their next answer. After three restarts in a day, each message says how
to restart the bridge. On Telegram the partial reply is kept, and a
stopped turn never sends its question later.

Reproduced by `tests/unit/messaging/test_bridge_turn_idle.py`,
`tests/unit/messaging/test_bridge_restart.py` and the Telegram tests
`test_a_reply_that_stops_streaming_is_stopped_and_frees_the_bot` and
`test_a_turn_stopped_before_its_thread_ran_never_sends_later`; they fail
on main and pass here.

<details>
<summary>🔍 Technical details</summary>

- `AgentChannel` takes:
- `idle_limit`: from `GAIA_STREAM_TIMEOUT`, else 4500 s, read through
the new shared `gaia.stream_timeout` that the Agent UI now uses too;
  - `cancel_grace`: 30 s;
  - `max_restarts` and `restart_window`: 3 per 24 h;
  - `restart_hint`, `clock` and `poll_seconds`.

Between `tool_call` and `tool_result`, and while a `needs_confirmation`
is pending, the idle clock does not run. Both have deadlines of their
own: the tool timeout, and Slack's 10-minute approval deny.
- When a turn goes idle:
  - `cancel` is sent;
  - output the child sends while the stop is pending is dropped;
- the child's own end of the turn is answered with the "continue"
message;
- the reader claims a terminal event under the lock before rendering it,
so a stop that races a real answer cannot render over it.
- If the child does not end the turn within the grace period, it is
terminated, waited on, and killed if needed, then respawned. The stopped
user gets the "reset" message, and `RESTART_NOTICE` is put in front of
the next answer for every other sender the old child had served.
- Children and turns are swapped under one lock. A reader drops lines
once its child has been replaced, and matches every line to the turn
current for that child. Closing during a respawn stops the new child,
and `close()` stops whichever child is current.
- Once the budget is used up, queued turns get an error naming the
restart without becoming the active turn. Slack's hint,
`slack_restart_hint(background)`, is "Ctrl+C, then `gaia slack start
--allowed-users …`", or "`gaia slack stop`, then … `--background`" when
the bridge was started in the background. `gaia slack start` and `gaia
telegram start` report a bad `GAIA_STREAM_TIMEOUT` as a clean error.
- Telegram uses `wait_for(queue.get(), idle_limit)`. The generation
thread checks the stop before it creates the session and again before it
sends. On a stop, only the session the turn actually used is dropped.
- Each stuck Telegram generation keeps one default-executor thread until
its model call ends. That pool is bounded; the LLM layer's own stall
timeout is what frees them.
- Docs: `guides/slack.mdx` and `guides/telegram-adapter.mdx`. There is
no messaging CHANGELOG to update.
</details>

## Test plan
- [x] `python -m pytest tests/unit/messaging
tests/unit/test_telegram_adapter.py
tests/unit/test_telegram_allowlist.py
tests/unit/test_stream_timeout_env.py
tests/unit/chat/ui/test_turn_idle_limit.py`: 295 passed, three runs in a
row. The bridge tests run on a fake clock against fake children.
- [x] Each fix was reverted by mutation and its test failed:
  - removing the reader's identity check, the late-line test fails;
- claiming the terminal event after rendering, the slow-render test
fails;
- removing the kill in `_stop_child`, the terminate-then-kill test
fails;
  - showing late tokens of a stopped turn, the silent-turn test fails.

Against the previous head, the close-during-respawn, reset-message,
rolling-budget and default-budget tests fail.
- [x] `python util/lint.py --black --isort --flake8 --pylint
--test-lanes`

---------

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 documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ui): Agent UI ends any turn after 10 minutes of work and says the request was stopped

1 participant