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): report invalid LoRA selector fields
svonavab4f642e3400e
diff --git a/packages/sie_gateway/src/handlers/decisions.rs b/packages/sie_gateway/src/handlers/decisions.rsindex 19de6388b..6e60429a2 100644--- a/packages/sie_gateway/src/handlers/decisions.rs+++ b/packages/sie_gateway/src/handlers/decisions.rs@@ -309,7 +309,7 @@ fn normalize_request(parsed: &Value) -> Result<(Value, Vec<Value>), Invalid> {native.insert(format!("question_{index}"), normalized);}let selectors =- super::lora::selectors(body).map_err(|message| invalid(message, "lora_adapter"))?;+ super::lora::selectors(body).map_err(|error| invalid(error.message, error.field))?;let mut request = json!({"model": model, "state": body["input"], "questions": native});request.as_object_mut().unwrap().extend(selectors);Ok((request, questions.clone()))@@ -664,6 +664,103 @@ mod tests {assert!(normalize_request(&conflict).is_err());}+ async fn assert_lora_error_fields(path: &str, base: Value, status: StatusCode) {+ let gateway = TestGateway::new(&[LOCAL_DECISION_MODEL]).await;+ let router = create_router(+ Arc::clone(&gateway.state),+ Arc::clone(&gateway.state.config),+ );+ let mut cases = Vec::new();+ for field in ["lora", "lora_id", "lora_adapter"] {+ for value in [+ json!(false),+ json!(1),+ json!([]),+ json!({}),+ json!(""),+ json!(" \t"),+ ] {+ cases.push((+ json!({field: value}),+ field,+ format!("'{field}' must be a non-empty string or null"),+ ));+ }+ }+ for (first, second) in [+ ("lora_adapter", "lora"),+ ("lora_adapter", "lora_id"),+ ("lora", "lora_id"),+ ] {+ for (left, right) in [+ (Value::Null, json!("private-selection-a")),+ (json!("private-selection-a"), Value::Null),+ (json!("private-selection-a"), json!("private-selection-b")),+ ] {+ cases.push((+ json!({first: left, second: right}),+ second,+ "LoRA selector fields must agree, including explicit null values".into(),+ ));+ }+ }+ for (selectors, field, message) in cases {+ let mut payload = base.clone();+ payload+ .as_object_mut()+ .unwrap()+ .extend(selectors.as_object().unwrap().clone());+ let request = Request::builder()+ .method(Method::POST)+ .uri(path)+ .header(header::CONTENT_TYPE, "application/json")+ .body(Body::from(serde_json::to_vec(&payload).unwrap()))+ .unwrap();+ let response = router.clone().oneshot(request).await.unwrap();+ assert_eq!(response.status(), status, "{path}: {selectors}");+ let body = body_json(response).await;+ if path == "/v1/decisions" {+ assert_eq!(+ body["error"],+ json!({+ "message": message, "param": field,+ "type": "invalid_request_error", "code": "invalid_request",+ }),+ "{selectors}"+ );+ } else {+ assert_eq!(+ body["detail"][0]["loc"],+ json!(["body", field]),+ "{selectors}"+ );+ assert_eq!(body["detail"][0]["msg"], message, "{selectors}");+ }+ assert!(!body.to_string().contains("private-selection"));+ assert!(gateway.dispatcher.dispatched().is_empty());+ }+ }++ #[tokio::test]+ async fn registered_decisions_route_identifies_invalid_lora_fields() {+ assert_lora_error_fields(+ "/v1/decisions",+ predicate_request(),+ StatusCode::BAD_REQUEST,+ )+ .await;+ }++ #[tokio::test]+ async fn registered_systemone_route_identifies_invalid_lora_fields() {+ assert_lora_error_fields(+ "/v1/systemone",+ json!({"model": "acme/decide", "state": "Continue?", "questions": {"q": {"type": "noul"}}}),+ StatusCode::UNPROCESSABLE_ENTITY,+ )+ .await;+ }+#[test]fn shared_fixtures_pin_request_and_response_parity() {for case in fixture()["requests"].as_array().unwrap() {diff --git a/packages/sie_gateway/src/handlers/lora.rs b/packages/sie_gateway/src/handlers/lora.rsindex ba1f4fa51..82c0cf253 100644--- a/packages/sie_gateway/src/handlers/lora.rs+++ b/packages/sie_gateway/src/handlers/lora.rs@@ -4,8 +4,14 @@ use serde_json::{Map, Value};pub(crate) const FIELDS: [&str; 3] = ["lora_adapter", "lora", "lora_id"];+#[derive(Debug)]+pub(crate) struct SelectorError {+ pub field: &'static str,+ pub message: String,+}+/// Retain the supplied spellings so legacy source-only admission cannot be lost.-pub(crate) fn selectors(body: &Map<String, Value>) -> Result<Map<String, Value>, String> {+pub(crate) fn selectors(body: &Map<String, Value>) -> Result<Map<String, Value>, SelectorError> {let mut selected = None;let mut fields = Map::new();for field in FIELDS {@@ -13,10 +19,16 @@ pub(crate) fn selectors(body: &Map<String, Value>) -> Result<Map<String, Value>,continue;};if !value.is_null() && !value.as_str().is_some_and(|s| !s.trim().is_empty()) {- return Err(format!("'{field}' must be a non-empty string or null"));+ return Err(SelectorError {+ field,+ message: format!("'{field}' must be a non-empty string or null"),+ });}if selected.is_some_and(|prior| prior != value) {- return Err("LoRA selector fields must agree, including explicit null values".into());+ return Err(SelectorError {+ field,+ message: "LoRA selector fields must agree, including explicit null values".into(),+ });}selected = Some(value);fields.insert(field.into(), value.clone());@@ -27,7 +39,9 @@ pub(crate) fn selectors(body: &Map<String, Value>) -> Result<Map<String, Value>,pub(crate) fn validate_options(options: Option<&Value>) -> Result<(), String> {match options {None | Some(Value::Null) => Ok(()),- Some(Value::Object(options)) => selectors(options).map(|_| ()),+ Some(Value::Object(options)) => selectors(options)+ .map(|_| ())+ .map_err(|error| error.message),_ => Err("'options' must be an object or null".into()),}}@@ -61,7 +75,9 @@ pub(crate) fn validate_options_rmpv(options: Option<&rmpv::Value>) -> Result<(),return Err(format!("duplicate LoRA selector '{key}'"));}}- selectors(&selected).map(|_| ())+ selectors(&selected)+ .map(|_| ())+ .map_err(|error| error.message)}#[cfg(test)]diff --git a/packages/sie_gateway/src/handlers/systemone.rs b/packages/sie_gateway/src/handlers/systemone.rsindex 6b22f5126..b201d6cc9 100644--- a/packages/sie_gateway/src/handlers/systemone.rs+++ b/packages/sie_gateway/src/handlers/systemone.rs@@ -169,7 +169,7 @@ pub(crate) fn normalize_request(parsed: &Value) -> Result<SystemOneRequest, Invanormalized.insert(qid.clone(), Value::Object(question));}let lora_options =- super::lora::selectors(body).map_err(|message| invalid(&["lora_adapter"], message))?;+ super::lora::selectors(body).map_err(|error| invalid(&[error.field], error.message))?;Ok(SystemOneRequest {model,item,