From e1681e0424794684bf83eca51d8fc35cafefd5cd Mon Sep 17 00:00:00 2001 From: xiaoxixi Date: Wed, 29 Apr 2026 22:51:50 +0800 Subject: [PATCH] =?UTF-8?q?debug(session):=20=E6=B7=BB=E5=8A=A0=20handle?= =?UTF-8?q?=5Fmessage=20=E5=92=8C=20session=20=E6=81=A2=E5=A4=8D=E7=9A=84?= =?UTF-8?q?=20tracing=20=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用于排查 restart 后 session 恢复和 TTL 刷新问题。 --- src/session/session.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/session/session.rs b/src/session/session.rs index 025e315..c780398 100644 --- a/src/session/session.rs +++ b/src/session/session.rs @@ -206,6 +206,7 @@ impl Session { // Sync message_count to Storage if persist { + tracing::debug!(session_id = %self.id, last_active_at = %now, message_count = %self.message_count, "Persisting session meta after add_message"); if let Err(e) = self.persist_session_meta().await { tracing::warn!("failed to persist session meta: {}", e); } @@ -891,6 +892,7 @@ impl SessionManager { // Try to restore from Storage match self.storage.get_session(&session_id_str).await { Ok(meta) => { + tracing::debug!(session_id = %session_id_str, last_active_at = %meta.last_active_at, message_count = %meta.message_count, "Restoring session from Storage"); let (user_tx, _rx) = mpsc::channel::(100); let session = Session::from_storage( unified_id.clone(), @@ -1070,11 +1072,14 @@ impl SessionManager { } else { // No current session tracked, find active or create new let ttl_millis = self.inner.lock().await.session_ttl.as_millis() as i64; + tracing::debug!(channel, chat_id, ttl_millis, "No current_sessions entry, searching Storage for active session"); match self.storage.find_active_session(channel, chat_id, ttl_millis).await { Ok(Some(meta)) => { + tracing::debug!(session_id = %meta.id, dialog_id = %meta.dialog_id, last_active_at = %meta.last_active_at, "Found active session in Storage"); UnifiedSessionId::new(channel, chat_id, &meta.dialog_id) } Ok(None) | Err(_) => { + tracing::debug!("No active session found in Storage, creating new session"); // Create new session let (new_id, _) = self.create_session(channel, chat_id, None, String::new()).await?; new_id @@ -1082,6 +1087,7 @@ impl SessionManager { } } }; + tracing::debug!(unified_id = %unified_id, "handle_message resolved unified_id"); let session = self.get_or_create_session(&unified_id).await?; // Check for slash command