Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix(server): reject a config delta per model instead of stalling its bundle (#489)
Krisztian Gajdar81cc42789544
diff --git a/packages/sie_gateway/docs/architecture-guide.md b/packages/sie_gateway/docs/architecture-guide.mdindex 5a213659e..0eec63c30 100644--- a/packages/sie_gateway/docs/architecture-guide.md+++ b/packages/sie_gateway/docs/architecture-guide.md@@ -238,7 +238,7 @@ Concurrency on the gateway's `ModelRegistry`:## 6. Worker-Ack Status (`GET /v1/configs/models/{id}/status`)-Admin tooling uses this endpoint after a `sie-config` write to observe whether configured workers are reporting the expected `bundle_config_hash` for each affected bundle. Worker-sidecar containers advance that hash after their bundle-scoped NATS delta is accepted by backend IPC `ApplyModelConfig`, or after the worker export reconciler replaces the bundle-scoped backend registry/catalog view from `sie-config`. During that replacement the Python worker applies every entry its `ModelConfig` schema accepts; for a rejected entry it logs the model and reason and keeps that model's current registry entries, if any. The sidecar still advances the advertised hash only when the worker's resulting hash equals the control-plane hash, and it commits the worker's `unsupported_models` together with that hash (§7).+Admin tooling uses this endpoint after a `sie-config` write to observe whether configured workers are reporting the expected `bundle_config_hash` for each affected bundle. Worker-sidecar containers advance that hash after their bundle-scoped NATS delta is accepted by backend IPC `ApplyModelConfig`, or after the worker export reconciler replaces the bundle-scoped backend registry/catalog view from `sie-config`. During that replacement the Python worker applies every entry its `ModelConfig` schema accepts; for a rejected entry it logs the model and reason and keeps that model's current registry entries, if any. It handles a live delta it rejects the same way, so a rejected delta advances the hash and is reported in `unsupported_models` instead of failing the apply. The sidecar still advances the advertised hash only when the worker's resulting hash equals the control-plane hash, and it commits the worker's `unsupported_models` together with that hash (§7).Response shape:@@ -277,7 +277,7 @@ Computation rules:`bundle_config_hash` is computed independently by `sie-config`, the gateway, and workers. The `sie-config` export/epoch surface keeps the global per-bundle hash for bootstrap and drift detection, while export snapshots and live NATS deltas also carry per-bundle/per-pool hashes for worker convergence. Worker sidecars apply only models whose top-level `pool` matches their own `SIE_POOL`, then advertise that pool-scoped hash. Gateway hot routing/readiness compares workers against the hash for the same materialized scope the worker serves: the default pool scope for unfiltered workers, or the named physical queue-pool scope for workers filtered by `SIE_POOL`. Logical API pools may draw from a different backing queue pool via `PoolSpec.queue_pool`; for the admin-tooling readiness flow to work, gateway and worker hashes must be byte-identical for that backing bundle/pool scope. A model config's top-level `pool` must therefore match the physical queue scope that will materialize it; dynamic logical pools backed by `default` should use default-scoped model configs unless a dedicated worker queue exists.-A model belongs to a bundle's hash when one of its profiles resolves to an adapter module in that bundle's `adapters` list. All three services use `sie-config`'s list for this. `sie-config` sends it as `bundle_adapters` (bundle id to adapter modules) with every export snapshot and live delta, and the worker sidecar forwards the list for its bundle over backend IPC (`ApplyModelConfig` / `ReplaceModelConfigs`). The Python worker then hashes the configs it received with that list, so a worker whose image predates an adapter still reproduces the control-plane hash. A worker that has not yet received a list, or whose `sie-config` does not send one, uses the list in its image's bundle file, as before. When the worker's schema rejects an export entry, the worker hashes the received entry's routable fields, so the hash still identifies what the control plane sent.+A model belongs to a bundle's hash when one of its profiles resolves to an adapter module in that bundle's `adapters` list. All three services use `sie-config`'s list for this. `sie-config` sends it as `bundle_adapters` (bundle id to adapter modules) with every export snapshot and live delta, and the worker sidecar forwards the list for its bundle over backend IPC (`ApplyModelConfig` / `ReplaceModelConfigs`). The Python worker then hashes the configs it received with that list, so a worker whose image predates an adapter still reproduces the control-plane hash. A worker that has not yet received a list, or whose `sie-config` does not send one, uses the list in its image's bundle file, as before. When the worker's schema rejects an export entry or a live delta, the worker hashes the received entry's routable fields, so the hash still identifies what the control plane sent.Hash equality therefore no longer implies that the worker can serve every model it covers. The worker reports the routable ids it cannot serve as `unsupported_models`: those whose adapter module is in the control-plane list but not in its image's bundle file, and those whose export entry its schema rejected when the config it retains differs in hashed fields (or it has none). The sidecar commits the list together with the hash, publishes it in its heartbeat (omitted when empty), and NAKs work for a listed model before backend IPC. The gateway routes a model to a worker only when the hash matches and the model is not listed (§2). A worker that sends no list serves every model its hash covers: before this field existed, workers hashed with their image's adapter list, so a matching hash already implied that the image contains every covered adapter. The same holds for a hash that reaches a heartbeat without a list today. Backend IPC `Ping` carries no list, so the Python worker's `Ping` hash stays scoped by its image's bundle file, and a sidecar adopts it only while it has committed no config (at startup, including a sidecar restart next to a running worker). The gateway accepts at most 1024 ids per heartbeat. A worker that reports more counts as unable to serve any model until it reports fewer, because a dropped id would otherwise read as supported. A lane is eligible only when every hash-matching worker in it can serve the model (§2), so the whole lane of an overflowing worker is routed no model while it overflows. The Candle worker reports no list. It echoes the control-plane hash only after it has parsed and applied every entry of the export or delta, so an echoed hash implies full support. An entry it cannot parse fails the whole apply: the worker keeps its previous hash and the sidecar does not advance, so the bundle is held on that worker as before.diff --git a/packages/sie_server/src/sie_server/queue_executor.py b/packages/sie_server/src/sie_server/queue_executor.pyindex 4190fedcc..31dc03673 100644--- a/packages/sie_server/src/sie_server/queue_executor.py+++ b/packages/sie_server/src/sie_server/queue_executor.py@@ -537,10 +537,10 @@ def _wrap_encode_output(output: dict, config: Any) -> dict:return wrapped-def _rejected_entry_mapping(entry: ReplaceModelConfigEntry, model_id: str) -> dict[str, Any] | None:- """Return a rejected export entry as a mapping for hashing, if it names ``model_id``."""+def _rejected_config_mapping(model_config: str, model_id: str) -> dict[str, Any] | None:+ """Return a rejected model config as a mapping for hashing, if it names ``model_id``."""try:- raw = yaml.safe_load(entry.model_config) if entry.model_config.strip() else None+ raw = yaml.safe_load(model_config) if model_config.strip() else Noneexcept yaml.YAMLError:return Noneif not isinstance(raw, dict) or raw.get("sie_id", model_id) != model_id:@@ -548,6 +548,11 @@ def _rejected_entry_mapping(entry: ReplaceModelConfigEntry, model_id: str) -> direturn raw+def _rejected_entry_mapping(entry: ReplaceModelConfigEntry, model_id: str) -> dict[str, Any] | None:+ """Return a rejected export entry as a mapping for hashing, if it names ``model_id``."""+ return _rejected_config_mapping(entry.model_config, model_id)++def _parse_exported_model_config(entry: ReplaceModelConfigEntry) -> ModelConfig:if not entry.model_config.strip():msg = "model_config is required"@@ -666,7 +671,14 @@ class QueueExecutor:self._view_state_version += 1async def apply_model_config(self, req: ApplyModelConfigRequest) -> ApplyModelConfigResponse:- """Validate and add a bundle-scoped config delta to the local registry."""+ """Validate and add a bundle-scoped config delta to the local registry.++ A delta whose config this worker rejects is handled like a rejected+ export entry in :meth:`replace_model_configs`: the model keeps its+ current registry entries, if any, and the received config is hashed and+ reported in ``unsupported_models``. A config that cannot be attributed+ to the notification's model still fails the apply.+ """if not req.bundle_id:msg = "bundle_id is required"raise ValueError(msg)@@ -675,21 +687,35 @@ class QueueExecutor:raise ValueError(msg)self._record_control_plane_adapters(req.bundle_id, req.bundle_adapters)- raw = yaml.safe_load(req.model_config)- if not isinstance(raw, dict):- msg = "model_config must decode to a YAML mapping"- raise ValueError(msg)-- model_config = ModelConfig(**raw)- if req.model_id and model_config.sie_id != req.model_id:- msg = f"model_id mismatch: notification={req.model_id!r} config={model_config.sie_id!r}"- raise ValueError(msg)-- updated_model_ids = await self._registry.add_config_async(model_config)- for model_id in updated_model_ids:- self.invalidate_model_descriptor(model_id)- if self._rejected_configs.get(req.bundle_id, {}).pop(model_config.sie_id, None) is not None:+ try:+ raw = yaml.safe_load(req.model_config)+ if not isinstance(raw, dict):+ msg = "model_config must decode to a YAML mapping"+ raise ValueError(msg)++ model_config = ModelConfig(**raw)+ if req.model_id and model_config.sie_id != req.model_id:+ msg = f"model_id mismatch: notification={req.model_id!r} config={model_config.sie_id!r}"+ raise ValueError(msg)++ updated_model_ids = await self._registry.add_config_async(model_config)+ except (TypeError, ValueError, yaml.YAMLError) as exc:+ rejected = _rejected_config_mapping(req.model_config, req.model_id) if req.model_id else None+ if rejected is None:+ raise+ logger.warning(+ "Rejected model config delta %r for bundle %s; keeping its current config, if any: %s",+ req.model_id,+ req.bundle_id,+ exc,+ )+ self._rejected_configs.setdefault(req.bundle_id, {})[req.model_id] = rejectedself._view_state_version += 1+ else:+ for model_id in updated_model_ids:+ self.invalidate_model_descriptor(model_id)+ if self._rejected_configs.get(req.bundle_id, {}).pop(model_config.sie_id, None) is not None:+ self._view_state_version += 1view = self.bundle_config_view(req.bundle_id)return ApplyModelConfigResponse(applied=True,diff --git a/packages/sie_server/tests/test_config_delta_rejection.py b/packages/sie_server/tests/test_config_delta_rejection.pynew file mode 100644index 000000000..7927c8048--- /dev/null+++ b/packages/sie_server/tests/test_config_delta_rejection.py@@ -0,0 +1,176 @@+"""A config delta the worker rejects is reported per model and does not stall its bundle.++The sidecar advertises a delta's result only when the worker's hash equals the+control-plane hash. A rejected delta must therefore still produce that hash, the+way a rejected entry in a full export does, or the worker drops out of routing+for every model of the bundle until the next export replay.+"""++from __future__ import annotations++from collections.abc import Iterator++import pytest+import yaml+from sie_server.config.upstreams import Upstream, install_upstreams+from sie_server.core.registry import ModelRegistry+from sie_server.ipc_types import ApplyModelConfigRequest, ReplaceModelConfigEntry, ReplaceModelConfigsRequest+from sie_server.queue_executor import QueueExecutor++LOCAL_MODEL = """\+sie_id: acme/local+hf_id: sentence-transformers/all-MiniLM-L6-v2+tasks:+ encode:+ dense:+ dim: 384+profiles:+ default:+ adapter_path: sie_server.adapters.sentence_transformer:Adapter+ max_batch_tokens: 4096+"""+UNKNOWN_FIELD_MODEL = LOCAL_MODEL.replace("acme/local", "acme/unknown-field") + "not_a_model_field: 1\n"+++def remote_model(model_id: str, upstream: str) -> str:+ return f"""\+sie_id: {model_id}+remote_backed: true+tasks:+ encode:+ dense:+ dim: 384+profiles:+ default:+ adapter_path: sie_server.adapters.remote.sie:SieUpstreamAdapter+ max_batch_tokens: 8192+ adapter_options:+ loadtime:+ upstream: {upstream}+ upstream_model: sie-fake+"""++[email protected](autouse=True)+def _no_upstreams() -> Iterator[None]:+ install_upstreams({})+ yield+ install_upstreams({})+++def delta(model_id: str, model_config: str, epoch: int) -> ApplyModelConfigRequest:+ return ApplyModelConfigRequest(+ bundle_id="default",+ model_id=model_id,+ epoch=epoch,+ bundle_config_hash="",+ model_config=model_config,+ )+++async def export_view(*entries: tuple[str, str]) -> tuple[str, list[str]]:+ """The hash and unsupported ids a fresh worker reports after an export of ``entries``."""+ executor = QueueExecutor(ModelRegistry(models_dir=None))+ response = await executor.replace_model_configs(+ ReplaceModelConfigsRequest(+ bundle_id="default",+ epoch=1,+ bundle_config_hash="",+ models=[ReplaceModelConfigEntry(model_id=model_id, model_config=text) for model_id, text in entries],+ )+ )+ return response.bundle_config_hash, response.unsupported_models+++ ("model_id", "rejected_config"),+ [+ ("acme/remote", remote_model("acme/remote", "team-sie")),+ ("acme/unknown-field", UNKNOWN_FIELD_MODEL),+ ],+ ids=["undefined-upstream", "schema-violation"],+)+async def test_a_rejected_delta_reports_the_export_hash_and_keeps_the_other_models(+ model_id: str, rejected_config: str+) -> None:+ registry = ModelRegistry(models_dir=None)+ executor = QueueExecutor(registry)+ await executor.apply_model_config(delta("acme/local", LOCAL_MODEL, 1))++ response = await executor.apply_model_config(delta(model_id, rejected_config, 2))++ assert response.applied is True+ assert response.unsupported_models == [model_id]+ assert (response.bundle_config_hash, response.unsupported_models) == await export_view(+ ("acme/local", LOCAL_MODEL), (model_id, rejected_config)+ )+ assert registry.has_model("acme/local")+ assert not registry.has_model(model_id)+++async def test_a_rejected_delta_keeps_the_models_current_config() -> None:+ install_upstreams(+ {+ "team-sie": Upstream.model_validate(+ {+ "kind": "sie",+ "base_url": "http://127.0.0.1:9",+ "rate_cap": {"requests_per_minute": 60, "max_concurrency": 4},+ }+ )+ }+ )+ registry = ModelRegistry(models_dir=None)+ executor = QueueExecutor(registry)+ defined = remote_model("acme/remote", "team-sie")+ await executor.apply_model_config(delta("acme/remote", defined, 1))++ response = await executor.apply_model_config(delta("acme/remote", remote_model("acme/remote", "nobody"), 2))++ assert response.unsupported_models == ["acme/remote"]+ config = registry.get_config("acme/remote")+ assert config.resolve_profile("default").loadtime["upstream"] == "team-sie"+++async def test_a_later_valid_delta_clears_the_rejection() -> None:+ install_upstreams(+ {+ "team-sie": Upstream.model_validate(+ {+ "kind": "sie",+ "base_url": "http://127.0.0.1:9",+ "rate_cap": {"requests_per_minute": 60, "max_concurrency": 4},+ }+ )+ }+ )+ registry = ModelRegistry(models_dir=None)+ executor = QueueExecutor(registry)+ await executor.apply_model_config(delta("acme/remote", remote_model("acme/remote", "nobody"), 1))++ corrected = remote_model("acme/remote", "team-sie")+ response = await executor.apply_model_config(delta("acme/remote", corrected, 2))++ assert response.unsupported_models == []+ assert registry.has_model("acme/remote")+ assert (response.bundle_config_hash, response.unsupported_models) == await export_view(("acme/remote", corrected))+++ "model_config",+ [+ "- not a mapping\n",+ "sie_id: [unclosed\n",+ LOCAL_MODEL.replace("acme/local", "acme/other"),+ ],+ ids=["not-a-mapping", "invalid-yaml", "another-model"],+)+async def test_a_delta_that_does_not_name_its_model_still_fails(model_config: str) -> None:+ registry = ModelRegistry(models_dir=None)+ executor = QueueExecutor(registry)++ with pytest.raises((ValueError, yaml.YAMLError)):+ await executor.apply_model_config(delta("acme/local", model_config, 1))++ assert not registry.has_model("acme/local")+ assert not registry.has_model("acme/other")diff --git a/packages/sie_server/tests/test_ipc_server.py b/packages/sie_server/tests/test_ipc_server.pyindex 5fce75af9..1ffb72a38 100644--- a/packages/sie_server/tests/test_ipc_server.py+++ b/packages/sie_server/tests/test_ipc_server.py@@ -1031,18 +1031,19 @@ profiles:assert worker_telemetry._dimensions(base_id, "rtx-pro-6000") == expected_dimensionsexecutor._descriptor_cache[variant_id] = MagicMock()- with pytest.raises(ValueError, match="legacy scalar"):- await executor.apply_model_config(- ApplyModelConfigRequest(- bundle_id="sglang",- model_id=base_id,- epoch=8,- bundle_config_hash="from-sie-config",- profiles_added=["default"],- model_config=_qwen_invalid_legacy_lora_yaml(),- )+ resp = await executor.apply_model_config(+ ApplyModelConfigRequest(+ bundle_id="sglang",+ model_id=base_id,+ epoch=8,+ bundle_config_hash="from-sie-config",+ profiles_added=["default"],+ model_config=_qwen_invalid_legacy_lora_yaml(),)+ )+ assert resp.applied is True+ assert resp.unsupported_models == [base_id]assert registry.has_model(base_id)assert registry.has_model(variant_id)assert registry._model_filter == {base_id, variant_id}diff --git a/packages/sie_server_sidecar/docs/architecture-guide.md b/packages/sie_server_sidecar/docs/architecture-guide.mdindex d07e290ff..6219ee8cb 100644--- a/packages/sie_server_sidecar/docs/architecture-guide.md+++ b/packages/sie_server_sidecar/docs/architecture-guide.md@@ -508,7 +508,10 @@ bundle, epoch, and payload size. Accepted deltas are forwarded to the colocated`ApplyModelConfig`, together with the notification's `bundle_adapters` list forthis bundle when `sie-config` sends one. The backend returns the applied bundleconfig hash and `unsupported_models`, the routable ids that hash covers but the-backend cannot serve. The sidecar stores the hash and the list together in+backend cannot serve. A delta whose config the Python backend rejects is not an+apply failure: the backend keeps the model's current config, hashes the received+config, and lists the model in `unsupported_models`, as it does for a rejected+export entry. The sidecar stores the hash and the list together in`ConfigApplyState` only when the hash exactly matches a non-empty control-planehash. Before anything is committed, the sidecar adopts the backend's IPC `Ping`hash, which never replaces a committed pair. `Ping` carries no list, so its hash