Skip to content

fix(ui): an upload queued for the model isn't stopped as stuck, and Cancel reaches it - #5448

Merged
kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:claude/rel-ui-index-queue-progress
Oct 21, 2026
Merged

kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:claude/rel-ui-index-queue-progress

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Before: an Agent UI upload waiting in line for the model slot (the embedder load, or a vision model call) got no page or batch done, so after GAIA_INDEX_TIMEOUT (10 min) it was stopped as "no progress", even though it was only queued behind a long chat. Cancel didn't reach it either: it waited for the slot, loaded the model, embedded a batch, and only then stopped. After: queue updates from the broker count as progress, and Cancel or the no-progress stop end the wait at once. A cancelled wait on a cached document keeps its cache.

This is the #5339 × #5328 merge item, "whichever lands second wires lease_wait_listener". It didn't land with either PR.

Reproduced by tests/unit/chat/ui/test_indexing_bounds.py::test_waiting_in_line_for_the_embedder_counts_as_progress, ::test_cancel_reaches_an_index_waiting_in_line_for_the_model and tests/unit/rag/test_indexing_stopped.py::test_a_cancelled_wait_for_the_model_keeps_the_cache_too; all three fail on main and pass here.

Test plan

  • pytest tests/unit/chat/ui tests/unit/rag tests/unit/agents/tools tests/unit/test_broker_wiring.py: 2655 passed
  • python util/lint.py --black --isort --pylint --flake8 --imports --test-lanes
🔍 Technical details
  • _index_document._do_index runs rag.index_document inside lease_wait_listener(_queue_update) and lease_cancel_scope(stop). Both are contextvars set on the indexing thread, which is where the embedder's load_model and the VLM calls take their leases. The listener only notes the time, since it runs on the waiting thread and must not block or raise.
  • LeaseWaitCancelled from that scope becomes IndexingStopped. In rag/sdk.py, both of index_document's broad handlers re-raise it, as they do IndexingStopped. Without that, the cache-hit path took it for a corrupt cache.
  • Not LLM-affecting.

…stuck

Indexing stops after GAIA_INDEX_TIMEOUT seconds without progress. Since
model-slot waits no longer have a cap, an upload queued behind a long chat
for the embedder or vision model got no page or batch done for that long
and was stopped as 'no progress'. Queue updates from the broker now count
as progress while the document indexes.
An upload queued for the model slot ignored Cancel and the no-progress
stop until it got the slot, then loaded the model and embedded a batch
before stopping. The index now runs inside the broker's cancel scope, so
the wait ends at once. RAG re-raises the cancelled wait past its broad
handlers, as it does IndexingStopped, so a cached document's cache isn't
taken for corrupt and deleted.
@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

An Agent UI upload that is only waiting in line for the model is no longer stopped as "made no progress", and Cancel now ends that wait right away instead of after a full model load and batch. The code is correct and small. I found no blocking issues. Both new handlers keep their cache, which matches how the existing stop path already works.

Two small follow-ups, neither blocking:

  • If Cancel lands while a PDF or slide page is waiting for the vision model, the logs record it as "image extraction failed on page N", not as a stop. Indexing still stops at the next page, so users see no difference, but anyone debugging later will be misled.
  • The indexing function's docstring still says only page and batch progress count. It should also mention that queue updates count, and that Cancel ends a model wait.

Real-world evidence

N/A: no evidence bundle was produced for this run. This is an internal indexing change that only shows up in the Agent UI when uploads have to compete for the model, so it can't easily be exercised on a no-inference runner. The verdict rests on static review and the PR's three unit reproductions. I couldn't run them here because pytest isn't installed in this review environment. A later Agent UI check would close the gap: upload a large PDF during a long chat, then press Cancel.

🔍 Technical details

🟢 Minor: a cancelled vision wait is logged as a page failure (src/gaia/rag/sdk.py:1194, same pattern at :1576)
VLMClient.extract_from_image wraps any exception, LeaseWaitCancelled included, in VLMExtractionError. The per-page except Exception as img_error then turns that into a page warning. The next page's _beat() raises IndexingStopped. On the last page, the embed step's _step() raises it before _save_cache, so no degraded cache is written. The behaviour is correct; only the log is misleading. One option is to re-raise LeaseWaitCancelled (or IndexingStopped) from VLMClient, or to check __cause__ in those two handlers.

🟢 Minor: docstring is out of date (src/gaia/ui/_chat_helpers.py:4553-4557)

    files have their own, and the rest wait their turn). Cancelling the
    awaiting task stops indexing at its next page or embedding batch, or
    ends a wait for the model slot at once; so does going
    ``GAIA_INDEX_TIMEOUT`` seconds without progress. Queue updates from the
    broker count as progress; time spent waiting for a worker doesn't.

What I checked:

  • Where the scopes are set. Both are set inside _do_index, on the pool thread. run_in_executor doesn't copy context, so this is the right place. _scoped resets the token, so nothing leaks to the next job on that worker. The only extra thread in the embed path is the rag-embed-wait reporter, and it doesn't take leases.
  • Wait updates keep the timer alive. Only daemon-scope waits call notify_wait, from _queued and on grant (broker_client.py:854,875). They fire every couple of seconds, well inside the 10-minute GAIA_INDEX_TIMEOUT.
  • Circular import risk. The new top-level import in rag/sdk.py is safe: broker_client only pulls in gaia.daemon.constants and gaia.logger.

Strengths

  • The fix uses the broker's existing lease_wait_listener and lease_cancel_scope hooks rather than adding a parallel mechanism, and the listener stays non-blocking as their contract requires.
  • The tests reproduce the real failures: a queued wait longer than the timeout, Cancel reaching a wait in progress, and the cache surviving a cancelled wait on the cache-hit path.

…he page

Cancel during a page's wait for the vision model was logged as an image extraction failure. VLMClient and the PDF/PPTX page handlers now let LeaseWaitCancelled through, and the indexing docstring says that queue updates count as progress.
@github-actions github-actions Bot added the llm LLM backend changes label Oct 21, 2026
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Both suggestions are in. Cancel during a page's wait for the vision model now stops indexing instead of being logged as a failed page, and the docstring says queue updates count as progress. On the "what if the holder dies" question: the wait still ends. The broker takes back a lease whose holder stops renewing or passes its max hold time, and a daemon that goes silent ends the stream, so a queued upload is never kept alive forever by queue updates alone.

🔍 Technical details
  • VLMClient.extract_from_image re-raises LeaseWaitCancelled unwrapped; the PDF page and PPTX slide handlers in rag/sdk.py re-raise it before their broad except.
  • New tests (both fail without the change): test_a_cancelled_wait_for_the_model_is_a_stop_not_a_failed_page (test_vlm_extraction_failures.py) and test_a_cancelled_wait_for_the_vision_model_stops_the_pdf (test_damaged_pdf_page.py).
  • Merged main; tests/unit/chat/ui tests/unit/rag tests/unit/agents/tools + broker/VLM tests: 2730 passed. lint.py --all clean.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 21, 2026
Merged via the queue into amd:main with commit d343b3a Oct 21, 2026
43 of 44 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/rel-ui-index-queue-progress branch October 21, 2026 08:26
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Oct 21, 2026
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.
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 21, 2026
…amd#5452)

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. amd#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
- [x] `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 amd#5448 wiring removed)
- [x] `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
- [x] `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".

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

- `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.
</details>

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

llm LLM backend changes 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