From 7916be1656d8ee9c5882b52753cd47f5e58e3e7e Mon Sep 17 00:00:00 2001 From: JJ Liebig Date: Sat, 5 Sep 2026 02:38:14 +0200 Subject: fix: make Windows Codex prompt delay size-aware (#3552) refs #3187 --- src/api/server.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'src/api/server.rs') diff --git a/src/api/server.rs b/src/api/server.rs index 64beec33..655d89c5 100644 --- a/src/api/server.rs +++ b/src/api/server.rs @@ -369,7 +369,7 @@ fn handle_request( ); } - dispatch_to_app(request, api_tx, None, response_write_complete, None) + dispatch_to_app(request, api_tx, None, response_write_complete, None, None) } pub(crate) fn api_method_name(method: &Method) -> &'static str { @@ -798,7 +798,22 @@ pub(super) fn dispatch_to_app_with_timeout( api_tx: &ApiRequestSender, timeout: Option, ) -> String { - dispatch_to_app(request, api_tx, timeout, None, None) + dispatch_to_app(request, api_tx, timeout, None, None, None) +} + +pub(super) fn dispatch_to_app_with_caller_timeout( + request: Request, + api_tx: &ApiRequestSender, + timeout: Option, +) -> String { + dispatch_to_app( + request, + api_tx, + timeout, + None, + None, + Some(("timeout", "timed out waiting for agent status")), + ) } pub(super) fn dispatch_stream_open( @@ -807,7 +822,7 @@ pub(super) fn dispatch_stream_open( timeout: Duration, active: Arc, ) -> String { - dispatch_to_app(request, api_tx, Some(timeout), None, Some(active)) + dispatch_to_app(request, api_tx, Some(timeout), None, Some(active), None) } pub(super) fn dispatch_stream_frame( @@ -821,6 +836,7 @@ pub(super) fn dispatch_stream_frame( Some(crate::app::pane_graphics::DIRECT_OUTER_TIMEOUT), None, Some(active), + None, ) } @@ -830,6 +846,7 @@ fn dispatch_to_app( timeout: Option, response_write_complete: Option>, stream_active: Option>, + timeout_response: Option<(&str, &str)>, ) -> String { let request_id = request.id.clone(); let request_active = stream_active.clone(); @@ -875,6 +892,11 @@ fn dispatch_to_app( if let Some(active) = request_active { active.store(false, Ordering::Release); } + if err.kind() == std::io::ErrorKind::TimedOut { + if let Some((code, message)) = timeout_response { + return error_response_json(request_id, code, message.into()); + } + } error_response_json( request_id, "server_unavailable", @@ -884,6 +906,26 @@ fn dispatch_to_app( } } +#[cfg(test)] +#[test] +fn caller_timeout_dispatch_uses_timeout_error() { + let (tx, _rx) = tokio::sync::mpsc::unbounded_channel(); + let response = dispatch_to_app_with_caller_timeout( + Request { + id: "prompt-timeout".into(), + method: Method::AgentPrompt(crate::api::schema::AgentPromptParams { + target: "reviewer".into(), + text: "review this".into(), + wait: None, + }), + }, + &tx, + Some(Duration::ZERO), + ); + let error: ErrorResponse = serde_json::from_str(&response).unwrap(); + assert_eq!(error.error.code, "timeout"); +} + fn error_response_json(id: String, code: &str, message: String) -> String { serde_json::to_string(&ErrorResponse { id, -- cgit v1.2.3