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
Expand Up @@ -82,8 +82,9 @@ Routes: `GET /api/llm/providers`, `GET /api/llm/models`,
`active_profile` resolve the connection into `agent_settings.llm`
(`GET /api/settings` with `X-Expose-Secrets: plaintext` shows it);
`POST /api/conversations/{conversation_id}/switch_llm` resolves it for a
running conversation (model switching family). `POST /api/profiles/{name}/validate`
does not resolve it today (`F23.validate-linked-draft`).
running conversation (model switching family), and
`POST /api/profiles/{name}/validate` resolves it for the pre-flight of a
draft (`F23.validate-linked-draft`).
- SDK: no Python client calls these routes. In-process code uses
`ProviderConnectionStore` and `LLMProfileStore(provider_store=...)`
(`openhands-sdk/openhands/sdk/llm/`). `RemoteWorkspace.get_llm()` of a
Expand Down Expand Up @@ -505,7 +506,7 @@ Preconditions:
(`****QA23`). With the real key rotated back and the profile activated
through `POST /api/profiles/{name}/activate`, a new conversation
finishes.
- **Validate a linked draft (`F23.validate-linked-draft`), known bug.**
- **Validate a linked draft (`F23.validate-linked-draft`).**
Pre-flight the same DeepSeek model with the key inline (positive
control), then as a draft linked to `CONN`.

Expand All @@ -515,15 +516,13 @@ Preconditions:
| control-agent-server api POST /api/profiles/qa-f23-draft/validate --stdin --timeout 120 --expect 200 --check valid eq true
control-agent-server api POST /api/profiles/qa-f23-draft/validate --timeout 120 --expect 200 \
--json "{\"llm\": {\"model\": \"deepseek/deepseek-flash\", \"provider_connection_id\": \"$CONN\", \"num_retries\": 0}}" \
--save F23.validate-linked-draft/linked --check valid eq true --check error eq null # bug: status eq 200 && response.body.valid eq false && response.body.error.type eq LLMAuthenticationError
--save F23.validate-linked-draft/linked --check valid eq true --check error eq null
```
Expected: both `valid: true`, since a linked draft runs on the
connection's key once saved and activated. Today the linked draft is
`valid: false` with `LLMAuthenticationError` (`Authentication Fails`):
`validate_profile` sends the posted LLM unchanged and never calls
`resolve_provider_connection`, unlike activation and `switch_llm`. A
client cannot work around it by sending the key, because the connection
routes never return it.
Expected: both `valid: true`. `validate_profile` resolves
`provider_connection_id` to the connection's `api_key` and `base_url`
before the pre-flight, as activation and `switch_llm` do, so a client
never needs the key (the connection routes never return it). A dangling
`provider_connection_id` is 422 naming the missing connection.
- **Restart (`F23.persist-restart`).** Restart the run and read everything
back.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ async def validate_profile(
"""
cipher = get_cipher(request)
llm = decrypt_incoming_llm_secrets(body.llm, cipher) if cipher else body.llm
# Check a draft linked to a provider connection with the connection's
# credentials, as activation and ``switch_llm`` run it. No-op without
# ``provider_connection_id``; a dangling link is a 422 naming it.
with store_errors():
llm = get_llm_profile_store().resolve_provider_connection(llm, cipher=cipher)

messages = [
Message(
Expand Down
67 changes: 67 additions & 0 deletions tests/agent_server/test_profiles_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,3 +2210,70 @@ def test_validate_profile_subscription_missing_credentials(client):
body = response.json()
assert body["valid"] is False
assert "subscription login" in body["error"]["message"].lower()


def test_validate_profile_resolves_provider_connection(client):
"""A draft linked to a provider connection is checked with its credentials.

Regression for #5644: the pre-flight sent the posted LLM as is, so a
linked draft without an inline key was checked keyless and reported
``valid=False`` even though activating it would run on the connection's
key.
"""
from unittest.mock import MagicMock

connection_id = client.post(
"/api/llm/provider-connections",
json={
"display_name": "Anthropic Work",
"provider": "anthropic",
"api_key": "sk-ant-conn",
"base_url": "https://conn.example.com",
},
).json()["id"]

captured: dict = {}

async def fake_acompletion(self, messages, **kwargs):
captured["api_key"] = self._get_litellm_api_key_value()
captured["base_url"] = self.base_url
return MagicMock()

with (
patch("openhands.sdk.llm.llm.LLM.uses_responses_api", return_value=False),
patch("openhands.sdk.llm.llm.LLM.acompletion", fake_acompletion),
):
response = client.post(
"/api/profiles/draft/validate",
json={
"llm": {
"model": "anthropic/claude-sonnet-4",
"provider_connection_id": connection_id,
}
},
)

assert response.status_code == 200
assert response.json() == {"valid": True, "error": None}
assert captured == {
"api_key": "sk-ant-conn",
"base_url": "https://conn.example.com",
}


def test_validate_profile_with_dangling_provider_connection_returns_422(client):
"""A draft linked to a missing connection names it, like activation does."""
with patch("openhands.sdk.llm.llm.LLM.acompletion") as acompletion:
response = client.post(
"/api/profiles/draft/validate",
json={
"llm": {
"model": "anthropic/claude-sonnet-4",
"provider_connection_id": "missing-connection",
}
},
)

assert response.status_code == 422
assert "missing-connection" in response.json()["detail"]
acompletion.assert_not_called()
Loading