Repository navigation
fix(ui): stop an Agent UI turn only when it makes no progress - #5200
Conversation
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.
|
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:
Real-world evidenceFrom the evidence bundle (PR head On the base commit, the non-streaming path ignored the limit and ran for 156 s. Bad What wasn't tested:
🔍 Technical details🟡 Rejected repeat tool call leaves the tool marked as running (
🟢 The non-streaming path counts only
🟢 The non-streaming worker has no deadline after the turn is stopped
Strengths
|
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.
|
Fixed the two code findings in the latest push. The third is pre-existing and left out of this PR.
|
…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
…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]>
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_TIMEOUTkeeps 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.progress.loghas 22 lines, andsummary.txtis written.python util/lint.py --black --isort