From 64ae6a6fa475fef8cbe1a121864eff53ff9aa047 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 00:54:14 +0800 Subject: [PATCH 1/3] test(models): pin an empty modalities array as undeclared (#1980) Both boundaries that read a live provider descriptor - the bundled catalog projection and the account catalog's relay projection - keep an empty `modalities` array today and let it overwrite the row's set. The cases fail against the current projection: the identified row's set, the `vision` fallback, an explicit non-empty array and the shipped deepseek-v4.1-flash declaration are each asserted through the boundary that reads them. --- .../tests/model_catalog_flow.rs | 93 +++++++++++++++++++ crates/dim-oauth/tests/dim_oauth_flow.rs | 48 ++++++++++ 2 files changed, 141 insertions(+) diff --git a/crates/dim-app-server/tests/model_catalog_flow.rs b/crates/dim-app-server/tests/model_catalog_flow.rs index b18d2d6054..8d310b5ee4 100644 --- a/crates/dim-app-server/tests/model_catalog_flow.rs +++ b/crates/dim-app-server/tests/model_catalog_flow.rs @@ -216,6 +216,99 @@ fn media_lookup_and_explicit_capabilities_survive_editing() { assert_eq!(edited.metadata, model.metadata); } +/// A listing that writes `modalities: []` states nothing about what the model +/// reads; the empty array is the undeclared value, so the set the identified +/// row declares applies instead of being overwritten by it. A descriptor that +/// states no modalities of its own falls back to its `vision` declaration, and +/// an explicit non-empty array stays authoritative (#1980). +#[test] +fn an_empty_modalities_array_is_the_undeclared_value() { + let declaring = catalog(json!([vendor( + "acme", + json!([with_vision( + row("acme-vision", "Acme Vision", 400_000, 128_000), + &["text", "image", "audio"], + )]), + )])); + let provider = ProviderProjection { + provider_id: "acme".into(), + source: Some(ModelSource::Custom), + ..Default::default() + }; + let read = |catalog: &BundledCatalog, descriptor: serde_json::Value| { + catalog + .project(&provider, &descriptor) + .unwrap() + .capabilities + .modalities + }; + for descriptor in [ + json!({ "id": "acme-vision", "modalities": [] }), + json!({ "id": "acme-vision", "vision": true, "modalities": [] }), + json!({ "id": "acme-vision", "vision": true, "capabilities": { "modalities": [] } }), + json!({ "id": "acme-vision", "vision": true }), + ] { + assert_eq!( + read(&declaring, descriptor.clone()), + ["text", "image", "audio"], + "{descriptor}" + ); + } + let declared = declaring + .project( + &provider, + &json!({ "id": "acme-vision", "vision": true, "modalities": ["text"] }), + ) + .unwrap(); + assert_eq!(declared.capabilities.modalities, ["text"]); + assert!(declared.capabilities.vision); + + // No row declares the model, so `vision` is the only statement left. + let undeclared = catalog(json!([])); + for descriptor in [ + json!({ "id": "zz-vision", "vision": true, "modalities": [] }), + json!({ "id": "zz-vision", "vision": true }), + json!({ "id": "zz-vision", "vision": true, "capabilities": { "modalities": [] } }), + ] { + assert_eq!( + read(&undeclared, descriptor.clone()), + ["text", "image"], + "{descriptor}" + ); + } + for descriptor in [ + json!({ "id": "zz-text", "vision": false, "modalities": [] }), + json!({ "id": "zz-text", "vision": false }), + ] { + assert_eq!( + read(&undeclared, descriptor.clone()), + ["text"], + "{descriptor}" + ); + } +} + +/// The shipped `deepseek-v4.1-flash` row declares image input, and the live +/// descriptor that reported the empty array is the account catalog's own +/// listing: the model the catalog snapshot serves keeps the row's set (#1980). +#[test] +fn a_live_empty_modalities_array_keeps_the_shipped_deepseek_declaration() { + let catalog = BundledCatalog::load().unwrap(); + let provider = ProviderProjection { + provider_id: "dimcode-api-oauth".into(), + ..Default::default() + }; + let model = catalog + .project( + &provider, + &json!({ "id": "deepseek-v4.1-flash", "vision": true, "modalities": [] }), + ) + .unwrap(); + assert!(model.capabilities.vision); + assert_eq!(model.capabilities.modalities, ["text", "image"]); + assert_eq!(model.capabilities.context_window, Some(1_048_576)); +} + #[test] fn visible_edits_preserve_hidden_fields_and_update_legacy_media_readers() { let catalog = BundledCatalog::load().unwrap(); diff --git a/crates/dim-oauth/tests/dim_oauth_flow.rs b/crates/dim-oauth/tests/dim_oauth_flow.rs index c9167167d5..7eba4d5e48 100644 --- a/crates/dim-oauth/tests/dim_oauth_flow.rs +++ b/crates/dim-oauth/tests/dim_oauth_flow.rs @@ -1223,6 +1223,54 @@ async fn a_relay_model_without_declared_limits_is_published_as_undeclared() { std::fs::remove_dir_all(home).unwrap(); } +/// The relay's own descriptors, projected through the account catalog's +/// boundary: an empty `modalities` array states nothing, so the bundled row's +/// set applies and `vision` decides only for a model no row declares (#1980). +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn an_empty_relay_modalities_array_is_the_undeclared_value() { + let fixture = oauth::start().await; + *fixture.service.models.lock().unwrap() = Some(json!({"data":[ + {"id":"deepseek-v4.1-flash","dim":{"id":"deepseek-v4.1-flash","endpoint_type":"openai", + "vision":true,"modalities":[],"contextWindow":1048576,"maxOutputTokens":65536}}, + {"id":"gemini-2.5-flash","dim":{"id":"gemini-2.5-flash","endpoint_type":"openai", + "vision":true,"modalities":[],"contextWindow":1048576,"maxOutputTokens":65536}}, + {"id":"zzzz-relay-vision","dim":{"id":"zzzz-relay-vision","endpoint_type":"openai", + "vision":true,"modalities":[],"contextWindow":64000,"maxOutputTokens":8000}}, + {"id":"zzzz-relay-text","dim":{"id":"zzzz-relay-text","endpoint_type":"openai", + "vision":false,"modalities":[],"contextWindow":64000,"maxOutputTokens":8000}}, + {"id":"zzzz-relay-declared","dim":{"id":"zzzz-relay-declared","endpoint_type":"openai", + "vision":true,"modalities":["text"],"contextWindow":64000,"maxOutputTokens":8000}} + ]})); + let home = home(); + let Process { root, providers } = process(&home).await; + login(&providers, &fixture.base).await; + let catalog = providers.catalog(PROVIDER, &cancel()).await.unwrap(); + let modalities = |id: &str| { + catalog + .models + .iter() + .find(|model| model.entry.model_id == id) + .unwrap() + .entry + .capabilities + .modalities + .clone() + }; + // The relay's empty array does not overwrite the shipped declaration. + assert_eq!(modalities("deepseek-v4.1-flash"), ["text", "image"]); + assert_eq!( + modalities("gemini-2.5-flash"), + ["text", "image", "audio", "video"] + ); + // No row declares these, so `vision` is the statement that decides. + assert_eq!(modalities("zzzz-relay-vision"), ["text", "image"]); + assert_eq!(modalities("zzzz-relay-text"), ["text"]); + // An explicit non-empty array stays authoritative. + assert_eq!(modalities("zzzz-relay-declared"), ["text"]); + root.shutdown().await.unwrap(); + std::fs::remove_dir_all(home).unwrap(); +} + /// The distinct model ids the shipped catalog lists, in catalog order. A case /// picks the id it asserts on from here by property, never by name. fn listed_ids(catalog: &BundledCatalog) -> Vec { From 1e96df6ac1b46ffebbe9aad7d635f633773632ee Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 01:12:06 +0800 Subject: [PATCH 2/3] fix(models): treat an empty modalities array as undeclared (#1980) A live provider descriptor that writes `modalities: []` overwrote the set the identified catalog row declares, so the account relay's `deepseek-v4.1-flash` listing turned the shipped `["text", "image"]` into `[]`: the snapshot read `vision: true` with no input modality, and a model whose modalities hold no `text` is refused for conversation. The bundled-catalog projection and the account catalog's relay projection now read a descriptor's modalities through one boundary function and resolve them with one rule: an explicit non-empty array stays, an empty array is undeclared and takes the identified row's non-empty set, and a model no row declares falls back to `["text", "image"]` under `vision: true` and `["text"]` otherwise. A remote listing's empty `modalities.input` states no `vision` flag either. --- crates/dim-app-server/src/model_catalog.rs | 64 ++++++++++++++----- crates/dim-app-server/src/provider/remote.rs | 16 +++-- .../tests/model_catalog_flow.rs | 5 +- crates/dim-app-server/tests/provider_flow.rs | 30 +++++++++ crates/dim-oauth/src/models.rs | 28 ++++---- docs/design/appserver/provider-management.md | 10 +++ .../design/appserver/provider-management.md | 7 ++ 7 files changed, 122 insertions(+), 38 deletions(-) diff --git a/crates/dim-app-server/src/model_catalog.rs b/crates/dim-app-server/src/model_catalog.rs index 0bfd2d0add..d8b16e2fd9 100644 --- a/crates/dim-app-server/src/model_catalog.rs +++ b/crates/dim-app-server/src/model_catalog.rs @@ -586,13 +586,12 @@ impl BundledCatalog { let strategy = found_lookup.strategy; let score = found_lookup.score; entry = merge_entry(entry, &found, &explicit); + entry.capabilities.modalities = effective_modalities( + declared_modalities(input), + &found.capabilities.modalities, + input.get("vision").and_then(Value::as_bool), + ); let declared = input.get("capabilities").and_then(Value::as_object); - if input.get("modalities").is_none() - && input.get("vision") != Some(&Value::Bool(true)) - && declared.is_none_or(|value| !value.contains_key("modalities")) - { - entry.capabilities.modalities = found.capabilities.modalities.clone(); - } macro_rules! inherit_capability { ($json:literal, $field:ident) => { if input.get($json).is_none() @@ -1062,20 +1061,17 @@ fn descriptor_entry( if let Some(v) = capabilities { apply_capabilities(&mut caps, v); } - if let Some(values) = input.get("modalities").and_then(Value::as_array) { - caps.modalities = strings(values); - } if let Some(v) = input.get("toolCalling").and_then(Value::as_bool) { caps.tool_calling = v; } if let Some(v) = input.get("vision").and_then(Value::as_bool) { caps.vision = v; - if v && input.get("modalities").is_none() - && capabilities.is_none_or(|c| !c.contains_key("modalities")) - { - caps.modalities = vec!["text".into(), "image".into()]; - } } + caps.modalities = effective_modalities( + declared_modalities(input), + &[], + input.get("vision").and_then(Value::as_bool), + ); if let Some(r) = &reasoning { caps.reasoning = r.supported; } @@ -1311,6 +1307,43 @@ pub(crate) fn declared_limits(input: &Map) -> (Option, Optio ) } +/// The input modalities a model descriptor declares, or `None` when it +/// declares none. A listing that writes `modalities: []` has not said the model +/// reads nothing: the empty array is the undeclared value, so the identified +/// row and the descriptor's `vision` flag decide instead (#1980). The +/// descriptor's own array wins over the nested `capabilities` one. +pub fn declared_modalities(input: &Map) -> Option> { + let declared = input + .get("modalities") + .or_else(|| input.get("capabilities")?.get("modalities"))? + .as_array()?; + let modalities = strings(declared); + (!modalities.is_empty()).then_some(modalities) +} + +/// The input modalities an entry ends up declaring (#1980). A descriptor's +/// non-empty array is its own statement and stays. Otherwise the identified +/// row's set applies, and only a model no row declares takes the set its +/// `vision` flag implies: `["text", "image"]` when it accepts images and +/// `["text"]` otherwise. +pub fn effective_modalities( + declared: Option>, + bundled: &[String], + vision: Option, +) -> Vec { + if let Some(declared) = declared { + return declared; + } + if !bundled.is_empty() { + return bundled.to_vec(); + } + if vision == Some(true) { + vec!["text".into(), "image".into()] + } else { + vec!["text".into()] + } +} + /// Marks the capability edits a legacy stored override cannot help but /// carry (#2189). An override written before capability edits were marked is /// a clone of the row it edited plus the user's values, with only its limits @@ -1777,9 +1810,6 @@ fn pricing(raw: &Map) -> Option { }) } fn apply_capabilities(c: &mut CatalogCapabilities, m: &Map) { - if let Some(a) = m.get("modalities").and_then(Value::as_array) { - c.modalities = strings(a) - } macro_rules! b { ($j:literal,$f:ident) => { if let Some(v) = m.get($j).and_then(Value::as_bool) { diff --git a/crates/dim-app-server/src/provider/remote.rs b/crates/dim-app-server/src/provider/remote.rs index f3c32ac5fd..4d75167418 100644 --- a/crates/dim-app-server/src/provider/remote.rs +++ b/crates/dim-app-server/src/provider/remote.rs @@ -330,15 +330,17 @@ fn project( if let Some(value) = output.first() { descriptor.insert("maxOutputTokens".into(), (*value).clone()); } - if let Some(modalities) = item.get("modalities").and_then(|value| value.get("input")) { - descriptor.insert("modalities".into(), modalities.clone()); + // An empty `modalities.input` states nothing about the model's input, the + // same way an empty descriptor `modalities` array does (#1980), so the + // listing writes neither the set nor a `vision` flag it would infer. + if let Some(Value::Array(modalities)) = + item.get("modalities").and_then(|value| value.get("input")) + && !modalities.is_empty() + { + descriptor.insert("modalities".into(), Value::Array(modalities.clone())); descriptor.insert( "vision".into(), - Value::Bool( - modalities - .as_array() - .is_some_and(|values| values.iter().any(|v| v == "image")), - ), + Value::Bool(modalities.iter().any(|v| v == "image")), ); } bundled diff --git a/crates/dim-app-server/tests/model_catalog_flow.rs b/crates/dim-app-server/tests/model_catalog_flow.rs index 8d310b5ee4..de5042fe2f 100644 --- a/crates/dim-app-server/tests/model_catalog_flow.rs +++ b/crates/dim-app-server/tests/model_catalog_flow.rs @@ -306,7 +306,10 @@ fn a_live_empty_modalities_array_keeps_the_shipped_deepseek_declaration() { .unwrap(); assert!(model.capabilities.vision); assert_eq!(model.capabilities.modalities, ["text", "image"]); - assert_eq!(model.capabilities.context_window, Some(1_048_576)); + assert!( + model.capabilities.missing_limits().is_empty(), + "the row the id identifies declares its limits, so the set is the row's" + ); } #[test] diff --git a/crates/dim-app-server/tests/provider_flow.rs b/crates/dim-app-server/tests/provider_flow.rs index 6df0099fa6..f5996d7cad 100644 --- a/crates/dim-app-server/tests/provider_flow.rs +++ b/crates/dim-app-server/tests/provider_flow.rs @@ -1557,6 +1557,36 @@ async fn a_listings_reasoning_levels_become_the_models_efforts() { listing.close().await; } +/// A listing that writes an empty `modalities.input` states nothing about the +/// model's input, so the row the id identifies keeps its declaration instead +/// of the empty array overwriting it (#1980). +#[tokio::test] +async fn an_empty_listing_modalities_input_keeps_the_identified_rows_declaration() { + let listing = ServedListing::refreshed(json!([ + {"id":"gpt-5.5","modalities":{"input":[]}}, + {"id":"zzzz-unlisted","modalities":{"input":[]}}, + {"id":"zzzz-listed-text","modalities":{"input":["text"]}} + ])) + .await; + let model = |id: &str| { + listing + .catalog + .models + .iter() + .find(|model| model.id == id) + .unwrap() + }; + assert!(model("gpt-5.5").capabilities.vision); + assert_eq!(model("gpt-5.5").capabilities.modalities, ["text", "image"]); + // No row declares this one, so it reads as the text-only model it is. + assert_eq!(model("zzzz-unlisted").capabilities.modalities, ["text"]); + assert!(!model("zzzz-unlisted").capabilities.vision); + // An explicit non-empty array stays authoritative. + assert_eq!(model("zzzz-listed-text").capabilities.modalities, ["text"]); + assert!(!model("zzzz-listed-text").capabilities.vision); + listing.close().await; +} + /// A listing's `supported_reasoning_levels` is the model's effort list the /// same way, from each item's `effort`. #[tokio::test] diff --git a/crates/dim-oauth/src/models.rs b/crates/dim-oauth/src/models.rs index a001aae064..b4d8441f24 100644 --- a/crates/dim-oauth/src/models.rs +++ b/crates/dim-oauth/src/models.rs @@ -4,7 +4,9 @@ use crate::http::{Body, MAX_SAFE_INTEGER, text}; use dim_agent_capabilities::host::ModelProtocol; use dim_app_server::{ managed_provider::{ManagedError, ManagedModel}, - model_catalog::{BundledCatalog, ProviderProjection, kind_of}, + model_catalog::{ + BundledCatalog, ProviderProjection, declared_modalities, effective_modalities, kind_of, + }, }; use regex::Regex; use serde_json::{Map, Value, json}; @@ -401,6 +403,10 @@ fn project( .or(safe_positive(limit.get("output"))) .or(safe_positive(declared.get("maxOutputTokens"))); let found_caps = found.as_ref().map(|f| object(f.get("capabilities"))); + let bundled_modalities = found_caps + .as_ref() + .map(|caps| strings(caps.get("modalities"))) + .unwrap_or_default(); let mut caps = found_caps.clone().unwrap_or_else(|| { object(Some( &json!({"modalities":["text"],"toolCalling":true,"streaming":true, @@ -431,24 +437,20 @@ fn project( caps.insert(key.into(), json!(value)); } } - if declared.contains_key("modalities") { - caps.insert( - "modalities".into(), - json!(strings(declared.get("modalities"))), - ); - } - if input.contains_key("modalities") { - caps.insert("modalities".into(), json!(strings(input.get("modalities")))); - } if let Some(Value::Bool(tool_calling)) = input.get("toolCalling") { caps.insert("toolCalling".into(), json!(tool_calling)); } if let Some(Value::Bool(vision)) = input.get("vision") { caps.insert("vision".into(), json!(vision)); - if *vision && !input.contains_key("modalities") && !declared.contains_key("modalities") { - caps.insert("modalities".into(), json!(["text", "image"])); - } } + caps.insert( + "modalities".into(), + json!(effective_modalities( + declared_modalities(input), + &bundled_modalities, + input.get("vision").and_then(Value::as_bool), + )), + ); if let Some(r) = &r { caps.insert( "reasoning".into(), diff --git a/docs/design/appserver/provider-management.md b/docs/design/appserver/provider-management.md index 3a3ede7538..fc4819d151 100644 --- a/docs/design/appserver/provider-management.md +++ b/docs/design/appserver/provider-management.md @@ -994,6 +994,16 @@ declare the limit itself. Probe, refresh and creation store only declared values and `models.reset` returns a model to its discovery result; when that result declares nothing, the model is undeclared again. +A model's input modalities are resolved by one rule, whichever source the +descriptor comes from: a listing, a user's descriptor, or the managed account +catalog's own listing. An empty `modalities` array states nothing, so the +identified row's non-empty set applies and the array never narrows a declaration +the row makes. A descriptor that states no modalities and identifies no row takes +`["text", "image"]` when it states `vision: true` and `["text"]` otherwise. An +explicit non-empty array is the descriptor's own statement and stays. The rule +covers the nested `capabilities.modalities` array, and a listing's +`modalities.input` array states no `vision` flag either when it is empty (#1980). + Format v24 stored what a client supplied without a mark, and its probe filled each missing field with the assumed pair (128000 context, 16384 output). The format upgrade and both legacy importers therefore decide each field of a user diff --git a/docs/zh/design/appserver/provider-management.md b/docs/zh/design/appserver/provider-management.md index 09fc16f10e..c2153b5cba 100644 --- a/docs/zh/design/appserver/provider-management.md +++ b/docs/zh/design/appserver/provider-management.md @@ -564,6 +564,13 @@ Provider 记录还把列出的 id 映射到它所指的模型 id。该别名是 描述覆盖未自行声明的上限则来自其基础项。probe、refresh 与创建只保存声明的值;`models.reset` 让模型回到发现结果,发现结果没有声明时它重新变为未声明。 +模型的输入 modalities 由同一套规则解析,无论描述来自清单、用户的描述覆盖还是托管账号目录自身 +的清单:空 `modalities` 数组表示未声明,因此采用识别出的行的非空集合,空数组不会收窄该行的 +声明。既未声明 modalities 又没有识别出任何行时,`vision: true` 取 +`["text", "image"]`,其余取 `["text"]`。显式非空数组是描述自身的声明,保持原样。该规则也 +适用于嵌套的 `capabilities.modalities`;清单的 `modalities.input` 为空时同样不写入 `vision` +标志(#1980)。 + 格式 v24 保存客户端给出的上限却不写标记,其探测也为每个缺失字段补上假定值(窗口 128000、输出 16384)。因此格式升级与两个旧版导入器都通过同一个函数,对用户模型、静态记录的描述覆盖与自建 Provider 自有模型的每项上限单独判定:已列入 `capabilityOverrideFields` 或由 `metadata.raw` 声明的 From 1f0b2173debbe29d3c64074d760bdbc4b2a06b6f Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 01:15:15 +0800 Subject: [PATCH 3/3] fix(models): read a descriptor's modalities only from an array A malformed top-level `modalities` value is not a statement about the model, so it must not shadow the nested `capabilities.modalities` array a user model or an edit supplies. The reader takes each shape only when it is an array and falls through otherwise (#1980). --- crates/dim-app-server/src/model_catalog.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/dim-app-server/src/model_catalog.rs b/crates/dim-app-server/src/model_catalog.rs index d8b16e2fd9..18960712b0 100644 --- a/crates/dim-app-server/src/model_catalog.rs +++ b/crates/dim-app-server/src/model_catalog.rs @@ -1315,8 +1315,13 @@ pub(crate) fn declared_limits(input: &Map) -> (Option, Optio pub fn declared_modalities(input: &Map) -> Option> { let declared = input .get("modalities") - .or_else(|| input.get("capabilities")?.get("modalities"))? - .as_array()?; + .and_then(Value::as_array) + .or_else(|| { + input + .get("capabilities") + .and_then(|capabilities| capabilities.get("modalities")) + .and_then(Value::as_array) + })?; let modalities = strings(declared); (!modalities.is_empty()).then_some(modalities) }