Repository navigation
Description
Problem
RAG gives reviews nothing today, and the RAG client has six defects that would keep it that way once an index exists. Lines are at release/v0.2.25 (e3ff98c).
1. One failed lookup turns RAG off for the whole run.
_stop_rag_for_run(src/devops_cli/ai/rag/investigator.py:55-62) sets_RAG_STOPPEDon the firstEmbeddingsErrorof any kind (:194-196), and every later lookup returns None (:172-173,:260).- The reason in the comment (
:34-36) is that on a node that keeps one model loaded, the failing request can evict the run's model. fix(ai): reviews ask an unserved embedding model on every lookup and search with a hash fallback #945 added it for an embedding model that is not served at all. - It also fires on a timeout. The gateway path's read timeout is
max(timeout, 30)= 30 s (ai/rag/embeddings.py:812). On 2026-10-03, hog's Ollama log shows 6 embeddings taking 31.1–40.0 s at 06:19:36–37 while bge-m3 and qwen3-coder evicted each other. No embedding arrived after 06:19:37, while chat calls continued until 06:32:26 [measured; that the stop fired is an inference about the client side]. fix(k8s): ollama-48gib-slow keeps its embedding model and qwen3-coder loaded and leaves every interactive pool, so a review no longer evicts the embedder #1064 (the fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061 follow-up) removes that eviction, but a restart of hog's Ollama pod or a slow reply still ends RAG for the run. - Skipping a failed lookup instead is not enough. Until a lookup has succeeded, lookups take turns under
_PROBE_LOCK(investigator.py:147-155). With the embedder down or hung, each of a review's per-file and per-finding lookups would wait up to 30 s in series. While LiteLLM cools a deployment down, it answers 429 "No deployments available": a 4xx, but transient.
2. Cache keys ignore the prefix. The L1 key (embeddings.py:103-106) and the Valkey key (:391-395) hash the model, a query/document tag and the unprefixed text. The prefix is applied only to misses (:630), and vectors are stored under the original text (:654-655). Changing the prompt for the same model therefore keeps serving vectors made with the old prompt for the Valkey TTL of 7 days (config/defaults.py:210). That covers rag index --force too.
3. The prompts are wrong for both candidate models. Any model whose name contains qwen, bge or e5 gets query: / passage: (embeddings.py:668-680).
- The bge-m3 card says it needs no instruction [sourced: https://huggingface.co/BAAI/bge-m3].
- Qwen3-Embedding wants
Instruct: {task}\nQuery:{query}on queries and nothing on documents. The card says that leaving out the query instruction costs about 1–5% in retrieval [sourced: https://huggingface.co/Qwen/Qwen3-Embedding-0.6B]. qwen3-embedding:0.6bis devops-cli's default embedding model (config/defaults.py:201).
4. The fallback dimension for qwen3-embedding is wrong. CONST_KNOWN_EMBEDDING_DIMENSIONS (config/constants.py:2096-2108) gives qwen3-embedding 768 (:2106). The model's vectors have 1024 dimensions [sourced: the card above]. EmbeddingsEngine falls back to this table when it cannot probe the model (embeddings.py:471-475), and so sizes a new collection wrongly.
5. ai.rag.top_k and ai.rag.score_threshold are never read.
AIRAGConfigdeclares them (config/settings.py:368-369), andconfig/options.py:60-61names them, but the onlyai.ragfield anything reads isenabled(investigator.py:264,commands/rag.py:487).- The retriever takes
top_k or DEFAULT_RAG_TOP_Kandscore_threshold or DEFAULT_RAG_SCORE_THRESHOLD(investigator.py:106-107). - No review, verification or chat lookup passes a threshold (
ai/review/pipeline.py:1484,ai/review/verification.py:297,commands/ai.py:202), so the 0.35 constant (defaults.py:212) always applies. It cannot be recalibrated for a new model until the setting is read.
6. Nothing bounds a chunk's size, and one failed batch ends the index.
- The line-window chunker counts lines, not tokens (
ai/rag/chunker.py:626-630, windowDEFAULT_RAG_CHUNK_SIZE= 2400 lines). - Run offline at this commit's chunker,
uv.lock(3,741 lines) gives two chunks of 160,554 and 109,480 cl100k tokens (lines 1–2400 and 2161–3741). - The slow-tier plan's offline run over the repository found 17,499 chunks, 23 of them over 8,192 tokens, with a p99 of 1,557.
_upsert_chunks(ai/rag/indexer.py:591-611) embeds each batch with no handling, so one failed batch (up to 256 chunks,:586-587) raises out ofindex_workspaceand ends the index.- Through the gateway, each batch is one request with the 30 s read timeout.
- Ollama silently cuts bge-m3 inputs at about 2,048 tokens. Qwen3-Embedding reads up to 32K, so it embeds such chunks in full [code: Ollama v0.34.4
server/routes.go, per the plan's verification].
The Qdrant collections are effectively empty today: 76 of 76 searches returned nothing [measured: qdrant-0 log]. So these fixes come before the first index, and the switch to qwen3-embedding:0.6b (#481) comes after them.
Source: .data/slow-tier-plan-20261003.md, sections 1 and 4, and its verification pass. The cited lines were re-read at e3ff98c.
Acceptance criteria
- Permanent errors stop RAG; transient ones pause it.
- An
EmbeddingsErrorfrom a 400 or 404 that names an unknown or unserved model is permanent. It stops RAG for the run as today, with one warning.tests/test_review_embeddings_unserved.py(five findings, at most one embedding request) keeps passing. - A timeout, connection error, 408, 429 or 5xx is transient. It skips that lookup only.
- After 3 consecutive transient failures, a circuit breaker opens for 60 s. While it is open, lookups return None without sending a request. After the pause, one lookup probes. A success closes the breaker; a failure opens it again.
EmbeddingsErrorrecords which kind it is where it is raised. The investigator does not parse message text.
- An
- No failed lookup waits its turn. While no lookup has succeeded, one lookup probes. Lookups that arrive meanwhile wait for its outcome, not for their turn under
_PROBE_LOCK: if it succeeds they run concurrently, and if it fails they skip.- A test runs 20 concurrent lookups against a stub embedder that hangs until a patched 0.2 s timeout. They finish in under 1 s in total, and the stub receives at most 2 requests. The test fails on the current code.
- With a healthy stub, all 20 lookups get context.
- Tests with a stub embedder and a patched clock:
- three timeouts, then lookups during the pause send no request;
- the probe after the pause succeeds and lookups resume;
- a 429 "No deployments available" counts as transient.
- Cache keys hash the text sent. The L1 and Valkey keys hash the text after its prompt is applied. A test embeds the same text for the same model under two prompts and gets two cache misses. It fails on the current code.
- Per-model prompts. bge-m3 gets no prefix.
qwen3-embedding*queries getInstruct: Given a code search query, retrieve relevant code or documentation\nQuery:and its documents get none.nomic*keepssearch_query:/search_document:,e5*keepsquery:/passage:, and every other model gets none. A parametrised test covers each family, for queries and for documents. -
CONST_KNOWN_EMBEDDING_DIMENSIONS["qwen3-embedding"]is 1024, and a test pins it. - The
ai.ragsettings are read. The retriever's defaults come fromai.rag.top_kandai.rag.score_threshold, compared withis None, so a threshold of 0 is honoured. A caller's explicit per-usetop_k(3 per file in reviews, 2 per finding) still wins. Chat's lookup takes its default fromai.rag.top_k, not from the constant (commands/ai.py:196). A test setsscore_threshold: 0.5and sees it reach the Qdrant search. - Lockfiles are not indexed. The indexer skips
uv.lock, other*.lockfiles,package-lock.json,pnpm-lock.yamlandgo.sum. - No chunk sent to the embedder is over 8,192 tokens (the project's token estimate). Longer line windows are split. A test chunks a 4,000-line synthetic file and checks every chunk.
- A failed batch still ends the index with exit 1 (fix(ai): reviews ask an unserved embedding model on every lookup and search with a hash fallback #945's rule), naming the batch's first and last file. Earlier batches stay indexed and recorded in the index cache, so
devops ai rag indexwithout--forceresumes after them. A test with a stub embedder that fails the second batch pins both. -
MESSAGES.raggains the pause message. The investigator docstring (investigator.py:248) and the knowledge base (src/devops_cli/ai/knowledge_base/devops_cli/tasks/rag_context_indexing.md:52) describe the breaker instead of "RAG is off for the rest of the run". - The tests run offline with stub embedders and a fake Qdrant client, call no gateway, Ollama, Qdrant or Valkey, and each runs in under 1 s.
-
changelog.d/1065.mdrecords the fix under### Fixed.CHANGELOG.mdis not edited. -
uv run devops cipasses. - (person-run) After fix(k8s): ollama-48gib-slow keeps its embedding model and qwen3-coder loaded and leaves every interactive pool, so a review no longer evicts the embedder #1064 is applied: restart hog's Ollama pod while a multi-file review runs. The review logs the pause, RAG lookups resume once hog is back, and the review finishes. Across several multi-file reviews, no "RAG is off for the rest of this run" warning appears unless the embedding model is not served.
Key questions
- Why a breaker rather than skipping failed lookups? (proposed) Skipping alone costs up to 30 s per lookup, in series, while hog is down. A review makes hundreds of lookups, so that would slow the interactive reviews the slow tier is meant to protect. A breaker bounds the cost to one timeout per pause.
- K = 3 and a 60 s pause: why these numbers? (proposed) Three failures in a row separate a down or hung host from a single slow reply. 60 s is two LiteLLM cooldowns (
cooldown_time: 30), long enough for the gateway to notice the host is back. Both are module constants named once, not config, until a measurement asks for tuning. - Is a 429 permanent, since it is a 4xx? (proposed) No. LiteLLM answers 429 "No deployments available" while it cools a deployment down. Only a 400 or 404 that names the model counts as permanent.
- Which prompt for documents with Qwen3? (proposed) None. The card applies the instruction to queries only. The task text is the card's code-search example, written once as a constant.
- Should
ai.rag.chunk_sizeandchunk_overlapset the token cap? (proposed) No. They are in lines and are never passed to the indexer (commands/rag.py:176,:271). The cap is a separate token limit. Reading or deleting those two keys is refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000's job (settings as the one declaration). - Should a failed batch be skipped so the index finishes? (proposed) No. fix(ai): reviews ask an unserved embedding model on every lookup and search with a hash fallback #945 made indexing store no vector for a text the model did not embed, and exit 1. Resuming without
--forcemakes a failure cheap instead. With the chunk cap and lockfiles skipped, a 30 s timeout per batch is unlikely; a person can raise it withDEVOPS_CLI_AI_TASK_EMBEDDING_TIMEOUT(capped at 120). - Is this a v0.2.25 critical fix? (proposed) No. The run-wide stop came in with fix(ai): reviews ask an unserved embedding model on every lookup and search with a hash fallback #945 in v0.2.25 and works as specified. The live trigger was fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061's eviction, which fix(k8s): ollama-48gib-slow keeps its embedding model and qwen3-coder loaded and leaves every interactive pool, so a review no longer evicts the embedder #1064 removes. The other five defects predate v0.2.25. It is P1, and v0.2.26 to v0.2.29 are at or over the cap of 12, so it waits in the backlog.
Depends on: none.
Order:
- Lands before the first full index and before feat(ai): embeddings through the llm gateway, with embedding model evaluation #481's switch to
qwen3-embedding:0.6b. - fix(ai): a rag collection records its embedding model, a mismatch fails instead of wiping the collection, and ranking keeps the cosine score #1066 (RAG index integrity) edits
ai/rag/qdrant.py,indexer.pyandretriever.py. This item editsinvestigator.py,embeddings.pyand the indexer's batch loop. Whichever lands second rebases. - refactor(ai): the agent, rag, benchmark and spend tables move out of config/ next to their owners #1028 moves the
ai/ragconstants out ofconfig/. refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 movesembeddings.pyonto the model adapters. Whichever lands second rebases.
Related:
- fix(ai): reviews ask an unserved embedding model on every lookup and search with a hash fallback #945: the run-wide stop and no fallback vectors.
- fix(k8s): every ollama tier keeps one model loaded and serves one request at a time, so its kv cache holds one context #1061 and its follow-up fix(k8s): ollama-48gib-slow keeps its embedding model and qwen3-coder loaded and leaves every interactive pool, so a review no longer evicts the embedder #1064: hog's eviction.
- feat(ai): embeddings through the llm gateway, with embedding model evaluation #481: the embedding-model comparison and switch.
- feat(rag): embedding-cache hits and misses as counters #817: embedding-cache counters.
- fix(ai): the embedding benchmark takes any endpoint from an MCP client and counts failed embeddings as results #954: the embedding benchmark's failure accounting.
- feat(cli): recovery transitions for adaptive knobs coalesced decrease, valkey breaker, failback #596: AIMD batch sizing and the Valkey cache's run-wide stop, in
embeddings.py.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 3, 2026
Review redesign (#1137, 2026-10-03): this item is a phase P0 child, kept whole. Its breaker, per-model prompts, cache keys, chunk caps and
ai.ragsettings serve the chat and the KB index that #1139 keeps current. Its person-run line stands until #1151 removes review-time RAG; after that, #1139's person-run covers it. (A separate consolidation proposal, that the breaker comes from a maintained library behind a reusable seam shared with #596, is left to a person.)dan-petty-bot commentedon Oct 6, 2026
Moved to v0.2.28: v0.2.28 started with fewer than its 12 items and was topped up to 12 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)
fix(ai): a failing embedding model pauses rag lookups instead of endi…
dan-petty commentedon Oct 7, 2026
Resolved by #1274.
dan-petty-bot commentedon Oct 7, 2026
What changed
#1274, merged into
release/v0.2.28as ad9fba0.15 file(s) changed.
How it was verified
Check runs at ed0bfc4:
Acceptance Criteria of
docs/agent/tasks/task-1065-failing-embedding-model-pauses-rag.md:EmbeddingsErrorrecordsis_transient).bge-m3,qwen3-embedding,nomic,e5, and others verified with parametrized tests.CONST_KNOWN_EMBEDDING_DIMENSIONS["qwen3-embedding"]is pinned to 1024.ai.ragsettings fortop_kandscore_thresholdare read and reach Qdrant search.uv.lock,*.lock,package-lock.json,pnpm-lock.yaml,go.sum) are skipped by indexer.MESSAGES.rag.pausedadded, docstrings and knowledge base updated.changelog.d/1065.mdrecords the fix under### Fixed.uv run devops cipasses.feat(release): v0.2.28 (#1283)