mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Add an async user messaging opt-in for spawned subagents (#63069)
## Why Async user messaging was limited to root agents. Spawned subagents need their own opt-in so they can send messages without requiring the root feature flag. ## What changed Add independent `root_agent` and `subagents` settings under `features.send_message_to_user_async`. For example, this opts spawned subagents in and turns off the root feature flag: ```toml [features.send_message_to_user_async] root_agent = false subagents = true ``` The existing boolean shorthand still sets the root feature flag, and the model catalog can still enable the tool for the root agent. Config layer merges, CLI overrides, and feature toggle edits preserve the separate `subagents` setting when changing the root flag. ## Testing Extend coverage for tool availability across root agents, spawned subagents, and compaction helpers, and for preserving the subagent setting when applying boolean overrides. GitOrigin-RevId: 5f34f182bc107d32797143a58f0d79395767ed49
This commit is contained in:
@@ -24,6 +24,7 @@ use codex_config::config_toml::ConfigToml;
|
||||
use codex_config::is_structured_feature_path;
|
||||
use codex_config::merge_toml_values;
|
||||
use codex_config::shell_environment_filter_entry;
|
||||
use codex_config::structured_feature_toggle_field;
|
||||
use codex_config::validate_shell_environment_policy_filter_config;
|
||||
use codex_connectors::apps_config_from_layer_stack;
|
||||
use codex_connectors::apps_config_origins_from_layer_stack;
|
||||
@@ -425,15 +426,15 @@ impl ConfigManager {
|
||||
})?;
|
||||
}
|
||||
|
||||
let structured_feature_toggle = preserves_network_proxy_settings
|
||||
|| is_structured_feature_path(&segments)
|
||||
&& parsed_value.as_ref().is_some_and(|value| {
|
||||
value.is_bool()
|
||||
|| matches!(strategy, MergeStrategy::Upsert)
|
||||
&& value.as_table().is_some_and(|table| {
|
||||
table.len() == 1 && table.contains_key("enabled")
|
||||
})
|
||||
});
|
||||
let toggle_field = structured_feature_toggle_field(&segments).filter(|&field| {
|
||||
parsed_value.as_ref().is_some_and(|value| {
|
||||
value.is_bool()
|
||||
|| matches!(strategy, MergeStrategy::Upsert)
|
||||
&& value
|
||||
.as_table()
|
||||
.is_some_and(|table| table.len() == 1 && table.contains_key(field))
|
||||
})
|
||||
});
|
||||
|
||||
if let Some(edit) = credential_provider_edits.apply(
|
||||
&mut user_config,
|
||||
@@ -444,8 +445,8 @@ impl ConfigManager {
|
||||
config_edits.push(edit);
|
||||
}
|
||||
|
||||
if structured_feature_toggle {
|
||||
segments.push("enabled".to_string());
|
||||
if let Some(field) = toggle_field {
|
||||
segments.push(field.to_string());
|
||||
}
|
||||
parsed_segments.push(segments);
|
||||
}
|
||||
@@ -921,10 +922,7 @@ fn value_at_semantic_path<'a>(root: &'a TomlValue, segments: &[String]) -> Optio
|
||||
.or_else(|| value_at_path(root, segments))
|
||||
.or_else(|| {
|
||||
let (field, parents) = segments.split_last()?;
|
||||
if field != "enabled" {
|
||||
return None;
|
||||
}
|
||||
if structured_feature_depth(parents) != Some(parents.len()) {
|
||||
if structured_feature_toggle_field(parents) != Some(field.as_str()) {
|
||||
return None;
|
||||
}
|
||||
let feature = value_at_path(root, parents)?;
|
||||
|
||||
@@ -2483,21 +2483,25 @@ span_attributes = { "service.name" = "managed-service" }"#,
|
||||
);
|
||||
}
|
||||
|
||||
/// Legacy managed feature toggles own their normalized enabled origin and override metadata.
|
||||
/// Managed booleans override only the corresponding toggle in a feature table.
|
||||
#[test_case::test_case("features.multi_agent_v2.enabled"; "multi-agent toggle")]
|
||||
#[test_case::test_case("features.send_message_to_user_async"; "async message shorthand")]
|
||||
#[tokio::test]
|
||||
async fn multi_agent_v2_boolean_layer_owns_enabled_origin_and_overrides() {
|
||||
async fn managed_feature_boolean_owns_toggle_origin_and_overrides(key_path: &str) {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
let user_path = tmp.path().join(CONFIG_TOML_FILE);
|
||||
std::fs::write(
|
||||
&user_path,
|
||||
"[features.multi_agent_v2]\nenabled = true\nsubagent_usage_hint_text = \"keep\"\n\n[features.network_proxy]\nenabled = true\ncredential_broker = true\n",
|
||||
"[features.multi_agent_v2]\nenabled = true\nsubagent_usage_hint_text = \"keep\"\n\n\
|
||||
[features.network_proxy]\nenabled = true\ncredential_broker = true\n\n\
|
||||
[features.send_message_to_user_async]\nroot_agent = false\nsubagents = true\n",
|
||||
)
|
||||
.expect("user config");
|
||||
|
||||
let managed_path = tmp.path().join("managed_config.toml");
|
||||
std::fs::write(
|
||||
&managed_path,
|
||||
"[features]\nmulti_agent_v2 = false\nnetwork_proxy = false\n",
|
||||
"[features]\nmulti_agent_v2 = false\nnetwork_proxy = false\nsend_message_to_user_async = false\n",
|
||||
)
|
||||
.expect("managed config");
|
||||
let managed_file = AbsolutePathBuf::try_from(managed_path.clone()).expect("managed file");
|
||||
@@ -2519,6 +2523,8 @@ async fn multi_agent_v2_boolean_layer_owns_enabled_origin_and_overrides() {
|
||||
"features.multi_agent_v2.enabled",
|
||||
"features.network_proxy",
|
||||
"features.network_proxy.enabled",
|
||||
"features.send_message_to_user_async",
|
||||
"features.send_message_to_user_async.root_agent",
|
||||
] {
|
||||
assert_eq!(
|
||||
read.origins.get(path).expect("managed feature origin").name,
|
||||
@@ -2531,7 +2537,7 @@ async fn multi_agent_v2_boolean_layer_owns_enabled_origin_and_overrides() {
|
||||
let result = service
|
||||
.write_value(ConfigValueWriteParams {
|
||||
file_path: Some(user_path.display().to_string()),
|
||||
key_path: "features.multi_agent_v2.enabled".to_string(),
|
||||
key_path: key_path.to_string(),
|
||||
value: serde_json::json!(true),
|
||||
merge_strategy: MergeStrategy::Upsert,
|
||||
expected_version: None,
|
||||
|
||||
@@ -1408,7 +1408,9 @@ async fn dispatch_cli(
|
||||
continue;
|
||||
}
|
||||
let value = if let Some(table) = value.as_table() {
|
||||
let Some(enabled) = table.get("enabled") else {
|
||||
let Some(enabled) =
|
||||
table.get(codex_features::feature_toggle_field(name))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
enabled
|
||||
|
||||
@@ -187,6 +187,8 @@ fn explicit_restart_applies_feature_overrides_and_preserves_saved_settings() ->
|
||||
"connectors",
|
||||
"-c",
|
||||
"features.network_proxy.enabled=false",
|
||||
"-c",
|
||||
"features.send_message_to_user_async.root_agent=true",
|
||||
],
|
||||
true,
|
||||
),
|
||||
@@ -216,7 +218,8 @@ fn explicit_restart_applies_feature_overrides_and_preserves_saved_settings() ->
|
||||
"api_key_model_discovery": discovery,
|
||||
"auth_elicitation": true,
|
||||
"apps": false,
|
||||
"network_proxy": false
|
||||
"network_proxy": false,
|
||||
"send_message_to_user_async": true
|
||||
})
|
||||
);
|
||||
assert_eq!(settings["updater"]["autoUpdateEnabled"], false);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::ConfigLayerMetadata;
|
||||
use crate::merge::is_structured_feature_path;
|
||||
use crate::merge::structured_feature_toggle_field;
|
||||
use serde_json::Value as JsonValue;
|
||||
use sha2::Digest;
|
||||
use sha2::Sha256;
|
||||
@@ -33,14 +33,16 @@ pub(super) fn record_origins(
|
||||
if !include(path) {
|
||||
return;
|
||||
}
|
||||
if matches!(value, TomlValue::Boolean(_)) && is_structured_feature_path(path) {
|
||||
if path
|
||||
.last()
|
||||
.is_some_and(|feature| feature == "network_proxy")
|
||||
{
|
||||
if matches!(value, TomlValue::Boolean(_))
|
||||
&& let Some(toggle_field) = structured_feature_toggle_field(path)
|
||||
{
|
||||
if matches!(
|
||||
path.last().map(String::as_str),
|
||||
Some("network_proxy" | "send_message_to_user_async")
|
||||
) {
|
||||
origins.insert(path.join("."), meta.clone());
|
||||
}
|
||||
path.push("enabled".to_string());
|
||||
path.push(toggle_field.to_string());
|
||||
origins.insert(path.join("."), meta.clone());
|
||||
path.pop();
|
||||
return;
|
||||
|
||||
@@ -209,6 +209,7 @@ pub use merge::ShellEnvironmentPolicyFilterRepresentation;
|
||||
pub use merge::is_structured_feature_path;
|
||||
pub use merge::merge_toml_values;
|
||||
pub use merge::shell_environment_filter_entry;
|
||||
pub use merge::structured_feature_toggle_field;
|
||||
pub use model_provider_defaults::apply_default_gcp_auth;
|
||||
pub use overrides::build_cli_overrides_layer;
|
||||
pub use path_context::ConfigPathContext;
|
||||
|
||||
@@ -74,11 +74,18 @@ pub fn is_structured_feature_path<S: AsRef<str>>(path: &[S]) -> bool {
|
||||
| "guardianv3"
|
||||
| "multi_agent_v2"
|
||||
| "network_proxy"
|
||||
| "send_message_to_user_async"
|
||||
| "sleep_tool"
|
||||
| "runtime_agent_instances"
|
||||
)
|
||||
}
|
||||
|
||||
/// Resolve the toggle field only at feature paths that support merging a boolean and a table.
|
||||
pub fn structured_feature_toggle_field<S: AsRef<str>>(path: &[S]) -> Option<&'static str> {
|
||||
let feature = path.last()?;
|
||||
is_structured_feature_path(path).then(|| codex_features::feature_toggle_field(feature.as_ref()))
|
||||
}
|
||||
|
||||
fn merge_toml_values_at_path(base: &mut TomlValue, overlay: TomlValue, path: &mut Vec<String>) {
|
||||
// A server and tool identify one provider. A partial override cannot inherit half an identity.
|
||||
if matches!(path.as_slice(), [tui, key] if tui == "tui" && key == "status_line_provider") {
|
||||
@@ -87,18 +94,18 @@ fn merge_toml_values_at_path(base: &mut TomlValue, overlay: TomlValue, path: &mu
|
||||
}
|
||||
replace_shell_environment_policy_filter_representation(base, &overlay, path);
|
||||
|
||||
if is_structured_feature_path(path) {
|
||||
if let Some(toggle_field) = structured_feature_toggle_field(path) {
|
||||
if let TomlValue::Boolean(enabled) = base
|
||||
&& overlay.is_table()
|
||||
{
|
||||
*base = TomlValue::Table(toml::map::Map::from_iter([(
|
||||
"enabled".to_string(),
|
||||
toggle_field.to_string(),
|
||||
TomlValue::Boolean(*enabled),
|
||||
)]));
|
||||
} else if let TomlValue::Table(table) = base
|
||||
&& let TomlValue::Boolean(enabled) = overlay
|
||||
{
|
||||
table.insert("enabled".to_string(), TomlValue::Boolean(enabled));
|
||||
table.insert(toggle_field.to_string(), TomlValue::Boolean(enabled));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,34 +255,30 @@ fn multi_agent_v2_cli_overrides_preserve_boolean_and_nested_configuration() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_mode_overrides_preserve_enabled_state_and_cell_overhead() {
|
||||
#[test_case::test_case("code_mode", "enabled", "experimental_show_cell_overhead"; "code mode")]
|
||||
#[test_case::test_case("send_message_to_user_async", "root_agent", "subagents"; "async user messages")]
|
||||
fn boolean_overrides_preserve_nested_option(feature: &str, toggle_field: &str, option: &str) {
|
||||
for feature_path in ["features", "profiles.work.features"] {
|
||||
for enabled in [true, false] {
|
||||
let toggle = (
|
||||
format!("{feature_path}.code_mode"),
|
||||
format!("{feature_path}.{feature}"),
|
||||
TomlValue::Boolean(enabled),
|
||||
);
|
||||
let overhead = (
|
||||
format!("{feature_path}.code_mode.experimental_show_cell_overhead"),
|
||||
let nested = (
|
||||
format!("{feature_path}.{feature}.{option}"),
|
||||
TomlValue::Boolean(true),
|
||||
);
|
||||
let expected = parse_toml(&format!(
|
||||
"[{feature_path}.code_mode]\nenabled = {enabled}\nexperimental_show_cell_overhead = true\n",
|
||||
"[{feature_path}.{feature}]\n{toggle_field} = {enabled}\n{option} = true\n",
|
||||
));
|
||||
|
||||
// Adding a display option must preserve the toggle in either override order.
|
||||
for overrides in [
|
||||
vec![toggle.clone(), overhead.clone()],
|
||||
vec![overhead, toggle],
|
||||
] {
|
||||
for overrides in [vec![toggle.clone(), nested.clone()], vec![nested, toggle]] {
|
||||
assert_eq!(crate::build_cli_overrides_layer(&overrides), expected);
|
||||
}
|
||||
|
||||
let boolean_layer = parse_toml(&format!("[{feature_path}]\ncode_mode = {enabled}\n"));
|
||||
let table_layer = parse_toml(&format!(
|
||||
"[{feature_path}.code_mode]\nexperimental_show_cell_overhead = true\n",
|
||||
));
|
||||
let boolean_layer = parse_toml(&format!("[{feature_path}]\n{feature} = {enabled}\n"));
|
||||
let table_layer =
|
||||
parse_toml(&format!("[{feature_path}.{feature}]\n{option} = true\n",));
|
||||
for (mut base, overlay) in [
|
||||
(boolean_layer.clone(), table_layer.clone()),
|
||||
(table_layer, boolean_layer),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::merge::is_structured_feature_path;
|
||||
use crate::merge::merge_toml_values;
|
||||
use crate::merge::structured_feature_toggle_field;
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
pub(crate) fn default_empty_table() -> TomlValue {
|
||||
@@ -29,17 +29,18 @@ fn apply_toml_override(root: &mut TomlValue, path: &str, value: TomlValue) {
|
||||
if is_last {
|
||||
match current {
|
||||
TomlValue::Table(table) => {
|
||||
if is_structured_feature_path(&traversed_segments)
|
||||
if let Some(toggle_field) = structured_feature_toggle_field(&traversed_segments)
|
||||
&& let Some(existing) = table.get_mut(segment)
|
||||
{
|
||||
match (&mut *existing, &value) {
|
||||
(TomlValue::Table(feature), TomlValue::Boolean(enabled)) => {
|
||||
feature.insert("enabled".to_string(), TomlValue::Boolean(*enabled));
|
||||
feature
|
||||
.insert(toggle_field.to_string(), TomlValue::Boolean(*enabled));
|
||||
return;
|
||||
}
|
||||
(TomlValue::Boolean(enabled), TomlValue::Table(_)) => {
|
||||
*existing = TomlValue::Table(Table::from_iter([(
|
||||
"enabled".to_string(),
|
||||
toggle_field.to_string(),
|
||||
TomlValue::Boolean(*enabled),
|
||||
)]));
|
||||
merge_toml_values(existing, &value);
|
||||
@@ -77,11 +78,11 @@ fn apply_toml_override(root: &mut TomlValue, path: &str, value: TomlValue) {
|
||||
current = table
|
||||
.entry(segment.to_string())
|
||||
.or_insert_with(|| TomlValue::Table(Table::new()));
|
||||
if is_structured_feature_path(&traversed_segments)
|
||||
if let Some(toggle_field) = structured_feature_toggle_field(&traversed_segments)
|
||||
&& let TomlValue::Boolean(enabled) = current
|
||||
{
|
||||
*current = TomlValue::Table(Table::from_iter([(
|
||||
"enabled".to_string(),
|
||||
toggle_field.to_string(),
|
||||
TomlValue::Boolean(*enabled),
|
||||
)]));
|
||||
}
|
||||
|
||||
@@ -162,6 +162,15 @@ pub fn features_schema(schema_gen: &mut SchemaGenerator) -> Schema {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if feature.id == codex_features::Feature::SendMessageToUserAsync {
|
||||
validation.properties.insert(
|
||||
feature.key.to_string(),
|
||||
schema_gen.subschema_for::<codex_features::FeatureToml<
|
||||
codex_features::SendMessageToUserAsyncConfigToml,
|
||||
>>(),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if feature.id == codex_features::Feature::RuntimeAgentInstances {
|
||||
validation.properties.insert(
|
||||
feature.key.to_string(),
|
||||
|
||||
@@ -1370,7 +1370,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"send_message_to_user_async": {
|
||||
"type": "boolean"
|
||||
"$ref": "#/definitions/FeatureToml_for_SendMessageToUserAsyncConfigToml"
|
||||
},
|
||||
"shell_snapshot": {
|
||||
"type": "boolean"
|
||||
@@ -1995,6 +1995,16 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"FeatureToml_for_SendMessageToUserAsyncConfigToml": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SendMessageToUserAsyncConfigToml"
|
||||
}
|
||||
]
|
||||
},
|
||||
"FeatureToml_for_SleepToolConfigToml": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -5045,6 +5055,21 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"SendMessageToUserAsyncConfigToml": {
|
||||
"additionalProperties": false,
|
||||
"description": "Controls which agents can send async user messages.",
|
||||
"properties": {
|
||||
"root_agent": {
|
||||
"description": "Sets the root agent's feature flag, just like the plain boolean shorthand. The model catalog can still enable the tool for the root when this is false.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"subagents": {
|
||||
"description": "Allow spawned subagents to use the tool independently of `root_agent` and the model catalog. Defaults to false.",
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"SessionPickerViewMode": {
|
||||
"description": "Preferred layout for the resume/fork session picker.",
|
||||
"enum": [
|
||||
@@ -8748,7 +8773,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"send_message_to_user_async": {
|
||||
"type": "boolean"
|
||||
"$ref": "#/definitions/FeatureToml_for_SendMessageToUserAsyncConfigToml"
|
||||
},
|
||||
"shell_snapshot": {
|
||||
"type": "boolean"
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::path_utils::write_atomically;
|
||||
use anyhow::Context;
|
||||
use codex_config::CONFIG_TOML_FILE;
|
||||
use codex_config::is_structured_feature_path;
|
||||
use codex_config::structured_feature_toggle_field;
|
||||
use codex_config::types::McpServerConfig;
|
||||
use codex_config::types::ResumeCwdMode;
|
||||
use codex_config::types::SessionPickerViewMode;
|
||||
@@ -75,6 +76,8 @@ pub enum ConfigEdit {
|
||||
},
|
||||
/// Remove the value stored at the exact dotted path.
|
||||
ClearPath { segments: Vec<String> },
|
||||
/// Disable the root opt-in without clearing a separate subagent setting.
|
||||
DisableRootAsyncMessages,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -332,13 +335,15 @@ impl ConfigDocument {
|
||||
}
|
||||
ConfigEdit::SetPath { segments, value } => {
|
||||
let mut path = Cow::Borrowed(segments.as_slice());
|
||||
if is_structured_feature_path(segments) && value.as_bool().is_some() {
|
||||
if value.as_bool().is_some()
|
||||
&& let Some(toggle_field) = structured_feature_toggle_field(segments)
|
||||
{
|
||||
let mut existing = Some(self.doc.as_item());
|
||||
for segment in segments {
|
||||
existing = existing.and_then(|item| item.as_table_like()?.get(segment));
|
||||
}
|
||||
if existing.and_then(TomlItem::as_table_like).is_some() {
|
||||
path.to_mut().push("enabled".to_string());
|
||||
path.to_mut().push(toggle_field.to_string());
|
||||
}
|
||||
}
|
||||
anyhow::ensure!(
|
||||
@@ -348,6 +353,21 @@ impl ConfigDocument {
|
||||
);
|
||||
Ok(true)
|
||||
}
|
||||
ConfigEdit::DisableRootAsyncMessages => {
|
||||
let key = codex_features::Feature::SendMessageToUserAsync.key();
|
||||
if self
|
||||
.doc
|
||||
.get("features")
|
||||
.and_then(|features| features.get(key))
|
||||
.and_then(|feature| feature.get("subagents"))
|
||||
.is_some()
|
||||
{
|
||||
let toggle_field = codex_features::feature_toggle_field(key);
|
||||
Ok(self.write_value(&["features", key, toggle_field], value(false)))
|
||||
} else {
|
||||
Ok(self.clear(&["features", key]))
|
||||
}
|
||||
}
|
||||
ConfigEdit::ClearPath { segments } => {
|
||||
let preserves_broker_settings = is_structured_feature_path(segments)
|
||||
&& segments
|
||||
@@ -655,11 +675,12 @@ impl ConfigDocument {
|
||||
}
|
||||
|
||||
let item = current.get_mut(segment.as_str())?;
|
||||
if is_structured_feature_path(&segments[..=index])
|
||||
&& let Some(enabled) = item.as_bool()
|
||||
if let Some(enabled) = item.as_bool()
|
||||
&& let Some(toggle_field) =
|
||||
structured_feature_toggle_field(&segments[..=index])
|
||||
{
|
||||
let mut feature = document_helpers::new_implicit_table();
|
||||
feature.insert("enabled", value(enabled));
|
||||
feature.insert(toggle_field, value(enabled));
|
||||
*item = TomlItem::Table(feature);
|
||||
}
|
||||
current = document_helpers::ensure_table_for_write(item)?;
|
||||
@@ -885,8 +906,8 @@ impl ConfigEditsBuilder {
|
||||
///
|
||||
/// Disabling a default-false feature clears the key instead of
|
||||
/// persisting `false`, so the config does not pin the feature once it
|
||||
/// graduates to globally enabled. Structured multi-agent v2 settings are
|
||||
/// an exception: its explicit `enabled = false` preserves nested options.
|
||||
/// graduates to globally enabled. Structured features can retain a false
|
||||
/// toggle to preserve their other settings.
|
||||
pub fn set_feature_enabled(mut self, key: &str, enabled: bool) -> Self {
|
||||
let mut segments = vec!["features".to_string(), key.to_string()];
|
||||
if key == "multi_agent_v2" && !enabled {
|
||||
@@ -906,6 +927,8 @@ impl ConfigEditsBuilder {
|
||||
segments,
|
||||
value: value(enabled),
|
||||
});
|
||||
} else if key == codex_features::Feature::SendMessageToUserAsync.key() {
|
||||
self.edits.push(ConfigEdit::DisableRootAsyncMessages);
|
||||
} else {
|
||||
self.edits.push(ConfigEdit::ClearPath { segments });
|
||||
}
|
||||
|
||||
@@ -136,27 +136,24 @@ fn multi_agent_v2_feature_toggle_preserves_nested_configuration() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sleep_tool_feature_toggle_preserves_mode() {
|
||||
#[test_case::test_case("sleep_tool", "enabled", "mode = \"always_on\""; "sleep mode")]
|
||||
#[test_case::test_case("send_message_to_user_async", "root_agent", "subagents = true"; "subagent messages")]
|
||||
fn feature_toggle_preserves_nested_setting(key: &str, toggle: &str, setting: &str) {
|
||||
let tmp = tempdir().expect("tmpdir");
|
||||
let codex_home = tmp.path();
|
||||
let config_path = codex_home.join(CONFIG_TOML_FILE);
|
||||
std::fs::write(
|
||||
&config_path,
|
||||
"[features.sleep_tool]\nmode = \"always_on\"\n",
|
||||
)
|
||||
.expect("write config");
|
||||
std::fs::write(&config_path, format!("[features.{key}]\n{setting}\n")).expect("write config");
|
||||
|
||||
for enabled in [false, true] {
|
||||
ConfigEditsBuilder::new(codex_home)
|
||||
.set_feature_enabled("sleep_tool", enabled)
|
||||
.set_feature_enabled(key, enabled)
|
||||
.apply_blocking()
|
||||
.expect("toggle feature");
|
||||
let actual: TomlValue =
|
||||
toml::from_str(&std::fs::read_to_string(&config_path).expect("read config"))
|
||||
.expect("parse config");
|
||||
let expected: TomlValue = toml::from_str(&format!(
|
||||
"[features.sleep_tool]\nenabled = {enabled}\nmode = \"always_on\"\n",
|
||||
"[features.{key}]\n{toggle} = {enabled}\n{setting}\n",
|
||||
))
|
||||
.expect("parse expected config");
|
||||
assert_eq!(actual, expected);
|
||||
|
||||
@@ -1312,14 +1312,16 @@ fn add_core_utility_tools(context: &CoreToolPlanContext<'_>, registry: &mut Tool
|
||||
);
|
||||
}
|
||||
|
||||
if !turn_context.root_capabilities_restricted
|
||||
let root_messages = !turn_context.root_capabilities_restricted
|
||||
&& (features.enabled(Feature::SendMessageToUserAsync)
|
||||
|| context
|
||||
.model_info
|
||||
.experimental_supported_tools
|
||||
.iter()
|
||||
.any(|tool| tool == "send_message_to_user_async"))
|
||||
{
|
||||
.any(|tool| tool == "send_message_to_user_async"));
|
||||
let subagent_messages = features.subagent_async_messages_enabled
|
||||
&& turn_context.session_source.parent_thread_id().is_some();
|
||||
if root_messages || subagent_messages {
|
||||
registry.add_with_exposure(SendMessageToUserAsyncHandler, ToolExposure::DirectModelOnly);
|
||||
}
|
||||
|
||||
|
||||
@@ -208,21 +208,42 @@ async fn persistent_async_message_guidance_follows_tool_availability(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(SessionSource::Exec, None, &[], false; "root_without_opt_in")]
|
||||
#[test_case(SessionSource::Exec, None, &[Feature::SendAsyncMessage], false; "root_with_retired_feature")]
|
||||
#[test_case(SessionSource::Exec, Some("send_user_message_async"), &[], false; "root_with_legacy_question_tool")]
|
||||
#[test_case(SessionSource::Exec, Some("request_user_input_async"), &[], false; "root_with_question_tool")]
|
||||
#[test_case(SessionSource::Exec, Some("send_message_to_user_async"), &[], true; "root_with_catalog_opt_in")]
|
||||
#[test_case(SessionSource::Exec, None, &[Feature::SendMessageToUserAsync], true; "root_with_feature_opt_in")]
|
||||
#[test_case(SessionSource::Exec, Some("send_message_to_user_async"), &[Feature::SendMessageToUserAsync], true; "root_with_both_opt_ins")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Other("test".to_string())), Some("send_message_to_user_async"), &[], false; "subagent_with_catalog_opt_in")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Other("test".to_string())), None, &[Feature::SendMessageToUserAsync], false; "subagent_with_feature_opt_in")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Other("test".to_string())), Some("send_message_to_user_async"), &[Feature::SendMessageToUserAsync], false; "subagent_with_both_opt_ins")]
|
||||
const ROOT_MESSAGES: &str = "[features]\nsend_message_to_user_async = true";
|
||||
const EXPLICIT_ROOT_MESSAGES: &str =
|
||||
"[features.send_message_to_user_async]\nroot_agent = true\nsubagents = false";
|
||||
const SUBAGENT_MESSAGES: &str =
|
||||
"[features.send_message_to_user_async]\nroot_agent = false\nsubagents = true";
|
||||
|
||||
#[test_case(SessionSource::Exec, None, "", false; "root_without_opt_in")]
|
||||
#[test_case(SessionSource::Exec, None, "[features]\nsend_async_message = true", false; "root_with_retired_feature")]
|
||||
#[test_case(SessionSource::Exec, Some("send_user_message_async"), "", false; "root_with_legacy_question_tool")]
|
||||
#[test_case(SessionSource::Exec, Some("request_user_input_async"), "", false; "root_with_question_tool")]
|
||||
#[test_case(SessionSource::Exec, Some("send_message_to_user_async"), SUBAGENT_MESSAGES, true; "root_with_catalog_opt_in")]
|
||||
#[test_case(SessionSource::Exec, None, ROOT_MESSAGES, true; "root_with_feature_opt_in")]
|
||||
#[test_case(SessionSource::Exec, None, EXPLICIT_ROOT_MESSAGES, true; "root_with_named_opt_in")]
|
||||
#[test_case(SessionSource::Exec, Some("send_message_to_user_async"), ROOT_MESSAGES, true; "root_with_both_opt_ins")]
|
||||
#[test_case(SessionSource::Exec, None, SUBAGENT_MESSAGES, false; "child_opt_in_does_not_enable_root")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Other("test".to_string())), Some("send_message_to_user_async"), "", false; "subagent_with_catalog_opt_in")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Other("test".to_string())), None, ROOT_MESSAGES, false; "subagent_with_feature_opt_in")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Other("test".to_string())), Some("send_message_to_user_async"), ROOT_MESSAGES, false; "subagent_with_both_opt_ins")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Compact), None, SUBAGENT_MESSAGES, false; "compaction_helper_cannot_message_user")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: codex_protocol::ThreadId::new(), depth: 1, agent_path: None,
|
||||
agent_nickname: None, agent_role: None,
|
||||
}), Some("send_message_to_user_async"), ROOT_MESSAGES, false; "spawned_child_requires_opt_in")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: codex_protocol::ThreadId::new(), depth: 1, agent_path: None,
|
||||
agent_nickname: None, agent_role: None,
|
||||
}), Some("send_message_to_user_async"), EXPLICIT_ROOT_MESSAGES, false; "explicitly_disabled_child_with_catalog_opt_in")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: codex_protocol::ThreadId::new(), depth: 1, agent_path: None,
|
||||
agent_nickname: None, agent_role: None,
|
||||
}), None, SUBAGENT_MESSAGES, true; "spawned_child_with_root_disabled")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn freeform_async_message_requires_root_and_catalog_or_feature_opt_in(
|
||||
async fn freeform_async_message_respects_independent_agent_opt_ins(
|
||||
session_source: SessionSource,
|
||||
catalog_tool: Option<&'static str>,
|
||||
enabled_features: &'static [Feature],
|
||||
feature_config: &'static str,
|
||||
expected: bool,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -239,13 +260,9 @@ async fn freeform_async_message_requires_root_and_catalog_or_feature_opt_in(
|
||||
model.experimental_supported_tools =
|
||||
catalog_tool.map(str::to_string).into_iter().collect();
|
||||
})
|
||||
.with_config(move |config| {
|
||||
for &feature in enabled_features {
|
||||
config
|
||||
.features
|
||||
.enable(feature)
|
||||
.expect("enable async messaging test feature");
|
||||
}
|
||||
.with_pre_build_hook(move |home| {
|
||||
std::fs::write(home.join("config.toml"), feature_config)
|
||||
.expect("write async messaging config");
|
||||
})
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
|
||||
@@ -34,6 +34,26 @@ pub struct ToolRegistryConfigToml {
|
||||
pub turn_metadata_includes_tool_info: Option<bool>,
|
||||
}
|
||||
|
||||
/// Controls which agents can send async user messages.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SendMessageToUserAsyncConfigToml {
|
||||
/// Sets the root agent's feature flag, just like the plain boolean shorthand.
|
||||
/// The model catalog can still enable the tool for the root when this is false.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub root_agent: Option<bool>,
|
||||
/// Allow spawned subagents to use the tool independently of `root_agent`
|
||||
/// and the model catalog. Defaults to false.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub subagents: Option<bool>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for SendMessageToUserAsyncConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.root_agent
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CodeModeConfigToml {
|
||||
|
||||
@@ -41,6 +41,7 @@ pub use feature_configs::NonPrefixedMcpToolNamesConfigToml;
|
||||
pub use feature_configs::RemoteMessageBoardConfigToml;
|
||||
use feature_configs::RemovedAppsMcpPathOverrideConfigToml;
|
||||
pub use feature_configs::RolloutBudgetConfigToml;
|
||||
pub use feature_configs::SendMessageToUserAsyncConfigToml;
|
||||
pub use feature_configs::SleepToolConfigToml;
|
||||
pub use feature_configs::SleepToolMode;
|
||||
pub use feature_configs::TokenBudgetConfigToml;
|
||||
@@ -634,6 +635,8 @@ pub struct LegacyFeatureUsage {
|
||||
pub struct Features {
|
||||
enabled: BTreeSet<Feature>,
|
||||
legacy_usages: BTreeSet<LegacyFeatureUsage>,
|
||||
/// Spawned agents require their own opt-in, independent of the root feature flag.
|
||||
pub subagent_async_messages_enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@@ -671,7 +674,7 @@ impl Features {
|
||||
}
|
||||
Self {
|
||||
enabled: set,
|
||||
legacy_usages: BTreeSet::new(),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -984,6 +987,14 @@ pub fn canonical_feature_for_key(key: &str) -> Option<Feature> {
|
||||
.map(|spec| spec.id)
|
||||
}
|
||||
|
||||
/// Field that carries a feature's boolean shorthand when it is written as a table.
|
||||
pub fn feature_toggle_field(key: &str) -> &'static str {
|
||||
match key {
|
||||
"send_message_to_user_async" => "root_agent",
|
||||
_ => "enabled",
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the provided string matches a known `[features]` key.
|
||||
pub fn is_known_feature_key(key: &str) -> bool {
|
||||
key == "tool_registry" || feature_for_key(key).is_some()
|
||||
@@ -1021,6 +1032,8 @@ pub struct FeaturesToml {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub current_time_reminder: Option<FeatureToml<CurrentTimeReminderConfigToml>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub send_message_to_user_async: Option<FeatureToml<SendMessageToUserAsyncConfigToml>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub sleep_tool: Option<FeatureToml<SleepToolConfigToml>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub runtime_agent_instances: Option<FeatureToml<RuntimeAgentInstancesConfigToml>>,
|
||||
@@ -1035,6 +1048,11 @@ pub struct FeaturesToml {
|
||||
|
||||
impl Features {
|
||||
fn apply_toml(&mut self, features: &FeaturesToml) {
|
||||
if let Some(FeatureToml::Config(config)) = &features.send_message_to_user_async
|
||||
&& let Some(subagents) = config.subagents
|
||||
{
|
||||
self.subagent_async_messages_enabled = subagents;
|
||||
}
|
||||
let entries = features.entries();
|
||||
self.apply_map(&entries);
|
||||
}
|
||||
@@ -1101,6 +1119,13 @@ impl FeaturesToml {
|
||||
if let Some(enabled) = self.network_proxy.as_ref().and_then(FeatureToml::enabled) {
|
||||
entries.insert(Feature::NetworkProxy.key().to_string(), enabled);
|
||||
}
|
||||
if let Some(enabled) = self
|
||||
.send_message_to_user_async
|
||||
.as_ref()
|
||||
.and_then(FeatureToml::enabled)
|
||||
{
|
||||
entries.insert(Feature::SendMessageToUserAsync.key().to_string(), enabled);
|
||||
}
|
||||
if let Some(enabled) = self.sleep_tool.as_ref().and_then(FeatureToml::enabled) {
|
||||
entries.insert(Feature::SleepTool.key().to_string(), enabled);
|
||||
}
|
||||
@@ -2571,7 +2596,7 @@ pub fn unstable_features_warning_event(
|
||||
let is_enabled = value.as_bool() == Some(true)
|
||||
|| value
|
||||
.as_table()
|
||||
.and_then(|table| table.get("enabled"))
|
||||
.and_then(|table| table.get(feature_toggle_field(key)))
|
||||
.and_then(toml::Value::as_bool)
|
||||
== Some(true);
|
||||
if !is_enabled {
|
||||
|
||||
Reference in New Issue
Block a user