From 50b3a1b9978aa70b7277b78ff7fef1f6ef1c36b1 Mon Sep 17 00:00:00 2001 From: zhangheng Date: Wed, 22 Jul 2026 19:54:39 +0800 Subject: [PATCH] fix(feedback): isolate summary state failures --- server/src/recording_routes.rs | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/server/src/recording_routes.rs b/server/src/recording_routes.rs index bc8a3d2..73b4b0b 100644 --- a/server/src/recording_routes.rs +++ b/server/src/recording_routes.rs @@ -1310,6 +1310,22 @@ async fn load_summary_run_by_idempotency( summary_run_response(pool, row).await } +async fn load_latest_summary_run( + pool: &PgPool, + session_id: Uuid, +) -> Result, ApiError> { + let row = sqlx::query_as::<_, SummaryRunRow>( + "SELECT id, feedback_session_id, status, content, method, model, prompt_version, \ + character_count, error_message, attempts, created_at, completed_at, applied_at \ + FROM feedback_summary_runs WHERE feedback_session_id = $1 \ + ORDER BY created_at DESC, id DESC LIMIT 1", + ) + .bind(session_id) + .fetch_optional(pool) + .await?; + summary_run_response(pool, row).await +} + async fn summary_run_response( pool: &PgPool, row: Option, @@ -1380,16 +1396,19 @@ async fn load_session_response( .bind(session.id) .fetch_all(pool) .await?; - let latest_summary_run_row = sqlx::query_as::<_, SummaryRunRow>( - "SELECT id, feedback_session_id, status, content, method, model, prompt_version, \ - character_count, error_message, attempts, created_at, completed_at, applied_at \ - FROM feedback_summary_runs WHERE feedback_session_id = $1 \ - ORDER BY created_at DESC, id DESC LIMIT 1", - ) - .bind(session.id) - .fetch_optional(pool) - .await?; - let latest_summary_run = summary_run_response(pool, latest_summary_run_row).await?; + let latest_summary_run = match load_latest_summary_run(pool, session.id).await { + Ok(run) => run, + Err(error) => { + tracing::warn!( + event = "summary_state_load_failed", + feedback_session_id = %session.id, + error_class = "summary_database_query_failed", + error = %error, + "summary state could not be loaded; returning the feedback session without it" + ); + None + } + }; let processing_segment_count = segments .iter() .filter(|segment| segment.status == "processing")