Skip to content

fix(rag): wait visibly on a busy embedder instead of resending batches - #5348

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/embed-busy-gpu-policy
Oct 19, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/embed-busy-gpu-policy

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

When the GPU was busy with another session's model, indexing a document went silent for about nine minutes per batch of chunks. Each batch was tried three times at 180 s, with only a log warning between tries, and the same work was queued again on hardware already too busy to finish it once. Then indexing failed with advice to reinstall the embedding model. Now each batch is sent once and waits up to 300 s. While it waits, the still-indexing message says the embedding model is slow because it is sharing the GPU or CPU. A timeout now says "busy, wait and retry" instead of "run gaia init".

Reproduced by tests/unit/rag/test_embedding_retry_policy.py; it fails on main and passes here.

🔍 Technical details
  • In RAGSDK._encode_texts, a timed-out batch is not resent; it raises EmbeddingUnavailableError with a new busy flag.
  • Malformed replies, error envelopes, server errors and an unreachable server fail on the first try, with the backend's error text when it sent one.
  • Only two cases are tried again, and both are logged:
    • no vectors at all, meaning the embedder is still loading (three tries, 2 s apart);
    • the known "physical batch size" error (the embedder is reloaded once).
  • index_document(..., wait_callback=) reports every 15 s how long the current batch has waited, and reports 0 when it answers. The background index job from fix(rag): stop big documents from hanging index_document until timeout #4754 (Indexing a very large PDF runs past the 10-minute tool limit and is abandoned #4744) shows this in its in-progress result as embedder_wait_seconds.
  • Two old tests asserted the blind retry (call_count == 3); they now assert one send.
  • LLM-affecting: new text in the in-progress result, and a new busy next_step for search and indexing. Category to watch in the next RC eval: rag_quality.

Test plan

  • python -m pytest tests/unit/rag/ tests/unit/test_rag*.py tests/unit/test_indexed_docs_per_turn.py tests/test_rag.py -q

@github-actions github-actions Bot added documentation Documentation changes rag RAG system changes tests Test changes performance Performance-critical changes agents labels Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

When the GPU is shared, indexing a document no longer sits silent for about nine minutes per batch before failing with "reinstall the model" advice. Each batch is now sent once and waits up to 300 s. While it waits, the "still indexing" message says the embedder is slow, not stuck. A timeout now tells the user to wait and retry. I traced how a timeout travels from the HTTP layer up to the new "busy" flag, and it is classified correctly (it is not mistaken for "server unreachable"). Nothing blocks the merge.

Two small things worth fixing:

  • The troubleshooting page says a batch is "never resent", but two cases are still retried on purpose: an embedder that is still loading, and the known batch-size reload. One clause would make the page accurate.
  • If the progress callback ever throws when a batch finishes, that exception would replace the real embedding error.

Real-world evidence

N/A: no evidence bundle was produced for this run. This change touches an internal RAG path, and the only user-visible part is text in tool results. The verdict rests on static review alone. I could not run the PR's test plan here either, because this runner has no pytest. The author lists rag_quality for the next RC eval, which is the right category to watch for the new in-progress and next_step wording.

🔍 Technical details

Issues

🟢 Doc overstates "never resent" (docs/reference/troubleshooting.mdx:10). _embed_batch still retries a warming embedder (up to 3 tries) and the "physical batch size" reload (once). Suggested wording:

    When another model or app is using the GPU or CPU the embedding model runs on, indexing waits for it. A document still indexing says how long the embedding model has taken on its current batch. Each batch of 25 chunks gets one 300-second wait and is not resent after a timeout, so busy hardware doesn't get the same work queued again. A batch still unanswered after that fails with `did not answer within 300s; the GPU or CPU it runs on is likely busy`. Index the document again once the other work finishes.

🟢 wait_callback(0) in finally can mask the real error (src/gaia/rag/sdk.py, _request_embeddings). If the callback raises while a ReadTimeout is propagating, the caller gets the callback's exception, and EmbeddingUnavailableError/busy is lost. Today's only callback (_IndexJob.waiting) is a plain assignment, so this is hypothetical. You could clear the wait on the success path only and let the job's terminal state cover failure. Or keep it as is, since the contract is internal.

