Allow async user messages through code mode (#63730)

## Why

Agents could send async user messages only through a top-level tool call, even in code mode.

## What changed

Set `features.send_message_to_user_async.direct_only` to `false` to make the tool follow the session's tool mode. Direct mode exposes it as a top-level tool, code mode allows both top-level and nested calls, and code-mode-only sessions require nested calls and reject direct calls. The default keeps the tool top-level only. Existing agent opt-ins still apply.

## Testing

Add integration coverage for tool visibility, call results, and message delivery across all three tool modes with both values of `direct_only`. Improve failure diagnostics in the multiline shell snapshot test and paste `/status` as a single input event in the daemon compatibility test.

GitOrigin-RevId: c69bb2fba8bf776eff01382d8869fc869fc9d479
This commit is contained in:
surajs-oai
2026-11-24 19:56:22 +00:00
committed by copyberry
parent 7015377ecd
commit 7a24022794
8 changed files with 158 additions and 17 deletions
+4 -1
View File
@@ -34,7 +34,7 @@ pub struct ToolRegistryConfigToml {
pub turn_metadata_includes_tool_info: Option<bool>,
}
/// Controls which agents can send async user messages.
/// Controls which agents can send async user messages and how they call the tool.
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct SendMessageToUserAsyncConfigToml {
@@ -46,6 +46,9 @@ pub struct SendMessageToUserAsyncConfigToml {
/// and the model catalog. Defaults to false.
#[serde(skip_serializing_if = "Option::is_none")]
pub subagents: Option<bool>,
/// Keep async user messages top-level only (default). Set to false to follow the session's tool mode.
#[serde(skip_serializing_if = "Option::is_none")]
pub direct_only: Option<bool>,
}
impl FeatureConfig for SendMessageToUserAsyncConfigToml {
+8 -4
View File
@@ -643,6 +643,7 @@ pub struct Features {
legacy_usages: BTreeSet<LegacyFeatureUsage>,
/// Spawned agents require their own opt-in, independent of the root feature flag.
pub subagent_async_messages_enabled: bool,
pub async_messages_in_code_mode: bool,
}
#[derive(Debug, Clone, Default)]
@@ -1058,10 +1059,13 @@ 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;
if let Some(FeatureToml::Config(config)) = &features.send_message_to_user_async {
if let Some(subagents) = config.subagents {
self.subagent_async_messages_enabled = subagents;
}
if let Some(direct_only) = config.direct_only {
self.async_messages_in_code_mode = !direct_only;
}
}
let entries = features.entries();
self.apply_map(&entries);