Skip to content

fix(ai): a reply names its server by the origin of the URL called, so a password in an AI URL stays out of every record - #2488

Merged
dan-petty merged 8 commits into
mainfrom
fix/1110-reply-server-origin
Oct 28, 2026
Merged

dan-petty merged 8 commits into
mainfrom
fix/1110-reply-server-origin

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The AI client named the server of a reply with display text, and that text kept the userinfo of the configured URL. Each provider wrote "<type> (<host>)" with urlparse(...).netloc, which keeps user:password@. The client then read the host back out of that text for the spend ledger, the counter label and the span. Thus a password in ai.ollama_urls, ai.gateway_url or ai.api_base_url went to the terminal output of devops ai, devops analyze and the review. It also went to the spend ledger (server and backend_info), to the server label of the AI counters, to the llm_response_received span event and to the response cache. A streamed Ollama call and an embedding request kept the userinfo in the same way. devops ai cost report --by backend and the review benchmark showed a stored served_by value with its userinfo.

A reply now holds its server as an httpx2 origin:

  • LLMResponse.origin is httpx2.URL(url).origin of the URL that the provider called. The Ollama, OpenAI-compatible and Claude paths set it. An origin has a scheme, a host and a port, and never userinfo.
  • authority_label and origin_label in ai/client/models.py write host[:port] with the authority serialiser of httpx2. Every "<type> (<host>)" text uses them.
  • LLMClient gets the origins of its configured URLs one time. A configured URL with no origin shows unknown.
  • The ledger server, the counter server label and the span server.address and server.port come from the origin of the reply. A span that has server.address also has server.port. When the URL has no port, server.port is the default port of the scheme.
  • A streamed Ollama call keeps the origin of the leased server. An embedding request names its server by the origin of its endpoint.
  • served_by_authority reads a stored served_by value for the table of devops ai cost report --by backend and for the review benchmark. A value that it cannot read shows unknown.

The change deletes _extract_server_from_backend_info, _server_span_attributes and each urlparse(...).netloc and urlsplit(...).netloc read of an AI URL. Userinfo in a configured URL stays valid, because httpx2 sends it as Basic authentication. The new spec ai-reply-server holds this behavior. docs/TELEMETRY.md says that the span server comes from the origin of the URL.

The label is the text that httpx2 writes. Thus the host is in lower case, an IDN host is its A-label, and the label has no default port of the scheme. A configured URL with an upper-case host, an IDN host or an explicit :80 or :443 starts new ledger server groups and new counter series. A price override keyed on :80, :443 or a Unicode host does not match. Pricing compares the server host with the Unicode host of the settings, so it can treat a configured server with an IDN name as remote.

Ledger rows, response-cache entries and exported counter series from before this change keep the text that they hold. If a configured AI URL held a password, change that password, then run devops ai cost reset and devops ai cache clear. The JSON and YAML forms of the cost report export the stored values as they are.

