Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(server): keep upstream names out of remote profile error messages (#695)

Krisztian Gajdarc8c1c85c9004
diff --git a/packages/sie_server/src/sie_server/adapters/remote/_limits.py b/packages/sie_server/src/sie_server/adapters/remote/_limits.py
index f60acf5da..7e77ab328 100644
--- a/packages/sie_server/src/sie_server/adapters/remote/_limits.py
+++ b/packages/sie_server/src/sie_server/adapters/remote/_limits.py
@@ -39,6 +39,7 @@ like an inference call.
from __future__ import annotations
import contextvars
+import logging
import math
import threading
import time
@@ -56,6 +57,8 @@ from sie_server.adapters.errors import (
from sie_server.config.upstreams import RateCap, Upstream, installed_upstreams
from sie_server.observability.worker_telemetry import worker_telemetry
+logger = logging.getLogger(__name__)
+
_SLOT_RETRY_AFTER_S = 1
@@ -306,7 +309,8 @@ def _installed_limiter(
) -> UpstreamLimiter:
upstream = installed_upstreams().get(name)
if upstream is None:
- raise RuntimeError(f"upstream {name!r} is not defined in the startup configuration")
+ logger.warning("upstream %r is not defined in the startup configuration", name)
+ raise RuntimeError("this remote profile's upstream is not defined in the startup configuration")
with _REGISTRY_LOCK:
entry = limiters.get(name)
if entry is None or entry[0] is not upstream:
diff --git a/packages/sie_server/src/sie_server/adapters/remote/openai.py b/packages/sie_server/src/sie_server/adapters/remote/openai.py
index a4381b00d..cdae635f0 100644
--- a/packages/sie_server/src/sie_server/adapters/remote/openai.py
+++ b/packages/sie_server/src/sie_server/adapters/remote/openai.py
@@ -28,6 +28,7 @@ from __future__ import annotations
import asyncio
import json
+import logging
import math
from collections.abc import AsyncGenerator, AsyncIterator, Mapping
from concurrent.futures import ThreadPoolExecutor
@@ -76,6 +77,8 @@ if TYPE_CHECKING:
from sie_server.types.grammar import GrammarSpec
from sie_server.types.inputs import ImageInput, Item, VideoInput
+logger = logging.getLogger(__name__)
+
_JSON = "application/json"
REQUEST_DEADLINE_S = 60.0
READ_TIMEOUT_S = 10.0
@@ -127,7 +130,8 @@ class OpenAIUpstreamAdapter(BaseAdapter, GenerationAdapter):
def load(self, device: str) -> None:
upstream = upstream_for_serving(self._upstream_name)
if upstream.kind is not UpstreamKind.OPENAI:
- raise UpstreamConfigError(f"upstream {self._upstream_name!r} is not of kind 'openai'")
+ logger.warning("upstream %r is not of kind 'openai'", self._upstream_name)
+ raise UpstreamConfigError("this remote profile's upstream is not of kind 'openai'")
self._upstream = upstream
self._client = upstream_sync_client(upstream)
self._executor = ThreadPoolExecutor(
@@ -455,9 +459,14 @@ class OpenAIUpstreamAdapter(BaseAdapter, GenerationAdapter):
if self._client is None or self._executor is None or self._upstream is None:
raise RuntimeError(ERR_NOT_LOADED)
if endpoint not in self._upstream.endpoints:
+ logger.warning(
+ "upstream %r declares no %s endpoint, so its remote profile cannot %s",
+ self._upstream_name,
+ endpoint.value,
+ operation,
+ )
raise InvalidInputError(
- f"upstream {self._upstream_name!r} declares no {endpoint.value} endpoint, "
- f"so this profile cannot {operation}"
+ f"this remote profile cannot {operation}: its upstream declares no {endpoint.value} endpoint"
)
return self._executor, self._upstream
diff --git a/packages/sie_server/src/sie_server/adapters/remote/sie.py b/packages/sie_server/src/sie_server/adapters/remote/sie.py
index 8fd1a77d7..0058b4227 100644
--- a/packages/sie_server/src/sie_server/adapters/remote/sie.py
+++ b/packages/sie_server/src/sie_server/adapters/remote/sie.py
@@ -28,6 +28,7 @@ from __future__ import annotations
import asyncio
import json
+import logging
import math
from collections.abc import AsyncIterator, Mapping
from concurrent.futures import ThreadPoolExecutor
@@ -83,6 +84,8 @@ if TYPE_CHECKING:
from sie_server.types.grammar import GrammarSpec
from sie_server.types.inputs import ImageInput, Item, VideoInput
+logger = logging.getLogger(__name__)
+
_MSGPACK = "application/msgpack"
REQUEST_DEADLINE_S = 60.0
READ_TIMEOUT_S = 10.0
@@ -189,7 +192,8 @@ class SieUpstreamAdapter(BaseAdapter, GenerationAdapter):
def load(self, device: str) -> None:
upstream = upstream_for_serving(self._upstream_name)
if upstream.kind is not UpstreamKind.SIE:
- raise UpstreamConfigError(f"upstream {self._upstream_name!r} is not of kind 'sie'")
+ logger.warning("upstream %r is not of kind 'sie'", self._upstream_name)
+ raise UpstreamConfigError("this remote profile's upstream is not of kind 'sie'")
self._upstream = upstream
self._client = upstream_sync_client(upstream)
self._executor = ThreadPoolExecutor(
diff --git a/packages/sie_server/src/sie_server/config/upstreams.py b/packages/sie_server/src/sie_server/config/upstreams.py
index c580e8ff5..ed97245bd 100644
--- a/packages/sie_server/src/sie_server/config/upstreams.py
+++ b/packages/sie_server/src/sie_server/config/upstreams.py
@@ -20,6 +20,7 @@ from __future__ import annotations
import copy
import ipaddress
import json
+import logging
import math
import os
import re
@@ -40,6 +41,8 @@ from sie_server.config.model import UPSTREAM_NAME_PATTERN, is_remote_adapter_pat
if TYPE_CHECKING:
from sie_server.config.model import ModelConfig
+logger = logging.getLogger(__name__)
+
UPSTREAMS_FILE_ENV = "SIE_UPSTREAMS_FILE"
REMOTE_SERVING_ENV = "SIE_REMOTE_SERVING"
@@ -484,7 +487,8 @@ def upstream_for_serving(name: str) -> Upstream:
raise RemoteServingDisabledError(f"remote serving is switched off ({REMOTE_SERVING_ENV})")
upstream = _INSTALLED.upstreams.get(name)
if upstream is None:
- raise UpstreamConfigError(f"upstream {name!r} is not defined in the startup configuration")
+ logger.warning("upstream %r is not defined in the startup configuration", name)
+ raise UpstreamConfigError("this remote profile's upstream is not defined in the startup configuration")
return upstream
diff --git a/packages/sie_server/tests/adapters/test_remote_openai_adapter.py b/packages/sie_server/tests/adapters/test_remote_openai_adapter.py
index 56662b559..3343f0cdb 100644
--- a/packages/sie_server/tests/adapters/test_remote_openai_adapter.py
+++ b/packages/sie_server/tests/adapters/test_remote_openai_adapter.py
@@ -374,8 +374,9 @@ def test_an_upstream_without_usage_is_served_on_score_and_rerank_without_usage(
def test_an_operation_the_upstream_does_not_declare_is_refused_before_sending(
- fake_openai: FakeOpenAI, openai_app: Callable[..., FastAPI]
+ fake_openai: FakeOpenAI, openai_app: Callable[..., FastAPI], caplog: pytest.LogCaptureFixture
) -> None:
+ caplog.set_level(logging.WARNING)
with TestClient(openai_app(fake_openai.url, endpoints=("embeddings",))) as client:
response = post(
client, fake_openai, f"/v1/score/{MODEL}", {"query": {"text": "red"}, "items": [{"text": "red wine"}]}
@@ -383,7 +384,10 @@ def test_an_operation_the_upstream_does_not_declare_is_refused_before_sending(
assert response.status_code == 400, response.text
assert error_code(response) == "INVALID_INPUT"
- assert "declares no rerank endpoint" in response.text
+ assert "this remote profile cannot score: its upstream declares no rerank endpoint" in response.text
+ assert "open-host" not in response.text
+ assert "x-sie-upstream" not in response.headers
+ assert "upstream 'open-host' declares no rerank endpoint" in caplog.text
assert fake_openai.calls == []
@@ -625,16 +629,22 @@ def test_extraction_is_refused(adapter: OpenAIUpstreamAdapter, fake_openai: Fake
assert fake_openai.calls == []
-def test_a_profile_on_an_upstream_of_another_kind_does_not_load(fake_openai: FakeOpenAI) -> None:
+def test_a_profile_on_an_upstream_of_another_kind_does_not_load(
+ fake_openai: FakeOpenAI, caplog: pytest.LogCaptureFixture
+) -> None:
+ caplog.set_level(logging.WARNING)
install_upstreams(
{"open-host": Upstream.model_validate({"kind": "sie", "base_url": fake_openai.url, "rate_cap": RATE_CAP})}
)
try:
- with pytest.raises(UpstreamConfigError, match="is not of kind 'openai'"):
+ with pytest.raises(UpstreamConfigError, match="is not of kind 'openai'") as raised:
OpenAIUpstreamAdapter(upstream="open-host", upstream_model=UPSTREAM_MODEL).load("cpu")
finally:
install_upstreams({})
+ assert "open-host" not in str(raised.value)
+ assert "upstream 'open-host' is not of kind 'openai'" in caplog.text
+
def test_an_unloaded_adapter_sends_nothing(adapter: OpenAIUpstreamAdapter, fake_openai: FakeOpenAI) -> None:
adapter.unload()
diff --git a/packages/sie_server/tests/adapters/test_remote_sie_adapter.py b/packages/sie_server/tests/adapters/test_remote_sie_adapter.py
index cf7e75293..b2a0ebc49 100644
--- a/packages/sie_server/tests/adapters/test_remote_sie_adapter.py
+++ b/packages/sie_server/tests/adapters/test_remote_sie_adapter.py
@@ -26,7 +26,7 @@ from sie_server.adapters.remote import _http as remote_http
from sie_server.adapters.remote import sie as remote_sie
from sie_server.app.app_factory import AppFactory
from sie_server.app.app_state_config import AppStateConfig
-from sie_server.config.upstreams import Upstream, install_upstreams
+from sie_server.config.upstreams import Upstream, UpstreamConfigError, install_upstreams
from sie_server.core.oom import is_oom_error
from sie_server.core.upstream_client import upstream_sync_client
from sie_server.types.inputs import InvalidInputError, Item
@@ -188,6 +188,27 @@ def test_with_the_switch_off_a_stale_upstream_name_does_not_stop_startup(
assert "remote serving is switched off" in response.text
+def test_a_profile_on_an_upstream_of_another_kind_does_not_load(caplog: pytest.LogCaptureFixture) -> None:
+ caplog.set_level(logging.WARNING)
+ upstream = Upstream.model_validate(
+ {
+ "kind": "openai",
+ "base_url": "https://openai.example.internal/v1",
+ "endpoints": ["embeddings"],
+ "rate_cap": {"requests_per_minute": 60, "max_concurrency": 4},
+ }
+ )
+ install_upstreams({"team-sie": upstream})
+ try:
+ with pytest.raises(UpstreamConfigError, match="is not of kind 'sie'") as raised:
+ remote_sie.SieUpstreamAdapter(upstream="team-sie", upstream_model="sie-fake").load("cpu")
+ finally:
+ install_upstreams({})
+
+ assert "team-sie" not in str(raised.value)
+ assert "upstream 'team-sie' is not of kind 'sie'" in caplog.text
+
+
class Recorder:
def __init__(self, respond: httpx.Response) -> None:
self.requests: list[httpx.Request] = []
diff --git a/packages/sie_server/tests/adapters/test_remote_upstream_limits.py b/packages/sie_server/tests/adapters/test_remote_upstream_limits.py
index e27916e05..d2f4ce9e0 100644
--- a/packages/sie_server/tests/adapters/test_remote_upstream_limits.py
+++ b/packages/sie_server/tests/adapters/test_remote_upstream_limits.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import json
+import logging
import time
from collections.abc import Callable, Iterator
from concurrent.futures import ThreadPoolExecutor
@@ -661,6 +662,29 @@ def test_the_queue_path_answers_a_refused_item_at_once_with_the_wait(refusal: st
assert (outcome.error_code, outcome.retry_after_s) == ("QUEUE_FULL", 40)
+def test_an_upstream_missing_from_the_configuration_is_named_only_in_the_log(
+ adapter_over: Callable[..., remote_sie.SieUpstreamAdapter], caplog: pytest.LogCaptureFixture
+) -> None:
+ caplog.set_level(logging.WARNING)
+ recorder = Recorder(dense_answer)
+ adapter = adapter_over(recorder)
+ install_upstreams({})
+ item = EncodeBatchItem(
+ work_item_id="w.0", request_id="w", item_index=0, total_items=1, timestamp=0.0, item={"text": "a"}
+ )
+
+ with pytest.raises(RuntimeError) as raised:
+ adapter.encode([Item(text="a")], ["dense"])
+ outcome = _inference_exception_outcome(item, raised.value)
+
+ assert recorder.requests == []
+ assert (outcome.error_code, outcome.error) == (
+ "inference_error",
+ "this remote profile's upstream is not defined in the startup configuration",
+ )
+ assert f"upstream {UPSTREAM!r} is not defined in the startup configuration" in caplog.text
+
+
@pytest.mark.parametrize("reason", ["rate_cap", "concurrency_cap", "breaker_open", "half_open", "probe_active"])
def test_batch_refusal_counts_every_unsent_call(
limiter: Callable[..., UpstreamLimiter], clock: Clock, events: Events, reason: str
diff --git a/packages/sie_server/tests/config/test_upstreams.py b/packages/sie_server/tests/config/test_upstreams.py
index 18a5d078a..26c6391fc 100644
--- a/packages/sie_server/tests/config/test_upstreams.py
+++ b/packages/sie_server/tests/config/test_upstreams.py
@@ -12,7 +12,9 @@ from sie_server.config.upstreams import (
UpstreamConfigError,
UpstreamCredentialError,
UpstreamKind,
+ install_upstreams,
load_upstreams,
+ upstream_for_serving,
validate_upstream_url,
)
@@ -210,3 +212,14 @@ def test_the_credential_is_read_by_reference_when_needed(monkeypatch: pytest.Mon
assert upstream.api_key() == CANARY
for rendering in (repr(upstream), str(upstream), upstream.model_dump_json(), str(upstream.model_dump())):
assert CANARY not in rendering
+
+
+def test_an_upstream_missing_at_serving_time_is_named_only_in_the_log(caplog: pytest.LogCaptureFixture) -> None:
+ caplog.set_level(logging.WARNING)
+ install_upstreams({})
+
+ with pytest.raises(UpstreamConfigError) as raised:
+ upstream_for_serving("team-sie")
+
+ assert str(raised.value) == "this remote profile's upstream is not defined in the startup configuration"
+ assert "upstream 'team-sie' is not defined in the startup configuration" in caplog.text