From 5bb7de4d43df739526828d5738502d26a8a4f93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 17 Sep 2026 16:34:00 +0300 Subject: [PATCH] fix(clippy): then_some in the insight about-drop, small refusal enum in worker_for CI Clippy red with -D warnings: unnecessary_lazy_evaluations at src/web/insights.rs:694 and result_large_err at src/web/podcast.rs:476 (the Err half was a 128-byte axum Response). worker_for now returns a small NoWorker enum and the four doors build the 503 at the call site via NoWorker::refusal(), so status and body are unchanged. --- src/web/insights.rs | 2 +- src/web/podcast.rs | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/web/insights.rs b/src/web/insights.rs index 8a5ab03..e2f9c73 100644 --- a/src/web/insights.rs +++ b/src/web/insights.rs @@ -692,7 +692,7 @@ async fn cards_of( // ever set it — so the value is dropped for a student caller, not // merely absent. about: (role != Role::Student) - .then(|| row.about) + .then_some(row.about) .flatten() .map(|about| about.key().to_string()), audience_role: row.audience_role, diff --git a/src/web/podcast.rs b/src/web/podcast.rs index f482803..074a918 100644 --- a/src/web/podcast.rs +++ b/src/web/podcast.rs @@ -180,7 +180,7 @@ async fn submit( ) -> Result { let bridge = match worker_for(&st, AI_PODCAST_SUBMIT_CAPABILITY) { Ok(bridge) => bridge, - Err(refusal) => return Ok(refusal), + Err(no_worker) => return Ok(no_worker.refusal()), }; // Whitespace-only is empty: the service applies the same rule, so checking @@ -226,7 +226,7 @@ async fn status( ) -> Result { let bridge = match worker_for(&st, AI_PODCAST_STATUS_CAPABILITY) { Ok(bridge) => bridge, - Err(refusal) => return Ok(refusal), + Err(no_worker) => return Ok(no_worker.refusal()), }; match podcast::status(&bridge, &slug, PodcastStatusPayload { job_id: id }).await { Ok(reply) => Ok(Json(snapshot(reply)).into_response()), @@ -259,7 +259,7 @@ async fn result( ) -> Result { let bridge = match worker_for(&st, AI_PODCAST_RESULT_CAPABILITY) { Ok(bridge) => bridge, - Err(refusal) => return Ok(refusal), + Err(no_worker) => return Ok(no_worker.refusal()), }; match podcast::result(&bridge, &slug, PodcastResultPayload { job_id: id }).await { Ok(reply) => Ok(Json(artifacts(reply)).into_response()), @@ -291,7 +291,7 @@ async fn cancel( ) -> Result { let bridge = match worker_for(&st, AI_PODCAST_CANCEL_CAPABILITY) { Ok(bridge) => bridge, - Err(refusal) => return Ok(refusal), + Err(no_worker) => return Ok(no_worker.refusal()), }; match podcast::cancel(&bridge, &slug, PodcastCancelPayload { job_id: id }).await { Ok(reply) => Ok(Json(verdict(reply)).into_response()), @@ -468,19 +468,39 @@ fn pump(file: tokio::fs::File) -> impl Stream Response { + ai_unavailable(match self { + NoWorker::Disabled => "the AI service is not enabled on this deployment", + NoWorker::Unconnected => "no AI service is connected right now", + }) + } +} + /// The 503 gate every dispatching door shares: no bridge configured, or no /// worker declaring this door's capability. `has_capability` is documented /// racy — fine here: it never guards a write, and the dispatch that follows /// re-checks for real; this only spares a caller a round trip into a service /// that cannot answer. -fn worker_for(st: &AppState, capability: &str) -> Result { +fn worker_for(st: &AppState, capability: &str) -> Result { let Some(bridge) = st.ai.clone() else { - return Err(ai_unavailable( - "the AI service is not enabled on this deployment", - )); + return Err(NoWorker::Disabled); }; if !bridge.has_capability(capability) { - return Err(ai_unavailable("no AI service is connected right now")); + return Err(NoWorker::Unconnected); } Ok(bridge) }