Simplify client compatibility storage

This commit is contained in:
Eric Traut
2026-05-04 15:28:13 -07:00
parent efc64b0349
commit 1113126c80
15 changed files with 75 additions and 133 deletions
+23 -27
View File
@@ -195,15 +195,12 @@ fn client_compatibility_flags_for_app_server_client(
client_name: &str,
client_version: &str,
) -> ClientCompatibilityFlags {
// Xcode 26.4 shipped against CLI behavior from before PR #17043, when
// Codex only advertised MCP elicitation support to the built-in
// `codex_apps` server. If Codex advertises custom-server elicitation
// support to that client family, those requests become new app-server
// events/messages that the client cannot handle. Preserve the old
// capability surface for that client only.
//
// TODO: Remove this Xcode 26.4 compatibility path once that client version
// has aged out of support.
// Compatibility hack for Xcode 26.4: that client shipped against the
// pre-PR #17043 MCP surface, where only `codex_apps` advertised elicitation
// support. Advertising custom-server elicitations creates app-server
// events/messages that Xcode 26.4 cannot handle, so keep that client on the
// old capability surface.
// TODO: Remove once Xcode 26.4 ages out of support.
let mcp_elicitation =
if client_name.eq_ignore_ascii_case("xcode") && client_version.starts_with("26.4") {
McpElicitationCompatibility::CodexAppsOnly
@@ -1141,6 +1138,7 @@ impl MessageProcessor {
params,
app_server_client_name.clone(),
client_version.clone(),
client_compatibility_flags,
)
.await
}
@@ -1307,24 +1305,22 @@ mod client_compatibility_tests {
#[test]
fn xcode_26_4_uses_legacy_mcp_elicitation_compatibility() {
fn mcp_elicitation(name: &str, version: &str) -> McpElicitationCompatibility {
client_compatibility_flags_for_app_server_client(name, version).mcp_elicitation
use McpElicitationCompatibility::CodexAppsOnly;
use McpElicitationCompatibility::Default as DefaultCompatibility;
let cases = [
("Xcode", "26.4", CodexAppsOnly),
("xcode", "26.4.1", CodexAppsOnly),
("Xcode", "26.4-beta", CodexAppsOnly),
("Xcode", "26.3", DefaultCompatibility),
("Xcode", "26.5", DefaultCompatibility),
("codex-vscode", "26.4", DefaultCompatibility),
];
for (name, version, expected) in cases {
assert_eq!(
client_compatibility_flags_for_app_server_client(name, version).mcp_elicitation,
expected
);
}
assert_eq!(
mcp_elicitation("xcode", "26.4.1"),
McpElicitationCompatibility::CodexAppsOnly
);
assert_eq!(
mcp_elicitation("Xcode", "26.4-beta"),
McpElicitationCompatibility::CodexAppsOnly
);
assert_eq!(
mcp_elicitation("Xcode", "26.5"),
McpElicitationCompatibility::Default
);
assert_eq!(
mcp_elicitation("codex-vscode", "26.4"),
McpElicitationCompatibility::Default
);
}
}
@@ -597,21 +597,6 @@ impl ThreadRequestProcessor {
})
}
async fn set_app_server_client_info(
thread: &CodexThread,
app_server_client_name: Option<String>,
app_server_client_version: Option<String>,
) -> Result<(), JSONRPCErrorError> {
thread
.set_app_server_client_info(app_server_client_name, app_server_client_version)
.await
.map_err(|err| JSONRPCErrorError {
code: INTERNAL_ERROR_CODE,
message: format!("failed to set app server client info: {err}"),
data: None,
})
}
async fn finalize_thread_teardown(&self, thread_id: ThreadId) {
self.pending_thread_unloads.lock().await.remove(&thread_id);
self.outgoing
@@ -1003,12 +988,13 @@ impl ThreadRequestProcessor {
err => internal_error(format!("error creating thread: {err}")),
})?;
Self::set_app_server_client_info(
thread.as_ref(),
app_server_client_name,
app_server_client_version,
)
.await?;
thread
.set_app_server_client_info(
app_server_client_name,
app_server_client_version,
client_compatibility_flags,
)
.await;
let config_snapshot = thread
.config_snapshot()
@@ -51,12 +51,14 @@ impl TurnRequestProcessor {
params: TurnStartParams,
app_server_client_name: Option<String>,
app_server_client_version: Option<String>,
client_compatibility_flags: ClientCompatibilityFlags,
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
self.turn_start_inner(
request_id,
params,
app_server_client_name,
app_server_client_version,
client_compatibility_flags,
)
.await
.map(|response| Some(response.into()))
@@ -332,6 +334,7 @@ impl TurnRequestProcessor {
params: TurnStartParams,
app_server_client_name: Option<String>,
app_server_client_version: Option<String>,
client_compatibility_flags: ClientCompatibilityFlags,
) -> Result<TurnStartResponse, JSONRPCErrorError> {
if let Err(error) = Self::validate_v2_input_limit(&params.input) {
self.track_error_response(
@@ -347,15 +350,13 @@ impl TurnRequestProcessor {
.inspect_err(|error| {
self.track_error_response(&request_id, error, /*error_type*/ None);
})?;
Self::set_app_server_client_info(
thread.as_ref(),
app_server_client_name,
app_server_client_version,
)
.await
.inspect_err(|error| {
self.track_error_response(&request_id, error, /*error_type*/ None);
})?;
thread
.set_app_server_client_info(
app_server_client_name,
app_server_client_version,
client_compatibility_flags,
)
.await;
let collaboration_mode = params
.collaboration_mode
@@ -556,21 +557,6 @@ impl TurnRequestProcessor {
Ok(ThreadInjectItemsResponse {})
}
async fn set_app_server_client_info(
thread: &CodexThread,
app_server_client_name: Option<String>,
app_server_client_version: Option<String>,
) -> Result<(), JSONRPCErrorError> {
thread
.set_app_server_client_info(app_server_client_name, app_server_client_version)
.await
.map_err(|err| JSONRPCErrorError {
code: INTERNAL_ERROR_CODE,
message: format!("failed to set app server client info: {err}"),
data: None,
})
}
async fn turn_steer_inner(
&self,
request_id: &ConnectionRequestId,
@@ -904,7 +890,7 @@ impl TurnRequestProcessor {
};
let mut config = self.config.as_ref().clone();
config.client_compatibility_flags = parent_thread.client_compatibility_flags().await;
config.client_compatibility_flags = parent_thread.config().await.client_compatibility_flags;
if let Some(review_model) = &config.review_model {
config.model = Some(review_model.clone());
}
@@ -26,7 +26,6 @@ use futures::FutureExt;
use pretty_assertions::assert_eq;
use rmcp::model::CreateElicitationRequestParams;
use rmcp::model::ElicitationAction;
use rmcp::model::ElicitationCapability;
use rmcp::model::JsonObject;
use rmcp::model::Meta;
use rmcp::model::NumberOrString;
@@ -292,10 +291,7 @@ async fn codex_apps_only_custom_server_elicitation_is_declined_without_event() {
assert_eq!(response.action, ElicitationAction::Decline);
assert_eq!(response.content, None);
assert!(matches!(
rx_event.try_recv(),
Err(async_channel::TryRecvError::Empty)
));
assert!(rx_event.try_recv().is_err());
}
#[test]
@@ -847,12 +843,11 @@ fn elicitation_capability_uses_2025_06_18_shape_for_all_servers() {
fn codex_apps_only_elicitation_capability_suppresses_custom_servers() {
let compatibility = McpElicitationCompatibility::CodexAppsOnly;
assert_eq!(
elicitation_capability_for_server(CODEX_APPS_MCP_SERVER_NAME, compatibility),
Some(ElicitationCapability::default())
);
assert_eq!(
elicitation_capability_for_server("custom_mcp", compatibility),
None
(
elicitation_capability_for_server(CODEX_APPS_MCP_SERVER_NAME, compatibility).is_some(),
elicitation_capability_for_server("custom_mcp", compatibility).is_some(),
),
(true, false)
);
}
+2 -9
View File
@@ -37,7 +37,7 @@ pub(crate) struct ElicitationRequestManager {
requests: Arc<Mutex<ResponderMap>>,
pub(crate) approval_policy: Arc<StdMutex<AskForApproval>>,
pub(crate) permission_profile: Arc<StdMutex<PermissionProfile>>,
compatibility: McpElicitationCompatibility,
pub(crate) compatibility: McpElicitationCompatibility,
}
impl ElicitationRequestManager {
@@ -191,10 +191,6 @@ impl ElicitationRequestManager {
.boxed()
})
}
pub(crate) fn compatibility(&self) -> McpElicitationCompatibility {
self.compatibility
}
}
/// Compatibility policy for the MCP elicitation capability surface.
@@ -209,10 +205,7 @@ pub enum McpElicitationCompatibility {
impl McpElicitationCompatibility {
pub fn allows_server_elicitation(self, server_name: &str) -> bool {
match self {
Self::Default => true,
Self::CodexAppsOnly => server_name == CODEX_APPS_MCP_SERVER_NAME,
}
self == Self::Default || server_name == CODEX_APPS_MCP_SERVER_NAME
}
}
+1 -1
View File
@@ -467,7 +467,7 @@ async fn start_server_task(
codex_apps_tools_cache_context,
} = params;
let elicitation =
elicitation_capability_for_server(&server_name, elicitation_requests.compatibility());
elicitation_capability_for_server(&server_name, elicitation_requests.compatibility);
let params = InitializeRequestParams {
meta: None,
capabilities: ClientCapabilities {
+3 -4
View File
@@ -62,7 +62,7 @@ use crate::session::completed_session_loop_termination;
/// The returned `ops_tx` allows the caller to submit additional `Op`s to the sub-agent.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn run_codex_thread_interactive(
mut config: Config,
config: Config,
auth_manager: Arc<AuthManager>,
models_manager: SharedModelsManager,
parent_session: Arc<Session>,
@@ -73,7 +73,6 @@ pub(crate) async fn run_codex_thread_interactive(
) -> Result<Codex, CodexErr> {
let (tx_sub, rx_sub) = async_channel::bounded(SUBMISSION_CHANNEL_CAPACITY);
let (tx_ops, rx_ops) = async_channel::bounded(SUBMISSION_CHANNEL_CAPACITY);
config.client_compatibility_flags = parent_session.client_compatibility_flags().await;
let CodexSpawnOk { codex, .. } = Box::pin(Codex::spawn(CodexSpawnArgs {
config,
auth_manager,
@@ -101,10 +100,10 @@ pub(crate) async fn run_codex_thread_interactive(
.or_cancel(&cancel_token)
.await??;
let thread_config = codex.thread_config_snapshot().await;
let app_server_client_metadata = parent_session.app_server_client_metadata().await;
let client_metadata = parent_session.app_server_client_metadata().await;
emit_subagent_session_started(
&parent_session.services.analytics_events_client,
app_server_client_metadata,
client_metadata,
codex.session.conversation_id,
Some(parent_session.conversation_id),
thread_config,
+7 -6
View File
@@ -219,16 +219,17 @@ impl CodexThread {
&self,
app_server_client_name: Option<String>,
app_server_client_version: Option<String>,
) -> ConstraintResult<()> {
client_compatibility_flags: ClientCompatibilityFlags,
) {
self.codex
.set_app_server_client_info(app_server_client_name, app_server_client_version)
.set_app_server_client_info(
app_server_client_name,
app_server_client_version,
client_compatibility_flags,
)
.await
}
pub async fn client_compatibility_flags(&self) -> ClientCompatibilityFlags {
self.codex.session.client_compatibility_flags().await
}
/// Validate persistent turn context overrides without committing them.
pub async fn validate_turn_context_overrides(
&self,
+1
View File
@@ -1101,6 +1101,7 @@ async fn maybe_request_mcp_tool_approval(
.features
.enabled(Feature::ToolCallMcpElicitation)
&& turn_context
.config
.client_compatibility_flags
.mcp_elicitation
.allows_server_elicitation(&invocation.server);
+2 -4
View File
@@ -1,5 +1,4 @@
use super::*;
use crate::ClientCompatibilityFlags;
use crate::McpElicitationCompatibility;
use crate::config::ConfigBuilder;
use crate::session::tests::make_session_and_context;
@@ -2287,10 +2286,9 @@ async fn prompt_mode_waits_for_approval_when_annotations_do_not_require_approval
.features
.enable(Feature::ToolCallMcpElicitation)
.expect("test setup should allow enabling tool call MCP elicitation");
config.client_compatibility_flags.mcp_elicitation =
McpElicitationCompatibility::CodexAppsOnly;
turn_context.config = Arc::new(config);
turn_context.client_compatibility_flags = ClientCompatibilityFlags {
mcp_elicitation: McpElicitationCompatibility::CodexAppsOnly,
};
}
{
let mut active_turn = session.active_turn.lock().await;
+4 -1
View File
@@ -252,7 +252,10 @@ impl Session {
codex_apps_tools_cache_key(auth.as_ref()),
tool_plugin_provenance,
auth.as_ref(),
turn_context.client_compatibility_flags.mcp_elicitation,
turn_context
.config
.client_compatibility_flags
.mcp_elicitation,
)
.await;
{
+8 -17
View File
@@ -750,14 +750,14 @@ impl Codex {
&self,
app_server_client_name: Option<String>,
app_server_client_version: Option<String>,
) -> ConstraintResult<()> {
self.session
.update_settings(SessionSettingsUpdate {
app_server_client_name,
app_server_client_version,
..Default::default()
})
.await
client_compatibility_flags: ClientCompatibilityFlags,
) {
let mut state = self.session.state.lock().await;
state.session_configuration.app_server_client_name = app_server_client_name;
state.session_configuration.app_server_client_version = app_server_client_version;
let mut config = (*state.session_configuration.original_config_do_not_use).clone();
config.client_compatibility_flags = client_compatibility_flags;
state.session_configuration.original_config_do_not_use = Arc::new(config);
}
pub(crate) async fn agent_status(&self) -> AgentStatus {
@@ -835,15 +835,6 @@ async fn thread_title_from_state_db(
}
impl Session {
pub(crate) async fn client_compatibility_flags(&self) -> ClientCompatibilityFlags {
self.state
.lock()
.await
.session_configuration
.original_config_do_not_use
.client_compatibility_flags
}
pub(crate) async fn app_server_client_metadata(&self) -> AppServerClientMetadata {
let state = self.state.lock().await;
AppServerClientMetadata {
-1
View File
@@ -130,7 +130,6 @@ pub(super) async fn spawn_review_thread(
current_date: parent_turn_context.current_date.clone(),
timezone: parent_turn_context.timezone.clone(),
app_server_client_name: parent_turn_context.app_server_client_name.clone(),
client_compatibility_flags: parent_turn_context.client_compatibility_flags,
developer_instructions: None,
user_instructions: None,
compact_prompt: parent_turn_context.compact_prompt.clone(),
-1
View File
@@ -315,7 +315,6 @@ pub(crate) struct SessionSettingsUpdate {
pub(crate) app_server_client_version: Option<String>,
}
#[derive(Default)]
pub(crate) struct AppServerClientMetadata {
pub(crate) client_name: Option<String>,
pub(crate) client_version: Option<String>,
@@ -69,7 +69,6 @@ pub(crate) struct TurnContext {
pub(crate) current_date: Option<String>,
pub(crate) timezone: Option<String>,
pub(crate) app_server_client_name: Option<String>,
pub(crate) client_compatibility_flags: ClientCompatibilityFlags,
pub(crate) developer_instructions: Option<String>,
pub(crate) compact_prompt: Option<String>,
pub(crate) user_instructions: Option<String>,
@@ -237,7 +236,6 @@ impl TurnContext {
current_date: self.current_date.clone(),
timezone: self.timezone.clone(),
app_server_client_name: self.app_server_client_name.clone(),
client_compatibility_flags: self.client_compatibility_flags,
developer_instructions: self.developer_instructions.clone(),
compact_prompt: self.compact_prompt.clone(),
user_instructions: self.user_instructions.clone(),
@@ -530,9 +528,6 @@ impl Session {
current_date: Some(current_date),
timezone: Some(timezone),
app_server_client_name: session_configuration.app_server_client_name.clone(),
client_compatibility_flags: session_configuration
.original_config_do_not_use
.client_compatibility_flags,
developer_instructions: session_configuration.developer_instructions.clone(),
compact_prompt: session_configuration.compact_prompt.clone(),
user_instructions: session_configuration.user_instructions.clone(),