Other issues hold the related work: the qdrant.upsert_points span (#2459), a stored served_by that pricing.is_local cannot read (#2462), and the server names of devops ai benchmark and the embedding benchmark (#2481).

Closes #1110

Change: openspec/changes/archive/2026-10-28-1110-reply-server-origin/

…called

Plan the change 1110-reply-server-origin and add the tests that fail on
main: a password in a configured AI URL reaches the backend_info text,
the spend ledger, the counter labels, the spans and the response cache;
a span has no server.port for a URL without a port; and the served_by
displays show the stored text.
A reply now carries httpx2.URL(url).origin of the URL that the provider
called. The display text, the spend ledger server, the counter server
label and the span server.address and server.port come from that
origin, so the userinfo of a configured AI URL stays out of them. The
span server.port is now the default port of the scheme when the URL has
none. A streamed Ollama call keeps the origin of the leased server.

Delete _extract_server_from_backend_info, _server_span_attributes and the
urlparse(...).netloc reads of AI URLs.
…s endpoint

The ledger server and backend_info of an embedding request, and the
server.address and server.port of its ai.rag.ollama_embed_batch span, now
come from the httpx2 origin of the endpoint. A password in ai.ollama_urls
no longer reaches the spend ledger, the counter labels or the span through
an embedding request. The span helper moves next to the label helper, so
the chat client and the embedding engine share it.
…erinfo

devops ai cost report --by backend and devops review benchmark read a
stored served_by value with one parse next to the label helper: httpx2
for an absolute URL and read_url_or_authority for a bare host:port. The
cost report shows host:port and the review benchmark shows the host.
Both show unknown for a value that names no server, and never the stored
text. Delete the urlparse and urlsplit reads of served_by.
…w-up issues

The comment of CONST_AI_BACKEND_HOST_UNKNOWN names each case that shows
it. The change folder names the follow-up issues for the Qdrant span and
the pricing read of a stored served_by value.
…, with no patch of devops-cli

The span test sends each call through the `transport=` parameter of `LLMClient` to an httpx2 `MockTransport`. It does not replace `_ollama_messages` or `track_request_spend`. The dispatch span names the server that answered: with two Ollama URLs, the server that refuses the connection is not named. A URL with no port gets the default port of its scheme. The stream span names a server only when one server is configured.

The cost report test writes to the shared `spend_ledger` fixture and does not patch `get_spend_ledger`.
…for the benchmarks

The spec of `ai-reply-server` now says that the table of `devops ai cost report --by backend` shows the label. The `--json` and `--yaml` forms export the stored values as data. The design records this, and it records that `devops ai cost reset` removes an old row that holds userinfo.

The spec has no scenario for a dispatched reply with no origin, because no public path gives such a reply. New scenarios pin the server that answered from two Ollama URLs and the stream span of one Ollama URL. The design says why the fallback stays.

`devops ai benchmark` and the embedding benchmark name each server by the text of its configured URL. They are not sites of #1110, so the design and the tasks name the follow-up #2481.

The span sentence in docs/TELEMETRY.md and the requirement sentences of the spec are now at most 25 words, as ASD-STE100 requires. The design uses "A URL" and "does not match".
@dan-petty dan-petty added scope/ai AI review pipeline, personas, prompts, LLM client, or RAG scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault scope/telemetry OpenTelemetry tracing spans, Prometheus metrics, and Jaeger type/security Type security: a vulnerability or a leak labels Oct 28, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results

Local runs on head 7fb66bae, after the rebase onto origin/main at 08d70ca6.

Targeted tests: uv run devops ci test tests/ai/client/test_reply_server.py tests/test_ai_client_telemetry.py tests/test_telemetry.py tests/test_ai_streaming.py tests/test_ai_gateway.py tests/test_ai_gateway_base_url.py tests/test_ai_client_providers_and_embeddings.py tests/test_rag_embeddings.py tests/test_ai_served_by.py tests/test_review_profile.py tests/test_http_egress.py tests/test_embedding_benchmark.py tests/test_ai_spend_pricing.py: 487 passed, 0 failed.

uv run devops docs generate --sync-readme makes no change. uv run devops openspec archive 1110-reply-server-origin: every spec and change validates. The pre-push hook passed.

The rebase had one conflict in src/devops_cli/ai/rag/embeddings.py. #2484 deleted the validate_configured_service_url pre-flight check of the Ollama embedding batch. The resolution keeps that deletion and keeps the origin imports of this change.

Fail-to-pass

uv run devops ci fail-to-pass --base origin/main (the replay of the changed tests on 08d70ca6):

  failed on base: tests.ai.client.test_reply_server::test_a_password_in_a_configured_url_stays_out_of_every_record[gateway] (assert (['Basic dXNl...0b9"}'], ...}) == (['Basic dXNl...ns': [], ...}))
  failed on base: tests.ai.client.test_reply_server::test_a_reply_names_its_server_by_the_origin_of_the_url_called[claude-default] (AssertionError: assert (None, 'claud...thropic.com'}) == (Origin(schem...r.port': 443}))
  failed on base: tests.ai.client.test_reply_server::test_a_configured_url_with_no_origin_displays_unknown[no-scheme] (AssertionError: assert ('4000', 'openai (4000)') == ('unknown', '...ai (unknown)'))
  failed on base: tests.ai.client.test_reply_server::test_a_reply_names_its_server_by_the_origin_of_the_url_called[ollama-upper-case-host] (AssertionError: assert (None, 'ollam...port': 11434}) == (Origin(schem...port': 11434}))
  failed on base: tests.ai.client.test_reply_server::test_a_reply_names_its_server_by_the_origin_of_the_url_called[ollama-ipv6] (AssertionError: assert (None, 'ollam...port': 11434}) == (Origin(schem...port': 11434}))
  failed on base: tests.ai.client.test_reply_server::test_a_reply_names_its_server_by_the_origin_of_the_url_called[ollama-userinfo] (AssertionError: assert (None, 'ollam...port': 11434}) == (Origin(schem...port': 11434}))
  failed on base: tests.ai.client.test_reply_server::test_a_reply_names_its_server_by_the_origin_of_the_url_called[ollama-default-port] (AssertionError: assert (None, 'ollam...er.port': 80}) == (Origin(schem...er.port': 80}))
  failed on base: tests.ai.client.test_reply_server::test_a_configured_url_with_no_origin_displays_unknown[unreadable] (ValueError: Invalid IPv6 URL)
  failed on base: tests.ai.client.test_reply_server::test_a_streamed_reply_names_its_leased_server_without_its_password (AssertionError: assert (['Hello ', '...m:11434'], {}) == (['Hello ', '...m:11434'], {}))
  failed on base: tests.ai.client.test_reply_server::test_a_password_in_a_configured_url_stays_out_of_every_record[ollama] (assert (['Basic dXNl...c89"}'], ...}) == (['Basic dXNl...ns': [], ...}))
  failed on base: tests.ai.client.test_reply_server::test_a_reply_names_its_server_by_the_origin_of_the_url_called[gateway-userinfo] (AssertionError: assert (None, 'gatew....port': 4000}) == (Origin(schem....port': 4000}))
  failed on base: tests.test_ai_client_telemetry::test_server_attributes_come_from_the_origin_of_the_url_called[dispatch-scheme-default-port] (AssertionError: assert {'server.addr...'example.com'} == {'server.addr...er.port': 443})
  failed on base: tests.test_ai_served_by::test_cost_command_names_a_serving_backend_by_its_host_and_port[url-userinfo] (AssertionError: assert (0, ['user:pw...e.com:11434']) == (0, ['example.com:11434']))
  failed on base: tests.test_ai_served_by::test_cost_command_names_a_serving_backend_by_its_host_and_port[no-server] (AssertionError: assert (0, ['example.com:']) == (0, ['unknown']))
  failed on base: tests.test_review_profile::test_backend_labels_drop_the_cluster_dns_suffix (AssertionError: assert ['ollama-0', ...m:11434', ...] == ['ollama-0', ...ple.com', ...])
  failed on base: tests.test_telemetry::test_response_span_attributes_and_semantic_conventions (TypeError: LLMResponse.__new__() got an unexpected keyword argument 'origin')
  failed on base: tests.test_telemetry::test_response_span_attributes_enriched (TypeError: LLMResponse.__new__() got an unexpected keyword argument 'origin')
  failed on base: tests.test_rag_embeddings::test_an_ollama_batch_names_its_server_without_the_password_of_its_url (AssertionError: assert ([('user:pw@e...e.com:11434'}) == ([('example.c...rt': '11434'}))
18 failed on base (18 failed and 166 passed in tests/ai/client/test_reply_server.py, tests/test_ai_client_telemetry.py, tests/test_ai_served_by.py, tests/test_rag_embeddings.py, tests/test_review_profile.py, tests/test_telemetry.py; 0 errored).

Pending a person

  • If ai.ollama_urls, ai.gateway_url or ai.api_base_url held user:password before this change, change that password. Then run devops ai cost reset and devops ai cache clear.
  • Review the diff in tuicr (tuicr -r origin/main..HEAD).

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 18:34
@dan-petty
dan-petty merged commit 3ec083f into main Oct 28, 2026
17 of 19 checks passed
@dan-petty
dan-petty deleted the fix/1110-reply-server-origin branch October 28, 2026 18:42
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.10.1](v0.10.0...v0.10.1)
(2026-10-28)


### Bug Fixes

* **ai:** a reply names its server by the origin of the URL called, so a
password in an AI URL stays out of every record
([#2488](#2488))
([3ec083f](3ec083f)),
closes [#1110](#1110)
* **ai:** the AI service clients dial through the egress-checked factory
and check the address at the connect
([#2484](#2484))
([08d70ca](08d70ca))


### Code Refactoring

* **config:** each setting declares its variable on its settings field,
and the option, variable and secret registries are derived from it
([#2466](#2466))
([daaffc6](daaffc6))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/ai AI review pipeline, personas, prompts, LLM client, or RAG scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault scope/telemetry OpenTelemetry tracing spans, Prometheus metrics, and Jaeger type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ai): replies carry their server as an httpx2 origin, so a password in an AI URL stays out of output, the spend ledger, metrics, spans and cache

1 participant