Skip to content

fix(models): treat an empty modalities array as undeclared - #2321

Open
eric8810 wants to merge 3 commits into
mainfrom
fix/1980-empty-modalities-fallback
Open

eric8810 wants to merge 3 commits into
mainfrom
fix/1980-empty-modalities-fallback

Conversation

@eric8810

@eric8810 eric8810 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1980.

A live provider descriptor that writes "modalities": [] overwrote the set the
identified catalog row declares. The shipped deepseek-v4.1-flash rows declare
["text", "image"]; the account relay reports [], so the runtime snapshot
became {"vision": true, "modalities": []}. Besides the UI and
modality.capabilities reading the model as accepting no image, a model whose
modalities hold no text is refused for conversation, so the empty array could
take a shipped vision model out of use.

An empty array is the undeclared value, not a statement that the model reads
nothing. Both boundaries that read a live descriptor — the bundled-catalog
projection (crates/dim-app-server/src/model_catalog.rs) and the account
catalog's relay projection (crates/dim-oauth/src/models.rs) — now share one
reading of a descriptor's modalities (declared_modalities) and one resolution
(effective_modalities):

  • an explicit non-empty modalities array stays authoritative;
  • otherwise the identified row's non-empty set applies, so modalities: []
    never overwrites 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.

The same reading covers the nested capabilities.modalities array. The remote
listing's modalities.input array also states no vision flag when it is empty
(crates/dim-app-server/src/provider/remote.rs), instead of inferring
vision: false from it and then keeping a row's image modality beside it.

An explicit vision: false does not add the image fallback; it does not erase a
set the identified row declares either, which is the existing rule for a
descriptor that states no modalities.

The projection rule is stated in
docs/design/appserver/provider-management.md
(§3.5) beside the other effective-catalog rules, with the docs/zh/ mirror.

The PR starts with the failing boundary tests (64ae6a6); the fix and the
design statement follow in 1e96df6, and 1f0b217 keeps a malformed top-level
modalities value from shadowing the nested capabilities.modalities array.

Design rule checklist

  • Scope: n/a — no part is added or moved; the change is inside Provider's
    projection of its own descriptors.
  • Commands and results: n/a — both functions are pure projections of
    external descriptors and change no state.
  • Handover: n/a — no handover point is introduced.
  • Timeline before: n/a — no Timeline event is written or transformed.
  • Infrastructure: unchanged.
  • Core mechanisms and consumers gain no plugin-specific handling. The rule
    is about the external descriptor boundary, not a provider or model name.
  • Batch: n/a — no events.
  • Context: n/a — no context input path changes.
  • No reading another plugin's internal state.
  • Cross-language faces: n/a — no service is added; capabilities.modalities
    stays a string array and the management reads keep their shape.
  • Business configuration stays out of loader rows; the rule is data
    semantics, not configuration.
  • Missing mechanism capabilities: none.
  • Timeline holds only facts; this change writes no Timeline state.

Documentation

  • No accepted ADR is modified or deleted.
  • The change is stated in Provider's own design document
    (docs/design/appserver/provider-management.md §3.5, with the
    docs/zh/ mirror); no other module's design is changed.
  • No delivery status is added to an ADR, index or roadmap.

Verification

Red step (64ae6a6, before the fix):

cargo test --locked -p dim-app-server --test app_server_flow -- \
  model_catalog_flow::an_empty_modalities_array model_catalog_flow::a_live_empty_modalities
# 2 failed: both report modalities [] instead of the row's set

cargo test --locked -p dim-oauth --test dim_oauth_flow -- \
  an_empty_relay_modalities_array_is_the_undeclared_value
# 1 failed: deepseek-v4.1-flash reports [] instead of ["text", "image"]

After the fix (1e96df6, 1f0b217), with CARGO_TARGET_DIR=/mnt/data/dim-targets/1980 CARGO_BUILD_JOBS=2:

cargo test --locked -p dim-app-server --test app_server_flow -- model_catalog_flow::
# ok. 64 passed; 0 failed

cargo test --locked -p dim-app-server --test app_server_flow -- provider_flow::
# ok. 79 passed; 0 failed; 1 ignored

cargo test --locked -p dim-app-server --test app_server_flow
# ok. 515 passed; 0 failed; 6 ignored

cargo test --locked -p dim-oauth --test dim_oauth_flow
# ok. 35 passed; 0 failed; 1 ignored

cargo test --locked -p dim-app-server --test transport_flow -- managed_provider
# ok. 14 passed; 0 failed

cargo clippy --locked -p dim-app-server -p dim-oauth --all-targets -- -D warnings
# Finished with no warnings

./dev check
# exit 0 (fmt + clippy for dim-cli, dim-app-server, dim-oauth, dimcode)

The whole cargo test --locked -p dim-app-server run reported 705 passed and 2
failed in transport_flow; neither is a modalities case, and each passes alone:

cargo test --locked -p dim-app-server --test transport_flow -- sessions::model_get_names_the_catalog_provider_of_a_routed_adoption
# ok (the full run hit provider_route_conflict under suite load)
cargo test --locked -p dim-app-server --test transport_flow -- history_window::the_latest_turn_window_measures_the_three_issue_sizes
# ok (the full run hit the Session-creation deadline under suite load)
cargo run --locked -p xtask-check
# exit 0: access, service declarations, plugin locks, comment links, i18n, literal main

node scripts/adr-check.mjs --base origin/main
# ADR freeze passed: 8 changed files

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.
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.
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).
@eric8810
eric8810 marked this pull request as ready for review November 28, 2026 17:15

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new projection covers a fresh listing with an empty array and a matching vision-enabled catalog row. Two gaps remain for #1980:

  1. An undeclared field can still override live capability data. The shared parser chooses the top-level array before checking whether it is nonempty, so modalities: [] can hide a nested nonempty declaration. The relay supplies only top-level vision to fallback, even when nested vision is published. The shared helper also returns bundled image modalities before considering explicit vision: false. Verify that both projections preserve nonempty declarations, use the same effective vision value for the snapshot and inferred fallback, and do not infer image support from a bundled row when a live descriptor explicitly denies vision and declares no modalities.
  2. Existing saved entries still return the original empty array until refresh. The fix is on fresh projection; normal managed reads and static reads still serve saved modalities. Verify an existing pre-upgrade catalog with an empty array serves the corrected capabilities and selection for a fresh request without waiting for a successful network refresh. This does not require changing previously adopted session snapshots.

These are source findings; no live provider calls. Exact CI had macOS native green and Linux workspace verification pending at the evidence snapshot.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 at 1f0b2173. The PR fixes #1980: a live descriptor that writes modalities: [] must read as undeclared, so the identified row's non-empty set, or the descriptor's vision flag when no row matches, decides. The bundled projection and the account relay share declared_modalities and effective_modalities, and an empty remote modalities.input no longer infers vision: false.

I agree with the existing review that non-empty nested declarations and stored entries still need coverage. Two P2s remain.

  1. An empty top-level modalities array hides a non-empty nested capabilities.modalities array. declared_modalities (crates/dim-app-server/src/model_catalog.rs:1315-1327) takes the top-level value whenever it is an array and only otherwise reads the nested one, so modalities: [] becomes None before nested is considered. Failure scenario: a descriptor {"modalities": [], "capabilities": {"modalities": ["text", "image"]}} for a model no row declares and with no top-level vision resolves to ["text"]; the nested image declaration disappears. The contract at docs/design/appserver/provider-management.md section 3.5 says an empty array states nothing and the rule covers the nested array. Fix: take the first non-empty array, top-level when non-empty and nested otherwise.

  2. Existing saved catalogs still serve the empty array until a refresh replaces the record. The fix runs at projection time (model_catalog.rs:589-593 and :1070-1074, crates/dim-oauth/src/models.rs:446-453). Reads that clone a stored entry (crates/dim-app-server/src/provider.rs:559-581 and :1138-1171; crates/dim-app-server/src/provider/query.rs:296; provider.rs:2016) still return the persisted capabilities because identify_entry (model_catalog.rs:767-800) fills only limits. A static remote listing or a ManagedModel.entry saved before this fix keeps modalities: [] (provider.rs:286-291; crates/dim-app-server/src/managed_provider.rs:59-62). Failure scenario: a user upgrades with such a catalog and the provider cannot refresh; provider.catalog for a static provider and the target/query reads for a managed account still report vision: true, modalities: [], and chat_only_unavailable (provider.rs:1280) marks the model unavailable for conversation, which is the state #1980 accepts must stop. Fix: resolve empty stored modalities on read with the identified row and the effective vision, or normalize stored records on load; adopted Session snapshots can stay as the PR states.

Optional P3: the fallback reads only the top-level vision flag. A descriptor with capabilities: {"vision": true}, no top-level vision or modalities, and no row gets caps.vision = true from apply_capabilities (model_catalog.rs:1828) while effective_modalities receives None (model_catalog.rs:1070-1074) and returns ["text"]; the relay has the same split (crates/dim-oauth/src/models.rs:436-445 versus :446-453). Passing the effective vision (top-level when declared, otherwise nested) would make the boundaries agree with the rule that a descriptor stating vision: true and no modalities takes ["text", "image"].

The fresh paths check out: an identified row keeps its set for an empty top-level or nested array, a model no row declares follows the top-level vision flag, an explicit non-empty array stays authoritative, an empty remote modalities.input writes neither the set nor a flag, and the EN/ZH section 3.5 text matches those cases. I ran the three new focused tests at this head; all pass:

  • model_catalog_flow::an_empty_modalities_array_is_the_undeclared_value
  • provider_flow::an_empty_listing_modalities_input_keeps_the_identified_rows_declaration
  • dim_oauth_flow::an_empty_relay_modalities_array_is_the_undeclared_value

CI at review time is green, including verify (linux) and ci-ok. No old comments need withdrawal; there are no inline threads.

let declared = input
.get("modalities")
.and_then(Value::as_array)
.or_else(|| {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem: an empty top-level modalities array is taken as the declaration before the nested one is considered, so it hides a non-empty capabilities.modalities array. Failure scenario: {"modalities": [], "capabilities": {"modalities": ["text", "image"]}} for a model no row declares and with no top-level vision resolves to ["text"], losing the nested image declaration. Evidence: crates/dim-app-server/src/model_catalog.rs:1315-1327; the contract says an empty array states nothing and the rule covers the nested array (docs/design/appserver/provider-management.md section 3.5). Fix: take the first non-empty array, top-level when non-empty and nested otherwise.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[models] Empty modalities array overrides vision fallback (vision:true + modalities:[])

3 participants