Lightweight coding agent that runs in your terminal
Rust
Reduce typed app-server request serialization overhead (#34766)
jife370d23691fb
diff --git a/codex-rs/app-server-client/src/lib.rs b/codex-rs/app-server-client/src/lib.rsindex a46feb544a..c25fbe57fb 100644--- a/codex-rs/app-server-client/src/lib.rs+++ b/codex-rs/app-server-client/src/lib.rs@@ -617,20 +617,22 @@ impl InProcessAppServerClient {whereT: DeserializeOwned,{- let method = request_method_name(&request);+ let method = request.method_name();let response =self.request(request).await.map_err(|source| TypedRequestError::Transport {- method: method.clone(),+ method: method.to_string(),source,})?;let result = response.map_err(|source| TypedRequestError::Server {- method: method.clone(),+ method: method.to_string(),source,})?;- serde_json::from_value(result)- .map_err(|source| TypedRequestError::Deserialize { method, source })+ serde_json::from_value(result).map_err(|source| TypedRequestError::Deserialize {+ method: method.to_string(),+ source,+ })}/// Sends a typed client notification.@@ -790,20 +792,22 @@ impl InProcessAppServerRequestHandle {whereT: DeserializeOwned,{- let method = request_method_name(&request);+ let method = request.method_name();let response =self.request(request).await.map_err(|source| TypedRequestError::Transport {- method: method.clone(),+ method: method.to_string(),source,})?;let result = response.map_err(|source| TypedRequestError::Server {- method: method.clone(),+ method: method.to_string(),source,})?;- serde_json::from_value(result)- .map_err(|source| TypedRequestError::Deserialize { method, source })+ serde_json::from_value(result).map_err(|source| TypedRequestError::Deserialize {+ method: method.to_string(),+ source,+ })}}@@ -904,20 +908,6 @@ impl AppServerClient {}}-/// Extracts the JSON-RPC method name for diagnostics without extending the-/// protocol crate with in-process-only helpers.-pub(crate) fn request_method_name(request: &ClientRequest) -> String {- serde_json::to_value(request)- .ok()- .and_then(|value| {- value- .get("method")- .and_then(serde_json::Value::as_str)- .map(ToOwned::to_owned)- })- .unwrap_or_else(|| "<unknown>".to_string())-}-#[cfg(test)]mod tests {use super::*;diff --git a/codex-rs/app-server-client/src/remote.rs b/codex-rs/app-server-client/src/remote.rsindex 5575fe4ad4..e8cb7122f6 100644--- a/codex-rs/app-server-client/src/remote.rs+++ b/codex-rs/app-server-client/src/remote.rs@@ -21,7 +21,6 @@ use crate::AppServerEvent;use crate::RequestResult;use crate::SHUTDOWN_TIMEOUT;use crate::TypedRequestError;-use crate::request_method_name;use codex_app_server_protocol::ClientInfo;use codex_app_server_protocol::ClientNotification;use codex_app_server_protocol::ClientRequest;@@ -498,20 +497,22 @@ impl RemoteAppServerClient {whereT: DeserializeOwned,{- let method = request_method_name(&request);+ let method = request.method_name();let response =self.request(request).await.map_err(|source| TypedRequestError::Transport {- method: method.clone(),+ method: method.to_string(),source,})?;let result = response.map_err(|source| TypedRequestError::Server {- method: method.clone(),+ method: method.to_string(),source,})?;- serde_json::from_value(result)- .map_err(|source| TypedRequestError::Deserialize { method, source })+ serde_json::from_value(result).map_err(|source| TypedRequestError::Deserialize {+ method: method.to_string(),+ source,+ })}pub async fn notify(&self, notification: ClientNotification) -> IoResult<()> {@@ -658,20 +659,22 @@ impl RemoteAppServerRequestHandle {whereT: DeserializeOwned,{- let method = request_method_name(&request);+ let method = request.method_name();let response =self.request(request).await.map_err(|source| TypedRequestError::Transport {- method: method.clone(),+ method: method.to_string(),source,})?;let result = response.map_err(|source| TypedRequestError::Server {- method: method.clone(),+ method: method.to_string(),source,})?;- serde_json::from_value(result)- .map_err(|source| TypedRequestError::Deserialize { method, source })+ serde_json::from_value(result).map_err(|source| TypedRequestError::Deserialize {+ method: method.to_string(),+ source,+ })}}diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rsindex 329637b119..e2b2a9b0c1 100644--- a/codex-rs/app-server-protocol/src/protocol/common.rs+++ b/codex-rs/app-server-protocol/src/protocol/common.rs@@ -239,10 +239,6 @@ macro_rules! client_request_definitions {}}- pub fn method(&self) -> String {- self.method_name().to_string()- }-pub fn serialization_scope(&self) -> Option<ClientRequestSerializationScope> {match self {$(@@ -2671,7 +2667,6 @@ mod tests {params: None,};assert_eq!(request.id(), &RequestId::Integer(1));- assert_eq!(request.method(), "account/rateLimits/read");assert_eq!(json!({"method": "account/rateLimits/read",@@ -2689,7 +2684,6 @@ mod tests {params: None,};assert_eq!(request.id(), &RequestId::Integer(1));- assert_eq!(request.method(), "account/usage/read");assert_eq!(json!({"method": "account/usage/read",@@ -2707,7 +2701,6 @@ mod tests {params: None,};assert_eq!(request.id(), &RequestId::Integer(1));- assert_eq!(request.method(), "account/workspaceMessages/read");assert_eq!(json!({"method": "account/workspaceMessages/read",