Skip to content

armgit / sie

Public Imported from GitHub
0

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

feat(worker): add versioned execution authority IPC methods (#544)

Krisztian Gajdar5f832a4fab97
diff --git a/packages/sie_server/src/sie_server/ipc_server.py b/packages/sie_server/src/sie_server/ipc_server.py
index ce2183722..2b8e648e3 100644
--- a/packages/sie_server/src/sie_server/ipc_server.py
+++ b/packages/sie_server/src/sie_server/ipc_server.py
@@ -30,9 +30,11 @@ from sie_server.ipc_types import (
METHOD_PROCESS_ENCODE_BATCH,
METHOD_PROCESS_EXTRACT_BATCH,
METHOD_PROCESS_GENERATE,
+ METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1,
METHOD_PROCESS_SCORE_BATCH,
METHOD_REPLACE_MODEL_CONFIGS,
METHOD_RUN_BATCH,
+ METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1,
METHOD_SET_PINNED_MODELS,
METHOD_SIGNAL_GENERATE_CANCEL,
METHOD_WORKER_CAPABILITIES,
@@ -429,6 +431,8 @@ class IpcServer:
METHOD_PROCESS_EXTRACT_BATCH,
METHOD_RUN_BATCH,
METHOD_PROCESS_GENERATE,
+ METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1,
+ METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1,
):
if self._drain_event.is_set():
await self._send_error(writer, request_id, "draining")
@@ -488,11 +492,12 @@ class IpcServer:
import msgspec # noqa: PLC0415
try:
- if method == METHOD_PROCESS_GENERATE:
+ if method in (METHOD_PROCESS_GENERATE, METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1):
await self._handle_process_generate(
msgspec.convert(body, ProcessGenerateRequest),
request_id=request_id,
writer=writer,
+ require_authority=method == METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1,
)
return
if method == METHOD_PING:
@@ -507,12 +512,15 @@ class IpcServer:
resp_body = await self._handle_process_score(msgspec.convert(body, ProcessScoreBatchRequest))
elif method == METHOD_PROCESS_EXTRACT_BATCH:
resp_body = await self._handle_process_extract(msgspec.convert(body, ProcessExtractBatchRequest))
- elif method == METHOD_RUN_BATCH:
+ elif method in (METHOD_RUN_BATCH, METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1):
# Rust scheduler drove the batch formation; we just fan
# the items into the existing
# per-op handlers. See adapter_call_loop.py for the
# full fallback matrix.
- resp_body = await self._handle_run_batch(msgspec.convert(body, RunBatchRequest))
+ resp_body = await self._handle_run_batch(
+ msgspec.convert(body, RunBatchRequest),
+ require_authority=method == METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1,
+ )
elif method == METHOD_APPLY_MODEL_CONFIG:
resp_body = await self._handle_apply_model_config(msgspec.convert(body, ApplyModelConfigRequest))
elif method == METHOD_REPLACE_MODEL_CONFIGS:
@@ -690,13 +698,15 @@ class IpcServer:
return self._config_retry(req.items)
return await self._executor.process_extract_batch(req)
- async def _handle_run_batch(self, req: RunBatchRequest) -> BatchOutcome:
- hashes = (
- payload.bundle_config_hash
- for item in req.items
- if (payload := {"encode": item.encode, "score": item.score, "extract": item.extract}.get(item.op))
- is not None
- )
+ async def _handle_run_batch(self, req: RunBatchRequest, *, require_authority: bool = False) -> BatchOutcome:
+ payloads = [
+ {"encode": item.encode, "score": item.score, "extract": item.extract}.get(item.op) for item in req.items
+ ]
+ if require_authority and (
+ not payloads or any(payload is None or not payload.bundle_config_hash for payload in payloads)
+ ):
+ raise IpcServerError("execution authority requires a nonempty hash for every batch item")
+ hashes = (payload.bundle_config_hash for payload in payloads if payload is not None)
async with self._execution_config(req.model_id, hashes) as valid:
if not valid:
return self._config_retry(req.items)
@@ -770,6 +780,7 @@ class IpcServer:
generation_models.sort()
return WorkerCapabilitiesResponse(
+ supports_execution_authority_v1=True,
has_generation_models=bool(generation_models),
generation_models=generation_models,
supported_models=supported_models,
@@ -791,6 +802,7 @@ class IpcServer:
*,
request_id: str,
writer: asyncio.StreamWriter,
+ require_authority: bool = False,
) -> None:
work_item = msgpack.unpackb(req.work_item_msgpack, raw=False)
if not isinstance(work_item, dict):
@@ -798,6 +810,8 @@ class IpcServer:
expected_hash = work_item.get("bundle_config_hash")
if expected_hash is not None and not isinstance(expected_hash, str):
raise IpcServerError("generation bundle_config_hash must be a string")
+ if require_authority and not expected_hash:
+ raise IpcServerError("execution authority requires a nonempty generation hash")
async with self._execution_config(req.model_id, [expected_hash]) as valid:
# Gateway generation routing already selects the grammar profile.
# Those routing fields are not part of the bundle hash; a worker
diff --git a/packages/sie_server/src/sie_server/ipc_types.py b/packages/sie_server/src/sie_server/ipc_types.py
index dd98cf11b..ade99e0ab 100644
--- a/packages/sie_server/src/sie_server/ipc_types.py
+++ b/packages/sie_server/src/sie_server/ipc_types.py
@@ -62,6 +62,10 @@ METHOD_SIGNAL_GENERATE_CANCEL = "SignalGenerateCancel"
# contract for focused IPC parity tests and Python-framed callers.
# Direct ``sie-server`` HTTP execution does not use this IPC boundary.
METHOD_RUN_BATCH = "RunBatch"
+# These distinct methods require live configuration authority. Older backends
+# reject the method before processing inputs, even after a child restart.
+METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1 = "RunBatchWithExecutionAuthorityV1"
+METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1 = "ProcessGenerateWithExecutionAuthorityV1"
METHOD_APPLY_MODEL_CONFIG = "ApplyModelConfig"
METHOD_REPLACE_MODEL_CONFIGS = "ReplaceModelConfigs"
METHOD_SET_PINNED_MODELS = "SetPinnedModels"
@@ -263,6 +267,7 @@ class WorkerCapabilitiesRequest(msgspec.Struct):
class WorkerCapabilitiesResponse(msgspec.Struct):
+ supports_execution_authority_v1: bool = False
has_generation_models: bool = False
generation_models: list[str] = msgspec.field(default_factory=list)
supported_models: list[str] = msgspec.field(default_factory=list)
diff --git a/packages/sie_server/tests/test_ipc_server.py b/packages/sie_server/tests/test_ipc_server.py
index 7ef248f45..1904487d4 100644
--- a/packages/sie_server/tests/test_ipc_server.py
+++ b/packages/sie_server/tests/test_ipc_server.py
@@ -32,6 +32,8 @@ from sie_server.core.worker.types import WorkerResult
from sie_server.ipc_server import IpcServer, IpcServerError
from sie_server.ipc_types import (
IPC_VERSION,
+ METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1,
+ METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1,
ApplyModelConfigRequest,
BatchOutcome,
IpcResponseChunkV1,
@@ -45,6 +47,7 @@ from sie_server.ipc_types import (
RunBatchRequest,
SetPinnedModelsRequest,
SignalGenerateCancelRequest,
+ WorkerCapabilitiesResponse,
)
from sie_server.observability import worker_telemetry
from sie_server.queue_executor import QueueExecutor
@@ -415,6 +418,106 @@ class _CapturingWriter:
return None
[email protected]("op", ["encode", "score", "extract"])
[email protected]("authority", ["valid", "stale", "missing", "empty", "decoy"])
+async def test_authority_batch_method_never_falls_back_to_unpinned_execution(
+ monkeypatch: pytest.MonkeyPatch, op: str, authority: str
+) -> None:
+ server, _, expected = _pinned_execution_server(monkeypatch)
+ inference = AsyncMock(return_value=BatchOutcome(outcomes=[]))
+ monkeypatch.setattr(server._executor, f"process_{op}_batch", inference)
+ payload = {
+ "work_item_id": "req.0",
+ "request_id": "req",
+ "item_index": 0,
+ "total_items": 1,
+ "timestamp": 1.0,
+ "bundle_config_hash": {"valid": expected, "stale": "stale", "missing": None, "empty": "", "decoy": None}[
+ authority
+ ],
+ "item": {"text": "secret-input"},
+ "query_item": {"text": "query"},
+ "score_items": [{"text": "doc"}],
+ }
+ item = {"op": op, op: payload, "work_item_id": "req.0", "request_id": "req", "item_index": 0}
+ if authority == "decoy":
+ item["score" if op != "score" else "encode"] = {**payload, "bundle_config_hash": expected}
+ writer = _CapturingWriter()
+ await server._dispatch_frame(
+ msgpack.packb(
+ {
+ "version": IPC_VERSION,
+ "method": METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1,
+ "request_id": "req",
+ "body": {
+ "model_id": "Qwen/Qwen3.6-27B",
+ "batch_id": 1,
+ "lora_key": "",
+ "total_cost": 1,
+ "items": [item],
+ },
+ },
+ use_bin_type=True,
+ ),
+ cast("asyncio.StreamWriter", writer),
+ )
+ await asyncio.gather(*server._inflight)
+ response = _decode_written_frames(writer)[0]
+ if authority == "valid":
+ assert response["ok"] is True
+ inference.assert_awaited_once()
+ else:
+ inference.assert_not_awaited()
+ if authority == "stale":
+ assert response["body"]["outcomes"][0]["disposition"] == "nak_retry"
+ else:
+ assert response["ok"] is False
+ assert "requires a nonempty hash" in response["error"]
+
+
[email protected]("authority", ["valid", "stale", "missing", "empty"])
+async def test_authority_generation_method_requires_live_hash_before_processor(
+ monkeypatch: pytest.MonkeyPatch, authority: str
+) -> None:
+ server, _, expected = _pinned_execution_server(monkeypatch)
+ inference = AsyncMock()
+ monkeypatch.setattr(server, "_process_generate", inference)
+ writer = _CapturingWriter()
+ await server._run_method(
+ METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1,
+ "req",
+ {
+ "model_id": "Qwen/Qwen3.6-27B",
+ "work_item_msgpack": msgpack.packb(
+ {
+ "model_id": "Qwen/Qwen3.6-27B",
+ "bundle_config_hash": {"valid": expected, "stale": "stale", "missing": None, "empty": ""}[
+ authority
+ ],
+ "generate": {"prompt": "secret-input"},
+ },
+ use_bin_type=True,
+ ),
+ },
+ cast("asyncio.StreamWriter", writer),
+ )
+ if authority == "valid":
+ inference.assert_awaited_once()
+ else:
+ inference.assert_not_awaited()
+ frames = _decode_written_frames(writer)
+ if authority == "stale":
+ assert [frame["body"]["kind"] for frame in frames] == ["nak", "done"]
+ else:
+ assert frames[0]["ok"] is False
+ assert "requires a nonempty generation hash" in frames[0]["error"]
+
+
+def test_legacy_capability_response_does_not_authorize_execution() -> None:
+ response = msgspec.convert({"has_generation_models": True}, type=WorkerCapabilitiesResponse)
+ assert response.supports_execution_authority_v1 is False
+
+
def _decode_written_frames(writer: _CapturingWriter) -> list[dict]:
frames: list[dict] = []
offset = 0
@@ -2592,6 +2695,7 @@ class TestGenerationSidecarIpc:
assert resp["ok"] is True
assert resp["body"] == {
+ "supports_execution_authority_v1": True,
"has_generation_models": True,
"generation_models": ["z-generate/model"],
"supported_models": ["encode/model", "z-generate/model"],
diff --git a/packages/sie_server_rust/src/ipc.rs b/packages/sie_server_rust/src/ipc.rs
index 9bfec056c..01749251a 100644
--- a/packages/sie_server_rust/src/ipc.rs
+++ b/packages/sie_server_rust/src/ipc.rs
@@ -187,6 +187,7 @@ impl IpcServer {
let supported_models = self.backend.supported_models();
let loaded_models = self.backend.loaded_models();
WorkerCapabilitiesResponse {
+ supports_execution_authority_v1: false,
has_generation_models: false,
generation_models: Vec::new(),
supported_models: supported_models.clone(),
diff --git a/packages/sie_server_rust/src/ipc_types.rs b/packages/sie_server_rust/src/ipc_types.rs
index 03e31b578..672b16781 100644
--- a/packages/sie_server_rust/src/ipc_types.rs
+++ b/packages/sie_server_rust/src/ipc_types.rs
@@ -20,6 +20,9 @@ pub const METHOD_PROCESS_GENERATE: &str = "ProcessGenerate";
pub const METHOD_WORKER_CAPABILITIES: &str = "WorkerCapabilities";
pub const METHOD_SIGNAL_GENERATE_CANCEL: &str = "SignalGenerateCancel";
pub const METHOD_RUN_BATCH: &str = "RunBatch";
+pub const METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1: &str = "RunBatchWithExecutionAuthorityV1";
+pub const METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1: &str =
+ "ProcessGenerateWithExecutionAuthorityV1";
pub const METHOD_APPLY_MODEL_CONFIG: &str = "ApplyModelConfig";
pub const METHOD_REPLACE_MODEL_CONFIGS: &str = "ReplaceModelConfigs";
pub const METHOD_SET_PINNED_MODELS: &str = "SetPinnedModels";
@@ -192,6 +195,8 @@ pub struct WorkerCapabilitiesRequest {}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkerCapabilitiesResponse {
+ #[serde(default)]
+ pub supports_execution_authority_v1: bool,
#[serde(default)]
pub has_generation_models: bool,
#[serde(default)]
diff --git a/packages/sie_server_sidecar/docs/architecture-guide.md b/packages/sie_server_sidecar/docs/architecture-guide.md
index 5da2d1e4a..12352788f 100644
--- a/packages/sie_server_sidecar/docs/architecture-guide.md
+++ b/packages/sie_server_sidecar/docs/architecture-guide.md
@@ -324,6 +324,8 @@ The Rust and Python protocol copies define the same method names:
- `WorkerCapabilities`
- `SignalGenerateCancel`
- `RunBatch`
+- `RunBatchWithExecutionAuthorityV1`
+- `ProcessGenerateWithExecutionAuthorityV1`
- `ApplyModelConfig`
- `ReplaceModelConfigs`
- `Drain`
@@ -331,6 +333,25 @@ The Rust and Python protocol copies define the same method names:
`tools/check_ipc_types_parity.py` checks the Rust protocol schema against
`packages/sie_server/src/sie_server/ipc_types.py`.
+### Execution authority protocol amendment (#415)
+
+Verified execution uses the two `WithExecutionAuthorityV1` methods. They
+require a nonempty configuration hash for every batch item or generation work
+item and retain the live Python execution lease described above. An old backend
+rejects these unknown methods before inference. The backend capability
+`supports_execution_authority_v1` defaults to false when absent; the Python
+backend advertises support, while Candle remains closed until it implements
+the same contract. Capability discovery cannot replace the method fence: a
+backend child can restart after its last positive capability response.
+
+These entrypoints prepare the backend boundary; current producers still use
+the existing methods. Gateway activation also requires a distinct versioned
+worker-direct queue subject and consumer that older sidecars cannot receive.
+Every publish and retry must retain both fences, with no legacy pool or IPC
+fallback. A missing, stale, unsupported, or unavailable authority refuses work
+before inputs execute. This extends the queue contract while preserving the
+gateway's queue-only ownership and worker-owned inference.
+
Non-streaming backend responses use one physical frame while the serialized
response is at most 32 MiB. For a larger response, the sidecar explicitly sets
the top-level `accepts_ipc_response_chunks_v1` capability on the request. A
diff --git a/packages/sie_server_sidecar/src/protocol/ipc_types.rs b/packages/sie_server_sidecar/src/protocol/ipc_types.rs
index 8a7357766..918d027d3 100644
--- a/packages/sie_server_sidecar/src/protocol/ipc_types.rs
+++ b/packages/sie_server_sidecar/src/protocol/ipc_types.rs
@@ -42,6 +42,9 @@ pub const METHOD_SIGNAL_GENERATE_CANCEL: &str = "SignalGenerateCancel";
/// for backends that don't implement `run_batch` and for unit tests
/// that don't wire a scheduler.
pub const METHOD_RUN_BATCH: &str = "RunBatch";
+pub const METHOD_RUN_BATCH_WITH_EXECUTION_AUTHORITY_V1: &str = "RunBatchWithExecutionAuthorityV1";
+pub const METHOD_PROCESS_GENERATE_WITH_EXECUTION_AUTHORITY_V1: &str =
+ "ProcessGenerateWithExecutionAuthorityV1";
pub const METHOD_APPLY_MODEL_CONFIG: &str = "ApplyModelConfig";
pub const METHOD_REPLACE_MODEL_CONFIGS: &str = "ReplaceModelConfigs";
pub const METHOD_SET_PINNED_MODELS: &str = "SetPinnedModels";
@@ -434,6 +437,8 @@ pub struct WorkerCapabilitiesRequest {
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct WorkerCapabilitiesResponse {
+ #[serde(default)]
+ pub supports_execution_authority_v1: bool,
#[serde(default)]
pub has_generation_models: bool,
#[serde(default)]