Skip to content

fix(ui): an unanswered prompt in one chat no longer blocks every other chat - #5609

Merged
kovtcharov-amd merged 7 commits into
amd:mainfrom
kovtcharov:kalin/turn-queue-release-while-waiting
Oct 23, 2026
Merged

kovtcharov-amd merged 7 commits into
amd:mainfrom
kovtcharov:kalin/turn-queue-release-while-waiting

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Before: on a desktop install (flagship relayed to the daemon sidecar), one chat left on an unanswered Allow once / Deny prompt blocked every other chat indefinitely. A new chat's "what is 6 times 7?" sat at "Waiting for the GPU — 1st in line" forever, even on a cloud model that never touches the GPU. After: a chat waiting on you steps out of the line, so other chats run, and comes back at the front once you answer. Chats on a cloud model don't queue at all.

Why cloud turns skip the line: the line (#5226) serializes turns on the one local chat model and protects its prompt cache. A cloud turn never touches either. What it runs locally (the RAG embedder, a vision model) is already arbitrated by the daemon broker's lease, and the tool registry has its own lock. Local turns still queue, so "Waiting for the GPU" stays accurate: only local work holds the line.

Test plan

  • New tests in tests/unit/chat/ui/test_turn_slot_reliability.py; all 6 fail on main and pass here:
    • a relayed turn parked on a permission prompt or a question frees the model, and a new chat's first message runs right away; answering resumes the relayed turn, which completes
    • an answered relayed turn rejoins at the front (ahead of a chat that arrived meanwhile), its wait counts from 0, it shows resumed, and it no longer shows as needing you
    • Stop on a parked relayed turn never retakes the model
    • streamed and non-streamed cloud turns run while a local turn holds the line; a local turn still waits and says "Waiting for the GPU"
  • The in-process permission and question waits were already covered (test_turn_waiting_on_the_user_lets_other_chats_run) and still pass
  • pytest tests/unit/chat -n 4 plus the relay suites (test_relay_*, test_email_sidecar_relay, test_sidecar_relay_fidelity, test_daemon_relay): 2375 passed, 11 skipped. One failure, test_issue_841_custom_python_agent_model_id_respected, came from the temporary GAIA_HOME the run used (the test patches HOME); it passes without it
  • python util/lint.py --black --isort --flake8 --pylint
  • Live: repeat the repro on a desktop install (chat 1 left on a shell prompt, then a new chat asks a question). It should answer right away, and allowing chat 1 afterwards should finish it. Done in the Agent UI with a relayed sidecar: chat 2 answered in 2 s while chat 1 sat on its prompt, and Allow then finished chat 1 (evidence)
🔍 Technical details

Root cause: relay_query (src/gaia/ui/email_sidecar/relay.py, the event loop at ~518 on main) dispatched needs_confirmation / needs_input, then blocked on the sidecar's socket while still holding the turn's TurnSlot. Only the in-process waits (SSEOutputHandler.confirm_tool_execution / request_user_input_blocking, via _away_from_model) stepped away. Path-access prompts go through confirm_tool_execution, so they were already covered.

  • Relay: after a waiting event, the relay calls step_away_from_model(). The next sidecar event means the user answered or the wait ended, so it calls come_back_to_model() (acquire(front=True)) before dispatching. A final/error event ends the turn without queuing, and a Stop or stream end while stepped away never retakes the model. The sidecar run itself stays alive throughout.
  • After the answer is POSTed, the sidecar continues at once, before the UI-side slot is retaken. If its model is local, the broker lease still arbitrates its calls against the slot holder's. That window lasts only until the relay reads the sidecar's next event.
  • _away_from_model is split into step_away_from_model / come_back_to_model so the relay can use them across loop iterations. Behaviour is unchanged.
  • A relayed needs_input is now tracked (set_relay_question), so waiting_on() reports "question" (sidebar "Needs you") and awaiting_user_input() keeps the idle timeout from stopping a turn that waits on the user.
  • turn_takes_the_line() resolves the turn's model as _stream_chat_impl does and classifies it with _turn_location. If it can't classify the model, the turn queues, and the turn's own model resolution reports the error.
  • queue_waited_s used the turn's start time, so a resumed turn showed the whole prompt time as time in line. It now uses TurnSlot.waiting_since, reset on each acquire.
  • The "Waiting for another chat to finish…" greeting: the only strings with that text come from the in-turn setup lock and model-load lock (writing_tool_registry, _take_model_load_lock). The new-chat warm-up is skipped for sidecar and cloud turns and never takes the line. With the relay stepping away, a new chat's first turn isn't blocked; the relayed-wait test covers it.
  • The docs (agent-ui.mdx guide and SDK page) describe the cloud skip and the rejoin, and drop a stale "non-streamed waits 60 s then 429" claim.

…r chat

A relayed flagship turn parked on a permission prompt or question kept its
place on the model, so every other chat sat at "Waiting for the GPU — 1st in
line" until someone answered. Relayed waits now step out of the line like
in-process ones and come back at the front once the sidecar moves on, and a
relayed question counts as "needs you" and is not mistaken for a stall.

Turns on a cloud model no longer join the line at all: it protects the one
local chat model and its prompt cache, which a cloud turn never touches; the
embedder and vision model are leased from the daemon's broker. A turn that
rejoins the line counts its wait from the rejoin, not from when it started.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

On a desktop install, one chat left on an unanswered Allow/Deny prompt or question no longer blocks every other chat: the waiting chat leaves the line and rejoins at the front once you answer. Turns on a cloud model now skip the line entirely. The logic holds up. The parked sidecar run stays alive, a Stop never retakes the model, and the stream's : keepalive heartbeats are filtered out before the relay sees them, so a heartbeat can't pull a parked turn back into line early. The six new tests cover the user-visible cases.

The one gap is proof on the real surface. This changes what users see in the Agent UI ("Waiting for the GPU", "Needs you"), and the PR's only live check, the desktop repro, is still unticked. Run it before merge and paste the result: chat 1 parked on a shell prompt, a new chat answering right away, then chat 1 finishing after Allow. A screenshot of both chats is best, and the streamed /api/chat/send events (no queued phase on chat 2, then queued → resumed on chat 1) also work.

Real-world evidence

N/A: no evidence bundle was produced for this run. The Agent UI desktop repro is still pending, so this verdict rests on static review and the unit tests alone.

🔍 Technical details

Issues

🟡 No live evidence for a UI-visible change. The test plan's "Live: repeat the repro on a desktop install" box is unchecked, and no route or CLI capture is linked. Unit tests gate the logic, but this bug only existed on the daemon-sidecar relay path. Please attach either the screenshot or the streamed event sequence from a real relayed turn.

Checked and fine

  • relay.py: proxy.query_stream drops SSE comment lines, so the sidecar's : keepalive during a park never reaches the loop. The first event after a park really is the post-answer event.
  • relay.py: if step_away_from_model() returns False (no slot, such as a cloud or non-streamed turn), come_back_to_model() is never called. That keeps the self.turn_slot.come_back call in sse_handler.py safe from a None slot.
  • A final/error right after the answer skips re-queuing. run.slot.close() in _run_chat_lifecycle then handles an unheld slot.
  • turn_takes_the_line: on failure it queues the turn and logs a warning, and the turn's own model resolution raises the real error. This is not a silent fallback.
  • _agent_cache_lock exists (_chat_helpers.py:250), so the rewritten thread-safety comment is accurate now that turns in different chats can overlap.

Strengths

  • Splitting _away_from_model into step_away_from_model / come_back_to_model lets the relay reuse the in-process wait logic instead of copying it.
  • Resetting TurnSlot.waiting_since on each acquire fixes the inflated queue_waited_s on resumed turns, and a test asserts the new value.
  • Both doc pages were updated together, and the stale "non-streamed waits 60 s then 429" claim is gone.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Checked live in the Agent UI (desktop-style install, relayed sidecar, Fireworks DeepSeek V4 Flash): a chat waiting on a permission prompt no longer blocks other chats.

🔍 Technical details
  • Chat 1: "Run the shell command: echo f47-retest" → Allow once / Deny prompt, left unanswered.
  • Chat 2 (new): "what is 6 times 7?" → "42." in 2 s (before this branch: "Waiting for the GPU — 1st in line" indefinitely, until chat 1's prompt was answered).
  • Back in chat 1 → Allow once → ran the command and answered "f47-retest".

Built together with #5538, #5541, #5543 and #5580 (125 relay/title/queue tests pass combined). See the merge note below for the overlap.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Merge note: #5538, #5541 and #5609 all change the relay loop and the relayed question/prompt state in sse_handler.py, so whichever merges later needs a hand merge that keeps all three behaviours.

🔍 Technical details

Resolution tested live and in unit tests (125 relay/title/queue tests pass combined):

@kovtcharov

Copy link
Copy Markdown
Contributor Author

The live check the review asked for is in this comment, posted a minute after the review ran. Chat 2 answered in 2 s while chat 1 waited on its prompt, and Allow then finished chat 1. The test-plan box is now ticked and links to it. No code change was needed.

🔍 Technical details
  • The run used the Agent UI on a desktop-style install, with the relayed sidecar and Fireworks DeepSeek V4 Flash. This is the daemon-sidecar relay path the bug lived on.
  • It's a UI walkthrough, not a screenshot or an /api/chat/send event capture. Chat 2 never showed "Waiting for the GPU", and chat 1 resumed after Allow and printed the command's output.
  • CI: 24 checks pass and 10 are skipped.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Merged current main (6cbb246) into this branch. I resolved three conflicts and kept both sides each time. The relay and turn-queue tests pass. The one failing test also fails on main.

🔍 Technical details

@kovtcharov-amd
kovtcharov-amd merged commit e9e775a into amd:main Oct 23, 2026
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants