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: replace unmaintained YAML parser in Rust services (#714)
Attila László Nagy5f6d4518e814
diff --git a/Cargo.lock b/Cargo.lockindex 856102f68..5653a4947 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1402,6 +1402,16 @@ dependencies = ["smallvec",]+[[package]]+name = "granit-parser"+version = "1.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e20f99e46474f56bd905c56e817ebddcf377a611f94c53ac4649e4d3fa3c0cd0"+dependencies = [+ "arraydeque",+ "smallvec",+]+[[package]]name = "h2"version = "0.4.16"@@ -2046,7 +2056,7 @@ dependencies = ["rustls","secrecy","serde",- "serde-saphyr",+ "serde-saphyr 0.0.27","serde_json","thiserror","tokio",@@ -3584,7 +3594,7 @@ dependencies = ["base64 0.22.1","encoding_rs_io","getrandom 0.3.4",- "granit-parser",+ "granit-parser 0.0.3","nohash-hasher","num-traits","serde",@@ -3592,6 +3602,23 @@ dependencies = ["zmij",]+[[package]]+name = "serde-saphyr"+version = "1.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8050abb251097357e24aff63ba2c52a6309ecb7d23a5474023df960a02694d8"+dependencies = [+ "annotate-snippets",+ "base64 0.23.1",+ "encoding_rs_io",+ "granit-parser 1.3.0",+ "nohash-hasher",+ "num-traits",+ "serde_core",+ "smallvec",+ "zmij",+]+[[package]]name = "serde-value"version = "0.7.0"@@ -3700,19 +3727,6 @@ dependencies = ["serde",]-[[package]]-name = "serde_yaml"-version = "0.9.34+deprecated"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"-dependencies = [- "indexmap",- "itoa",- "ryu",- "serde",- "unsafe-libyaml",-]-[[package]]name = "sha1"version = "0.10.7"@@ -3825,9 +3839,9 @@ dependencies = ["rmpv","rustls","serde",+ "serde-saphyr 1.3.0","serde_bytes","serde_json",- "serde_yaml","sha2 0.11.0","sie-telemetry","subtle",@@ -4277,7 +4291,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"dependencies = ["fastrand",- "getrandom 0.3.4",+ "getrandom 0.4.3","once_cell","rustix","windows-sys 0.61.2",@@ -4800,12 +4814,6 @@ version = "0.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"-[[package]]-name = "unsafe-libyaml"-version = "0.2.11"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"-[[package]]name = "untrusted"version = "0.9.0"diff --git a/packages/sie_gateway/Cargo.toml b/packages/sie_gateway/Cargo.tomlindex 5fd725043..d75811241 100644--- a/packages/sie_gateway/Cargo.toml+++ b/packages/sie_gateway/Cargo.toml@@ -32,7 +32,7 @@ serde = { version = "1", features = ["derive"] }# on it). Hashes and generated files that must be canonical sort explicitly via# `canonical_json`.serde_json = { version = "1", features = ["preserve_order"] }-serde_yaml = "0.9"+serde-saphyr = "1.3"clap = { version = "4", features = ["derive", "env"] }tracing = "0.1"tracing-subscriber = { version = "0.3", features = ["json", "env-filter"] }diff --git a/packages/sie_gateway/README.md b/packages/sie_gateway/README.mdindex ebb9eed98..a24c4a590 100644--- a/packages/sie_gateway/README.md+++ b/packages/sie_gateway/README.md@@ -226,6 +226,20 @@ cargo testcargo clippy --all-targets -- -D warnings```+The `yaml_compatibility` integration test loads every shipped model and bundle,+including filesystem bootstrap and config-delta registry states. To compare+the parser migration against a revision that still uses `serde_yaml`, run from+the repository root:++```bash+mise exec -- python tools/test_yaml_compatibility.py --baseline-ref f1702697f6ff6024d3f215b982c8b7f8444aace5+```++The runner builds that revision in a temporary checkout and compares parsed+documents, expanded profiles, capabilities, and bundle/pool hashes against the+current code using the same current catalog. The old parser is never added to+the current dependency graph.+## Project Structure```text@@ -278,4 +292,4 @@ src/- [async-nats](https://github.com/nats-io/nats.rs) — NATS/JetStream client- [kube](https://github.com/kube-rs/kube) — Kubernetes client- [OpenTelemetry](https://opentelemetry.io/) — canonical OTLP telemetry-- `serde`, `serde_json`, `serde_yaml` — config and payload serialization+- `serde`, `serde_json`, `serde-saphyr` — config and payload serializationdiff --git a/packages/sie_gateway/src/handlers/config_api.rs b/packages/sie_gateway/src/handlers/config_api.rsindex fa177e2aa..19e756a21 100644--- a/packages/sie_gateway/src/handlers/config_api.rs+++ b/packages/sie_gateway/src/handlers/config_api.rs@@ -33,7 +33,7 @@ use crate::server::AppState;use crate::state::model_registry::ResolveError;fn yaml_response<T: Serialize>(status: StatusCode, value: &T) -> Response {- let body = match serde_yaml::to_string(value) {+ let body = match serde_saphyr::to_string(value) {Ok(body) => body,Err(e) => {return (@@ -664,10 +664,53 @@ mod tests {.unwrap();assert_eq!(response.status(), StatusCode::OK);+ assert_eq!(response.headers()["content-type"], "application/x-yaml");let body = String::from_utf8(body_bytes(response).await).unwrap();- assert!(body.contains("name: default"));- assert!(body.contains("engine: pytorch"));- assert!(body.contains("source: gateway-registry"));+ let document: serde_json::Value = serde_saphyr::from_str(&body).unwrap();+ assert_eq!(+ document,+ json!({+ "name": "default",+ "engine": "pytorch",+ "priority": 100,+ "source": "gateway-registry",+ "adapters": ["module"],+ })+ );+ }++ #[tokio::test]+ async fn test_model_config_yaml_preserves_scalar_like_names() {+ let bundles_dir = tempfile::TempDir::new().unwrap();+ let models_dir = tempfile::TempDir::new().unwrap();+ let (app, state) = build_test_router_with_state(&bundles_dir, &models_dir).await;+ for name in ["null", "true", "1e3", "model: name", "model#tag"] {+ seed_model(&state, name);+ let encoded =+ percent_encoding::utf8_percent_encode(name, percent_encoding::NON_ALPHANUMERIC);+ let response = app+ .clone()+ .oneshot(+ Request::builder()+ .uri(format!("/v1/configs/models/{encoded}"))+ .body(Body::empty())+ .unwrap(),+ )+ .await+ .unwrap();+ assert_eq!(response.status(), StatusCode::OK);+ assert_eq!(response.headers()["content-type"], "application/x-yaml");+ let body = String::from_utf8(body_bytes(response).await).unwrap();+ let document: serde_json::Value = serde_saphyr::from_str(&body).unwrap();+ assert_eq!(+ document,+ json!({+ "sie_id": name,+ "source": "gateway-registry",+ "bundles": ["default"],+ })+ );+ }}#[tokio::test]diff --git a/packages/sie_gateway/src/handlers/models.rs b/packages/sie_gateway/src/handlers/models.rsindex b2333d044..dc530445b 100644--- a/packages/sie_gateway/src/handlers/models.rs+++ b/packages/sie_gateway/src/handlers/models.rs@@ -741,7 +741,7 @@ mod route_tests {pool: None,profiles,inputs: None,- tasks: Some(serde_yaml::from_str("generate: {}").unwrap()),+ tasks: Some(serde_saphyr::from_str("generate: {}").unwrap()),max_sequence_length: None,}).unwrap();diff --git a/packages/sie_gateway/src/handlers/proxy.rs b/packages/sie_gateway/src/handlers/proxy.rsindex 4e79b1eef..d5e9ee502 100644--- a/packages/sie_gateway/src/handlers/proxy.rs+++ b/packages/sie_gateway/src/handlers/proxy.rs@@ -17716,7 +17716,7 @@ mod tests {extends: None,},);- let tasks: serde_yaml::Value = serde_yaml::from_str(+ let tasks: serde_json::Value = serde_saphyr::from_str("generate:\n capabilities:\n grammar: [json_schema]\n streaming: false\n",).expect("generation task");@@ -25173,7 +25173,7 @@ mod tests {.into_iter().collect();let tasks =- serde_yaml::from_str("generate:\n capabilities:\n streaming: false\n").unwrap();+ serde_saphyr::from_str("generate:\n capabilities:\n streaming: false\n").unwrap();registry.add_model_config(ModelConfig {name: "org/buffered".to_string(),@@ -25233,7 +25233,7 @@ mod tests {profiles.insert("no-spec".to_string(), no_spec);// `tasks.generate.grammar_profile: no-spec` is what surfaces on// `info_extras.grammar_profile` — the field the handlers read.- let tasks: serde_yaml::Value = serde_yaml::from_str(+ let tasks: serde_json::Value = serde_saphyr::from_str("generate:\n grammar_profile: no-spec\n capabilities:\n grammar: [json_schema]\n",).unwrap();@@ -25385,8 +25385,8 @@ mod tests {let mut profiles = StdHashMap::new();profiles.insert("default".to_string(), default_profile);profiles.insert("no-spec".to_string(), nospec_profile);- let tasks: serde_yaml::Value =- serde_yaml::from_str("generate:\n grammar_profile: no-spec\n").unwrap();+ let tasks: serde_json::Value =+ serde_saphyr::from_str("generate:\n grammar_profile: no-spec\n").unwrap();registry.add_model_config(ModelConfig {name: "org/g2".to_string(),@@ -25446,7 +25446,7 @@ mod tests {extends: None,},);- let tasks: serde_yaml::Value = serde_yaml::from_str(+ let tasks: serde_json::Value = serde_saphyr::from_str("generate:\n grammar_profile: ghost\n capabilities:\n grammar: [json_schema]\n",).unwrap();diff --git a/packages/sie_gateway/src/nats/manager.rs b/packages/sie_gateway/src/nats/manager.rsindex ba6e93298..007aca93f 100644--- a/packages/sie_gateway/src/nats/manager.rs+++ b/packages/sie_gateway/src/nats/manager.rs@@ -377,7 +377,7 @@ impl NatsManager {return;}- let config: ModelConfig = match serde_yaml::from_str(¬ification.model_config) {+ let config: ModelConfig = match serde_saphyr::from_str(¬ification.model_config) {Ok(config) => config,Err(e) => {telemetry::record_config_operation(operation, ConfigOutcome::ParseError);diff --git a/packages/sie_gateway/src/observability/metrics.rs b/packages/sie_gateway/src/observability/metrics.rsindex eb17035f5..fb1b4b77e 100644--- a/packages/sie_gateway/src/observability/metrics.rs+++ b/packages/sie_gateway/src/observability/metrics.rs@@ -2709,13 +2709,13 @@ mod tests {#[test]fn every_admission_outcome_is_declared_in_the_telemetry_contract() {- let contract: serde_yaml::Value = serde_yaml::from_str(include_str!(concat!(+ let contract: serde_json::Value = serde_saphyr::from_str(include_str!(concat!(env!("CARGO_MANIFEST_DIR"),"/../../telemetry/contract.yaml"))).expect("telemetry contract parses");let declared: HashSet<&str> = contract["enums"]["admission_outcome"]- .as_sequence()+ .as_array().expect("admission_outcome is a contract enum").iter().map(|value| value.as_str().expect("enum values are strings"))diff --git a/packages/sie_gateway/src/state/config_bootstrap.rs b/packages/sie_gateway/src/state/config_bootstrap.rsindex e3f6d8b71..17535b279 100644--- a/packages/sie_gateway/src/state/config_bootstrap.rs+++ b/packages/sie_gateway/src/state/config_bootstrap.rs@@ -473,7 +473,7 @@ impl BootstrapClient {}let yaml = resp.text().await?;let spec: BundleSpec =- serde_yaml::from_str(&yaml).map_err(|e| BootstrapError::BadStatus {+ serde_saphyr::from_str(&yaml).map_err(|e| BootstrapError::BadStatus {status: 200,url: yaml_url.clone(),body: format!("malformed bundle YAML: {}", e),@@ -645,7 +645,7 @@ fn parse_exported_model(model: &ExportedModel) -> Result<Option<ModelConfig>, Stif let Some(yaml) = model.raw_yaml.as_deref() {let trimmed = yaml.trim();if !trimmed.is_empty() {- return serde_yaml::from_str::<ModelConfig>(trimmed)+ return serde_saphyr::from_str::<ModelConfig>(trimmed).map(Some).map_err(|e| e.to_string());}@@ -1686,7 +1686,7 @@ mod tests {let config = parse_exported_model(&model).unwrap().unwrap();assert_eq!(config.pool, Some("customer-a".to_string()));- let yaml = serde_yaml::to_string(&config).unwrap();+ let yaml = serde_saphyr::to_string(&config).unwrap();assert!(yaml.contains("pool: customer-a"));}diff --git a/packages/sie_gateway/src/state/model_registry.rs b/packages/sie_gateway/src/state/model_registry.rsindex 15384547f..1261414ca 100644--- a/packages/sie_gateway/src/state/model_registry.rs+++ b/packages/sie_gateway/src/state/model_registry.rs@@ -460,7 +460,7 @@ impl ModelRegistry {fn load_bundle_file(path: &Path) -> Result<BundleInfo, Box<dyn std::error::Error>> {let content = std::fs::read_to_string(path)?;- let data: serde_yaml::Value = serde_yaml::from_str(&content)?;+ let data: serde_json::Value = serde_saphyr::from_str(&content)?;let name = data.get("name")@@ -477,7 +477,7 @@ impl ModelRegistry {let adapters: Vec<String> = data.get("adapters")- .and_then(|v| v.as_sequence())+ .and_then(|v| v.as_array()).map(|seq| {seq.iter().filter_map(|v| v.as_str().map(|s| s.to_string()))@@ -544,7 +544,7 @@ impl ModelRegistry {threshold_enabled: bool,) -> Result<Vec<ModelEntry>, Box<dyn std::error::Error>> {let content = std::fs::read_to_string(path)?;- let config: ModelConfig = serde_yaml::from_str(&content)?;+ let config: ModelConfig = serde_saphyr::from_str(&content)?;Self::expand_model_config_with_threshold(&config, threshold_enabled).map_err(|message| {Box::new(std::io::Error::new(@@ -3115,13 +3115,13 @@ mod tests {})).unwrap(),);- config.tasks = Some(serde_yaml::from_str("generate: {}\n").unwrap());+ config.tasks = Some(serde_saphyr::from_str("generate: {}\n").unwrap());registry.replace_model_configs_authoritative(vec![config.clone()]).unwrap();assert_eq!(registry.threshold_targets(1).unwrap().1.len(), 1);assert!(registry.threshold_targets(0).is_err());- config.tasks = Some(serde_yaml::from_str("encode:\n dense:\n dim: 2\n").unwrap());+ config.tasks = Some(serde_saphyr::from_str("encode:\n dense:\n dim: 2\n").unwrap());registry.replace_model_configs_authoritative(vec![config]).unwrap();@@ -3384,7 +3384,7 @@ mod tests {#[test]fn fallback_plan_requires_bare_model_trigger_and_fresh_remote_contract() {let (_dir, registry, mut config) = remote_routing_fixture();- config.tasks = Some(serde_yaml::from_str("generate: {}\n").unwrap());+ config.tasks = Some(serde_saphyr::from_str("generate: {}\n").unwrap());config.routing = Some(serde_json::from_value(serde_json::json!({"policy":"fallback", "fallback_profile":"remote"@@ -3428,7 +3428,7 @@ mod tests {})).unwrap(),);- config.tasks = Some(serde_yaml::from_str("encode:\n dense:\n dim: 2\n").unwrap());+ config.tasks = Some(serde_saphyr::from_str("encode:\n dense:\n dim: 2\n").unwrap());registry.add_model_config(config.clone()).unwrap();let plan = registry.remote_fallback_plan("acme/hybrid", FallbackTrigger::Provisioning)@@ -3675,8 +3675,8 @@ mod tests {profiles.insert("h200-256k-no-spec".to_string(), scoped_fallback);// ``tasks.generate.grammar_profile: no-spec`` is the routing hint the// gateway reads off the base entry.- let tasks: serde_yaml::Value =- serde_yaml::from_str("generate:\n grammar_profile: no-spec\n").unwrap();+ let tasks: serde_json::Value =+ serde_saphyr::from_str("generate:\n grammar_profile: no-spec\n").unwrap();registry.add_model_config(ModelConfig {name: "org/g".to_string(),@@ -3770,7 +3770,7 @@ mod tests {},}));profiles.insert("safe".to_string(), safe);- let tasks: serde_yaml::Value = serde_yaml::from_str("generate: {}\n").unwrap();+ let tasks: serde_json::Value = serde_saphyr::from_str("generate: {}\n").unwrap();registry.add_model_config(ModelConfig {name: "org/scoped-only".to_string(),@@ -3860,7 +3860,7 @@ mod tests {}fn gemma_grammar_config() -> ModelConfig {- serde_yaml::from_str(include_str!(+ serde_saphyr::from_str(include_str!("../../../sie_server/models/google__gemma-4-31B-it.yaml")).unwrap()@@ -4024,7 +4024,7 @@ mod tests {#[test]fn test_grammar_route_variant_default_profile() {- let config: ModelConfig = serde_yaml::from_str(+ let config: ModelConfig = serde_saphyr::from_str(r#"name: org/grammar-modeltasks:@@ -4147,7 +4147,7 @@ profiles:#[test]fn test_grammar_profiles_reject_matching_raw_speculative_overrides() {- let config: ModelConfig = serde_yaml::from_str(+ let config: ModelConfig = serde_saphyr::from_str(r#"name: org/grammar-modelprofiles:@@ -4185,7 +4185,7 @@ profiles:"matching launch overrides must not establish grammar compatibility: {args}");config.tasks =- Some(serde_yaml::from_str("generate:\n grammar_profile: safe\n").unwrap());+ Some(serde_saphyr::from_str("generate:\n grammar_profile: safe\n").unwrap());let error = ModelRegistry::model_entry_from_config(&config).unwrap_err();assert!(error.contains("must not enable speculation"),@@ -4205,7 +4205,7 @@ profiles:#[test]fn test_grammar_target_rejects_raw_speculation_without_typed_settings() {- let config: ModelConfig = serde_yaml::from_str(+ let config: ModelConfig = serde_saphyr::from_str(r#"name: org/grammar-modeltasks:@@ -4228,7 +4228,7 @@ profiles:#[test]fn test_grammar_route_variant_matching_benign_launch_args() {- let config: ModelConfig = serde_yaml::from_str(+ let config: ModelConfig = serde_saphyr::from_str(r#"name: org/grammar-modeltasks:@@ -4353,8 +4353,8 @@ profiles:let mut profiles = StdHashMap::new();profiles.insert("default".to_string(), profile(true, 8192));profiles.insert("unsafe".to_string(), profile(true, 8192));- let tasks: serde_yaml::Value =- serde_yaml::from_str("generate:\n grammar_profile: unsafe\n").unwrap();+ let tasks: serde_json::Value =+ serde_saphyr::from_str("generate:\n grammar_profile: unsafe\n").unwrap();let error = registry.add_model_config(ModelConfig {name: "org/unsafe-global-target".to_string(),@@ -4575,8 +4575,8 @@ profiles:extends: None,},);- let tasks: serde_yaml::Value =- serde_yaml::from_str("generate:\n grammar_profile: ghost\n").unwrap();+ let tasks: serde_json::Value =+ serde_saphyr::from_str("generate:\n grammar_profile: ghost\n").unwrap();registry.add_model_config(ModelConfig {name: "org/g".to_string(),@@ -4826,7 +4826,7 @@ profiles:profiles,inputs: None,tasks: Some(- serde_yaml::from_str("encode:\n dense:\n dim: 384\n")+ serde_saphyr::from_str("encode:\n dense:\n dim: 384\n").expect("valid task fixture"),),max_sequence_length: Some(512),@@ -5003,7 +5003,7 @@ profiles:#[test]fn test_candle_sparse_only_profile_narrows_outputs_to_sparse() {- let config: ModelConfig = serde_yaml::from_str(+ let config: ModelConfig = serde_saphyr::from_str(r#"sie_id: acme/sparsetasks:@@ -5035,7 +5035,7 @@ profiles:#[test]fn test_candle_multivector_profile_drops_unsupported_sparse_output() {- let config: ModelConfig = serde_yaml::from_str(+ let config: ModelConfig = serde_saphyr::from_str(r#"sie_id: acme/sparse-multivectortasks:@@ -5073,7 +5073,7 @@ profiles:#[test]fn test_candle_multivector_score_requires_resolved_colbert_maxsim_strategy() {- let config: ModelConfig = serde_yaml::from_str(+ let config: ModelConfig = serde_saphyr::from_str(r#"sie_id: acme/multivectortasks:@@ -5146,7 +5146,7 @@ profiles:#[test]fn test_profile_variant_advertises_profile_max_sequence_length() {- let config: ModelConfig = serde_yaml::from_str(include_str!(+ let config: ModelConfig = serde_saphyr::from_str(include_str!("../../../sie_server/models/topk-io__Iso-ModernColBERT.yaml")).unwrap();@@ -5639,7 +5639,7 @@ adapters:inputs: None,max_sequence_length: Some(512),tasks: Some(- serde_yaml::from_str(+ serde_saphyr::from_str(r#"encode:dense:@@ -5698,7 +5698,7 @@ encode:inputs: None,max_sequence_length: Some(1024),tasks: Some(- serde_yaml::from_str(+ serde_saphyr::from_str(r#"encode:sparse:@@ -5752,7 +5752,7 @@ encode:inputs: None,max_sequence_length: None,tasks: Some(- serde_yaml::from_str("generate:\n capabilities:\n streaming: false\n")+ serde_saphyr::from_str("generate:\n capabilities:\n streaming: false\n").unwrap(),),})@@ -5786,7 +5786,7 @@ encode:inputs: None,max_sequence_length: None,tasks: Some(- serde_yaml::from_str(&format!(+ serde_saphyr::from_str(&format!("generate:\n capabilities:\n streaming: {streaming}\n")).unwrap(),@@ -5856,7 +5856,7 @@ adapters:inputs: None,max_sequence_length: Some(512),tasks: Some(- serde_yaml::from_str(+ serde_saphyr::from_str(r#"encode:dense:@@ -6429,7 +6429,7 @@ adapters:// Seed: ``default`` plus the grammar-safe parent. The later delta only// carries the child, so ``no-spec`` exists solely in stored state.- let seed: ModelConfig = serde_yaml::from_str(+ let seed: ModelConfig = serde_saphyr::from_str(r#"sie_id: test/modeltasks: {generate: {grammar_profile: no-spec, max_output_tokens: 4096}}@@ -6450,7 +6450,7 @@ profiles:// Delta: a second config bringing only ``h100-fp8`` which extends// ``no-spec``. ``no-spec`` lives only in ``existing.profile_configs``// at this point.- let delta: ModelConfig = serde_yaml::from_str(+ let delta: ModelConfig = serde_saphyr::from_str(r#"sie_id: test/modelprofiles:diff --git a/packages/sie_gateway/src/types/bundle.rs b/packages/sie_gateway/src/types/bundle.rsindex 6d0a49e42..00e1357b9 100644--- a/packages/sie_gateway/src/types/bundle.rs+++ b/packages/sie_gateway/src/types/bundle.rs@@ -111,7 +111,7 @@ adapters:- sie_server.adapters.cross_encoderdefault: true"#;- let config: BundleConfig = serde_yaml::from_str(yaml).unwrap();+ let config: BundleConfig = serde_saphyr::from_str(yaml).unwrap();assert_eq!(config.name, "default");assert_eq!(config.priority, 10);assert_eq!(config.adapters.len(), 2);@@ -121,7 +121,7 @@ default: true#[test]fn test_bundle_config_defaults() {let yaml = r#"name: minimal"#;- let config: BundleConfig = serde_yaml::from_str(yaml).unwrap();+ let config: BundleConfig = serde_saphyr::from_str(yaml).unwrap();assert_eq!(config.priority, 100); // default_priority()assert!(config.adapters.is_empty());assert!(!config.default);diff --git a/packages/sie_gateway/src/types/model.rs b/packages/sie_gateway/src/types/model.rsindex 2ab991654..fc54a41de 100644--- a/packages/sie_gateway/src/types/model.rs+++ b/packages/sie_gateway/src/types/model.rs@@ -101,16 +101,14 @@ impl ModelInfoExtras {/// Best-effort extraction from a raw model YAML document (same files as/// ``sie_server`` / ``sie-config``). Missing sections fall back to/// conservative defaults so the JSON shape stays valid.- pub fn from_yaml_raw(raw: &serde_yaml::Value) -> Self {+ pub fn from_yaml_raw(raw: &serde_json::Value) -> Self {let mut extras = Self::default();- if let serde_yaml::Value::Mapping(m) = raw.get("inputs").unwrap_or(&serde_yaml::Value::Null)+ if let serde_json::Value::Object(m) = raw.get("inputs").unwrap_or(&serde_json::Value::Null){for (k, v) in m {- let Some(ks) = k.as_str() else {- continue;- };- if matches!(v, serde_yaml::Value::Bool(true)) {+ let ks = k.as_str();+ if matches!(v, serde_json::Value::Bool(true)) {extras.inputs.push(ks.to_string());}}@@ -128,22 +126,20 @@ impl ModelInfoExtras {extras.routing = raw.get("routing")- .and_then(|value| serde_yaml::from_value(value.clone()).ok());+ .and_then(|value| serde_json::from_value(value.clone()).ok());let tasks = raw.get("tasks");if let Some(enc) = tasks.and_then(|t| match t.get("encode")? {- serde_yaml::Value::Mapping(m) => Some(m),+ serde_json::Value::Object(m) => Some(m),_ => None,}) {for (k, v) in enc {- let Some(key) = k.as_str() else {- continue;- };+ let key = k.as_str();if key.is_empty() {continue;}match v {- serde_yaml::Value::Mapping(vm) => {+ serde_json::Value::Object(vm) => {if let Some(dim) = vm.get("dim").and_then(|d| {d.as_u64().or_else(|| d.as_i64().map(|i| i.max(0) as u64))}) {@@ -153,7 +149,7 @@ impl ModelInfoExtras {extras.outputs.push(key.to_string());}}- serde_yaml::Value::Null => {}+ serde_json::Value::Null => {}_ => {extras.outputs.push(key.to_string());}@@ -164,13 +160,13 @@ impl ModelInfoExtras {// Non-encode tasks contribute output kinds too, mirroring// ``ModelConfig.outputs`` in ``packages/sie_server/src/sie_server/config/model.py``.if let Some(t) = tasks {- if matches!(t.get("score"), Some(serde_yaml::Value::Mapping(_))) {+ if matches!(t.get("score"), Some(serde_json::Value::Object(_))) {extras.outputs.push("score".to_string());}- if matches!(t.get("extract"), Some(serde_yaml::Value::Mapping(_))) {+ if matches!(t.get("extract"), Some(serde_json::Value::Object(_))) {extras.outputs.push("json".to_string());}- if let Some(serde_yaml::Value::Mapping(gen)) = t.get("generate") {+ if let Some(serde_json::Value::Object(gen)) = t.get("generate") {extras.outputs.push("tokens".to_string());// Surface the per-request cap so// ``proxy_chat`` can reject overflowing@@ -192,13 +188,13 @@ impl ModelInfoExtras {// None`` so non-generation endpoints don't fail the// gate.let capabilities = gen.get("capabilities").and_then(|c| match c {- serde_yaml::Value::Mapping(m) => Some(m),+ serde_json::Value::Object(m) => Some(m),_ => None,});let grammar = capabilities.and_then(|m| m.get("grammar")).and_then(|g| match g {- serde_yaml::Value::Sequence(seq) => Some(+ serde_json::Value::Array(seq) => Some(seq.iter().filter_map(|v| v.as_str().map(String::from)).collect::<Vec<String>>(),@@ -249,12 +245,10 @@ impl ModelInfoExtras {}}- if let Some(serde_yaml::Value::Mapping(profiles)) = raw.get("profiles") {+ if let Some(serde_json::Value::Object(profiles)) = raw.get("profiles") {for (profile_name, profile) in profiles {- let (Some(profile_name), Some(parent_name)) = (- profile_name.as_str(),- profile.get("extends").and_then(serde_yaml::Value::as_str),- ) else {+ let Some(parent_name) = profile.get("extends").and_then(serde_json::Value::as_str)+ else {continue;};extras@@ -263,27 +257,27 @@ impl ModelInfoExtras {}fn resolve_profile_output_cap(- profiles: &serde_yaml::Mapping,+ profiles: &serde_json::Map<String, serde_json::Value>,profile_name: &str,seen: &mut HashSet<String>,) -> Option<u32> {if !seen.insert(profile_name.to_string()) {return None;}- let profile = profiles.get(profile_name)?.as_mapping()?;+ let profile = profiles.get(profile_name)?.as_object()?;if let Some(cap) = profile.get("max_output_tokens")- .and_then(serde_yaml::Value::as_u64)+ .and_then(serde_json::Value::as_u64).filter(|value| *value > 0).and_then(|value| u32::try_from(value).ok()){return Some(cap);}- let parent = profile.get("extends").and_then(serde_yaml::Value::as_str)?;+ let parent = profile.get("extends").and_then(serde_json::Value::as_str)?;resolve_profile_output_cap(profiles, parent, seen)}- for profile_name in profiles.keys().filter_map(serde_yaml::Value::as_str) {+ for profile_name in profiles.keys() {if let Some(cap) =resolve_profile_output_cap(profiles, profile_name, &mut HashSet::new()){@@ -300,27 +294,23 @@ impl ModelInfoExtras {// against; the union is preserved for back-compat on /v1/models.// Only the public served-names are advertised — never the source// HF-ids/paths.- if let Some(serde_yaml::Value::Mapping(profiles)) = raw.get("profiles") {+ if let Some(serde_json::Value::Object(profiles)) = raw.get("profiles") {let mut per_profile: HashMap<String, Vec<String>> = HashMap::new();let mut union_names: Vec<String> = Vec::new();for (pname, pcfg) in profiles {- let Some(profile_name) = pname.as_str() else {- continue;- };+ let profile_name = pname.as_str();let lora_paths = pcfg.get("adapter_options").and_then(|a| a.get("loadtime")).and_then(|l| l.get("lora_paths"));let mut profile_names: Vec<String> = Vec::new();- if let Some(serde_yaml::Value::Mapping(m)) = lora_paths {+ if let Some(serde_json::Value::Object(m)) = lora_paths {for k in m.keys() {- if let Some(s) = k.as_str() {- if !profile_names.iter().any(|n| n == s) {- profile_names.push(s.to_string());- }- if !union_names.iter().any(|n| n == s) {- union_names.push(s.to_string());- }+ if !profile_names.contains(k) {+ profile_names.push(k.clone());+ }+ if !union_names.contains(k) {+ union_names.push(k.clone());}}}@@ -337,8 +327,8 @@ impl ModelInfoExtras {}let tasks_absent_or_empty = match tasks {- None | Some(serde_yaml::Value::Null) => true,- Some(serde_yaml::Value::Mapping(m)) => m.is_empty(),+ None | Some(serde_json::Value::Null) => true,+ Some(serde_json::Value::Object(m)) => m.is_empty(),_ => false,};if extras.outputs.is_empty() && tasks_absent_or_empty {@@ -349,7 +339,7 @@ impl ModelInfoExtras {}pub fn from_model_config(config: &ModelConfig) -> Self {- let mut extras = match serde_yaml::to_value(config) {+ let mut extras = match serde_json::to_value(config) {Ok(v) => Self::from_yaml_raw(&v),Err(_) => Self {inputs: vec!["text".to_string()],@@ -580,7 +570,7 @@ pub struct ModelConfig {pub max_sequence_length: Option<u64>,/// Full ``tasks:`` tree from YAML (encode outputs / dims).#[serde(default)]- pub tasks: Option<serde_yaml::Value>,+ pub tasks: Option<serde_json::Value>,}#[derive(Debug, Clone, Deserialize, Serialize)]@@ -1101,7 +1091,7 @@ profiles:max_batch_tokens: 4096pool: customer-a"#;- let config: ModelConfig = serde_yaml::from_str(yaml).unwrap();+ let config: ModelConfig = serde_saphyr::from_str(yaml).unwrap();assert_eq!(config.name, "BAAI/bge-m3");assert_eq!(config.pool, Some("customer-a".into()));assert_eq!(config.profiles.len(), 1);@@ -1160,7 +1150,7 @@ pool: customer-a"{wire}");}- assert!(serde_yaml::from_str::<RoutingConfig>(+ assert!(serde_saphyr::from_str::<RoutingConfig>("policy: threshold\nfallback_profile: remote\nwake_above: .inf\nsleep_below: 1\nwindow_s: 1\ncooldown_s: 1\n").is_err());let threshold: RoutingConfig = serde_json::from_value(json!({"policy":"threshold",@@ -1191,8 +1181,8 @@ profiles:upstream: team-sieupstream_model: acme/hybrid"#;- let from_yaml: ModelConfig = serde_yaml::from_str(yaml).unwrap();- let value: serde_json::Value = serde_yaml::from_str(yaml).unwrap();+ let from_yaml: ModelConfig = serde_saphyr::from_str(yaml).unwrap();+ let value: serde_json::Value = serde_saphyr::from_str(yaml).unwrap();let from_json: ModelConfig = serde_json::from_value(value).unwrap();for config in [from_yaml, from_json] {assert_eq!(config.name, "acme/hybrid");@@ -1210,7 +1200,7 @@ profiles:#[test]fn test_profile_output_caps_are_inheritance_resolved_and_route_scoped() {- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"sie_id: acme/generatortasks:@@ -1273,7 +1263,7 @@ profiles:sie_id: my/modelprofiles: {}"#;- let config: ModelConfig = serde_yaml::from_str(yaml).unwrap();+ let config: ModelConfig = serde_saphyr::from_str(yaml).unwrap();assert_eq!(config.name, "my/model");}@@ -1301,7 +1291,7 @@ profiles: {}#[test]fn test_model_info_extras_defaults_dense_when_tasks_absent() {- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: example/modelinputs:@@ -1321,7 +1311,7 @@ inputs:// ``packages/sie_server/src/sie_server/config/model.py``), *not* a// synthesized ``"dense"``. ``dims`` stays empty because score has no// dimension to advertise.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: example/rerankerinputs:@@ -1345,7 +1335,7 @@ tasks:// scoping). The precise per-profile breakdown lives alongside// in ``profile_lora_adapters`` and is what the validation gate// checks (see ``test_per_profile_lora_capabilities_isolates_profiles``).- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: acme/qwen-lorainputs:@@ -1383,7 +1373,7 @@ profiles:// per declared profile, never collapse to the union. Profile A// carries [a1, a2]; profile B carries [b1]; the per-profile map// returns ONLY that profile's adapters on lookup.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: acme/multi-profile-lorainputs:@@ -1444,8 +1434,8 @@ profiles:#[test]fn test_model_info_extras_no_lora_adapters_when_absent() {- let raw: serde_yaml::Value =- serde_yaml::from_str("name: m\ninputs:\n text: true\ntasks:\n generate: {}\n")+ let raw: serde_json::Value =+ serde_saphyr::from_str("name: m\ninputs:\n text: true\ntasks:\n generate: {}\n").unwrap();let extras = ModelInfoExtras::from_yaml_raw(&raw);assert!(extras.lora_adapters.is_none());@@ -1454,7 +1444,7 @@ profiles:#[test]fn test_model_info_extras_tools_capability_parsed() {- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: Qwen/Qwen3-4B-Instruct-2507inputs:@@ -1475,12 +1465,12 @@ tasks:#[test]fn test_model_info_extras_streaming_capability_is_resolved_and_advertised() {- let disabled: serde_yaml::Value = serde_yaml::from_str(+ let disabled: serde_json::Value = serde_saphyr::from_str("name: m\ntasks:\n generate:\n capabilities:\n streaming: false\n",).unwrap();- let defaulted: serde_yaml::Value =- serde_yaml::from_str("name: m\ntasks:\n generate: {}\n").unwrap();+ let defaulted: serde_json::Value =+ serde_saphyr::from_str("name: m\ntasks:\n generate: {}\n").unwrap();let disabled_extras = ModelInfoExtras::from_yaml_raw(&disabled);let defaulted_extras = ModelInfoExtras::from_yaml_raw(&defaulted);@@ -1509,7 +1499,7 @@ tasks:// Qwen3-4B-Instruct-2507 advertises code + sql (and tools); it is// not a guard model. Mirrors// ``packages/sie_server/models/Qwen__Qwen3-4B-Instruct-2507.yaml``.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: Qwen/Qwen3-4B-Instruct-2507inputs:@@ -1533,7 +1523,7 @@ tasks:// Qwen3.6-27B also advertises code + sql. Mirrors// ``packages/sie_server/models/Qwen__Qwen3.6-27B.yaml``.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: Qwen/Qwen3.6-27Binputs:@@ -1557,7 +1547,7 @@ tasks:// Granite Guardian 3.0-2b advertises guard only. Mirrors// ``packages/sie_server/models/ibm-granite__granite-guardian-3.0-2b.yaml``.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: ibm-granite/granite-guardian-3.0-2binputs:@@ -1582,7 +1572,7 @@ tasks:#[test]fn test_model_info_extras_code_sql_guard_default_false_when_absent() {// No ``capabilities`` block at all — all three default to false.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: minputs:@@ -1604,7 +1594,7 @@ tasks:fn test_to_model_info_value_surfaces_code_sql_guard_flags() {// The three flags must surface inside the same ``capabilities``// JSON object as ``grammar``/``tools``, using snake_case wire keys.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: Qwen/Qwen3-4B-Instruct-2507inputs:@@ -1645,7 +1635,7 @@ tasks:#[test]fn test_model_info_extras_tools_capability_defaults_to_false() {- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: minputs:@@ -1667,7 +1657,7 @@ tasks:// ``GET /v1/models`` advertises the capability accurately. Without// this, generate-only models report ``outputs=[]`` and downstream// clients can't tell what the model produces.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: Qwen/Qwen3-4B-Instructinputs:@@ -1687,19 +1677,19 @@ tasks:#[test]fn test_supports_video_generation_requires_video_and_generate() {let video_gen = ModelInfoExtras::from_yaml_raw(- &serde_yaml::from_str(+ &serde_saphyr::from_str("name: m\ninputs:\n text: true\n video: true\ntasks:\n generate: {}\n",).unwrap(),);assert!(video_gen.supports_video_generation());let video_encode = ModelInfoExtras::from_yaml_raw(- &serde_yaml::from_str("name: m\ninputs:\n video: true\ntasks:\n encode: {}\n")+ &serde_saphyr::from_str("name: m\ninputs:\n video: true\ntasks:\n encode: {}\n").unwrap(),);assert!(!video_encode.supports_video_generation());let image_gen = ModelInfoExtras::from_yaml_raw(- &serde_yaml::from_str("name: m\ninputs:\n image: true\ntasks:\n generate: {}\n")+ &serde_saphyr::from_str("name: m\ninputs:\n image: true\ntasks:\n generate: {}\n").unwrap(),);assert!(!image_gen.supports_video_generation());@@ -1709,7 +1699,7 @@ tasks:fn test_supports_vision_generation_requires_image_and_generate() {// Vision-capable generation model (image input + generate task).let vlm = ModelInfoExtras::from_yaml_raw(- &serde_yaml::from_str(+ &serde_saphyr::from_str("name: m\ninputs:\n text: true\n image: true\ntasks:\n generate: {}\n",).unwrap(),@@ -1719,7 +1709,7 @@ tasks:// Encode-only image model (CLIP/SigLIP-style: image input, no generate// task) must NOT pass the vision-generation gate.let encode_only = ModelInfoExtras::from_yaml_raw(- &serde_yaml::from_str(+ &serde_saphyr::from_str("name: m\ninputs:\n text: true\n image: true\ntasks:\n encode: {}\n",).unwrap(),@@ -1728,7 +1718,7 @@ tasks:// Text-only generation model: generates but no image input.let text_gen = ModelInfoExtras::from_yaml_raw(- &serde_yaml::from_str("name: m\ninputs:\n text: true\ntasks:\n generate: {}\n")+ &serde_saphyr::from_str("name: m\ninputs:\n text: true\ntasks:\n generate: {}\n").unwrap(),);assert!(!text_gen.supports_vision_generation());@@ -1740,7 +1730,7 @@ tasks:// primitive — must hand back ONLY the requested profile's// adapters even when sibling profiles declare different ones.// This is the seam the proxy.rs lora_adapter gate consumes.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: acme/multi-profile-lorainputs:@@ -1796,7 +1786,7 @@ profiles:// the per-profile map (G-M10). Vanilla OpenAI clients keep// reading the union; consumers that need precise routing scope// read the per-profile breakdown without reverse-engineering it.- let raw: serde_yaml::Value = serde_yaml::from_str(+ let raw: serde_json::Value = serde_saphyr::from_str(r#"name: acme/multi-profile-lorainputs:@@ -1980,11 +1970,11 @@ profiles:#[test]fn test_every_remote_bundle_adapter_names_its_upstream_kind() {- let bundle: serde_yaml::Value =- serde_yaml::from_str(include_str!("../../../sie_server/bundles/remote.yaml"))+ let bundle: serde_json::Value =+ serde_saphyr::from_str(include_str!("../../../sie_server/bundles/remote.yaml")).expect("valid remote bundle YAML");let adapters: Vec<&str> = bundle["adapters"]- .as_sequence()+ .as_array().expect("remote bundle lists adapters").iter().map(|adapter| adapter.as_str().expect("adapter module name"))diff --git a/packages/sie_gateway/tests/yaml_compatibility.rs b/packages/sie_gateway/tests/yaml_compatibility.rsnew file mode 100644index 000000000..d51936efc--- /dev/null+++ b/packages/sie_gateway/tests/yaml_compatibility.rs@@ -0,0 +1,193 @@+use std::collections::BTreeSet;+use std::path::{Path, PathBuf};++use serde_json::{json, Map, Value};+use serde_saphyr as yaml;+use sie_gateway::state::model_registry::ModelRegistry;+use sie_gateway::types::model::{ModelConfig, ModelEntry};++fn yaml_files(directory: &Path) -> Vec<PathBuf> {+ let mut files: Vec<_> = std::fs::read_dir(directory)+ .unwrap()+ .map(|entry| entry.unwrap().path())+ .filter(|path| {+ matches!(+ path.extension().and_then(|ext| ext.to_str()),+ Some("yaml" | "yml")+ )+ })+ .collect();+ files.sort();+ assert!(+ !files.is_empty(),+ "no YAML files in {}",+ directory.display()+ );+ files+}++fn entry_snapshot(entry: &ModelEntry) -> Value {+ let extras = &entry.info_extras;+ let profiles: Map<_, _> = entry+ .profile_configs+ .iter()+ .map(|(name, profile)| {+ (+ name.clone(),+ json!({+ "kv_budget_tokens": profile.kv_budget_tokens,+ "adapter_path": profile.adapter_path,+ "max_batch_tokens": profile.max_batch_tokens,+ "compute_precision": profile.compute_precision,+ "max_output_tokens": profile.max_output_tokens,+ "adapter_options": profile.adapter_options,+ "grammar_profile": profile.grammar_profile,+ "chat_template_kwargs": profile.chat_template_kwargs,+ }),+ )+ })+ .collect();+ json!({+ "name": entry.name,+ "canonical_base_model": entry.canonical_base_model,+ "canonical_profile": entry.canonical_profile,+ "pool": entry.pool,+ "bundles": entry.bundles.iter().collect::<BTreeSet<_>>(),+ "adapter_modules": entry.adapter_modules.iter().collect::<BTreeSet<_>>(),+ "profile_names": entry.profile_names.iter().collect::<BTreeSet<_>>(),+ "profile_configs": profiles,+ "extras": {+ "inputs": extras.inputs.iter().collect::<BTreeSet<_>>(),+ "outputs": extras.outputs,+ "dims": extras.dims,+ "max_sequence_length": extras.max_sequence_length,+ "revision": extras.revision,+ "routing": extras.routing,+ "max_output_tokens": extras.max_output_tokens,+ "profile_max_output_tokens": extras.profile_max_output_tokens,+ "grammar_capabilities": extras.grammar_capabilities,+ "streaming_supported": extras.streaming_supported,+ "grammar_profile": extras.grammar_profile,+ "profile_parents": extras.profile_parents,+ "tools_supported": extras.tools_supported,+ "code": extras.code,+ "sql": extras.sql,+ "guard": extras.guard,+ "lora_adapters": extras.lora_adapters.as_ref().map(|names| names.iter().collect::<BTreeSet<_>>()),+ "profile_lora_adapters": extras.profile_lora_adapters,+ },+ })+}++fn registry_snapshot(registry: &ModelRegistry) -> Value {+ let models: Map<_, _> = registry+ .list_models()+ .into_iter()+ .map(|name| {+ let entry = registry.get_model_info(&name).unwrap();+ (name, entry_snapshot(&entry))+ })+ .collect();+ let bundles: Map<_, _> = registry+ .list_bundles()+ .into_iter()+ .map(|name| {+ let bundle = registry.get_bundle_info(&name).unwrap();+ let pools: BTreeSet<_> = registry+ .list_models()+ .iter()+ .filter_map(|model| registry.get_model_pool_name(model))+ .collect();+ let pool_hashes: Map<_, _> = pools+ .into_iter()+ .map(|pool| {+ let hash = registry.compute_bundle_config_hash_for_pool(&name, &pool);+ (pool, json!(hash))+ })+ .collect();+ let value = json!({+ "name": bundle.name,+ "priority": bundle.priority,+ "adapters": bundle.adapters,+ "engine": bundle.engine,+ "hash": registry.compute_bundle_config_hash(&name),+ "pool_hashes": pool_hashes,+ });+ (name, value)+ })+ .collect();+ json!({"models": models, "bundles": bundles})+}++#[test]+fn catalog_yaml_compatibility() {+ let root = std::env::var_os("SIE_YAML_CATALOG_ROOT")+ .map(PathBuf::from)+ .unwrap_or_else(|| Path::new(env!("CARGO_MANIFEST_DIR")).join("../sie_server"));+ let bundles = root.join("bundles");+ let models = root.join("models");+ let bundle_files = yaml_files(&bundles);+ let model_files = yaml_files(&models);+ let mut documents = Map::new();+ for (kind, files) in [("bundles", &bundle_files), ("models", &model_files)] {+ for path in files {+ let source = std::fs::read_to_string(path).unwrap();+ let raw: Value = yaml::from_str(&source)+ .unwrap_or_else(|error| panic!("{}: {error}", path.display()));+ let exported = yaml::to_string(&raw).unwrap();+ assert_eq!(+ raw,+ yaml::from_str::<Value>(&exported).unwrap(),+ "{}",+ path.display()+ );+ documents.insert(+ format!("{kind}/{}", path.file_name().unwrap().to_str().unwrap()),+ raw,+ );+ }+ }++ let mut per_file = Map::new();+ for path in &model_files {+ let source = std::fs::read_to_string(path).unwrap();+ let config: ModelConfig =+ yaml::from_str(&source).unwrap_or_else(|error| panic!("{}: {error}", path.display()));+ let single_model = tempfile::tempdir().unwrap();+ std::fs::write(single_model.path().join("model.yaml"), &source).unwrap();+ let filesystem =+ ModelRegistry::with_threshold_routing(&bundles, single_model.path(), true, true);+ assert!(+ filesystem.has_any_models(),+ "{} was skipped",+ path.display()+ );+ assert_eq!(filesystem.list_bundles().len(), bundle_files.len());++ let empty_models = tempfile::tempdir().unwrap();+ let delta =+ ModelRegistry::with_threshold_routing(&bundles, empty_models.path(), true, true);+ delta+ .add_model_config(config)+ .unwrap_or_else(|error| panic!("{}: {error}", path.display()));+ let snapshot = json!({+ "filesystem": registry_snapshot(&filesystem),+ "delta": registry_snapshot(&delta),+ });+ per_file.insert(+ path.file_name().unwrap().to_str().unwrap().to_owned(),+ snapshot,+ );+ }+ let full = ModelRegistry::with_threshold_routing(&bundles, &models, true, true);+ let snapshot =+ json!({"documents": documents, "per_file": per_file, "combined": registry_snapshot(&full)});+ if let Some(path) = std::env::var_os("SIE_YAML_SNAPSHOT") {+ std::fs::write(path, serde_json::to_vec_pretty(&snapshot).unwrap()).unwrap();+ }+ println!(+ "validated {} model files and {} bundle files",+ model_files.len(),+ bundle_files.len()+ );+}diff --git a/packages/sie_server_rust/Cargo.lock b/packages/sie_server_rust/Cargo.lockindex 7357d0f44..dcb2001db 100644--- a/packages/sie_server_rust/Cargo.lock+++ b/packages/sie_server_rust/Cargo.lock@@ -43,6 +43,17 @@ version = "0.2.21"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"+[[package]]+name = "annotate-snippets"+version = "0.12.16"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f211a51805bc641f3ad5b7664c77d2547af685cc33b4cd8d31964027a46f13f1"+dependencies = [+ "anstyle",+ "memchr",+ "unicode-width",+]+[[package]]name = "anstream"version = "1.0.0"@@ -99,6 +110,12 @@ version = "1.0.103"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3"+[[package]]+name = "arraydeque"+version = "0.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236"+[[package]]name = "arrayref"version = "0.3.9"@@ -981,6 +998,15 @@ dependencies = ["cfg-if",]+[[package]]+name = "encoding_rs_io"+version = "0.1.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fba3fe847045ecff794b9c138293a80db914678c453ad63fbf0c6a9eb6e00b22"+dependencies = [+ "encoding_rs",+]+[[package]]name = "enum-as-inner"version = "0.6.1"@@ -1526,6 +1552,16 @@ version = "0.3.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"+[[package]]+name = "granit-parser"+version = "1.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e20f99e46474f56bd905c56e817ebddcf377a611f94c53ac4649e4d3fa3c0cd0"+dependencies = [+ "arraydeque",+ "smallvec",+]+[[package]]name = "h2"version = "0.4.16"@@ -2196,6 +2232,12 @@ dependencies = ["tempfile",]+[[package]]+name = "nohash-hasher"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"+[[package]]name = "nom"version = "7.1.3"@@ -3269,6 +3311,23 @@ dependencies = ["serde_derive",]+[[package]]+name = "serde-saphyr"+version = "1.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8050abb251097357e24aff63ba2c52a6309ecb7d23a5474023df960a02694d8"+dependencies = [+ "annotate-snippets",+ "base64 0.22.1",+ "encoding_rs_io",+ "granit-parser",+ "nohash-hasher",+ "num-traits",+ "serde_core",+ "smallvec",+ "zmij",+]+[[package]]name = "serde_bytes"version = "0.11.19"@@ -3333,19 +3392,6 @@ dependencies = ["serde",]-[[package]]-name = "serde_yaml"-version = "0.9.34+deprecated"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"-dependencies = [- "indexmap",- "itoa",- "ryu",- "serde",- "unsafe-libyaml",-]-[[package]]name = "sha2"version = "0.10.9"@@ -3398,9 +3444,9 @@ dependencies = ["rmp-serde","rustls","serde",+ "serde-saphyr","serde_bytes","serde_json",- "serde_yaml","sha2","sie-telemetry","tempfile",@@ -3598,7 +3644,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"dependencies = ["fastrand",- "getrandom 0.3.4",+ "getrandom 0.4.3","once_cell","rustix","windows-sys 0.61.2",@@ -4106,12 +4152,6 @@ version = "0.5.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "81e544489bf3d8ef66c953931f56617f423cd4b5494be343d9b9d3dda037b9a3"-[[package]]-name = "unsafe-libyaml"-version = "0.2.11"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"-[[package]]name = "untrusted"version = "0.9.0"diff --git a/packages/sie_server_rust/Cargo.toml b/packages/sie_server_rust/Cargo.tomlindex b7402f424..6c28b4f5d 100644--- a/packages/sie_server_rust/Cargo.toml+++ b/packages/sie_server_rust/Cargo.toml@@ -60,7 +60,7 @@ rustls = { version = "0.23", default-features = false, features = ["ring"] }serde = { version = "1", features = ["derive"] }serde_bytes = "0.11"serde_json = { version = "1", features = ["float_roundtrip"] }-serde_yaml = "0.9"+serde-saphyr = "1.3"sha2 = "0.10"thiserror = "2"tokio = { version = "1", features = ["full"] }diff --git a/packages/sie_server_rust/src/candle_backend.rs b/packages/sie_server_rust/src/candle_backend.rsindex 85741f128..30bb5f90e 100644--- a/packages/sie_server_rust/src/candle_backend.rs+++ b/packages/sie_server_rust/src/candle_backend.rs@@ -3838,7 +3838,7 @@ fn parse_runtime_config(if model_config.trim().is_empty() {anyhow::bail!("model_config is required");}- let model_config: ModelConfigYaml = serde_yaml::from_str(model_config)+ let model_config: ModelConfigYaml = serde_saphyr::from_str(model_config).with_context(|| format!("invalid model_config for {expected_model_id}"))?;if !expected_model_id.is_empty() && model_config.sie_id != expected_model_id {anyhow::bail!(diff --git a/tools/test_yaml_compatibility.py b/tools/test_yaml_compatibility.pynew file mode 100644index 000000000..ce48f460a--- /dev/null+++ b/tools/test_yaml_compatibility.py@@ -0,0 +1,78 @@+"""Compare gateway YAML behavior with a pre-migration Git revision.++Run with Python's standard library only:+ python tools/test_yaml_compatibility.py --baseline-ref <commit>++Both builds read the current catalog. The legacy parser is confined to a+temporary checkout and never enters either production dependency graph.+"""++# ruff: noqa: INP001, S603, S607++import argparse+import json+import os+import subprocess+import tempfile+from pathlib import Path+++def main() -> None:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--baseline-ref", required=True)+ args = parser.parse_args()+ root = Path(__file__).resolve().parents[1]+ revision = subprocess.check_output(+ ["git", "rev-parse", "--verify", "--end-of-options", f"{args.baseline_ref}^{{commit}}"], cwd=root, text=True+ ).strip()+ test_path = Path("packages/sie_gateway/tests/yaml_compatibility.rs")+ environment = dict(os.environ)+ environment["SIE_YAML_CATALOG_ROOT"] = str(root / "packages/sie_server")+ environment["CARGO_TARGET_DIR"] = str(root / "target")+ with tempfile.TemporaryDirectory(prefix="sie-yaml-compat-") as temporary:+ scratch = Path(temporary)+ baseline = scratch / "baseline"+ subprocess.run(["git", "clone", "--shared", "--no-checkout", str(root), str(baseline)], check=True)+ subprocess.run(["git", "checkout", "--detach", revision], cwd=baseline, check=True)+ source = (root / test_path).read_text()+ (baseline / test_path).parent.mkdir(parents=True, exist_ok=True)+ (baseline / test_path).write_text(source.replace("use serde_saphyr as yaml;", "use serde_yaml as yaml;"))+ snapshots = []+ for name, checkout in [("baseline", baseline), ("candidate", root)]:+ destination = scratch / f"{name}.json"+ environment["SIE_YAML_SNAPSHOT"] = str(destination)+ subprocess.run(+ [+ "mise",+ "exec",+ "--",+ "cargo",+ "test",+ "--locked",+ "--manifest-path",+ str(checkout / "packages/sie_gateway/Cargo.toml"),+ "--test",+ "yaml_compatibility",+ "--",+ "--nocapture",+ ],+ cwd=root,+ env=environment,+ check=True,+ )+ snapshots.append(json.loads(destination.read_text()))+ for section in snapshots[0]:+ if snapshots[0][section] != snapshots[1][section]:+ changed = [+ key+ for key in snapshots[0][section].keys() | snapshots[1][section].keys()+ if snapshots[0][section].get(key) != snapshots[1][section].get(key)+ ]+ raise SystemExit(f"YAML compatibility mismatch in {section}: {changed}")+ print(+ f"YAML compatibility matches {revision}: {len(snapshots[0]['documents'])} files, per-file and combined registry states."+ )+++if __name__ == "__main__":+ main()