Skip to content

fix(provider): make serviceTier options authoritative - #2326

Open
eric8810 wants to merge 5 commits into
mainfrom
feat/2248-servicetier-options
Open

eric8810 wants to merge 5 commits into
mainfrom
feat/2248-servicetier-options

Conversation

@eric8810

@eric8810 eric8810 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

provider.management could report serviceTier.supported: true with no options
while provider.preferences.update rejected every tier of that model. A client then
has nothing authoritative to render, and the Desktop invents ['default','priority']
in the meantime (arcships/dim-electron#657). That consumer change is out of scope
here and must land separately
: this PR only makes the App Server's reply
authoritative, so the fallback has nothing left to work around.

The reply now has exactly one meaning per state:

Declaration serviceTier in replies
supported: true with options and a default among them {supported: true, default, options}
supported: true with options and no default {supported: true, options}
supported: true, no options enumerated {supported: false}
supported: false {supported: false}
a default outside the declared options the default option, else the first option

No optionsKnown flag and no second state is introduced.

Design material: provider management §3.2
(the invariant is stated once there, mirrored in docs/zh/).

Where the rule applies

ModelServiceTier::usable() states the capability shape, and the three entry
builders of the catalog read resolve their entries with it:

  • BundledCatalog::project — a descriptor a listing or an account catalog supplies
    (this is also the capability a temporary Session startup adopts);
  • BundledCatalog::effective_models — the entries a static Provider record serves;
  • ProviderRecord::effective_models — the single derivation an account-owned
    record's catalog, management view and whole-set write read.

The resolution runs after identification, not inside service_tier(): an
identified catalog row enumerates the options a listing declares without any (for
example an account listing that states serviceTier: true while the bundled row
lists default/priority), and collapsing the declaration to unavailable at parse
time would discard those options. A declaration that nothing enumerates — the row
included — reads as supported: false, so the delivered capability still always
satisfies the invariant.

preferences.update is unchanged: it rejects a tier unless the declaration is
supported and lists it, which now holds for every model. A declaration that names
no default keeps none, so an adoption of such a model sends no tier — the
projection still states a default for a catalog declaration by its existing rule.

Design rule checklist

Answer each item; write "n/a" with a reason where it does not apply. Rules: design rules §4, ADR 002.

  • Scope: n/a — the change stays inside Provider's own catalog projection; no new part, wiring module or lifecycle.
  • Commands and results: n/a — no state change and no new command; preferences.update keeps its existing write and reply.
  • Handover: n/a — no handover point is added or changed.
  • Timeline before callbacks: n/a — no Timeline callback is touched.
  • Infrastructure: n/a — Timeline, Dispatcher, assembly, lifecycle and facades are unchanged.
  • Core mechanisms and consumers gain no plugin-specific handling.
  • Batch: n/a — no Timeline write.
  • Context: n/a — the capability is UI/execution data; it is not context input.
  • No reading another plugin's internal state or deciding for it: the projection reads its own catalog and the descriptor its listing states.
  • Cross-language faces: n/a — no service name or method changes. ModelServiceTier keeps its wire shape; an unavailable declaration simply omits default/options, which every current reader already treats as "offer nothing" (web/src/rpc/management.ts, the CLI's /fast feature flag).
  • Business configuration stays out of loader rows; contracts are language-neutral.
  • Missing mechanism capabilities: n/a — no mechanism capability is missing.
  • Timeline holds only facts later decisions use: n/a.

Documentation

  • No accepted ADR is modified or deleted.
  • No other module's design is changed; the invariant is stated once in Provider management §3.2 and mirrored in docs/zh/.
  • Delivery status is not added to an ADR, index or roadmap.

Ablation review

The change is one capability rule and one call per entry builder. usable() is the
only definition of the shape; ModelEntry::resolve_service_tier applies it to the
metadata field; the three builders are the only places a served entry is assembled,
and each is needed (the startup path consumes project directly, the static record
serves BundledCatalog::effective_models, the account record serves its own
derivation). merge_entry's option fill stays: it is what keeps an identified row's
declared tiers usable. Nothing else could be removed without losing one of those
paths.

Verification

Environment: CARGO_TARGET_DIR=/mnt/data/dim-targets/2248 CARGO_BUILD_JOBS=2.

cargo test --locked -p dim-app-server --test app_server_flow a_service_tier_declaration_states_only_a_usable_set
# first commit, before the fix: FAILED
#   tier-unenumerated states no usable set
#   left: {"supported": true}   right: {"supported": false}

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

cargo test --locked -p dim-app-server --test transport_flow
# 707 passed; 0 failed; 101 ignored

cargo test --locked -p dim-agent-types
# 48 passed; 0 failed

./dev check
# passed (cargo fmt --all -- --check, clippy -D warnings for dim-cli, dim-app-server, dim-oauth, dimcode)

cargo clippy --locked -p dim-agent-types --all-targets -- -D warnings
# passed

cargo run --locked -p xtask-check
# module/crate boundaries, access layer, service declarations, plugin locks,
# comment links, i18n keys, literal main: all passed

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

The first CI run also caught transport_flow::product_protocol::the_configured_view_reads_back_the_adopted_model_preferences:
the first cut invented a default for a declaration that named none, which changed
what an adoption sent. usable() now leaves an unnamed default unnamed; that test
and the rest of transport_flow pass. transport_flow::model_get::a_reloading_active_line_keeps_its_error
failed in the same run with a plugin cancellation during a reload and passes on every
local run; it does not read a service tier.

New tests:

  • provider_flow::a_service_tier_declaration_states_only_a_usable_set — a listing
    declaring serviceTier: true, {supported: true, options: []},
    {supported: true, default: "priority", options: []}, false, and a default
    outside its options; asserts provider.refresh, provider.management and which
    tiers provider.preferences.update accepts.
  • model_catalog_flow::a_service_tier_declaration_states_only_a_usable_set — the
    descriptor projection and stored-entry paths, including a declaration that the
    row it identifies with enumerates.
  • managed_provider_flow::an_account_catalogs_service_tier_states_only_a_usable_set
    — an account catalog's declaration, read through provider.management and
    provider.preferences.update.

Fixes #2248

A serviceTier declaration means the model offers the tiers it lists, so
`supported: true` must state a usable set: non-empty `options` and a
`default` among them. The flow test reads both `provider.refresh` and
`provider.management` for a declaration with options, one without any,
one with an empty list, one that is unsupported, and one whose default is
outside its options, then checks which tiers `provider.preferences.update`
accepts.

Refs #2248
`ModelServiceTier` now states one of two shapes: a usable set, with
non-empty `options` and a `default` among them, or no capability at all.
`usable()` resolves a declaration to that shape, and the two entry
builders of the catalog read apply it after identification: `project`
covers the descriptors a listing or an account catalog supplies, and
`effective_models` covers the entries a record serves. Identification
still fills a declaration that names no options of its own before the
capability is read, so a model whose catalog row enumerates its tiers
keeps them.

`provider.management` therefore no longer advertises a supported tier
set with nothing to offer, and `preferences.update` keeps refusing every
tier such a model does not offer. No new state is introduced: an
unenumerable declaration simply reads as unsupported.

Fixes #2248
An account catalog's model entry reaches the record through the account
provider's own reply, not through the descriptor projection, so the
capability read had to resolve it as well. `ProviderRecord::effective_models`
is the one derivation its catalog, management view and whole-set write
read, so the resolution lives there: a stored declaration that lists no
options reads as unavailable, and an older record written before this
rule stays readable.

Refs #2248
@eric8810
eric8810 marked this pull request as ready for review November 28, 2026 18:10

@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 ordinary empty-options case is fixed, but three behaviors still prevent treating the advertised tier list as authoritative:

  1. Reject unusable advertised choices. In isolated read/write fixtures, empty strings from typed options or direct listing still become selectable tiers, and an Anthropic route advertises priority although its write rejects it. Verify that every advertised option is accepted by the same route and malformed or unrepresentable choices are not advertised. Normalize · Write gate
  2. Do not turn an absent or invalid default into an automatic selection. With only priority available and no valid declared default, a managed fixture now adopts priority without a preference. Verify that valid declared defaults and explicit or saved values still apply, and that absent or invalid defaults leave adoption unchanged. Default handling
  3. Keep unresolved declarations distinct from explicit denial in storage. An unmatched serviceTier: true discovery is persisted as unsupported. After a subsequent alias identifies a catalog row with options, that stored denial still prevents them from filling in. A disposable catalog round trip reproduced it. Verify that later identification can supply choices to the unresolved declaration while an explicit false still suppresses them. Discovery · Merge

The three new tests and existing static-provider flow passed on the tested merge. The findings are from additional isolated fixtures. Exact CI remains independent. No Desktop requirement is part of this review.

@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.

The direction is right: a service-tier declaration should be a capability, and ModelServiceTier::usable() plus resolution in the three entry builders gives provider.management, the catalog and the preference write one shape. The blocking problem is that usable() also invents a default.

usable() falls back to the option named default, else the first option, even when the declaration states no default (crates/dim-agent-types/src/model.rs:269-272). declared_service_tier then treats that invented value as the model's declared default (crates/dim-app-server/src/provider/preferences.rs:145-150), and catalog_defaults applies it to every untouched adoption (crates/dim-app-server/src/provider/preferences.rs:11-39). A declaration {supported: true, options: ["priority", "default"]} therefore adopts serviceTier: "default" and context/configured publishes model_preferences.serviceTier, although the user stated no preference. The existing flow test transport_flow::product_protocol::the_configured_view_reads_back_the_adopted_model_preferences fails on exactly this (crates/dim-app-server/tests/transport_flow/product_protocol.rs:2686-2688), and the same invented value comes back when a user clears the tier (crates/dim-app-server/src/provider.rs:2901-2903), so an omitted tier can no longer be restored. This changes how an untouched model is applied, which the issue boundary excludes, and contradicts default, when present, in the new paragraph.

Fix: keep default: None when the declaration states none, and only replace a stated default that is outside options with the option named default, else the first one. None of the new tests depends on an invented default, so that rule keeps them passing; add a case for options without a default and adjust the last sentence of the new paragraph to match.

One optional note on the account record builder is inline.

Verification: cargo test -p dim-app-server --test app_server_flow service_tier -> 3 passed (model_catalog_flow, provider_flow, managed_provider_flow); cargo test -p dim-agent-types -> 48 passed; the failing product_protocol test was reproduced locally at this head, and model_get::a_reloading_active_line_keeps_its_error passes locally (its CI failure is a shutdown Cancelled("prompt adoption")). CI: verify (linux) fails on those two tests, while changes, evaluate-pr, issue-gate, macos-native and windows-cli pass. Cross-PR: #2321 also edits crates/dim-app-server/tests/model_catalog_flow.rs and the two heads conflict there; source files merge cleanly.

Comment thread crates/dim-agent-types/src/model.rs Outdated
options: Vec::new(),
};
}
let default = default

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.

