From 549ab8a834c63f3f3ead78343c517ca1aba74358 Mon Sep 17 00:00:00 2001 From: Ben Gao Date: Mon, 25 May 2026 21:57:20 +0800 Subject: [PATCH] fix(runtime): use consistent error handling for user input API - Change 'not loaded' to 'not found' in submit_user_input and cancel_user_input so map_thread_err correctly maps to 404 - Use map_thread_err in submit_user_input API endpoint for consistent error response (404 for missing thread, 409 for conflict, etc.) instead of always returning 500 --- crates/tui/src/runtime_api.rs | 2 +- crates/tui/src/runtime_threads.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/tui/src/runtime_api.rs b/crates/tui/src/runtime_api.rs index 8c1bca34..52593d2c 100644 --- a/crates/tui/src/runtime_api.rs +++ b/crates/tui/src/runtime_api.rs @@ -1055,7 +1055,7 @@ async fn submit_user_input( .runtime_threads .submit_user_input(&thread_id, &input_id, response) .await - .map_err(|e| ApiError::internal(format!("Failed to submit user input: {e}")))?; + .map_err(map_thread_err)?; Ok(Json(SubmitUserInputResponse { ok: true, input_id, diff --git a/crates/tui/src/runtime_threads.rs b/crates/tui/src/runtime_threads.rs index 278a129e..376bbe77 100644 --- a/crates/tui/src/runtime_threads.rs +++ b/crates/tui/src/runtime_threads.rs @@ -841,7 +841,7 @@ impl RuntimeThreadManager { ) -> Result { let active = self.active.lock().await; let Some(state) = active.engines.get(thread_id) else { - bail!("thread '{thread_id}' not loaded"); + bail!("thread '{thread_id}' not found"); }; state.engine.submit_user_input(input_id, response).await?; Ok(true) @@ -851,7 +851,7 @@ impl RuntimeThreadManager { pub async fn cancel_user_input(&self, thread_id: &str, input_id: &str) -> Result { let active = self.active.lock().await; let Some(state) = active.engines.get(thread_id) else { - bail!("thread '{thread_id}' not loaded"); + bail!("thread '{thread_id}' not found"); }; state.engine.cancel_user_input(input_id).await?; Ok(true)