Repository navigation
Description
Problem
The "RAG Query Latency (p50, p95)" panel on the devops-cli Grafana dashboard flattens at exactly 5 s. The owner first read the flat line as a 5-second timeout. It is the histogram's top bucket: devops_cli_rag_query_duration_ms uses _MILLISECONDS = (10, 25, 50, 100, 250, 500, 1000, 2500, 5000) (telemetry/instruments.py:45). In any hour where more than 5% of queries exceed 5 s, histogram_quantile(0.95, …) returns the top finite bound, 5000. The panel's description says so, but the cap sits below the query's own timeouts, so the panel hides the tail it exists to show.
Measured on 2026-10-02 over 24 h, from Prometheus:
| Measure | Value |
|---|---|
| RAG queries | 2,856 |
| Mean | 822 ms |
| Took ≤1 s | 2,553 |
| Took ≤2.5 s | 2,714 |
| Took ≤5 s | 2,792 |
| Took over 5 s | 64 (2.2%) |
No timeout on the query path is near 5 s. The embedding request times out at ai.tasks.embedding.timeout (default 15 s), and the Qdrant client at 60 s or more. The 5 s values in ai/rag/embeddings.py:510,550 cap the dimension probes used at indexing, not at query time.
What the query's time is spent on (SemanticRetriever.search, ai/rag/retriever.py:234-297):
- One embedding call through the gateway. The gateway's
litellm_request_total_latency_metricforbge-m3:latestover the same 24 h: 2,859 requests, 102 over 1 s and 15 over 5 s. So embedding is only part of the tail. - Two Qdrant searches, one after the other (code and docs collections,
_search_collections). In the owner's config both the gateway and Qdrant are reached through Cloudflare (ai.retric.click,qdrant.retric.click), so a query makes three round trips through the tunnel. - Qdrant retries.
_execute_with_retryreconnects and sleeps0.5 * attempton a transient error, such as a keep-alive connection the tunnel closed while idle. Nothing counts these retries. - Local reranking (
SearchReranker), which makes no network call.
Nothing records the split between these stages, so the tail cannot be attributed today.
Acceptance criteria
- Buckets. The RAG query histogram's buckets reach past the query's own timeouts: up to 60 s, keeping the existing sub-second resolution. The panel description states the new cap, which the existing test in
tests/test_telemetry_instruments.pyderives from the bounds. - Stage timing. A query records each stage's time: embedding, Qdrant search and ranking. Either a
stagelabel on one histogram, or one histogram per stage with the same buckets. - The panel. The "RAG Query Latency" panel, or a new one next to it, shows p95 per stage.
- Retry counter. A counter records Qdrant retries by operation and error class, and the panel row shows it.
- Concurrent search. The two collections are searched at the same time. The result is identical to the sequential search; a test checks ordering and deduplication.
- Tests. Offline: stubs for the embedder and the Qdrant client. They show the stage timings, the retry counter and concurrent search. A test also asserts that the top bucket is at least the query path's largest timeout.
uv run devops cipasses.- Pending a person: a 24 h look at the per-stage p95, to name the tail's cause, and either a follow-up issue or the conclusion in the task file.
Key questions
- A label or separate histograms? A
stagelabel ondevops_cli_rag_query_duration_ms(proposed). One series name keeps the dashboard queries and the cap test simple. The whole-query observation keeps its own stage value,total. - Does the bucket change break history? For about one window, yes.
histogram_quantileover a range that mixes the old and newlesets reads oddly until the old series leave the window. The changelog says so.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(telemetry): rag query latency reaches past 5 s, times each stage,…
dan-petty commentedon Oct 2, 2026
Closed by #993, merged into
release/v0.2.25.GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by
devops gh issues close-merged.feat(release): v0.2.25 (#1089)