Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-30
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Design

## Decisions

- **One label function for the Qdrant client.** `qdrant_server_label(url)` is in `ai/rag/qdrant.py`, the only module that reads a Qdrant address. `QdrantClient.server_label` applies it to `base_url`. The retriever and `list_collections` read the property. The investigator holds the configured URL and no client property in its test doubles, so it calls `qdrant_server_label` with that URL. No caller formats a URL.
- **An HTTP URL uses `server_label` of #2481.** It already gives `host[:port]` and `unknown`. The RAG module imports it inside the function, as the module does for its other helpers.
- **A Service address uses `parse_service_url`.** The text is `<service>.<namespace>`, as the #2459 span writes `server.address`. A numeric port is added as `:<port>`, as for an HTTP URL, so two ports of one Service keep two cache keys. A named port gives no suffix. `ServiceAddressError` gives `unknown`: a label never raises, and the address text is not shown.
- **`InvalidURLError` is fixed at the class.** The cause is one place: the class writes its URL argument. Each raiser, in `validate_url` and in the clients, passes the URL it holds. The class now writes `server_label(url)` in the message and in `details["url"]`. A raiser needs no change, and a new raiser cannot leak.
- **The message tells the kind of problem when there is no server to name.** `Invalid URL for server <label>: <reason>` for a URL with an origin, and `Invalid URL: <reason>` for one with none. The quoted `'unknown'` looked like a URL and hid the problem. Each raiser already writes a reason that tells the kind (`Only http and https URLs may be requested`, `Invalid Ollama URL scheme ...`), so the class change loses no hint for the Ollama and broker raisers. The class never names a scheme, because a text such as `user:secret@host` reads with `user` as its scheme. The Qdrant `__init__` reason names `qdrant.url`.
- **The cache key holds the label and a digest of the whole base URL.** The label drops the scheme, the path and a default port, so `http://example.com` and `https://example.com` would share a key, and the model check of the second server would be skipped or compared with a wrong value. The key is `(label, sha256(base_url), collection)`. The digest is in memory only and is never logged.
- **The reason texts stop repeating the URL.** `validate_url` and `_validate_dns_name_syntax` wrote `'{url}'` in a reason. The class names the server already, so the reason drops it. The hostname text stays, because a host holds no userinfo.

## Rejected alternatives

- **Pass a label from `QdrantClient.__init__` to `InvalidURLError`.** `validate_url` raises the same class with the full URL, and the probe in the proposal shows the path in its text.
- **`mask_uri_credentials` for the log lines.** It masks the password only. A user name alone and the path stay in the text.
- **A label helper in `ai/client/models.py`.** `origin_label` takes an origin, not a URL string.
- **A shared label module for the `k8s://` form.** The Qdrant client is the only reader of that form here.

- **The label alone as the key.** The review showed two servers with one label (scheme and path prefix).
- **The label of a `k8s://` URL in `InvalidURLError`.** `server_label` reads the namespace as the host. No Service address reaches this class from the Qdrant client, and a new Service-aware label in the shared class has no other reader.

## Non-goals

- `OllamaClient` writes its URL in a reason text (`ai/models/ollama.py`), and `_parse_and_validate_scheme` writes it in a `missing valid hostname` text. The class change masks the URL argument of each, and the reason text is a separate site, outside this issue.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Proposal

## Why

Issue #2709: four places in the RAG module and one error class name the Qdrant server by the whole configured URL.

- The URL in `qdrant.url` can hold userinfo, which the client sends as Basic authentication, and a path.
- #2459 made the `qdrant.upsert_points` span name its server by host and port. Four sites still write the URL.
- `QdrantClient.list_collections` writes `self.base_url` in a debug log line.
- The investigator writes the configured `qdrant.url` in its "unreachable" debug line.
- `InvalidURLError` writes its URL in its message and in `details["url"]`. The Qdrant client raises it, and so does `validate_configured_service_url`.
- `_verify_single_collection_for_search` keys its in-memory cache with `str(qdrant.base_url)`.

Userinfo is valid configuration, so the change keeps it in the request and out of every text that the client writes.

## What Changes

