Skip to content

fix(ui): an upload waiting for the embedder is not stopped as stalled - #5452

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:claude/index-waits-count-as-progress
Oct 21, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:claude/index-waits-count-as-progress

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

An Agent UI upload queued for the embedder behind a long chat failed with "made no progress for 600 s", even though it was only waiting its turn for the model. #5448 made the broker's queue updates count as progress and let Cancel end that wait; this PR finishes the job. A Cancel during the embedder's wait is now logged as a stop rather than an embedder failure, and the fix is proven against a real daemon instead of a faked broker, including that a dead holder can't keep an upload waiting forever.

Test plan

  • python -m pytest tests/unit/test_daemon_broker_queue.py -k upload tests/unit/rag/test_embedding_outage.py -q (the three real-daemon tests fail with the fix(ui): an upload queued for the model isn't stopped as stuck, and Cancel reaches it #5448 wiring removed)
  • python -m pytest tests/unit/chat/ui tests/unit/rag tests/unit/agents/tools tests/unit/test_broker_wiring.py tests/unit/test_daemon_broker_queue.py tests/unit/test_vlm_extraction_failures.py -q: 2733 passed
  • python util/lint.py --all
  • With gaia daemon running, hold the model slot with a raw POST /host/v1/models/lease for longer than GAIA_INDEX_TIMEOUT, then upload a document in the Agent UI. It indexes once the slot is released, instead of failing with "made no progress".
🔍 Technical details
  • gaia.rag.sdk._stop_behind finds an IndexingStopped or LeaseWaitCancelled behind the client's wrapping (LemonadeClientError, then EmbeddingUnavailableError). _load_embedder and _embed_batch re-raise it.
  • _index_document._do_index raises IndexingStopped when the stop is set after index_document returns, which covers a stop absorbed along the way. The caller has already given up by then, so discarding that result changes nothing the user sees.
  • Real-daemon tests in test_daemon_broker_queue.py: a queued upload outlives an 0.8 s timeout while the holder lives; Cancel removes it from the broker's queue with exactly one lease request (no reattach retry); a granted lease that is never renewed is reclaimed and the upload indexes.
  • A daemon too old to stream its queue sends no updates, so a wait on one still counts against the timeout; the docstring says so.
  • Not LLM-affecting.

Since amd#5328, a wait for a model slot lasts as long as the holder is alive,
and amd#5339 stops an index that goes 600 s without progress. An upload queued
for the embedder or VLM behind a long chat reported no progress, so it failed
with "made no progress" while it was only waiting its turn. This was the
merge-order item amd#5328 owed as the later of the two to land.

- _do_index listens to the broker's queue updates: each one is progress, and
  Cancel ends the queued wait through the same _step check.
- A Cancel that reaches a model-slot wait is a stop, not an embedder failure:
  the RAG SDK unwraps an IndexingStopped found behind the client's wrapping
  instead of logging "Batch failed" and raising EmbeddingUnavailableError, and
  _do_index treats a stop absorbed along the way (a degraded image page) as
  the stop it was.
@github-actions github-actions Bot added rag RAG system changes tests Test changes performance Performance-critical changes labels Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Before this change, a document uploaded in the Agent UI while a long chat held the model failed with "made no progress for 600 s", even though it was only waiting in line. Now the broker's regular queue updates count as progress, so the upload keeps waiting, and Cancel during that wait still stops it at once. A Cancel that lands while the embedder is loading is now logged as a stop, not as an embedder outage. I traced the stop through the broker's queue loop, the in-process model lock, and the SDK's error wrapping. In each case it propagates cleanly and releases the lease or lock, and none of them retries it. I found no blocking bugs.

  • The end-to-end check hasn't been run yet. The test plan's daemon step (hold the model slot past the timeout, then upload) is still unchecked. Every new test fakes the broker's updates, so nothing here yet shows a real queued lease keeping an upload alive. Please run that step and paste the result before merge.

Real-world evidence

N/A: no evidence bundle was produced for this run, and reproducing the bug needs a running daemon holding the model slot. The verdict rests on static review alone. I could not run the new tests here either, because this runner has no pytest installed.

🔍 Technical details

Issues

🟡 No test drives a real queued lease (tests/unit/chat/ui/test_indexing_bounds.py:160): _QueuedForEmbedderRag calls broker_client.notify_wait directly, so the tests never reach acquire_lease's on_update(event) (src/gaia/daemon/broker_client.py:524) or model_lease's _queued. The fix relies on an IndexingStopped raised from the listener escaping with r: and _acquire_with_reattach without being retried. Today it does: only BrokerUnavailableError is caught there. A cheap guard would be one test that streams two NDJSON queued lines through a mocked requests.post, with the listener raising, and asserts that the stop propagates and no second acquire_lease call happens. Without it, a future broad except in the reattach path would silently swallow Cancel.

🟢 A pre-streaming daemon gives no progress during the wait (broker_client.py:491): when the daemon replies with plain JSON (return r.json()), no queued events arrive, so a wait longer than GAIA_INDEX_TIMEOUT is still treated as a stall. That is harmless at the 600 s default (the old daemon waits at most 300 s), but a user who lowers the timeout will still hit it. Consider a one-line note in the docstring.

🟢 The post-index stop check discards a finished result (src/gaia/ui/_chat_helpers.py:4597): if the timeout fires just as index_document returns successfully, the chunks are already persisted but the call raises anyway. The caller has already raised RuntimeError, so the user-visible outcome doesn't change. This is just worth knowing if the cache ever records per-file success.

Strengths

  • _stop_behind walks __cause__/__context__ with a cycle guard and re-raises the original stop object, so callers that check except IndexingStopped keep working through the LemonadeClientError → EmbeddingUnavailableError wrapping.
  • Raising from the listener uses existing teardown paths: the lease stream closes, lemonade_client.py:597 releases the local lock on BaseException, and model_lease's finally releases a granted lease.
  • run_in_executor doesn't copy contextvars, so the new listener can't leak into, or replace, a chat turn's own listener.

Combines with amd#5448: indexing now uses its lease_cancel_scope and a
non-raising queue listener; _stop_behind also unwraps a LeaseWaitCancelled,
so a cancelled embedder wait is a stop rather than an embedder failure.
The fake-broker tests duplicated amd#5448's and are replaced by tests against
a real daemon: a queued upload outlives the timeout, Cancel leaves the queue
without a second lease request, and a dead holder is reclaimed.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Merged main after #5448, which wired the same fix a different way, so this PR now builds on it. Every review point is covered: new tests run against a real daemon instead of faked broker updates, the old-daemon case is noted in the docstring, and discarding a result that finishes after a stop is kept on purpose, because the caller has already given up. The manual Agent UI step is still open, since this machine has no Lemonade running for the embedder.

🔍 Technical details

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 21, 2026
Merged via the queue into amd:main with commit ce37b28 Oct 21, 2026
36 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/index-waits-count-as-progress branch October 21, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance-critical changes rag RAG system changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants