Preserve multi-agent settings across config representations (#35656)

## Why

`features.multi_agent_v2` can be represented as either a legacy boolean toggle
or a table with an `enabled` field and nested settings. Layering or editing
configs that mix these forms could replace one form with the other and discard
the enabled state or nested settings.

## What changed

- Normalize boolean toggles to the table's `enabled` field when merging config
  layers, applying CLI overrides, and editing user or profile config.
- Preserve nested multi-agent settings when toggling the feature, while keeping
  ordinary replacement semantics for unrelated paths.
- Attribute normalized `enabled` values to the layer that supplied the boolean
  toggle so config write results report overrides correctly.

## Testing

Added coverage for layered config, CLI overrides, config edits, app-server
writes, and origin metadata using both root and profile feature paths.

GitOrigin-RevId: 38b248c949b9ea5d6340a73d754f91c1834ac486
This commit is contained in:
Adam Perry @ OpenAI authored and copyberry committed 2026-07-27 18:41:09 +00:00
1 parent 6b23635a7e
commit 2f19a57704
9 files changed
+560 -8

No files matched your search

@@ -583,10 +583,33 @@ fn apply_merge(
));
};
if matches!(strategy, MergeStrategy::Upsert)
&& (shell_environment_policy_representation_switch(root, segments, value)
|| (matches!(value_at_path(root, segments), Some(TomlValue::Table(_)))
&& matches!(value, TomlValue::Table(_))))
let multi_agent_v2_feature_depth = match segments {
[features, feature, ..] if features == "features" && feature == "multi_agent_v2" => Some(2),
[profiles, _, features, feature, ..]
if profiles == "profiles" && features == "features" && feature == "multi_agent_v2" =>
{
Some(4)
}
_ => None,
};
let preserves_multi_agent_v2_feature_config =
multi_agent_v2_feature_depth.is_some_and(|feature_depth| {
match value_at_path(root, &segments[..feature_depth]) {
Some(TomlValue::Boolean(_)) => {
segments.len() > feature_depth || matches!(value, TomlValue::Table(_))
}
Some(TomlValue::Table(_)) => {
segments.len() == feature_depth && matches!(value, TomlValue::Boolean(_))
}
_ => false,
}
});
if preserves_multi_agent_v2_feature_config
|| matches!(strategy, MergeStrategy::Upsert)
&& (shell_environment_policy_representation_switch(root, segments, value)
|| (matches!(value_at_path(root, segments), Some(TomlValue::Table(_)))
&& matches!(value, TomlValue::Table(_))))
{
let overlay = sparse_overlay(segments, value);
merge_toml_values(root, &overlay);
@@ -741,6 +764,24 @@ fn value_at_semantic_path<'a>(root: &'a TomlValue, segments: &[String]) -> Optio
shell_environment_filter_entry(root, segments)
.map(|(_, value)| value)
.or_else(|| value_at_path(root, segments))
.or_else(|| {
let (field, parents) = segments.split_last()?;
if field != "enabled" {
return None;
}
let is_multi_agent_v2_feature = match parents {
[features, feature] => features == "features" && feature == "multi_agent_v2",
[profiles, _, features, feature] => {
profiles == "profiles" && features == "features" && feature == "multi_agent_v2"
}
_ => false,
};
if !is_multi_agent_v2_feature {
return None;
}
let feature = value_at_path(root, parents)?;
matches!(feature, TomlValue::Boolean(_)).then_some(feature)
})
}
fn override_message(layer: &ConfigLayerSource) -> String {