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(api): constrain native stream execution evidence pairs
Attila Laszlo Nagy7cfa50e73068
diff --git a/packages/sie_gateway/openapi.json b/packages/sie_gateway/openapi.jsonindex fedb046d6..6354cc8dd 100644--- a/packages/sie_gateway/openapi.json+++ b/packages/sie_gateway/openapi.json@@ -1505,6 +1505,30 @@},"GenerateChunk": {"description": "One JSON payload from a SIE-native generation SSE ``data:`` event.\nThe stream is terminated separately by the literal ``data: [DONE]``.",+ "oneOf": [+ {+ "required": [+ "execution_identity_sha256",+ "execution_binding_sha256"+ ]+ },+ {+ "not": {+ "anyOf": [+ {+ "required": [+ "execution_identity_sha256"+ ]+ },+ {+ "required": [+ "execution_binding_sha256"+ ]+ }+ ]+ }+ }+ ],"properties": {"done": {"type": "boolean"diff --git a/packages/sie_gateway/src/openapi.rs b/packages/sie_gateway/src/openapi.rsindex 650b2c33c..77d822587 100644--- a/packages/sie_gateway/src/openapi.rs+++ b/packages/sie_gateway/src/openapi.rs@@ -278,6 +278,20 @@ fn apply_gateway_openapi_overrides(value: &mut Value) {}});+ if let Some(chunk) = value+ .get_mut("components")+ .and_then(|components| components.get_mut("schemas"))+ .and_then(|schemas| schemas.get_mut("GenerateChunk"))+ {+ chunk["oneOf"] = json!([+ {"required": ["execution_identity_sha256", "execution_binding_sha256"]},+ {"not": {"anyOf": [+ {"required": ["execution_identity_sha256"]},+ {"required": ["execution_binding_sha256"]}+ ]}}+ ]);+ }+if let Some(create_pool) = value.get_mut("components").and_then(|components| components.get_mut("schemas"))@@ -3526,6 +3540,16 @@ mod tests {.unwrap().contains(&json!(field)));}+ assert_eq!(+ chunk["oneOf"],+ json!([+ {"required": ["execution_identity_sha256", "execution_binding_sha256"]},+ {"not": {"anyOf": [+ {"required": ["execution_identity_sha256"]},+ {"required": ["execution_binding_sha256"]}+ ]}}+ ])+ );let revision = &spec["paths"]["/v1/generate/{model}"]["post"]["responses"]["200"]["headers"]["X-SIE-Model-Revision"];assert_eq!(revision["schema"]["pattern"], "^[0-9a-f]{64}$");diff --git a/packages/sie_sdk/tests/client/test_chat.py b/packages/sie_sdk/tests/client/test_chat.pyindex 1353194c5..4b107033b 100644--- a/packages/sie_sdk/tests/client/test_chat.py+++ b/packages/sie_sdk/tests/client/test_chat.py@@ -237,13 +237,7 @@ def test_stream_generate_yields_chunks_and_normalizes_model_path() -> None:@pytest.mark.parametrize("with_evidence", [False, True])def test_stream_generate_preserves_optional_terminal_execution_evidence(with_evidence: bool) -> None:- terminal: GenerateChunk = {- "request_id": "request-1",- "seq": 1,- "text_delta": "",- "done": True,- "finish_reason": "stop",- }+ terminal = GenerateChunk(request_id="request-1", seq=1, text_delta="", done=True, finish_reason="stop")if with_evidence:terminal.update(execution_identity_sha256="a" * 64, execution_binding_sha256="b" * 64)delta = {"request_id": "request-1", "seq": 0, "text_delta": "Hello", "done": False}diff --git a/packages/sie_server/openapi.json b/packages/sie_server/openapi.jsonindex 6df18a1eb..e9dca4f0f 100644--- a/packages/sie_server/openapi.json+++ b/packages/sie_server/openapi.json@@ -3038,6 +3038,38 @@},"GenerateChunk": {"description": "One SIE-native Server-Sent Event from a streaming generate request.",+ "oneOf": [+ {+ "properties": {+ "execution_identity_sha256": {+ "type": "string"+ },+ "execution_binding_sha256": {+ "type": "string"+ }+ },+ "required": [+ "execution_identity_sha256",+ "execution_binding_sha256"+ ]+ },+ {+ "not": {+ "anyOf": [+ {+ "required": [+ "execution_identity_sha256"+ ]+ },+ {+ "required": [+ "execution_binding_sha256"+ ]+ }+ ]+ }+ }+ ],"properties": {"request_id": {"description": "Request id shared by every event in the stream",@@ -3127,6 +3159,34 @@],"default": null,"description": "Terminal generation error"+ },+ "execution_identity_sha256": {+ "anyOf": [+ {+ "pattern": "^[0-9a-f]{64}$",+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "description": "Optional worker-origin execution identity, only on a successful terminal event together with execution_binding_sha256. Older or self-hosted deployments may omit both. Distinct from the catalog weights revision and executed bundle/config hash.",+ "title": "Execution Identity Sha256"+ },+ "execution_binding_sha256": {+ "anyOf": [+ {+ "pattern": "^[0-9a-f]{64}$",+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "default": null,+ "description": "Optional worker-origin execution binding, with the same successful-terminal complete-pair contract",+ "title": "Execution Binding Sha256"}},"required": [diff --git a/packages/sie_server/src/sie_server/types/openapi.py b/packages/sie_server/src/sie_server/types/openapi.pyindex 986bb869f..27cf89356 100644--- a/packages/sie_server/src/sie_server/types/openapi.py+++ b/packages/sie_server/src/sie_server/types/openapi.py@@ -714,3 +714,39 @@ class GenerateChunk(BaseModel):description="Per-token log probabilities aligned with text_delta",)error: GenerateChunkErrorModel | None = Field(default=None, description="Terminal generation error")+ execution_identity_sha256: str | None = Field(+ default=None,+ pattern=r"^[0-9a-f]{64}$",+ description=(+ "Optional worker-origin execution identity, only on a successful terminal event together with "+ "execution_binding_sha256. Older or self-hosted deployments may omit both. "+ "Distinct from the catalog weights revision and executed bundle/config hash."+ ),+ )+ execution_binding_sha256: str | None = Field(+ default=None,+ pattern=r"^[0-9a-f]{64}$",+ description="Optional worker-origin execution binding, with the same successful-terminal complete-pair contract",+ )++ model_config = {+ "json_schema_extra": {+ "oneOf": [+ {+ "required": ["execution_identity_sha256", "execution_binding_sha256"],+ "properties": {+ "execution_identity_sha256": {"type": "string"},+ "execution_binding_sha256": {"type": "string"},+ },+ },+ {+ "not": {+ "anyOf": [+ {"required": ["execution_identity_sha256"]},+ {"required": ["execution_binding_sha256"]},+ ]+ }+ },+ ]+ }+ }diff --git a/packages/sie_server/tests/test_openapi_export.py b/packages/sie_server/tests/test_openapi_export.pyindex e488e9388..369570809 100644--- a/packages/sie_server/tests/test_openapi_export.py+++ b/packages/sie_server/tests/test_openapi_export.py@@ -3,6 +3,8 @@ import tomllibfrom importlib.metadata import version as pkg_versionfrom pathlib import Path+import pytest+from jsonschema import Draft202012Validatorfrom sie_server.cli import appfrom typer.testing import CliRunner@@ -248,3 +250,24 @@ def test_openapi_version_from_package() -> None:assert pkg_version("sie-server") == project_versionassert spec["info"]["version"] == project_versionassert committed_spec["info"]["version"] == project_version++[email protected]("package", ["sie_server", "sie_gateway"])+ ("evidence", "valid"),+ [+ ({}, True),+ ({"execution_identity_sha256": "a" * 64, "execution_binding_sha256": "b" * 64}, True),+ ({"execution_identity_sha256": "a" * 64}, False),+ ({"execution_binding_sha256": "b" * 64}, False),+ ({"execution_identity_sha256": "A" * 64, "execution_binding_sha256": "b" * 64}, False),+ ({"execution_identity_sha256": "a" * 63, "execution_binding_sha256": "b" * 64}, False),+ ({"execution_identity_sha256": None, "execution_binding_sha256": None}, False),+ ],+)+def test_native_stream_schema_requires_complete_execution_evidence(package: str, evidence: dict, valid: bool) -> None:+ spec_path = Path(__file__).resolve().parents[3] / "packages" / package / "openapi.json"+ spec = json.loads(spec_path.read_text())+ validator = Draft202012Validator(spec["components"]["schemas"]["GenerateChunk"])+ terminal = {"request_id": "request-1", "seq": 1, "text_delta": "", "done": True, **evidence}+ assert validator.is_valid(terminal) is validdiff --git a/packages/sie_ts_sdk/tests/typecheck/generate-chunk.ts b/packages/sie_ts_sdk/tests/typecheck/generate-chunk.tsnew file mode 100644index 000000000..bf71444cd--- /dev/null+++ b/packages/sie_ts_sdk/tests/typecheck/generate-chunk.ts@@ -0,0 +1,21 @@+import type { GenerateChunk } from "../../src/types.js";++interface TaggedGenerateChunk extends GenerateChunk {+ tag: string;+}++const terminal: TaggedGenerateChunk = {+ request_id: "request-1",+ seq: 1,+ text_delta: "",+ done: true,+ tag: "completed",+};+const attestedTerminal: TaggedGenerateChunk = {+ ...terminal,+ execution_identity_sha256: "a".repeat(64),+ execution_binding_sha256: "b".repeat(64),+};++void terminal;+void attestedTerminal;