Blocking: usable() returns a default even when the declaration states none. For {supported: true, options: ["priority", "default"]} the chain at lines 269-272 returns Some("default"). declared_service_tier (crates/dim-app-server/src/provider/preferences.rs:145-150) then seeds catalog_defaults from it, so an untouched adoption sends serviceTier: "default" and context/configured publishes model_preferences.serviceTier, while the existing flow test expects no preference (crates/dim-app-server/tests/transport_flow/product_protocol.rs:2686-2688). Clearing the tier restores the invented value too (crates/dim-app-server/src/provider.rs:2901-2903), so omitting the tier becomes impossible. Fix: keep None when no default is declared; only replace a stated default that is outside options. Add a case for options without a default.

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.

Fixed in f123183.

None => source.entry.clone(),
};
bundled.identify_entry(&projection, &mut entry);
entry.resolve_service_tier();

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.

Optional (P3): this builder resolves the declaration but never adopts an identified row's options. identify_entry fills only the two limits (crates/dim-app-server/src/model_catalog.rs:676-716), while merge_entry fills serviceTier.options when the declaration lists none (crates/dim-app-server/src/model_catalog.rs:1217-1228). A managed catalog entry declaring supported: true with no options therefore reads as supported: false even when its identified row enumerates options, and the new paragraph (docs/design/appserver/provider-management.md:560-567) says the row it is identified with is consulted. No current managed catalog declares serviceTier, so this is dormant; either adopt the row's options here or scope the sentence to the builders that merge a row.

A supported declaration that names no default does not gain one: the
adoption of such a model sends no tier, exactly as before. Only a default
the options do not offer is replaced, by the option named `default`, else
the first one, so a named default is always one the model offers.

The projection still states a default for a catalog declaration by its own
rule, so a catalog model keeps adopting the tier it declares.

Refs #2248

@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 omitted typed default now stays absent on adoption and clear. The previously failing configured-view transport test passes, and valid declared, saved and explicit tiers still work. The remaining parts of the previous review are:

  1. Empty strings from typed options and raw listings are still advertised and rejected on write, and an Anthropic route still advertises a tier it cannot write. Verify every advertised option is usable on that route. Read normalization · Write gate
  2. An invalid typed default still selects a tier on adoption and clear. The listing parser also still assigns a default to options-only raw data. Verify both paths leave the tier unset if no valid default was declared.
  3. Discovery still persists an unresolved declaration as explicit denial. Verify an upgraded match can supply options later without making an explicitly unsupported model selectable.

All three remaining cases reproduced in isolated fixtures on the exact merge. The three tier tests, configured-view transport test and static-provider lifecycle flow passed. The separate intermittent reload cancellation remains unattributed; hosted CI is a separate gate.

@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.

The previous blocking point is fixed: usable() now keeps default: None when the declaration states none (crates/dim-agent-types/src/model.rs:269-279), the existing flow test at crates/dim-app-server/tests/transport_flow/product_protocol.rs:2686-2688 passes, and the three new service-tier tests pass.

