aboutsummaryrefslogtreecommitdiff
path: root/src/api/server.rs
diff options
context:
space:
mode:
authorJJ Liebig <jonathan.liebig@gmail.com>2026-09-05 02:38:14 +0200
committerGitHub <noreply@github.com>2026-09-05 02:38:14 +0200
commit7916be1656d8ee9c5882b52753cd47f5e58e3e7e (patch)
treed54015e01ecff6566bad26034ada4e8cca3d3edf /src/api/server.rs
parent987651a760cdfe4cd9493388e8c16b8f99643a05 (diff)
fix: make Windows Codex prompt delay size-aware (#3552)
refs #3187
Diffstat (limited to 'src/api/server.rs')
-rw-r--r--src/api/server.rs48
1 files changed, 45 insertions, 3 deletions
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<Duration>,
) -> 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<Duration>,
+) -> 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<AtomicBool>,
) -> 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<Duration>,
response_write_complete: Option<std::sync::mpsc::Receiver<()>>,
stream_active: Option<Arc<AtomicBool>>,
+ 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,