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(gateway): keep requests for undeclared outputs off numerical bridges (#597)
Krisztian Gajdarb6f17028156b
diff --git a/packages/sie_gateway/docs/architecture-guide.md b/packages/sie_gateway/docs/architecture-guide.mdindex 1e374ea5b..ae452a825 100644--- a/packages/sie_gateway/docs/architecture-guide.md+++ b/packages/sie_gateway/docs/architecture-guide.md@@ -972,10 +972,15 @@ when the gateway is about to commit to the remote attempt:- The request sets no runtime option other than `is_query`, and every output itasks for (`dense` when an encode names none, `score` for score) is listed in- the admission. Otherwise the remote process would refuse it, so it stays local- with the reason `unmeasured_request`. A request with another runtime option is- not a bridge candidate at all: a fallback trigger leaves it on its ordinary- local path instead of committing to the local refusal.+ the admission. Otherwise the remote process would refuse it, so the request+ stays local:+ - A request for an output that the model declares but the admission does not+ list stays local with the reason `unmeasured_request`.+ - A request with another runtime option, or one that asks for an output the+ model does not declare, is not a bridge candidate on a fallback route. The+ trigger leaves it on its ordinary local path instead of committing to the+ local refusal, and no decision is recorded. On a `threshold` route it stays+ local with the reason `unmeasured_request`.- An eligible remote worker is fresh and eligible for dispatch, reports`supports_execution_authority_v1`, `supports_numerical_admission_v1` and`supports_numerical_admission_subject_v1` (which builds that predate thediff --git a/packages/sie_gateway/src/handlers/proxy.rs b/packages/sie_gateway/src/handlers/proxy.rsindex ec2d5bef4..42d5dca07 100644--- a/packages/sie_gateway/src/handlers/proxy.rs+++ b/packages/sie_gateway/src/handlers/proxy.rs@@ -2473,7 +2473,7 @@ fn admit_numerical(let Some(route) = plan.numerical.as_ref() else {return Some(plan);};- let decision = match numerical_request_outputs(operation, parsed) {+ let decision = match numerical_request_outputs(operation, parsed, &route.outputs) {None => Err(crate::state::worker_registry::NumericalRefusal::UnmeasuredRequest),Some(outputs) => {let now_unix_ms = std::time::SystemTime::now()@@ -2510,12 +2510,15 @@ fn admit_numerical(}/// The outputs a numerical request asks for, when it sets no runtime option-/// that a numerical admission could not have measured. The remote process-/// refuses any option except `is_query` that differs from the measured-/// defaults, so a request with another option stays local.+/// that a numerical admission could not have measured and asks only for+/// outputs the model declares. The remote process refuses any option except+/// `is_query` that differs from the measured defaults, so a request with+/// another option stays local. A request for an undeclared output is invalid+/// on either side.fn numerical_request_outputs(operation: &str,parsed: Option<&(Vec<rmpv::Value>, publisher::WorkParams)>,+ declared: &[String],) -> Option<Vec<String>> {let (_, params) = parsed?;let measured = match params.options.as_ref() {@@ -2526,16 +2529,18 @@ fn numerical_request_outputs(if !measured {return None;}- match operation {- "encode" => Some(- params- .output_types- .clone()- .unwrap_or_else(|| vec!["dense".to_string()]),- ),- "score" => Some(vec!["score".to_string()]),- _ => None,- }+ let outputs = match operation {+ "encode" => params+ .output_types+ .clone()+ .unwrap_or_else(|| vec!["dense".to_string()]),+ "score" => vec!["score".to_string()],+ _ => return None,+ };+ outputs+ .iter()+ .all(|output| declared.contains(output))+ .then_some(outputs)}/// The admitted remote workers a bridged numerical plan pins, for its bare@@ -2766,7 +2771,9 @@ fn native_fallback_plan(trigger,).filter(|plan| {- plan.numerical.is_none() || numerical_request_outputs(endpoint, parsed).is_some()+ plan.numerical.as_ref().is_none_or(|route| {+ numerical_request_outputs(endpoint, parsed, &route.outputs).is_some()+ })})}@@ -21624,8 +21631,9 @@ mod tests {).unwrap()};+ let declared = ["dense", "sparse", "score"].map(String::from);let outputs = |operation: &str, params: serde_json::Value| {- numerical_request_outputs(operation, Some(&parsed(params)))+ numerical_request_outputs(operation, Some(&parsed(params)), &declared)};assert_eq!(outputs("encode", json!({})),@@ -21651,8 +21659,18 @@ mod tests {] {assert_eq!(outputs("encode", params.clone()), None, "{params}");}- assert_eq!(numerical_request_outputs("encode", None), None);+ assert_eq!(numerical_request_outputs("encode", None, &declared), None);assert_eq!(outputs("extract", json!({})), None);+ for params in [+ json!({"output_types": ["multivector"]}),+ json!({"output_types": ["dense", "multivector"]}),+ ] {+ assert_eq!(outputs("encode", params.clone()), None, "{params}");+ }+ assert_eq!(+ numerical_request_outputs("score", Some(&parsed(json!({}))), &["dense".to_string()]),+ None+ );}#[test]diff --git a/packages/sie_gateway/src/handlers/serving_disclosure.rs b/packages/sie_gateway/src/handlers/serving_disclosure.rsindex 73955306c..0ed850fa7 100644--- a/packages/sie_gateway/src/handlers/serving_disclosure.rs+++ b/packages/sie_gateway/src/handlers/serving_disclosure.rs@@ -3640,40 +3640,54 @@ mod tests {#[tokio::test]async fn a_request_that_can_never_bridge_keeps_its_ordinary_local_path() {- let gateway = numerical_gateway(NUMERICAL_FALLBACK, false).await;- gateway- .add_numerical_worker(- "local-1",- LOCAL_LANE,- &[],- true,- local_identity(ADMITTED_IDENTITY),+ for params in [+ json!({"output_dtype": "int8"}),+ json!({"output_types": ["sparse"]}),+ ] {+ let gateway = numerical_gateway(NUMERICAL_FALLBACK, false).await;+ gateway+ .add_numerical_worker(+ "local-1",+ LOCAL_LANE,+ &[],+ true,+ local_identity(ADMITTED_IDENTITY),+ )+ .await;+ let response = encode(+ &gateway,+ json!({"items":[{"text":"hello"}], "params": params}),).await;- let response = encode(- &gateway,- json!({"items":[{"text":"hello"}], "params":{"output_dtype":"int8"}}),- )- .await;- assert!(- !response.headers().contains_key("x-sie-fallback-reason"),- "a request outside the admission is not a bridge candidate"- );- assert!(gateway- .dispatcher- .dispatched()- .iter()- .all(|work| work.endpoint != "load" && work.bundle != REMOTE_LANE.2));- assert!(gateway- .dispatcher- .dispatched()- .iter()- .any(|work| work.bundle == LOCAL_LANE.2));- assert!(gateway- .dispatcher- .numerical_admissions()- .iter()- .all(Option::is_none));+ assert!(+ !response.headers().contains_key("x-sie-fallback-reason"),+ "{params}: a request outside the admission is not a bridge candidate"+ );+ assert!(+ gateway+ .dispatcher+ .dispatched()+ .iter()+ .all(|work| work.endpoint != "load" && work.bundle != REMOTE_LANE.2),+ "{params}"+ );+ assert!(+ gateway+ .dispatcher+ .dispatched()+ .iter()+ .any(|work| work.bundle == LOCAL_LANE.2),+ "{params}"+ );+ assert!(+ gateway+ .dispatcher+ .numerical_admissions()+ .iter()+ .all(Option::is_none),+ "{params}"+ );+ }}#[tokio::test]diff --git a/packages/sie_gateway/src/state/model_registry.rs b/packages/sie_gateway/src/state/model_registry.rsindex ab7394d78..b98cf7099 100644--- a/packages/sie_gateway/src/state/model_registry.rs+++ b/packages/sie_gateway/src/state/model_registry.rs@@ -236,6 +236,8 @@ pub(crate) struct NumericalRoute {/// The model's own pool, `default` when it names none. Workers load only/// the models of their own pool.pub local_pool: String,+ /// The numerical outputs the bare model declares.+ pub outputs: Vec<String>,pub admitted: Option<Arc<crate::state::worker_registry::AdmittedWorkers>>,}@@ -1819,22 +1821,25 @@ impl ModelRegistry {if config_hash.is_empty() {return None;}- let numerical = local+ let outputs: Vec<String> = local.info_extras.outputs.iter()- .any(|output| {+ .filter(|output| {matches!(output.as_str(),"dense" | "sparse" | "multivector" | "score")})- .then(|| NumericalRoute {- model: local.canonical_base_model.clone(),- local_bundles: local.bundles.clone(),- local_pool: Self::normalize_pool_name(Self::entry_pool_name(local)),- admitted: None,- });+ .cloned()+ .collect();+ let numerical = (!outputs.is_empty()).then(|| NumericalRoute {+ model: local.canonical_base_model.clone(),+ local_bundles: local.bundles.clone(),+ local_pool: Self::normalize_pool_name(Self::entry_pool_name(local)),+ outputs,+ admitted: None,+ });Some(RemoteFallbackPlan {local_model: local.canonical_base_model.clone(),model: remote_name,diff --git a/packages/sie_server/REMOTE_BACKENDS.md b/packages/sie_server/REMOTE_BACKENDS.mdindex 42a91d5bd..d2499bbf5 100644--- a/packages/sie_server/REMOTE_BACKENDS.md+++ b/packages/sie_server/REMOTE_BACKENDS.md@@ -564,8 +564,8 @@ bridge also changes local behavior while no admission holds: a trigger thatwould bridge a request commits to its local refusal, so a cold model answers`MODEL_LOADING` instead of waiting for its load, and an opted-in `saturated` or`unhealthy` trigger refuses instead of queueing. A request that could never-bridge, because it sets a runtime option other than `is_query`, keeps its-ordinary local path.+bridge, because it sets a runtime option other than `is_query` or asks for an+output the model does not declare, keeps its ordinary local path.## Single-node generation fallbackdiff --git a/packages/sie_server/tests/config/test_hybrid_admission.py b/packages/sie_server/tests/config/test_hybrid_admission.pyindex 731fb2edf..35052c984 100644--- a/packages/sie_server/tests/config/test_hybrid_admission.py+++ b/packages/sie_server/tests/config/test_hybrid_admission.py@@ -832,6 +832,7 @@ def _expire(path: Path, data: dict[str, Any]) -> None:(":other", {}, None),(":remote", {}, "expire"),(":remote", {}, "remove"),+ (":remote", {}, "replace"),],)async def test_fence_refuses_before_the_upstream_when_the_admission_does_not_cover_the_item(@@ -855,6 +856,8 @@ async def test_fence_refuses_before_the_upstream_when_the_admission_does_not_cov_expire(path, data)elif change == "remove":path.unlink()+ elif change == "replace":+ _refresh_record(path, data)outcome = await server._handle_run_batch(_bridged_batch(diff --git a/telemetry/README.md b/telemetry/README.mdindex c40f5cd6a..13d48409b 100644--- a/telemetry/README.md+++ b/telemetry/README.md@@ -741,7 +741,11 @@ contract outside the admission) or `unmeasured_request` (the request sets aruntime option other than `is_query`, or asks for an output, that the admissiondid not measure). A local worker past the heartbeat timeout, and every workeruntil the gateway has heard worker health for one heartbeat timeout, counts as-`local_unobserved`. A request counts once, with the decision that applied. It+`local_unobserved`. A request counts once, with the decision that applied. On a+fallback route, a request that sets another runtime option or asks for an+output the model does not declare is not a bridge candidate, so it records no+decision. On a `threshold` route the same request records+`unmeasured_request`. Itkeeps its own 256-model bound with the same `other` overflow, and thequeue-routing dashboard displays it.