Skip to content

fix(ai): a failing embedding model pauses rag lookups instead of ending rag for the run (#1065) - #1274

Merged
dan-petty merged 1 commit into
release/v0.2.28from
fix/failing-embedding-model-pauses-rag
Oct 7, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.28from
fix/failing-embedding-model-pauses-rag

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Description

Resolves #1065.

Previously, a transient embedding model failure (e.g. 5xx status, connection timeout, rate limit 429) stopped RAG lookups for the rest of the CLI run identically to an unserved or missing model. Furthermore, lookup requests while unserved queued sequentially under a lock rather than coordinating a single probe, embedding cache keys did not differentiate between models and task prompts, `qwen3-embedding` dimension was not pinned to 1024, package manager lockfiles were unnecessarily indexed, oversized chunk line windows could exceed model context boundaries, and indexer batch failures raised unhandled errors without naming the batch files or preserving earlier batches for resume.

This PR implements the following fixes:

  • Circuit Breaker on Transient Errors: Permanent errors (400 or 404 naming unserved/unknown models) stop RAG for the run with one warning. Transient errors (timeouts, connection resets, 408, 429, 5xx) skip only the failing lookup. After 3 consecutive transient failures, a circuit breaker opens for 60 seconds (`CONST_RAG_CIRCUIT_BREAKER_PAUSE_SECONDS`). While open, lookups immediately return `None` without dispatching requests.
  • Probe Coordination (`_ProbeCoordinator`): Instead of serializing all concurrent lookups under `_PROBE_LOCK`, lookups that arrive while no lookup has succeeded wait on a single probe lookup. If the probe succeeds, waiters run concurrently; if the probe fails, waiters skip immediately.
  • Prompted Cache Keys: L1 and Valkey L2 cache keys hash the text after prompt prefix application (`f"{model}\x00{sent_text}"`), ensuring queries and documents, or multiple prompts on identical text, map to distinct cache entries.
  • Per-Model Prompts: `bge-m3` uses no prompt prefix. `qwen3-embedding*` queries receive `CONST_QWEN3_EMBEDDING_QUERY_PREFIX` (`Instruct: Given a code search query, retrieve relevant code or documentation\nQuery:`) and documents receive none. `nomic*` uses `search_query: ` / `search_document: `, `e5*` uses `query: ` / `passage: `, and other models use none.
  • Pinned Known Dimensions: `CONST_KNOWN_EMBEDDING_DIMENSIONS["qwen3-embedding"] = 1024`.
  • RAG Settings Read: `SemanticRetriever` defaults are read from `st.ai.rag.top_k` and `st.ai.rag.score_threshold` compared with `is None`, honoring threshold `0.0`. CLI chat inherits `top_k` from settings.
  • Lockfile Skipping: `WorkspaceIndexer` skips `uv.lock`, other `*.lock` files, `package-lock.json`, `pnpm-lock.yaml`, and `go.sum`.
  • Bounded Chunk Tokens: All returned chunks are bounded to `CONST_RAG_MAX_CHUNK_TOKENS` (8,192 tokens). Longer line windows are split into sub-windows.
  • Batch Failure Naming and Incremental Resume: A failing batch in `_upsert_chunks` raises `EmbeddingsError` with exit code 1 naming the batch's first and last file, while earlier batches remain persisted in cache so `devops ai rag index` resumes without re-indexing.
  • Documentation & Messages: Added `MESSAGES.rag.paused`, updated docstrings in `investigator.py`, and updated task documentation in `rag_context_indexing.md`.

Acceptance Criteria

  • Permanent errors stop RAG; transient ones pause it (circuit breaker after 3 failures pauses for 60 s; `EmbeddingsError` records `is_transient`).
  • No failed lookup waits its turn (concurrent lookups wait on single probe outcome, finishing in < 1 s with $\le 2$ requests).
  • Tests with stub embedder and patched clock verify pause, resume, and 429 transient behavior.
  • Cache keys hash prompted text; same text under two prompts yields two cache misses.
  • Per-model prompt prefixes for `bge-m3`, `qwen3-embedding`, `nomic`, `e5`, and others verified with parametrized tests.
  • `CONST_KNOWN_EMBEDDING_DIMENSIONS["qwen3-embedding"]` is pinned to 1024.
  • `ai.rag` settings for `top_k` and `score_threshold` are read and reach Qdrant search.
  • Lockfiles (`uv.lock`, `*.lock`, `package-lock.json`, `pnpm-lock.yaml`, `go.sum`) are skipped by indexer.
  • No chunk sent to embedder exceeds 8,192 tokens; 4,000-line synthetic file chunking verified.
  • Failed batch ends index with exit 1 naming first and last file; earlier batches stay cached for resume.
  • `MESSAGES.rag.paused` added, docstrings and knowledge base updated.
  • Offline tests with stub embedders run without gateway/network and each under 1 s.
  • `changelog.d/1065.md` records the fix under `### Fixed`.
  • `uv run devops ci` passes.
  • Pending a person: (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) restart hog's Ollama pod while a multi-file review runs to verify pause and resume live.

@dan-petty
dan-petty merged commit ad9fba0 into release/v0.2.28 Oct 7, 2026
9 checks passed
@dan-petty
dan-petty deleted the fix/failing-embedding-model-pauses-rag branch October 7, 2026 01:29
dan-petty added a commit that referenced this pull request Oct 7, 2026
* fix(k8s): track main in argo cd git-source targetRevisions while service image pins release (#1261) (#1262)

* fix(k8s): track main in argo cd git-source targetRevisions while service image pins release (#1261)

* fix(release): parse applications in release prepare and generalize manifest counts

* fix(ui): defer dashboard refresh when unmounted to prevent NoMatches worker failure (#519) (#1263)

* fix(ui): defer dashboard refresh when unmounted to prevent NoMatches worker failure (#519)

* fix(k8s): ensure devops configmap exists in clean test environments

* fix(security): redact telemetry and kill process group on timeout in async process runner (#780) (#1264)

* fix(ai): web_fetch reports a failed fetch as a tool failure, not as page text (#894) (#1265)

* feat(ai): web_fetch renders pages as untrusted, escaped markdown within a budget (#896) (#1266)

* feat(ai): web_fetch renders pages as untrusted, escaped markdown within a budget (#896)

* fix(deps): pin markdownify and beautifulsoup4 to exact versions matching uv.lock

* fix(k8s): resolve portkey probe path and gpu-feature-discovery image tag (#1267) (#1268)

* fix(k8s): resolve portkey probe path and gpu-feature-discovery image tag (#1267)

- Fix Portkey AI Gateway liveness and readiness probe path to / instead of /health, resolving CrashLoopBackOff
- Align GPU Feature Discovery image to nvcr.io/nvidia/k8s-device-plugin:v0.16.2 to resolve ImagePullBackOff
- Update devops-cli AI gateway probe helper to check / for the Portkey provider
- Update test_k8s.py assertions and author changelog fragment and task tracking

* fix(test): disable logfire pytest plugin to prevent ambient telemetry DNS lookups (#1267)

* fix(ai): mcp command tools return the failing output and never write to the protocol stream (#839) (#1269)

* refactor(github): read a pull request's checks once, fail-closed, for wait, monitor and readiness (#769)

* feat(k8s): increase roadmap-service analysis context window to 64k (#1271) (#1272)

* fix(review): a verdict that both confirms and refutes its finding stays unverified with a contradiction note (#1059) (#1273)

* fix(ai): a failing embedding model pauses rag lookups instead of ending rag for the run (#1065) (#1274)

* fix(ai): review calls through the gateway no longer stall on ollama (#1069)

* docs: hand-written docs name only commands, options, and architecture patterns that exist (#921) (#1276)

* fix(review): a review scans a worktree of the reviewed revision, never hands a deleted file to a tool, and reports which files each tool scanned (#1047) (#1277)

* feat(review): every reported finding is admitted with anchor and commit location (#871) (#1278)

* fix(release): finalize v0.2.28 release preparation, changelog collation, and image pin

* fix(k8s): resolve argocd application out-of-sync and manifest generation failures (#1279) (#1281)

* fix(k8s): resolve argocd application out-of-sync and manifest generation failures (#1279)

* feat(k8s): add push-config command and dynamic configmap deployment

* feat(k8s): generate gitignored .argocd-source.yaml overrides and remove private references (#1279)

- Add devops k8s argocd-source command and devops_cli.k8s.argocd_source module
- Generate .argocd-source.yaml parameter overrides for devops and ingress overlays
- Remove hardcoded domain patches and ignoreDifferences
- Remove devops k8s push-config command in favor of .argocd-source.yaml overrides
- Sanitize internal hostnames, .lan servers, and private domains from repository

* fix(review): address copilot review remediations and collate changelog for v0.2.28 (#1284)

* fix(release): address second-round copilot review remediations for v0.2.28 (#1285)

* fix(k8s): apply active devops configmap dynamically via stdin without overwriting tracked files (#1286)

* fix(review): sanitize code language and propagate added diff lines to admission (#1287)

* fix(k8s): stream rendered ingress and patch argo cd application overrides during deployment (#1288)

* fix(review): integrate advisory anchor, base fingerprints, and fail-closed configmaps (#1289)

* fix(review): integrate advisory anchor, base fingerprints, and fail-closed configmaps

* refactor(review): isolate scanner file buckets into strongly-typed dataclass

* fix(k8s): argo cd takes homelab values from deploy-time overrides, and the repository holds no private or placeholder config (#1290) (#1292)

* fix(k8s): argo cd takes homelab values from deploy-time overrides, and the repository holds no private or placeholder config (#1290)

Argo CD reads .argocd-source.yaml only from the Git repository, so the gitignored generator from #1281 never reached it, and the tracked placeholder ConfigMap was enforced over the rendered one. deploy-stack now renders ConfigMap devops-cli-config from config.yaml outside Argo CD, and writes the configured hosts onto the devops and ingress Applications as Kustomize patches that the cluster app-of-apps ignores. Everything is rendered before anything is written, and an unset setting stops it with an error naming the setting.

Closes #1290

* fix(k8s): derive the argo cd host overrides from each application's revision, and close the review's gaps (#1290)

The host patches now come from what each Application renders at its targetRevision (or --argocd-revision), fetched into a temporary directory, never from the local checkout. They reuse the native template substitution and cover wildcard and TLS hosts. The ConfigMap renderer has no placeholder fallback, teardown deletes the ConfigMap, the dry run reports the new writes and refuses like the deploy, AppProject homelab ignores the orphaned ConfigMap, and the docs describe the release-merge steps.

* fix(k8s): git never reads an application's repository or revision as an option, and deploy-stack refuses to clear staged hosts (#1290)

The revision fetch reads the repository and revision after --end-of-options, without prompts and within a time limit. A revision whose Application renders no placeholder host is refused instead of writing an empty patch list, and a multi-source Application is refused by name. The dry run reports the domain the overrides would use, the docs set the service settings before the first deploy, describe the release-merge steps for releases after this one, and the changelog fragment drops the Removed entry for a command that never shipped.

* docs(k8s): the release-merge steps re-apply the devops config map when its template changes, and the dry run names why a domain is unusable (#1290)

* chore(release): the v0.2.28 changelog takes #1290 and drops the argocd-source entry it replaced (#1293)

* fix(k8s): a native deploy-stack applies the grafana dashboards again (#1297) (#1306)

* fix(ai): an interrupted rag index resumes every file whose chunks were not all stored (#1296) (#1305)

* fix(ai): an interrupted rag index resumes every file whose chunks were not all stored (#1296)

* fix(ai): a partly stored rag file is cached as incomplete, so its points are purged if it changes before the resume (#1296)

* fix(review): suppressed and pre-existing scanner findings reach their review.md sections, and profile.json counts admission rejections (#1295) (#1304)

* fix(review): suppressed and pre-existing scanner findings reach their review.md sections, and profile.json counts admission rejections (#1295)

* fix(review): each suppressed finding is its own row, by file and line, in review.md (#1295)

* chore(release): the v0.2.28 changelog takes #1295, #1296 and #1297 into the entries they complete (#1340)

* fix(review): an inline suppression marker hides only findings of the tool it belongs to (#1341) (#1342)

* fix(review): an inline suppression marker hides only findings of the tool it belongs to (#1341)

* chore(release): the v0.2.28 changelog records #1341 in the #871 entry, in this one pull request (#1341)

* chore(release): the v0.2.28 notes say dependency advisories are always listed as introduced and gateway reviews can exceed the slot count (#1355)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

1 participant