- New `qdrant_server_label(url)` in `ai/rag/qdrant.py`, and `QdrantClient.server_label`, which uses it for `self.base_url`.
- An `http` or `https` URL shows as `server_label` (`ai/benchmark/labels.py`, #2481) shows it: `host[:port]`.
- A `k8s://` address shows as `<service>.<namespace>`, with `:<port>` when the port is a number.
- A text with no origin, and a `k8s://` address that names no Service, show as `unknown`.
- The `list_collections` log line, the investigator log line and the retriever cache key use the label.
- The retriever cache key holds the label and a SHA-256 digest of the whole base URL. The label drops the scheme, the path and a default port, so two servers can share it. The digest tells them apart.
- `InvalidURLError` names its server with `server_label`, in its message and in `details["url"]`: `Invalid URL for server <label>: <reason>`. A URL with no origin gives `Invalid URL: <reason>`, so `unknown` never reads as a URL. This covers the Qdrant `__init__` error and the errors of `validate_url`, and it covers every other raiser of the class. The reason keeps the kind of problem. The Qdrant `__init__` reason names `qdrant.url`.
- Two reason texts of `validate_url` and `_validate_dns_name_syntax` no longer repeat the URL.
- The change alters observable text, so it has the spec delta `qdrant-server-label`. It fits one pull request.

## Capabilities

### New Capabilities

- `qdrant-server-label`: how the log lines, errors and cache keys of the Qdrant client name their server.

### Modified Capabilities

None.

## Impact

- `src/devops_cli/ai/rag/qdrant.py`, `investigator.py`, `retriever.py`.
- `src/devops_cli/exceptions/validation.py`, `src/devops_cli/core/validation.py`.
- `tests/test_rag_qdrant_server_label.py`.

## Feasibility

- The leak is real on `origin/main` at `a3453463`. With `http://user:secret@127.0.0.1:1/prefix/path`, `list_collections` writes `Failed to list Qdrant collections from http://user:secret@127.0.0.1:1/prefix/path: ...` to the debug log. The new tests read the log records and the error text.
- `validate_configured_service_url` does not name the server by host and port. The base `DevOpsCLIError` masks secrets in the message and in `details`, so the password and the user name show as `<masked-user>:<masked-password>`. The path stays. A URL with no scheme, such as `user:secret@example.com:6333/prefix`, has no URL syntax that the masker can read, so `InvalidURLError` shows it in full, in its message and in `details["url"]`. `validate_url` also repeats the URL in two reason texts.
- `SSRFBlockedError` already shows `scheme://<masked>:port/path`. It holds no userinfo and is outside this issue.
- `get_url_origin("user:secret@example.com:6333")` is `None`, because httpx2 reads `user` as a scheme. `server_label` then gives `unknown`. `get_url_origin("k8s://devops/qdrant:6333")` is the namespace with no port, so a `k8s://` address needs `parse_service_url`, as in #2459.
- The retriever cache key stays in memory. `_SEARCH_VERIFIED_MODELS` has no reader other than `_verify_single_collection_for_search` and `reset_search_verified_models`, so no export or log shows it.

## Existing Tool Considered

`server_label` (#2481) composes `get_url_origin` (#1112) and `origin_label` (#1110). httpx2 reads the origin, and its origin never holds userinfo. `parse_service_url` reads a Service address. The change builds no parser: `qdrant_server_label` is one branch for the `k8s://` form that calls these helpers. It deletes the four uses of the whole URL and the URL text in `InvalidURLError`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## Purpose

How the log lines, errors and cache keys of the Qdrant client name their server. The name is the host and the port of the configured address, so the userinfo and the path of the URL never get into a log, an error or a key.

## ADDED Requirements

### Requirement: A Qdrant server shows as host and port
The label of a Qdrant address SHALL be `host[:port]` for an `http` or `https` URL, with no scheme, no userinfo and no path. The label of a `k8s://` or `k8s+https://` Service address SHALL be `<service>.<namespace>`, followed by `:<port>` when the port is a number. The label of a text with no origin, and of a Service address that names no Service, SHALL be `unknown`.

#### Scenario: A URL with userinfo and a path
- **WHEN** the address is `http://user:secret@example.com:6333/prefix/path`
- **THEN** the label is `example.com:6333`

#### Scenario: A Service address
- **WHEN** the address is `k8s+https://user:secret@devops/qdrant:6333/prefix/path?q=secret`
- **THEN** the label is `qdrant.devops:6333`

#### Scenario: A text with no origin
- **WHEN** the address is `user:secret@example.com:6333/prefix`
- **THEN** the label is `unknown`

### Requirement: Log lines name the server by its label
The debug line of `QdrantClient.list_collections` for a failure, and the debug line of the RAG investigator for an unreachable Qdrant server, SHALL name the server by its label. They SHALL hold no userinfo and no path.

#### Scenario: The list of collections fails
- **WHEN** `qdrant.url` is `http://user:secret@example.com:6333/prefix/path` and `list_collections` fails
- **THEN** the log line is `Failed to list Qdrant collections from example.com:6333: <error>`

#### Scenario: The investigator finds the server unreachable
- **WHEN** `qdrant.url` is `http://user:secret@example.com:6333/prefix/path` and the server does not answer
- **THEN** the log line is `Qdrant vector store unreachable at example.com:6333, skipping RAG investigation`

### Requirement: An invalid URL error never holds the URL
`InvalidURLError` SHALL hold no userinfo, no path and no URL text in its message and in `details["url"]`. The errors of `QdrantClient` and of `validate_configured_service_url` for an invalid address SHALL hold no userinfo and no path.

#### Scenario: A URL with no scheme
- **WHEN** `qdrant.url` is `user:secret@example.com:6333/prefix/path`
- **THEN** the message is `Invalid URL: missing scheme or host in qdrant.url`
- **AND** the message and `details` hold no `secret`, no `user` and no `prefix`

#### Scenario: A URL with a scheme that the client refuses
- **WHEN** `qdrant.url` is `ftp://user:secret@example.com:6333/prefix/path`
- **THEN** the message is `Invalid URL for server example.com:6333: Invalid Qdrant URL scheme 'ftp': must be http or https`
- **AND** the message and `details` hold no `secret`, no `user`, no `prefix` and no `://`

### Requirement: An invalid URL error names its server or the kind of problem
When the URL has an origin, the message of `InvalidURLError` SHALL be `Invalid URL for server <label>: <reason>`. When it has none, the message SHALL be `Invalid URL: <reason>`, so the label `unknown` never reads as a URL. The reason SHALL tell the kind of problem. The reason of `QdrantClient` for an address with no scheme or host SHALL name the setting `qdrant.url`.

#### Scenario: An address with no scheme or host names the setting
- **WHEN** `qdrant.url` is `localhost:6333`
- **THEN** the message is `Invalid URL: missing scheme or host in qdrant.url`

#### Scenario: The broker refuses a scheme
- **WHEN** a request for `file:///etc/passwd` reaches the HTTP broker
- **THEN** the message is `Invalid URL: Only http and https URLs may be requested`

### Requirement: The search cache key tells servers apart without holding the URL
The in-memory key that records a verified collection SHALL hold the label of the server, the SHA-256 digest of the whole base URL, and the collection name. It SHALL NOT hold the URL. Two servers whose labels are equal SHALL have two keys when their base URLs differ.

#### Scenario: A URL with userinfo
- **WHEN** a collection is verified for a client with `qdrant.url` `http://user:secret@example.com:6333/prefix/path`
- **THEN** the key is `("example.com:6333", <digest of the base URL>, <collection>)`
- **AND** the key holds no `secret`, no `user` and no `prefix`

#### Scenario: Servers that differ in scheme or path prefix
- **WHEN** a collection is verified for `http://example.com` and for `https://example.com`, or for `http://example.com/qdrant-a` and for `http://example.com/qdrant-b`
- **THEN** each server has its own key, and the model of the second server is checked against its own recorded model

#### Scenario: Addresses with the label unknown
- **WHEN** two clients have different base URLs and the label `unknown`
- **THEN** each has its own key
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Tasks

## 1. Qdrant log lines, errors and cache key name the server by host and port

- [x] Add failing tests: the label of an HTTP URL, a Service address and a text with no origin; the `list_collections` and investigator log lines; the `InvalidURLError` text for four invalid URLs; the retriever cache key
- Verification: `uv run devops ci test tests/test_rag_qdrant_server_label.py`
- [x] Add `qdrant_server_label` and `QdrantClient.server_label`, and use them in the two log lines and the cache key
- Verification: `uv run devops ci test tests/test_rag_qdrant_server_label.py tests/test_rag_qdrant.py tests/test_rag_investigator.py tests/test_rag_indexer_retriever.py`
- [x] Make `InvalidURLError` name its server by label with the kind of problem kept, name `qdrant.url` in the Qdrant reason, and drop the URL from two reason texts of `validate_url`
- Verification: `uv run devops ci test tests/test_rag_qdrant_server_label.py tests/test_validation.py tests/test_http.py`
- [x] Key the retriever cache by label, digest of the base URL and collection name, and add the collision tests
- Verification: `uv run devops ci test tests/test_rag_qdrant_server_label.py tests/test_rag_indexer_retriever.py`
- [x] Regenerate the documentation that the change touches: it changes no command, option or MCP tool
- Verification: `uv run devops docs generate --sync-readme`

## 2. Archive

- [x] Archive the change
- Verification: `uv run devops openspec archive 2709-qdrant-log-host-label`
72 changes: 72 additions & 0 deletions openspec/specs/qdrant-server-label/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# qdrant-server-label Specification

## Purpose
How the log lines, errors and cache keys of the Qdrant client name their server. The name is the host and the port of the configured address, so the userinfo and the path of the URL never get into a log, an error or a key.

## Requirements

### Requirement: A Qdrant server shows as host and port
The label of a Qdrant address SHALL be `host[:port]` for an `http` or `https` URL, with no scheme, no userinfo and no path. The label of a `k8s://` or `k8s+https://` Service address SHALL be `<service>.<namespace>`, followed by `:<port>` when the port is a number. The label of a text with no origin, and of a Service address that names no Service, SHALL be `unknown`.

#### Scenario: A URL with userinfo and a path
- **WHEN** the address is `http://user:secret@example.com:6333/prefix/path`
- **THEN** the label is `example.com:6333`

#### Scenario: A Service address
- **WHEN** the address is `k8s+https://user:secret@devops/qdrant:6333/prefix/path?q=secret`
- **THEN** the label is `qdrant.devops:6333`

#### Scenario: A text with no origin
- **WHEN** the address is `user:secret@example.com:6333/prefix`
- **THEN** the label is `unknown`

### Requirement: Log lines name the server by its label
The debug line of `QdrantClient.list_collections` for a failure, and the debug line of the RAG investigator for an unreachable Qdrant server, SHALL name the server by its label. They SHALL hold no userinfo and no path.

#### Scenario: The list of collections fails
- **WHEN** `qdrant.url` is `http://user:secret@example.com:6333/prefix/path` and `list_collections` fails
- **THEN** the log line is `Failed to list Qdrant collections from example.com:6333: <error>`

#### Scenario: The investigator finds the server unreachable
- **WHEN** `qdrant.url` is `http://user:secret@example.com:6333/prefix/path` and the server does not answer
- **THEN** the log line is `Qdrant vector store unreachable at example.com:6333, skipping RAG investigation`

### Requirement: An invalid URL error never holds the URL
`InvalidURLError` SHALL hold no userinfo, no path and no URL text in its message and in `details["url"]`. The errors of `QdrantClient` and of `validate_configured_service_url` for an invalid address SHALL hold no userinfo and no path.

#### Scenario: A URL with no scheme
- **WHEN** `qdrant.url` is `user:secret@example.com:6333/prefix/path`
- **THEN** the message is `Invalid URL: missing scheme or host in qdrant.url`
- **AND** the message and `details` hold no `secret`, no `user` and no `prefix`

#### Scenario: A URL with a scheme that the client refuses
- **WHEN** `qdrant.url` is `ftp://user:secret@example.com:6333/prefix/path`
- **THEN** the message is `Invalid URL for server example.com:6333: Invalid Qdrant URL scheme 'ftp': must be http or https`
- **AND** the message and `details` hold no `secret`, no `user`, no `prefix` and no `://`

### Requirement: An invalid URL error names its server or the kind of problem
When the URL has an origin, the message of `InvalidURLError` SHALL be `Invalid URL for server <label>: <reason>`. When it has none, the message SHALL be `Invalid URL: <reason>`, so the label `unknown` never reads as a URL. The reason SHALL tell the kind of problem. The reason of `QdrantClient` for an address with no scheme or host SHALL name the setting `qdrant.url`.

#### Scenario: An address with no scheme or host names the setting
- **WHEN** `qdrant.url` is `localhost:6333`
- **THEN** the message is `Invalid URL: missing scheme or host in qdrant.url`

#### Scenario: The broker refuses a scheme
- **WHEN** a request for `file:///etc/passwd` reaches the HTTP broker
- **THEN** the message is `Invalid URL: Only http and https URLs may be requested`

### Requirement: The search cache key tells servers apart without holding the URL
The in-memory key that records a verified collection SHALL hold the label of the server, the SHA-256 digest of the whole base URL, and the collection name. It SHALL NOT hold the URL. Two servers whose labels are equal SHALL have two keys when their base URLs differ.

#### Scenario: A URL with userinfo
- **WHEN** a collection is verified for a client with `qdrant.url` `http://user:secret@example.com:6333/prefix/path`
- **THEN** the key is `("example.com:6333", <digest of the base URL>, <collection>)`
- **AND** the key holds no `secret`, no `user` and no `prefix`

#### Scenario: Servers that differ in scheme or path prefix
- **WHEN** a collection is verified for `http://example.com` and for `https://example.com`, or for `http://example.com/qdrant-a` and for `http://example.com/qdrant-b`
- **THEN** each server has its own key, and the model of the second server is checked against its own recorded model

#### Scenario: Addresses with the label unknown
- **WHEN** two clients have different base URLs and the label `unknown`
- **THEN** each has its own key
Loading
Loading