Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(host-core): read a stored model binding array entry by entry

zhangqingkun97618dc11e492f3
diff --git a/crates/host-core/src/providers/catalog.rs b/crates/host-core/src/providers/catalog.rs
index 7437ca73f..c6431de52 100644
--- a/crates/host-core/src/providers/catalog.rs
+++ b/crates/host-core/src/providers/catalog.rs
@@ -97,22 +97,94 @@ fn legacy_model_binding(model_id: Option<String>) -> Vec<ModelBinding> {
.unwrap_or_default()
}
+/// What `config_json.models` holds.
+enum StoredModels {
+ /// The key is absent — a record written before bindings existed.
+ Absent,
+ /// The key is present but is not an array, so there is nothing to decode.
+ NotAnArray,
+ /// The array, decoded one entry at a time.
+ Entries {
+ /// Entries that decoded, in stored order.
+ bindings: Vec<ModelBinding>,
+ /// `(index, reason)` for every entry that did not, so a reader can
+ /// name the exact entry instead of only counting the loss.
+ unreadable: Vec<(usize, String)>,
+ },
+}
+
+/// Decode `config_json.models` one entry at a time.
+///
+/// The array is the only place a provider's model list lives and it is written
+/// by more than one hand — a settings save, a plugin declaration, and an
+/// external edit of the stored row. Decoding it as a single `Vec<ModelBinding>`
+/// let one entry that no longer matched the schema discard every sibling, after
+/// which the provider read back as one legacy default model with nothing said
+/// about why (issue #784). Each entry is therefore decoded on its own and the
+/// ones that fail are collected for the caller to report.
+fn decode_stored_models(raw: &str) -> StoredModels {
+ let Some(models) = config_value(raw).and_then(|value| value.get("models").cloned()) else {
+ return StoredModels::Absent;
+ };
+ let Some(entries) = models.as_array() else {
+ return StoredModels::NotAnArray;
+ };
+ let mut bindings = Vec::with_capacity(entries.len());
+ let mut unreadable = Vec::new();
+ for (index, entry) in entries.iter().enumerate() {
+ match serde_json::from_value::<ModelBinding>(entry.clone()) {
+ Ok(binding) => bindings.push(binding),
+ Err(error) => unreadable.push((index, error.to_string())),
+ }
+ }
+ StoredModels::Entries {
+ bindings,
+ unreadable,
+ }
+}
+
+/// Read the provider's model bindings out of `config_json`.
+///
+/// An absent array, an empty one, and one whose every entry was unreadable all
+/// leave the single legacy binding, so a provider stays selectable whatever its
+/// stored shape. Only the third case is reported: an empty array is a legal
+/// state, and an absent one is a record that predates bindings.
pub(crate) fn config_model_bindings(
raw: &str,
legacy_model_id: Option<String>,
+ provider_id: &str,
) -> Vec<ModelBinding> {
let legacy_model_id = legacy_model_id.or_else(|| {
config_value(raw).and_then(|value| value.get("modelId")?.as_str().map(str::to_string))
});
- let parsed = config_value(raw)
- .and_then(|value| value.get("models").cloned())
- .and_then(|value| serde_json::from_value::<Vec<ModelBinding>>(value).ok())
- .map(|bindings| normalize_model_bindings(&bindings))
- .unwrap_or_default();
- if parsed.is_empty() {
- legacy_model_binding(legacy_model_id)
- } else {
- parsed
+ match decode_stored_models(raw) {
+ StoredModels::Entries {
+ bindings,
+ unreadable,
+ } => {
+ for (index, reason) in &unreadable {
+ tracing::warn!(
+ %provider_id,
+ index,
+ %reason,
+ "skipping an unreadable model binding"
+ );
+ }
+ let bindings = normalize_model_bindings(&bindings);
+ if bindings.is_empty() {
+ legacy_model_binding(legacy_model_id)
+ } else {
+ bindings
+ }
+ }
+ StoredModels::NotAnArray => {
+ tracing::warn!(
+ %provider_id,
+ "config_json.models is not an array; reading the legacy binding"
+ );
+ legacy_model_binding(legacy_model_id)
+ }
+ StoredModels::Absent => legacy_model_binding(legacy_model_id),
}
}
@@ -249,6 +321,12 @@ mod tests {
}
}
+ /// Every read names the provider it came from: a warning that does not is
+ /// not locatable, which is half of what issue #784 reports.
+ fn read(raw: &str) -> Vec<ModelBinding> {
+ config_model_bindings(raw, None, "provider-under-test")
+ }
+
/// The settings surface round-trips a provider through `config_json`, so a
/// marker the store drops would silently turn an inherited catalog value
/// into a frozen snapshot of its own.
@@ -256,13 +334,11 @@ mod tests {
fn a_catalog_sourced_binding_survives_the_config_round_trip() {
let raw = r#"{"models":[{"id":"terra","contextWindow":1048576,"maxTokens":64000,
"contextWindowSource":"catalog"}]}"#;
- let saved = config_with_model_bindings("{}", &config_model_bindings(raw, None)).unwrap();
+ let saved = config_with_model_bindings("{}", &read(raw)).unwrap();
let value: serde_json::Value = serde_json::from_str(&saved).unwrap();
assert_eq!(value["models"][0]["contextWindowSource"], "catalog");
assert_eq!(
- config_model_bindings(&saved, None)[0]
- .context_window_source
- .as_deref(),
+ read(&saved)[0].context_window_source.as_deref(),
Some("catalog")
);
@@ -270,9 +346,7 @@ mod tests {
user_binding.context_window_source = Some("user".to_string());
let saved = config_with_model_bindings("{}", &[user_binding]).unwrap();
assert_eq!(
- config_model_bindings(&saved, None)[0]
- .context_window_source
- .as_deref(),
+ read(&saved)[0].context_window_source.as_deref(),
Some("user")
);
}
@@ -281,10 +355,8 @@ mod tests {
/// every reader applies one documented rule instead of guessing.
#[test]
fn a_binding_without_a_source_stays_unmarked() {
- let bindings = config_model_bindings(
- r#"{"models":[{"id":"legacy","contextWindow":128000,"maxTokens":8192}]}"#,
- None,
- );
+ let bindings =
+ read(r#"{"models":[{"id":"legacy","contextWindow":128000,"maxTokens":8192}]}"#);
assert_eq!(bindings[0].context_window_source, None);
let saved = config_with_model_bindings("{}", &bindings).unwrap();
let value: serde_json::Value = serde_json::from_str(&saved).unwrap();
@@ -295,10 +367,9 @@ mod tests {
/// historical rule keeps applying to that row.
#[test]
fn an_unknown_source_is_dropped_instead_of_persisted() {
- let bindings = config_model_bindings(
+ let bindings = read(
r#"{"models":[{"id":"odd","contextWindow":256000,"maxTokens":8192,
"contextWindowSource":"derived"}]}"#,
- None,
);
assert_eq!(bindings[0].context_window_source, None);
}
@@ -327,4 +398,86 @@ mod tests {
);
assert_eq!(normalized[1].default_thinking_level.as_deref(), Some("off"));
}
+
+ /// A binding that omits its limits is one binding, not a broken array: the
+ /// absent key reads as zero and the zero normalisation already in place
+ /// seeds the generic default. This is the reported failure — a stored array
+ /// whose second entry lost `maxTokens` used to read back as one legacy
+ /// default model (issue #784).
+ #[test]
+ fn a_binding_without_limits_keeps_its_siblings() {
+ let bindings = read(
+ r#"{"models":[
+ {"id":"no-limits"},
+ {"id":"explicit","contextWindow":200000,"maxTokens":4096}
+ ]}"#,
+ );
+ assert_eq!(bindings.len(), 2);
+ assert_eq!(bindings[0].id, "no-limits");
+ assert_eq!(bindings[0].context_window, DEFAULT_CONTEXT_WINDOW);
+ assert_eq!(bindings[0].max_tokens, DEFAULT_MAX_TOKENS);
+ assert_eq!(bindings[1].id, "explicit");
+ assert_eq!(bindings[1].context_window, 200_000);
+ assert_eq!(bindings[1].max_tokens, 4_096);
+ }
+
+ /// An entry that no longer matches the schema costs itself, not the array:
+ /// the readable entries survive in their stored order.
+ #[test]
+ fn an_unreadable_binding_costs_only_itself() {
+ let bindings = read(
+ r#"{"models":[
+ {"id":"first","contextWindow":1000,"maxTokens":100},
+ {"id":"second","maxTokens":"not-a-number"},
+ {"id":"third","contextWindow":3000,"maxTokens":300}
+ ]}"#,
+ );
+ assert_eq!(
+ bindings
+ .iter()
+ .map(|binding| binding.id.as_str())
+ .collect::<Vec<_>>(),
+ ["first", "third"]
+ );
+ }
+
+ /// Every entry unreadable still leaves the legacy binding, so the provider
+ /// stays selectable; the loss is reported per entry rather than being
+ /// silent.
+ #[test]
+ fn an_all_unreadable_array_still_reads_the_legacy_binding() {
+ let bindings = config_model_bindings(
+ r#"{"models":[{"id":"a","maxTokens":"x"},{"id":"b","contextWindow":"y"}]}"#,
+ Some("fallback".into()),
+ "provider-under-test",
+ );
+ assert_eq!(bindings.len(), 1);
+ assert_eq!(bindings[0].id, "fallback");
+ }
+
+ /// An empty array is a legal state, not a damaged one, so it reads the
+ /// legacy binding without being reported as corruption.
+ #[test]
+ fn an_empty_models_array_reads_the_legacy_binding() {
+ let bindings = config_model_bindings(
+ r#"{"models":[],"modelId":"config-legacy"}"#,
+ None,
+ "provider-under-test",
+ );
+ assert_eq!(bindings.len(), 1);
+ assert_eq!(bindings[0].id, "config-legacy");
+ }
+
+ /// A `models` value that is not an array is reported rather than silently
+ /// read as the legacy binding.
+ #[test]
+ fn a_non_array_models_value_reads_the_legacy_binding() {
+ let bindings = config_model_bindings(
+ r#"{"models":{"id":"wrapped"},"modelId":"config-legacy"}"#,
+ None,
+ "provider-under-test",
+ );
+ assert_eq!(bindings.len(), 1);
+ assert_eq!(bindings[0].id, "config-legacy");
+ }
}
diff --git a/crates/host-core/src/providers/model.rs b/crates/host-core/src/providers/model.rs
index ad037bda3..ee7c84149 100644
--- a/crates/host-core/src/providers/model.rs
+++ b/crates/host-core/src/providers/model.rs
@@ -134,7 +134,16 @@ pub struct ModelBinding {
/// seed is inherited).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub context_window_source: Option<String>,
+ /// Context window in tokens. Optional on the wire: an absent key reads as
+ /// `0`, which `normalize_model_bindings` replaces with the generic default,
+ /// so a stored record that omits it still loads as one binding instead of
+ /// failing the whole array. A plugin manifest already declares a model
+ /// without either limit, and this is what makes the two paths agree.
+ #[serde(default)]
pub context_window: u32,
+ /// Max output tokens. Optional on the wire for the same reason as
+ /// `context_window`.
+ #[serde(default)]
pub max_tokens: u32,
#[serde(default)]
pub thinking_levels: Vec<String>,
diff --git a/crates/host-core/src/providers/repository.rs b/crates/host-core/src/providers/repository.rs
index b8e32b2d1..a497d983e 100644
--- a/crates/host-core/src/providers/repository.rs
+++ b/crates/host-core/src/providers/repository.rs
@@ -8,7 +8,7 @@ pub(crate) fn provider_from_row(
let id: String = row.get(0)?;
let legacy_model_id: Option<String> = row.get(9)?;
let config_raw: String = row.get(11).unwrap_or_else(|_| "{}".to_string());
- let models = config_model_bindings(&config_raw, legacy_model_id.clone());
+ let models = config_model_bindings(&config_raw, legacy_model_id.clone(), &id);
let has_api_key = secret_ref.as_ref().map(|r| secrets.has(r)).unwrap_or(false);
let has_oauth = secrets.has(&secret_ref_for_provider_oauth(&id));
Ok(ProviderPublic {
diff --git a/crates/host-core/src/providers/tests.rs b/crates/host-core/src/providers/tests.rs
index 4bd6c568d..3d16cc0e6 100644
--- a/crates/host-core/src/providers/tests.rs
+++ b/crates/host-core/src/providers/tests.rs
@@ -268,7 +268,12 @@ fn model_bindings_roundtrip_and_legacy_model_migrates_on_read() {
assert!(legacy.models[0].thinking_levels.is_empty());
assert_eq!(legacy.models[0].default_thinking_level, None);
assert_eq!(
- config_model_bindings(r#"{"modelId":"config-legacy"}"#, None)[0].id,
+ config_model_bindings(
+ r#"{"modelId":"config-legacy"}"#,
+ None,
+ "provider-under-test"
+ )[0]
+ .id,
"config-legacy"
);
}
@@ -1168,3 +1173,112 @@ fn headers_roundtrip_migrate_user_agent_clear_and_reject() {
assert!(reserved.is_err());
assert!(reserved.unwrap_err().to_string().contains("reserved"));
}
+
+fn binding_with_limits(id: &str, context_window: u32, max_tokens: u32) -> ModelBinding {
+ ModelBinding {
+ id: id.into(),
+ alias: None,
+ context_window_source: None,
+ context_window,
+ max_tokens,
+ thinking_levels: Vec::new(),
+ default_thinking_level: None,
+ supports_images: None,
+ supports_documents: None,
+ available_for_subagents: None,
+ native_web_search: None,
+ }
+}
+
+/// The stored array is the only place a provider's model list lives, and an
+/// external edit of the row is one of its writers. Reading it must cost the
+/// entry that no longer parses, never its siblings: the reported failure was a
+/// record whose second binding had lost `maxTokens`, after which the whole
+/// array was discarded and the provider read back as one legacy default model
+/// (issue #784).
+#[test]
+fn a_stored_array_survives_an_entry_that_lost_a_field() {
+ let (_dir, db, secrets) = test_context();
+ let provider = create_provider(
+ &db,
+ &secrets,
+ ProviderCreateInput {
+ name: "Stored array".into(),
+ vendor_key: None,
+ provider_type: None,
+ protocol: None,
+ base_url: None,
+ auth_kind: Some("none".into()),
+ models: Some(vec![
+ binding_with_limits("alpha", 128_000, 8_192),
+ binding_with_limits("beta", 256_000, 16_000),
+ binding_with_limits("gamma", 64_000, 4_096),
+ ]),
+ default_model_id: Some("alpha".into()),
+ secret_value: None,
+ api_style: None,
+ oauth_account_label: None,
+ headers: None,
+ context_window: None,
+ max_output_tokens: None,
+ temperature: None,
+ supports_reasoning: None,
+ supported_thinking_levels: None,
+ },
+ )
+ .unwrap();
+ assert_eq!(provider.models.len(), 3);
+
+ let stored_config = |db: &Database, id: &str| -> serde_json::Value {
+ let raw: String = db
+ .conn()
+ .query_row(
+ "SELECT config_json FROM providers WHERE id = ?1",
+ params![id],
+ |row| row.get(0),
+ )
+ .unwrap();
+ serde_json::from_str(&raw).unwrap()
+ };
+ let write_config = |db: &Database, id: &str, config: &serde_json::Value| {
+ db.conn()
+ .execute(
+ "UPDATE providers SET config_json = ?1 WHERE id = ?2",
+ params![config.to_string(), id],
+ )
+ .unwrap();
+ };
+ let model_ids = |provider: &ProviderPublic| -> Vec<String> {
+ provider.models.iter().map(|m| m.id.clone()).collect()
+ };
+
+ // The report's own step: delete one binding's `maxTokens` and read again.
+ let mut config = stored_config(&db, &provider.id);
+ config["models"][1]
+ .as_object_mut()
+ .unwrap()
+ .remove("maxTokens");
+ write_config(&db, &provider.id, &config);
+ let read_back = get_provider(&db, &secrets, &provider.id).unwrap().unwrap();
+ assert_eq!(model_ids(&read_back), ["alpha", "beta", "gamma"]);
+ // The absent key reads as zero, which the existing normalisation seeds.
+ assert_eq!(read_back.models[1].max_tokens, DEFAULT_MAX_TOKENS);
+ assert_eq!(read_back.models[1].context_window, 256_000);
+
+ // Restoring the field restores the value, as the report's last row says.
+ config["models"][1]["maxTokens"] = json!(16_000);
+ write_config(&db, &provider.id, &config);
+ let restored = get_provider(&db, &secrets, &provider.id).unwrap().unwrap();
+ assert_eq!(model_ids(&restored), ["alpha", "beta", "gamma"]);
+ assert_eq!(restored.models[1].max_tokens, 16_000);
+
+ // An entry that no longer matches the schema costs itself, not the array.
+ config["models"][2] = json!({
+ "id": "gamma",
+ "contextWindow": "not-a-number",
+ "maxTokens": 4_096,
+ });
+ write_config(&db, &provider.id, &config);
+ let damaged = get_provider(&db, &secrets, &provider.id).unwrap().unwrap();
+ assert_eq!(model_ids(&damaged), ["alpha", "beta"]);
+}
diff --git a/docs/spec/03-runtime/12-provider-config-schema.md b/docs/spec/03-runtime/12-provider-config-schema.md
index 864611528..d872f67ec 100644
--- a/docs/spec/03-runtime/12-provider-config-schema.md
+++ b/docs/spec/03-runtime/12-provider-config-schema.md
@@ -85,13 +85,13 @@ Tables (canonical DDL in [04-data-storage](04-data-storage.md) §4.3–4.4, §4.
"type": "array",
"items": {
"type": "object",
- "required": ["id", "contextWindow", "maxTokens", "thinkingLevels", "defaultThinkingLevel"],
+ "required": ["id"],
"properties": {
"id": { "type": "string", "minLength": 1 },
"alias": { "type": "string", "maxLength": 60 },
- "contextWindow": { "type": "integer", "minimum": 1 },
+ "contextWindow": { "type": "integer", "minimum": 0 },
"contextWindowSource": { "enum": ["catalog", "user"] },
- "maxTokens": { "type": "integer", "minimum": 1 },
+ "maxTokens": { "type": "integer", "minimum": 0 },
"thinkingLevels": {
"type": "array",
"items": { "enum": ["off", "minimal", "low", "medium", "high", "xhigh", "max"] },
@@ -192,6 +192,25 @@ output, no enabled thinking levels, and a null default. The settings editor
still renders all canonical choices for that legacy binding, and the next write
stores the explicit binding array in `config_json.models`.
+`models[].contextWindow` and `models[].maxTokens` are optional on the wire. An
+absent key, or an explicit `0`, is not a per-model choice: the host reads it as
+zero and seeds the generic default (128,000 / 8,192) — the same value the
+legacy binding above is materialized with, and the same value a plugin
+manifest that declares no limits already produces. The stored array and the
+manifest therefore agree on what a model without limits means (D610).
+
+Each entry of a stored `models` array is decoded on its own. An entry that no
+longer matches the schema is skipped and reported on the host log with the
+provider id, its index and the reason, instead of discarding the whole array:
+one hand-edited or partially written binding used to leave the provider reading
+as a single legacy default model, every other configured model gone and nothing
+said about why (D610). An absent `models` key, an empty array, and an array
+whose every entry was unreadable all still read as the legacy binding, so a
+provider stays selectable whatever its stored shape; only the third is
+reported, because an empty array is a legal state and an absent one predates
+bindings. A save still writes exactly the bindings the client sends, so the
+stored array is only ever replaced by an explicit write.
+
For context resolution, that 128,000 value is a backward-compatible generic
seed, not a reason to hide a published long-context limit. If models.dev now
publishes a positive `limit.context`, the effective runtime and inspector window
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 0aa54929f..0c83ee2ff 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -8037,6 +8037,8 @@ identify the platform validation still needed.
| M6+ (delegate context budget) | E2E-SUBAGENT-context-overflow-compacts-before-failing, E2E-SUBAGENT-context-overflow-reports-actionable-failure, E2E-SUBAGENT-resume-seeds-within-context-budget |
| C / F / Quality — The context estimate stays safe (calibration) | E2E-CONTEXT-estimate-calibration-stays-safe |
| C — Conversation & stream (unique tool-call ids) | E2E-RUNTIME-unique-tool-call-ids-per-request |
+| F — Persistence (stored model binding array) | E2E-PROVIDER-stored-binding-array-reads-entry-by-entry |
+| Quality (stored model binding array) | E2E-PROVIDER-stored-binding-array-reads-entry-by-entry |
| Quality (unique tool-call ids) | E2E-RUNTIME-unique-tool-call-ids-per-request |
| G — Plugin host lifecycle (crash report) | E2E-PLUGIN-crash-report-names-the-exit-code |
| Quality (crash report) | E2E-PLUGIN-crash-report-names-the-exit-code |
@@ -14196,6 +14198,28 @@ the latest destination. These assertions measure work counts, not device FPS.
success fixture uses a child-only extra CA; it does not reproduce a specific
antivirus installation or claim native macOS/Linux verification.
+
+### E2E-PROVIDER-stored-binding-array-reads-entry-by-entry
+
+- **Preconditions:** A throwaway data directory and the host-core binary; a
+ provider created through `providers.create` with at least three complete
+ bindings; no real provider or credentials.
+- **Steps:** Call `providers.list` and confirm every binding returns. Edit the
+ stored `config_json` to delete one binding's `maxTokens` and list again.
+ Restore the field and list again. Then set one binding's `contextWindow` to a
+ string and list once more.
+- **Expected:** All three bindings return in every case except the last, where
+ the two readable bindings return in their stored order. The binding that lost
+ `maxTokens` reads with the generic default output cap, and restoring the field
+ restores the value. The host log names the provider id, the entry's index and
+ the reason for the entry that could not be decoded.
+- **Specs linked:** `03-runtime/12-provider-config-schema.md` §2,
+ `08-meta/decisions-log.md` D610
+- **Acceptance:** F (persistence), Quality
+- **Status:** Unit-covered (`providers::catalog::tests`,
+ `providers::tests::a_stored_array_survives_an_entry_that_lost_a_field`); the
+ host RPC path is exercised by `scripts/e2e-smoke.mjs` for provider create and
+ list, but no suite drives a hand-edited `config_json`.
### E2E-CONTEXT-estimate-calibration-stays-safe
- **Preconditions:** Deterministic provider fixture whose reported usage can be
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index 59109a44a..2dd317781 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -6550,3 +6550,9 @@ that was sitting at the bottom — including after the turn had finished.
- Renderer only: no protocol, storage, host, permission, or migration change,
and no new default. See `04-ux/08-component-spec.md`, ADR 0233, ADR 0273, and
E2E-012a / E2E-256.
+## 2026-09-21 — A stored model binding array is read entry by entry (D610, issue #784)
+
+- `config_json.models` is the only place a provider's model list lives, and it has more than one writer: a settings save, a plugin declaration, and an external edit of the stored row. It was decoded as a single `Vec<ModelBinding>`, so one entry that no longer matched the schema discarded every sibling — after which the provider read back as the single legacy default model derived from `defaultModelId`, every other configured model gone, and nothing said about why. The report reproduced it by deleting one binding's `maxTokens`: 12 stored bindings read back as 1.
+- `contextWindow` and `maxTokens` are therefore optional on the wire, and each entry of the array is decoded on its own. An absent key, or an explicit `0`, reads as zero and is seeded with the generic default (128,000 / 8,192) by the normalisation that already existed for the explicit zero — the same value a record carrying only `defaultModelId` is materialized with, and the same value a plugin manifest that declares no limits already produces. The two paths now agree instead of one rejecting what the other accepts.
+- An entry that still fails to decode costs itself, not the array: the readable entries survive in their stored order, and the failure is reported on the host log with the provider id, the entry's index and the reason, so it is locatable rather than silent. An absent `models` key, an empty array, and an array whose every entry was unreadable all still read as the legacy binding, so a provider stays selectable whatever its stored shape; only the third is reported, because an empty array is a legal state and an absent one predates bindings.
+- Nothing is rewritten on disk and no write path changes: `providers.update` still persists exactly the bindings the client sends, so a save issued from a degraded view replaces the stored array as it always did. See `03-runtime/12-provider-config-schema.md` §2.
diff --git a/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md b/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md
index 92dcada18..bcd867706 100644
--- a/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md
+++ b/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md
@@ -82,13 +82,13 @@
"type": "array",
"items": {
"type": "object",
- "required": ["id", "contextWindow", "maxTokens", "thinkingLevels", "defaultThinkingLevel"],
+ "required": ["id"],
"properties": {
"id": { "type": "string", "minLength": 1 },
"alias": { "type": "string", "maxLength": 60 },
- "contextWindow": { "type": "integer", "minimum": 1 },
+ "contextWindow": { "type": "integer", "minimum": 0 },
"contextWindowSource": { "enum": ["catalog", "user"] },
- "maxTokens": { "type": "integer", "minimum": 1 },
+ "maxTokens": { "type": "integer", "minimum": 0 },
"thinkingLevels": {
"type": "array",
"items": { "enum": ["off", "minimal", "low", "medium", "high", "xhigh", "max"] },
@@ -124,6 +124,19 @@
身份,别名从不用于提供商或模型解析。host-core 会修剪别名、丢弃空白值,
并在超过 60 个 Unicode 字符时以 `MODEL_ALIAS_TOO_LONG` 拒绝。
+`models[].contextWindow` 与 `models[].maxTokens` 在线为可选。缺失的键、或显式的 `0`,
+都不是按模型的选择:host 把它读作 0 并补上通用默认值(128,000 / 8,192)——这与上面
+legacy 绑定被物化时用的是同一个值,也与未声明限额的插件 manifest 已经产生的值相同。
+存储数组与 manifest 由此对“没有限额的模型”取得一致(D610)。
+
+存储的 `models` 数组逐条解码。不再符合 schema 的条目会被跳过,并在宿主日志里带上
+提供商 id、条目下标与原因上报,而不是丢弃整个数组:此前一个手改或部分写入的绑定会让
+该提供商读回来只剩单个 legacy 默认模型,其它已配置模型全部消失且没有任何说明
+(D610)。缺失的 `models` 键、空数组、以及所有条目都不可读的数组,都仍旧读作 legacy
+绑定,使提供商无论存储形态如何都保持可选;只有第三种会被上报,因为空数组是合法状态,
+而缺失键则是早于绑定机制的记录。保存依旧只写入客户端发来的绑定,因此存储数组只会被
+一次显式写入替换。
+
`models[].contextWindowSource` 记录存储的 `contextWindow` 来自哪里:`catalog` 表示
models.dev 快照,之后的目录修正可以替换它;`user` 表示用户在设置中手改的值,永不被
替换。该字段可选,因此早于该标记写出的配置仍可读,旧客户端会忽略它。host-core 只
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 35e0ca654..ea3986a31 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -5295,6 +5295,8 @@ eleven-tool-round desktop paths are verified by
| 品质(工具调用 id 唯一) | E2E-RUNTIME-unique-tool-call-ids-per-request |
| G — 插件宿主生命周期(崩溃上报) | E2E-PLUGIN-crash-report-names-the-exit-code |
| 品质(崩溃上报) | E2E-PLUGIN-crash-report-names-the-exit-code |
+| F — 持久化(存储的模型绑定数组) | E2E-PROVIDER-stored-binding-array-reads-entry-by-entry |
+| 品质(存储的模型绑定数组) | E2E-PROVIDER-stored-binding-array-reads-entry-by-entry |
`US-UI-*` 视觉场景(§UI shell 视觉场景)追踪到
[决策日志 §D](/zh-CN/spec/08-meta/decisions-log) 中的法典平价决策
@@ -8491,3 +8493,21 @@ the latest destination. These assertions measure work counts, not device FPS.
- **Status:** Automated by `node --experimental-strip-types
scripts/e2e-scheduled-workspace.mjs`, using production Electron dispatch and
real Rust/stdio/SQLite. Only external inference is replaced with an observer.
+
+#### E2E-PROVIDER-stored-binding-array-reads-entry-by-entry:存储的模型绑定数组逐条读取
+
+- **前置条件**:一次性数据目录与 host-core 可执行文件;通过 `providers.create`
+ 建立一个至少含三条完整绑定的提供商;不使用真实提供商或凭据。
+- **步骤**:调用 `providers.list`,确认全部绑定都返回。编辑存储的
+ `config_json`,删掉其中一个绑定的 `maxTokens`,再次 list。补回该字段后再
+ list。最后把某个绑定的 `contextWindow` 改成字符串,再 list 一次。
+- **预期**:除最后一次外,三种情况下三条绑定全部返回;最后一次按存储顺序返回
+ 两条可读绑定。丢失 `maxTokens` 的绑定以通用默认输出上限读出,补回字段后数值
+ 恢复。宿主日志为无法解码的条目带上提供商 id、条目下标与原因。
+- **链接规格**:`03-runtime/12-provider-config-schema.md` §2、
+ `08-meta/decisions-log.md` D610
+- **验收**:F(持久化)、品质
+- **状态**:单元覆盖(`providers::catalog::tests`、
+ `providers::tests::a_stored_array_survives_an_entry_that_lost_a_field`);
+ 宿主 RPC 路径由 `scripts/e2e-smoke.mjs` 覆盖提供商的创建与列举,但没有套件
+ 驱动手工编辑的 `config_json`。
diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.md
index 2ff3481bd..8e13bd492 100644
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@ -4643,3 +4643,9 @@ that amendment are retired by ADR 0268; the upstream work-panel lifecycle stays.
`apps/desktop/src/lib/project-name.ts`,与对话框的文件夹行共用。
- 仅渲染器改动:不改协议、存储、宿主、权限或迁移,也不新增默认值。见
`04-ux/08-component-spec.md`、ADR 0233、ADR 0273、E2E-012a / E2E-256。
+## 2026-09-21 —— 存储的模型绑定数组逐条读取(D610,issue #784)
+
+- `config_json.models` 是提供商模型列表唯一的存放处,而它不止一个写入方:设置保存、插件声明,以及对存储行的外部编辑。此前它被当作单个 `Vec<ModelBinding>` 解码,于是只要有条目不再符合 schema,全部兄弟条目都会被丢弃——之后该提供商读回来只剩由 `defaultModelId` 派生的那一个 legacy 默认模型,其它已配置模型全部消失,且没有任何说明。报告的复现正是删掉某一个绑定的 `maxTokens`:库里 12 条绑定,读回来 1 条。
+- 因此 `contextWindow` 与 `maxTokens` 在线为可选,并且数组逐条解码。缺失的键、或显式的 `0`,都读作 0 并由既有的零值归一化补上通用默认值(128,000 / 8,192)——这与只带 `defaultModelId` 的记录被物化时用的是同一个值,也与未声明限额的插件清单已经产生的值相同。两条路径从此一致,而不是一条拒绝另一条接受的东西。
+- 仍然解码失败的条目只损失自己,不损失整个数组:可读条目按存储顺序保留,失败会在宿主日志里上报,带上提供商 id、条目下标与原因,因此可定位而不是静默。缺失的 `models` 键、空数组、以及所有条目都不可读的数组,都仍旧读作 legacy 绑定,使提供商无论存储形态如何都保持可选;只有第三种会被上报,因为空数组是合法状态,而缺失键则是早于绑定机制的记录。
+- 不改写磁盘上的任何内容,写路径也不变:`providers.update` 依旧只持久化客户端发来的绑定,因此从降级视图发出的保存会像从前一样替换存储数组。见 `03-runtime/12-provider-config-schema.md` §2。