Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(host-core): protect degraded model binding updates
vastsaa0018f83c152
diff --git a/crates/host-core/src/providers.rs b/crates/host-core/src/providers.rsindex cbfdfb820..e13f38ea5 100644--- a/crates/host-core/src/providers.rs+++ b/crates/host-core/src/providers.rs@@ -33,8 +33,8 @@ pub(crate) use repository::{delete_provider_row, provider_owner_plugin};pub(crate) use catalog::{config_model_bindings, config_thinking_levels_override, config_with_model_bindings,- normalize_model_bindings, CANONICAL_THINKING_LEVELS, DEFAULT_CONTEXT_WINDOW,- DEFAULT_MAX_TOKENS, PROVIDER_SELECT,+ ensure_model_bindings_update_safe, normalize_model_bindings, CANONICAL_THINKING_LEVELS,+ DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_TOKENS, PROVIDER_SELECT,};pub(crate) use credentials::{build_provider_config_json, config_headers, config_oauth_account_label,diff --git a/crates/host-core/src/providers/catalog.rs b/crates/host-core/src/providers/catalog.rsindex c6431de52..5845ff85b 100644--- a/crates/host-core/src/providers/catalog.rs+++ b/crates/host-core/src/providers/catalog.rs@@ -101,6 +101,11 @@ fn legacy_model_binding(model_id: Option<String>) -> Vec<ModelBinding> {enum StoredModels {/// The key is absent — a record written before bindings existed.Absent,+ /// The stored config is not valid JSON or is not an object.+ InvalidConfig {+ /// A safe, non-secret description suitable for the RPC error/log.+ reason: String,+ },/// The key is present but is not an array, so there is nothing to decode.NotAnArray,/// The array, decoded one entry at a time.@@ -123,7 +128,20 @@ enum StoredModels {/// 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 {+ let value = match serde_json::from_str::<serde_json::Value>(raw) {+ Ok(value) if value.is_object() => value,+ Ok(_) => {+ return StoredModels::InvalidConfig {+ reason: "config_json root must be an object".to_string(),+ };+ }+ Err(error) => {+ return StoredModels::InvalidConfig {+ reason: format!("config_json is not valid JSON: {error}"),+ };+ }+ };+ let Some(models) = value.get("models").cloned() else {return StoredModels::Absent;};let Some(entries) = models.as_array() else {@@ -133,6 +151,10 @@ fn decode_stored_models(raw: &str) -> StoredModels {let mut unreadable = Vec::new();for (index, entry) in entries.iter().enumerate() {match serde_json::from_value::<ModelBinding>(entry.clone()) {+ Ok(binding) if binding.id.trim().is_empty() => unreadable.push((+ index,+ "model binding id must be a non-empty string".to_string(),+ )),Ok(binding) => bindings.push(binding),Err(error) => unreadable.push((index, error.to_string())),}@@ -145,10 +167,10 @@ fn decode_stored_models(raw: &str) -> StoredModels {/// 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.+/// An absent array and an empty one leave the single legacy binding without a+/// warning. Invalid config shapes and unreadable entries are reported. An array+/// whose every entry is unreadable still falls back to the legacy binding, so a+/// provider stays selectable while the loss remains diagnosable.pub(crate) fn config_model_bindings(raw: &str,legacy_model_id: Option<String>,@@ -177,6 +199,14 @@ pub(crate) fn config_model_bindings(bindings}}+ StoredModels::InvalidConfig { reason } => {+ tracing::warn!(+ %provider_id,+ %reason,+ "invalid provider config_json; reading the legacy binding"+ );+ legacy_model_binding(legacy_model_id)+ }StoredModels::NotAnArray => {tracing::warn!(%provider_id,@@ -188,6 +218,33 @@ pub(crate) fn config_model_bindings(}}+/// Reject a full model-array replacement while the stored array is degraded.+///+/// Returning the readable subset from a degraded read keeps providers usable,+/// but accepting that subset back through `providers.update` would permanently+/// erase unreadable entries. Callers may still update unrelated provider fields;+/// only an explicit `models` replacement is blocked.+pub(crate) fn ensure_model_bindings_update_safe(raw: &str) -> Result<()> {+ match decode_stored_models(raw) {+ StoredModels::Absent => Ok(()),+ StoredModels::Entries { unreadable, .. } if unreadable.is_empty() => Ok(()),+ StoredModels::Entries { unreadable, .. } => {+ let details = unreadable+ .into_iter()+ .map(|(index, reason)| format!("index {index}: {reason}"))+ .collect::<Vec<_>>()+ .join("; ");+ bail!("MODEL_BINDINGS_DEGRADED: {details}");+ }+ StoredModels::InvalidConfig { reason } => {+ bail!("MODEL_BINDINGS_DEGRADED: {reason}");+ }+ StoredModels::NotAnArray => {+ bail!("MODEL_BINDINGS_DEGRADED: config_json.models is not an array");+ }+ }+}+pub(crate) fn config_with_model_bindings(raw: &str, bindings: &[ModelBinding]) -> Result<String> {let mut config = ensure_config_object(raw)?;config["models"] = serde_json::to_value(normalize_model_bindings(bindings))?;@@ -480,4 +537,37 @@ mod tests {assert_eq!(bindings.len(), 1);assert_eq!(bindings[0].id, "config-legacy");}+ #[test]+ fn malformed_model_storage_is_explicitly_degraded() {+ let invalid_json = ensure_model_bindings_update_safe("not-json").unwrap_err();+ assert!(invalid_json+ .to_string()+ .starts_with("MODEL_BINDINGS_DEGRADED: config_json is not valid JSON"));++ let non_object = ensure_model_bindings_update_safe("[]").unwrap_err();+ assert!(non_object+ .to_string()+ .contains("config_json root must be an object"));++ let non_array =+ ensure_model_bindings_update_safe(r#"{"models":{"id":"wrapped"}}"#).unwrap_err();+ assert!(non_array+ .to_string()+ .contains("config_json.models is not an array"));++ let empty_id = read(r#"{"models":[{"id":" "},{"id":"readable"}]}"#);+ assert_eq!(+ empty_id+ .iter()+ .map(|binding| binding.id.as_str())+ .collect::<Vec<_>>(),+ ["readable"]+ );+ let empty_id_error =+ ensure_model_bindings_update_safe(r#"{"models":[{"id":" "},{"id":"readable"}]}"#)+ .unwrap_err();+ assert!(empty_id_error.to_string().contains("index 0"));++ assert!(ensure_model_bindings_update_safe(r#"{"models":[]}"#).is_ok());+ }}diff --git a/crates/host-core/src/providers/repository.rs b/crates/host-core/src/providers/repository.rsindex a497d983e..934e9e5ca 100644--- a/crates/host-core/src/providers/repository.rs+++ b/crates/host-core/src/providers/repository.rs@@ -181,6 +181,15 @@ pub fn update_provider(if let Some(models) = input.models.as_deref() {validate_model_aliases(models)?;}+ let raw_config: String = db.conn().query_row(+ "SELECT config_json FROM providers WHERE id = ?1",+ params![input.id],+ |row| row.get(0),+ )?;+ // Do not let a partial read silently replace unreadable stored bindings.+ if input.models.is_some() {+ ensure_model_bindings_update_safe(&raw_config)?;+ }// Derive from the API key ref directly: `has_secret` now also covers an// OAuth credential, so reusing it here would stamp an api_key ref onto a// provider that only ever signed in with a vendor account.@@ -192,11 +201,6 @@ pub fn update_provider(upsert_secret_meta(db, &api_key_ref, &input.id, &backend)?;secret_ref = Some(api_key_ref);}- let raw_config: String = db.conn().query_row(- "SELECT config_json FROM providers WHERE id = ?1",- params![input.id],- |row| row.get(0),- )?;// `Some(None)` clears an explicit levels override; plain `None` leaves it.let levels_update = if input.supported_thinking_levels.is_some() {Some(input.supported_thinking_levels.clone())diff --git a/crates/host-core/src/providers/tests.rs b/crates/host-core/src/providers/tests.rsindex 3d16cc0e6..38b4ff479 100644--- a/crates/host-core/src/providers/tests.rs+++ b/crates/host-core/src/providers/tests.rs@@ -1282,3 +1282,85 @@ fn a_stored_array_survives_an_entry_that_lost_a_field() {let damaged = get_provider(&db, &secrets, &provider.id).unwrap().unwrap();assert_eq!(model_ids(&damaged), ["alpha", "beta"]);}+#[test]+fn degraded_model_array_cannot_be_overwritten_by_update() {+ let (_dir, db, secrets) = test_context();+ let provider = create_provider(+ &db,+ &secrets,+ ProviderCreateInput {+ name: "Protected array".into(),+ vendor_key: None,+ provider_type: None,+ protocol: None,+ base_url: Some("https://example.test/v1".into()),+ auth_kind: Some("api_key_and_base_url".into()),+ models: Some(vec![binding_with_limits("alpha", 128_000, 8_192)]),+ default_model_id: Some("alpha".into()),+ secret_value: Some("old-secret".into()),+ 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();+ let mut config: serde_json::Value = db+ .conn()+ .query_row(+ "SELECT config_json FROM providers WHERE id = ?1",+ params![provider.id],+ |row| row.get::<_, String>(0),+ )+ .map(|raw| serde_json::from_str(&raw).unwrap())+ .unwrap();+ config["models"][0]["contextWindow"] = json!("not-a-number");+ db.conn()+ .execute(+ "UPDATE providers SET config_json = ?1 WHERE id = ?2",+ params![config.to_string(), provider.id],+ )+ .unwrap();+ let before: String = db+ .conn()+ .query_row(+ "SELECT config_json FROM providers WHERE id = ?1",+ params![provider.id],+ |row| row.get(0),+ )+ .unwrap();++ let error = update_provider(+ &db,+ &secrets,+ ProviderUpdateInput {+ models: Some(vec![binding_with_limits("alpha", 128_000, 8_192)]),+ secret_value: Some("new-secret".into()),+ ..blank_update(provider.id.clone())+ },+ )+ .unwrap_err()+ .to_string();+ assert!(error.starts_with("MODEL_BINDINGS_DEGRADED:"), "{error}");++ let after: String = db+ .conn()+ .query_row(+ "SELECT config_json FROM providers WHERE id = ?1",+ params![provider.id],+ |row| row.get(0),+ )+ .unwrap();+ assert_eq!(after, before);+ assert_eq!(+ secrets+ .get(&secret_ref_for_provider(&provider.id))+ .unwrap()+ .as_deref(),+ Some("old-secret")+ );+}diff --git a/crates/host-core/src/rpc/mod.rs b/crates/host-core/src/rpc/mod.rsindex 837ef9ab9..a58381c16 100644--- a/crates/host-core/src/rpc/mod.rs+++ b/crates/host-core/src/rpc/mod.rs@@ -473,8 +473,10 @@ fn rpc_err(code: i64, message: impl Into<String>, error_code: &str) -> JsonRpcErfn provider_rpc_err(error: impl ToString) -> JsonRpcError {let message = error.to_string();- if message.starts_with("MODEL_ALIAS_TOO_LONG:") {- return rpc_err(1002, message, "MODEL_ALIAS_TOO_LONG");+ for error_code in ["MODEL_ALIAS_TOO_LONG", "MODEL_BINDINGS_DEGRADED"] {+ if message.starts_with(&format!("{error_code}:")) {+ return rpc_err(1002, message, error_code);+ }}rpc_err(1000, message, "INTERNAL")}diff --git a/docs/spec/03-runtime/06-host-rpc-protocol.md b/docs/spec/03-runtime/06-host-rpc-protocol.mdindex d4813a4ad..7be3e8e3a 100644--- a/docs/spec/03-runtime/06-host-rpc-protocol.md+++ b/docs/spec/03-runtime/06-host-rpc-protocol.md@@ -1092,6 +1092,7 @@ numeric slot; the string is the contract, the number is transport detail.| 1001 | HOST_SHUTTING_DOWN | the host is draining after EOF and refused the call || 1002 | INVALID_PARAMS | schema validation failed || 1002 | MODEL_ALIAS_TOO_LONG | provider row alias exceeds 60 code points |+| 1002 | MODEL_BINDINGS_DEGRADED | stored model bindings are unreadable; explicit model-array replacement is refused || 1003 | NOT_FOUND | entity missing (legacy slot, kept for old callers) || 1006 | RATE_LIMITED | a per-caller budget window was exhausted || 1007 | NOT_FOUND | entity missing |diff --git a/docs/spec/03-runtime/08-error-codes.md b/docs/spec/03-runtime/08-error-codes.mdindex ffd638b5e..4468fd325 100644--- a/docs/spec/03-runtime/08-error-codes.md+++ b/docs/spec/03-runtime/08-error-codes.md@@ -216,6 +216,7 @@ malformed.|---|---|---|| `PROVIDER_SECRET_MISSING` | no | enabled provider requires an API key || `MODEL_ALIAS_TOO_LONG` | no | configured model alias exceeds 60 Unicode characters |+| `MODEL_BINDINGS_DEGRADED` | no | stored model bindings are unreadable; explicit model-array replacement is blocked to prevent data loss || `SECRET_STORE_UNAVAILABLE` | maybe | OS secure storage unavailable (reserved) || `SETTINGS_INVALID` | no | settings payload invalid (reserved) |diff --git a/docs/spec/03-runtime/12-provider-config-schema.md b/docs/spec/03-runtime/12-provider-config-schema.mdindex d872f67ec..414441e34 100644--- a/docs/spec/03-runtime/12-provider-config-schema.md+++ b/docs/spec/03-runtime/12-provider-config-schema.md@@ -201,15 +201,15 @@ 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 nolonger 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.+provider id, its index and the reason, instead of discarding the whole array.+The read remains usable, but it is marked degraded: invalid JSON, a non-object+config, a non-array `models` value, or any unreadable entry is reported. An+absent `models` key and an empty array remain legal legacy states; an array+whose entries are all unreadable still falls back to the legacy binding and is+reported. To prevent a partial settings view from erasing stored data,+`providers.update` rejects an explicit model-array replacement with+`MODEL_BINDINGS_DEGRADED` while the stored value is degraded. Updates to+unrelated provider fields remain allowed.For context resolution, that 128,000 value is a backward-compatible genericseed, not a reason to hide a published long-context limit. If models.dev nowdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 0c83ee2ff..7359c94bd 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -14207,12 +14207,15 @@ the latest destination. These assertions measure work counts, not device FPS.- **Steps:** Call `providers.list` and confirm every binding returns. Edit thestored `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.+ string and list once more. Attempt `providers.update` with the readable+ subset and an unrelated provider change.+- **Expected:** All three bindings return in every case except the malformed+ entry, where the 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. The explicit+ model-array update is rejected with `MODEL_BINDINGS_DEGRADED`, while the+ stored `config_json` remains unchanged.- **Specs linked:** `03-runtime/12-provider-config-schema.md` §2,`08-meta/decisions-log.md` D610- **Acceptance:** F (persistence), Qualitydiff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.mdindex 2dd317781..6908216d1 100644--- a/docs/spec/08-meta/decisions-log.md+++ b/docs/spec/08-meta/decisions-log.md@@ -6555,4 +6555,4 @@ that was sitting at the bottom — including after the turn had finished.- `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.+- Nothing is rewritten on disk and the write path remains explicit: `providers.update` still persists exactly the bindings the client sends. Before accepting an explicit model-array replacement, the host checks the stored value and rejects it with `MODEL_BINDINGS_DEGRADED` when the value is degraded, so a partial settings view cannot erase unreadable entries; unrelated provider fields remain updatable. See `03-runtime/12-provider-config-schema.md` §2.diff --git a/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md b/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.mdindex 6d79161f4..9e2dc820d 100644--- a/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md+++ b/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md@@ -873,6 +873,7 @@ JSON-RPC 错误携带一个数字 `code` 以及 `data.errorCode`,后者是来| 1001 | HOST_SHUTTING_DOWN | 主机在 EOF 后正在排空,拒绝了该调用 || 1002 | INVALID_PARAMS | 架构验证失败 || 1002 | MODEL_ALIAS_TOO_LONG | 提供商行别名超过 60 个码点 |+| 1002 | MODEL_BINDINGS_DEGRADED | 存储模型绑定不可读;拒绝显式替换模型数组 || 1003 | NOT_FOUND | 实体缺失(遗留槽位,为旧调用方保留) || 1006 | RATE_LIMITED | 某个按调用方计的预算窗口已耗尽 || 1007 | NOT_FOUND | 实体缺失 |diff --git a/docs/zh-CN/spec/03-runtime/08-error-codes.md b/docs/zh-CN/spec/03-runtime/08-error-codes.mdindex c6ca4d98d..204b27dec 100644--- a/docs/zh-CN/spec/03-runtime/08-error-codes.md+++ b/docs/zh-CN/spec/03-runtime/08-error-codes.md@@ -212,6 +212,7 @@ reveal 不并入任何行,必须重新读取。|---|---|---|| `PROVIDER_SECRET_MISSING` | 不 | 启用的提供程序需要 API 密钥 || `MODEL_ALIAS_TOO_LONG` | 不 | 已配置模型别名超过 60 个 Unicode 字符 |+| `MODEL_BINDINGS_DEGRADED` | 不 | 存储模型绑定已降级;为防止数据丢失,拒绝显式替换模型数组 || `SECRET_STORE_UNAVAILABLE` | 也许 | 操作系统安全存储不可用(保留) || `SETTINGS_INVALID` | 不 | 设置有效负载无效(保留) |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.mdindex bcd867706..f6c3fbae8 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@@ -130,12 +130,11 @@ legacy 绑定被物化时用的是同一个值,也与未声明限额的插件存储数组与 manifest 由此对“没有限额的模型”取得一致(D610)。存储的 `models` 数组逐条解码。不再符合 schema 的条目会被跳过,并在宿主日志里带上-提供商 id、条目下标与原因上报,而不是丢弃整个数组:此前一个手改或部分写入的绑定会让-该提供商读回来只剩单个 legacy 默认模型,其它已配置模型全部消失且没有任何说明-(D610)。缺失的 `models` 键、空数组、以及所有条目都不可读的数组,都仍旧读作 legacy-绑定,使提供商无论存储形态如何都保持可选;只有第三种会被上报,因为空数组是合法状态,-而缺失键则是早于绑定机制的记录。保存依旧只写入客户端发来的绑定,因此存储数组只会被-一次显式写入替换。+提供商 id、条目下标与原因上报,而不是丢弃整个数组。读取仍可用,但会标记为降级:非法+JSON、根节点非对象、`models` 非数组,或任一条目不可读,都会被上报。缺失的 `models`+键和空数组仍是合法的 legacy 状态;所有条目都不可读的数组仍回退到 legacy 绑定并上报。+为防止设置页的部分视图覆盖并丢失存储数据,当存储值降级时,`providers.update` 会以+`MODEL_BINDINGS_DEGRADED` 拒绝显式替换模型数组;不涉及模型数组的提供商字段仍可更新。`models[].contextWindowSource` 记录存储的 `contextWindow` 来自哪里:`catalog` 表示models.dev 快照,之后的目录修正可以替换它;`user` 表示用户在设置中手改的值,永不被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.mdindex ea3986a31..d47163dc0 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@@ -8500,10 +8500,12 @@ the latest destination. These assertions measure work counts, not device FPS.建立一个至少含三条完整绑定的提供商;不使用真实提供商或凭据。- **步骤**:调用 `providers.list`,确认全部绑定都返回。编辑存储的`config_json`,删掉其中一个绑定的 `maxTokens`,再次 list。补回该字段后再- list。最后把某个绑定的 `contextWindow` 改成字符串,再 list 一次。-- **预期**:除最后一次外,三种情况下三条绑定全部返回;最后一次按存储顺序返回- 两条可读绑定。丢失 `maxTokens` 的绑定以通用默认输出上限读出,补回字段后数值- 恢复。宿主日志为无法解码的条目带上提供商 id、条目下标与原因。+ list。最后把某个绑定的 `contextWindow` 改成字符串,再 list 一次;用可读子集+ 携带一个无关字段变更调用 `providers.update`。+- **预期**:除损坏条目外,三条绑定都按存储顺序返回。丢失 `maxTokens` 的绑定以+ 通用默认输出上限读出,补回字段后数值恢复。宿主日志为无法解码的条目带上提供商+ id、条目下标与原因。显式模型数组更新返回 `MODEL_BINDINGS_DEGRADED`,而存储的+ `config_json` 保持不变。- **链接规格**:`03-runtime/12-provider-config-schema.md` §2、`08-meta/decisions-log.md` D610- **验收**:F(持久化)、品质diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.mdindex 8e13bd492..dd2109e30 100644--- a/docs/zh-CN/spec/08-meta/decisions-log.md+++ b/docs/zh-CN/spec/08-meta/decisions-log.md@@ -4648,4 +4648,4 @@ that amendment are retired by ADR 0268; the upstream work-panel lifecycle stays.- `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。+- 不改写磁盘上的任何内容,写路径仍是显式的:`providers.update` 依旧只持久化客户端发来的绑定。接受显式模型数组替换前,host 会检查存储值;若已降级则以 `MODEL_BINDINGS_DEGRADED` 拒绝,避免设置页的部分视图擦除不可读条目;不涉及模型数组的提供商字段仍可更新。见 `03-runtime/12-provider-config-schema.md` §2。