I agree with the open condition that an absent default must not become an automatic selection; the remaining source is earlier in the pipeline. Listing and descriptor entries are built through service_tier() before usable() runs, and that parser ends with a fallback to the option named default, else the first option (crates/dim-app-server/src/model_catalog.rs:1773-1775). descriptor_entry calls it (:1137), and BundledCatalog::project is the builder for provider listings and temporary Session startup (crates/dim-app-server/src/provider/remote.rs:345, crates/dim-app-server/src/provider/startup.rs:346). At this head, projecting a custom descriptor {"id": "zzzz-private-tier", "serviceTier": {"supported": true, "options": ["priority"]}} returns {supported: true, default: "priority", options: ["priority"]}. The descriptor names no default, yet the reply carries one; an untouched adoption applies priority through declared_service_tier and catalog_defaults (crates/dim-app-server/src/provider/preferences.rs:145-150, :11-39), and clearing the tier restores it (crates/dim-app-server/src/provider.rs:2902). That is the same user-visible behavior the previous round blocked, and it contradicts the sentence added at docs/design/appserver/provider-management.md:566: a declaration that names no default offers none at adoption.

The same parser also admits an empty scalar: serviceTier: "" becomes {supported: true, default: "", options: [""]} (crates/dim-app-server/src/model_catalog.rs:1764), while configure rejects an empty tier (crates/dim-app-server/src/provider/preferences.rs:249), so the advertised set contains a choice the same route refuses.

Fix: drop the final fallback in service_tier() so an object without a stated default keeps None; a scalar's own value still names a tier, and usable() already handles a stated default outside the options. Treat an empty scalar as no declaration, and add an options-only listing case to the provider flow matrix.

The earlier optional note still stands: ProviderRecord::effective_models resolves after identify_entry without adopting an identified row's options (crates/dim-app-server/src/provider.rs:581, crates/dim-app-server/src/model_catalog.rs:778, :1217-1228); no current managed catalog declares serviceTier, so this stays optional.

Verification: cargo test -p dim-app-server --test app_server_flow service_tier -> 3 passed; cargo test -p dim-agent-types -> 48 passed; cargo test -p dim-app-server --test transport_flow the_configured_view_reads_back_the_adopted_model_preferences -> 1 passed. CI: verify (linux) in progress, macos-native and windows-cli pass, web and scripts skipped. Cross-PR: #2321 also edits crates/dim-app-server/tests/model_catalog_flow.rs; GitHub reports this PR mergeable and the source files do not conflict.

the row it is identified with enumerates is `supported: false` with no
`default` and no `options`, and the preference patch then refuses every tier. A
`default` the options do not offer gives way to the option named `default`, else
the first one; a declaration that names no default offers none at adoption.

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.

service_tier() still gives this declaration a default before usable() runs: it falls back to the option named default, else the first one (crates/dim-app-server/src/model_catalog.rs:1773-1775). A descriptor {supported: true, options: ["priority"]} reaches the reply as {supported: true, default: "priority", options: ["priority"]}, and an untouched adoption applies that tier. Removing the fallback and treating an empty scalar as absent makes this sentence true for every builder.

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.

[feat] Provider model capability: make serviceTier options authoritative

3 participants