From a1b7dcb988a50427f003058494007cc1c4306022 Mon Sep 17 00:00:00 2001 From: sdcoffey Date: Wed, 18 Mar 2026 23:34:03 -0700 Subject: [PATCH] handle delegated requests in downstream clients --- codex-rs/exec/src/lib.rs | 24 ++++++ .../src/app/app_server_adapter.rs | 2 + .../src/app/app_server_requests.rs | 80 +++++++++++++++++++ codex-rs/tui_app_server/src/chatwidget.rs | 2 + 4 files changed, 108 insertions(+) diff --git a/codex-rs/exec/src/lib.rs b/codex-rs/exec/src/lib.rs index d27cec1f57..cf8be77035 100644 --- a/codex-rs/exec/src/lib.rs +++ b/codex-rs/exec/src/lib.rs @@ -1314,6 +1314,30 @@ async fn handle_server_request( ) .await } + ServerRequest::ModelRequest { request_id, params } => { + reject_server_request( + client, + request_id, + &method, + format!( + "delegated model requests are not supported in exec mode for thread `{}`", + params.thread_id + ), + ) + .await + } + ServerRequest::ModelCompact { request_id, params } => { + reject_server_request( + client, + request_id, + &method, + format!( + "delegated model compaction is not supported in exec mode for thread `{}`", + params.thread_id + ), + ) + .await + } ServerRequest::ApplyPatchApproval { request_id, params } => { reject_server_request( client, diff --git a/codex-rs/tui_app_server/src/app/app_server_adapter.rs b/codex-rs/tui_app_server/src/app/app_server_adapter.rs index 262cd4216a..4852a1dc34 100644 --- a/codex-rs/tui_app_server/src/app/app_server_adapter.rs +++ b/codex-rs/tui_app_server/src/app/app_server_adapter.rs @@ -398,6 +398,8 @@ fn server_request_thread_id(request: &ServerRequest) -> Option { ServerRequest::DynamicToolCall { params, .. } => { ThreadId::from_string(¶ms.thread_id).ok() } + ServerRequest::ModelRequest { params, .. } => ThreadId::from_string(¶ms.thread_id).ok(), + ServerRequest::ModelCompact { params, .. } => ThreadId::from_string(¶ms.thread_id).ok(), ServerRequest::ChatgptAuthTokensRefresh { .. } | ServerRequest::ApplyPatchApproval { .. } | ServerRequest::ExecCommandApproval { .. } => None, diff --git a/codex-rs/tui_app_server/src/app/app_server_requests.rs b/codex-rs/tui_app_server/src/app/app_server_requests.rs index 4381e883c0..12de52aa0c 100644 --- a/codex-rs/tui_app_server/src/app/app_server_requests.rs +++ b/codex-rs/tui_app_server/src/app/app_server_requests.rs @@ -90,6 +90,16 @@ impl PendingAppServerRequests { .to_string(), }) } + ServerRequest::ModelRequest { request_id, .. } => Some(UnsupportedAppServerRequest { + request_id: request_id.clone(), + message: "Delegated model requests are not available in app-server TUI yet." + .to_string(), + }), + ServerRequest::ModelCompact { request_id, .. } => Some(UnsupportedAppServerRequest { + request_id: request_id.clone(), + message: "Delegated model compaction is not available in app-server TUI yet." + .to_string(), + }), ServerRequest::ChatgptAuthTokensRefresh { .. } => None, ServerRequest::ApplyPatchApproval { request_id, .. } => { Some(UnsupportedAppServerRequest { @@ -501,6 +511,76 @@ mod tests { ); } + #[test] + fn rejects_delegated_model_requests_as_unsupported() { + let mut pending = PendingAppServerRequests::default(); + + let unsupported = pending + .note_server_request(&ServerRequest::ModelRequest { + request_id: AppServerRequestId::Integer(101), + params: codex_app_server_protocol::ModelRequestParams { + thread_id: "thread-1".to_string(), + turn_id: "turn-1".to_string(), + request_id: "request-1".to_string(), + request: codex_app_server_protocol::ModelRequestEnvelope { + model: "gpt-5".to_string(), + instructions: "hi".to_string(), + input: Vec::new(), + tools: Vec::new(), + tool_choice: "auto".to_string(), + parallel_tool_calls: false, + reasoning: None, + store: false, + stream: true, + include: Vec::new(), + service_tier: None, + prompt_cache_key: None, + text: None, + request_headers: None, + }, + }, + }) + .expect("delegated model requests should be rejected"); + + assert_eq!(unsupported.request_id, AppServerRequestId::Integer(101)); + assert_eq!( + unsupported.message, + "Delegated model requests are not available in app-server TUI yet." + ); + } + + #[test] + fn rejects_delegated_model_compaction_as_unsupported() { + let mut pending = PendingAppServerRequests::default(); + + let unsupported = pending + .note_server_request(&ServerRequest::ModelCompact { + request_id: AppServerRequestId::Integer(102), + params: codex_app_server_protocol::ModelCompactParams { + thread_id: "thread-1".to_string(), + turn_id: "turn-1".to_string(), + request_id: "request-1".to_string(), + request: codex_app_server_protocol::ModelCompactEnvelope { + model: "gpt-5".to_string(), + input: Vec::new(), + instructions: "hi".to_string(), + tools: Vec::new(), + parallel_tool_calls: false, + reasoning: None, + text: None, + request_headers: None, + }, + }, + }) + .expect("delegated model compaction should be rejected"); + + assert_eq!(unsupported.request_id, AppServerRequestId::Integer(102)); + assert_eq!( + unsupported.message, + "Delegated model compaction is not available in app-server TUI yet." + ); + } + #[test] fn does_not_mark_chatgpt_auth_refresh_as_unsupported() { let mut pending = PendingAppServerRequests::default(); diff --git a/codex-rs/tui_app_server/src/chatwidget.rs b/codex-rs/tui_app_server/src/chatwidget.rs index f91ebbaea4..0b7497bb32 100644 --- a/codex-rs/tui_app_server/src/chatwidget.rs +++ b/codex-rs/tui_app_server/src/chatwidget.rs @@ -5791,6 +5791,8 @@ impl ChatWidget { self.on_request_user_input(request_user_input_from_params(params)); } ServerRequest::DynamicToolCall { .. } + | ServerRequest::ModelRequest { .. } + | ServerRequest::ModelCompact { .. } | ServerRequest::ChatgptAuthTokensRefresh { .. } | ServerRequest::ApplyPatchApproval { .. } | ServerRequest::ExecCommandApproval { .. } => {