Skip to content

fix(telemetry): rag query latency tops out at a 5 s bucket, and its stages are not timed #975

Closed

Description

@dan-petty

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_metric for bge-m3:latest over 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_retry reconnects and sleeps 0.5 * attempt on 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.py derives from the bounds.
  • Stage timing. A query records each stage's time: embedding, Qdrant search and ranking. Either a stage label 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 ci passes.
  • 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 stage label on devops_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_quantile over a range that mixes the old and new le sets reads oddly until the old series leave the window. The changelog says so.

Activity

  1. added this to the v0.2.25 milestone on Oct 2, 2026
  2. added
    type/bug
    scope/telemetry
    priority/p2-medium
    on Oct 2, 2026
  3. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    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.

  4. added a commit that references this issue on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/telemetrytype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions