Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/crates/core/src/service/config/mode_config_canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ fn canonicalize_mode_config(
let Some(raw_mode) = raw_mode else {
return Ok(None);
};
if raw_mode.is_null() {
return Ok(None);
}

let mut stored: ModeConfig = serde_json::from_value(raw_mode.clone()).map_err(|error| {
BitFunError::config(format!(
Expand Down Expand Up @@ -454,7 +457,10 @@ pub async fn canonicalize_mode_configs() -> BitFunResult<ModeConfigCanonicalizat

#[cfg(test)]
mod tests {
use super::{normalize_skill_override_lists, stored_mode_from_overrides};
use super::{
canonicalize_mode_config, normalize_skill_override_lists, stored_mode_from_overrides,
};
use serde_json::Value;
use std::collections::HashSet;

#[test]
Expand Down Expand Up @@ -496,4 +502,17 @@ mod tests {
);
assert!(stored.disabled_user_skills.is_empty());
}

#[test]
fn canonicalize_mode_config_treats_null_as_missing() {
let canonical = canonicalize_mode_config(
"Claw",
Some(&Value::Null),
&[],
&HashSet::new(),
)
.expect("null mode config should be ignored");

assert!(canonical.is_none());
}
}
47 changes: 46 additions & 1 deletion src/crates/core/src/service/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

fn deserialize_mode_configs<'de, D>(deserializer: D) -> Result<HashMap<String, ModeConfig>, D::Error>
where
D: serde::Deserializer<'de>,
{
let raw = Option::<HashMap<String, Option<ModeConfig>>>::deserialize(deserializer)?;
Ok(raw
.unwrap_or_default()
.into_iter()
.filter_map(|(mode_id, config)| config.map(|config| (mode_id, config)))
.collect())
}

/// Web UI font preferences (settings → basics). Keys match `FontPreference` in the frontend (camelCase).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -516,7 +528,7 @@ pub struct AIConfig {

/// Mode configuration.
/// mode_id -> ModeConfig
#[serde(default)]
#[serde(default, deserialize_with = "deserialize_mode_configs")]
pub mode_configs: HashMap<String, ModeConfig>,

/// SubAgent configuration (enable/disable state).
Expand Down Expand Up @@ -2008,6 +2020,39 @@ mod tests {
assert_eq!(config.subagent_max_concurrency, 9);
}

#[test]
fn deserializes_mode_configs_with_null_entries() {
let config: AIConfig = serde_json::from_value(serde_json::json!({
"models": [],
"agent_models": {},
"func_agent_models": {},
"default_models": {},
"mode_configs": {
"Claw": null,
"Cowork": {
"mode_id": "Cowork",
"removed_tools": ["shell"]
}
},
"subagent_configs": {},
"proxy": {
"enabled": false,
"url": ""
}
}))
.expect("config with null mode config entries should deserialize");

assert!(!config.mode_configs.contains_key("Claw"));
assert_eq!(
config
.mode_configs
.get("Cowork")
.expect("non-null mode config should be retained")
.removed_tools,
vec!["shell".to_string()]
);
}

#[test]
fn deserializes_explicit_default_review_team_config() {
let config: AIConfig = serde_json::from_value(serde_json::json!({
Expand Down
Loading