Checked and fine

  • LemonadeClient._send_request re-raises RequestException inside the except block without from, and embeddings() does the same. The ReadTimeout therefore survives as __context__, and _is_read_timeout finds it. A read timeout's message ("Read timed out.") doesn't match CONNECTION_FAILURE_RE, so unreachable stays False and busy is set.
  • The reporter thread is joined in finally on both success and failure (and covered by test_wait_reporting_thread_stops_when_the_batch_fails).
  • Every index_document fake reached through _index_within_budget was updated for the new kwarg. CodeIndexSDK._encode_texts is independent of RAGSDK and unaffected.

Strengths

  • The retry policy is now explicit and narrow. Only the two failures a resend can fix are retried, and each retry is logged. Everything else fails on the first try with the backend's own error text, as the fail-loudly rule asks.
  • Malformed replies (None, a list, data that isn't a list, an error envelope) now raise a typed embedding error instead of an AttributeError, and parametrized tests cover each shape.
  • The new test file reproduces the original bug (one send on timeout, bounded warm-up), and the two old tests that pinned call_count == 3 were updated rather than deleted.

kovtcharov and others added 3 commits October 18, 2026 23:13
…atches

Under GPU contention a document's embedding batch was tried three times at
180 s each, with only a log warning in between: about nine minutes of
silence per batch, the same work queued twice more on a GPU already too
busy to finish it once, then a generic "embedding model failed" with
advice to reinstall it.

Each batch is now sent once with a 300 s wait. While it waits, the
background index job reports how long, and the tool tells the user the GPU
is busy and indexing is queued. A timed-out batch raises a busy error
whose next step is "wait, then retry", not "run gaia init". Malformed
replies, server errors and an unreachable server fail on the first try.
Only two cases are tried again, both logged: an embedder still loading
(no vectors back, three tries) and one reloaded with too small a batch
(reloaded once).
Review follow-ups. The wait and busy messages blamed the GPU, but on ROCm
machines the embedder runs on the CPU, so the model would tell users
something false about their hardware. A reply that wasn't a dict, or whose
items weren't, escaped as a raw AttributeError instead of an embedding
error with its next step; and a 200 carrying an error envelope was waited
out three times as a "still loading" embedder. Both now fail at once with
the backend's own error text when it sent one.
A wait-reporting callback that raised after a timed-out batch would have
replaced the busy-embedder error. The wait is now cleared only once the
batch answers. The troubleshooting page no longer says a batch is never
resent; it is not resent after a timeout.
@kovtcharov-amd
kovtcharov-amd force-pushed the kalin/embed-busy-gpu-policy branch from 9c61851 to 3bacbe1 Compare October 19, 2026 06:17
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 19, 2026
Merged via the queue into amd:main with commit 15200e8 Oct 19, 2026
44 of 45 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/embed-busy-gpu-policy branch October 19, 2026 08:29
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Oct 19, 2026
Resolves conflicts with amd#5336, amd#5348 and amd#5359, and makes the additions
this PR owes as the second to land:

- _preflight_load keeps amd#5336's re-raise of InsufficientMemoryError and
  ModelInUseError, and adds `except LeaseWaitCancelled` ahead of its
  catch-all, so a stopped queued wait is not reported as a failed load.
- The chat title's lease runs under lease_wait_limit(30), so a title gives
  up instead of holding a worker thread behind a long queue.
- Background indexing keeps amd#5348's embedder wait callback inside
  detached_from_turn.
- broker.py keeps both _renewed_at and amd#5359's _last_activity; a reclaim
  stamps _last_activity.

Review follow-ups: an unreadable queue-stream line is a
BrokerUnavailableError naming the daemon instead of a raw parse error, and
a test pins the email translator's copy of _QUEUE_FIELDS to the core one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation 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