fix(session): persist compression marker on retry, warn on storage/persist errors

This commit is contained in:
xiaoxixi 2026-05-10 14:52:10 +08:00
parent 709d70f828
commit 8c0c76a232

View File

@ -153,7 +153,10 @@ impl Session {
let timelines = storage
.load_session_timelines(&id.to_string(), 4)
.await
.unwrap_or_default();
.unwrap_or_else(|e| {
tracing::warn!(error = %e, "Failed to load session timelines");
Vec::new()
});
let has_more_timelines = timelines.len() > 3;
@ -175,7 +178,10 @@ impl Session {
let tail = storage
.load_messages_after_timestamp(&id.to_string(), after_ts)
.await
.unwrap_or_default();
.unwrap_or_else(|e| {
tracing::warn!(error = %e, "Failed to load messages after timestamp");
Vec::new()
});
let mut tail_msgs: Vec<ChatMessage> = tail.into_iter().map(|m| {
ChatMessage {
@ -476,6 +482,7 @@ impl Session {
&self.tools,
Some(&self.id.to_string()),
memory_context,
self.last_compressed_message_at.is_some(),
);
if skills_prompt.trim().is_empty() {
@ -920,7 +927,9 @@ impl SessionManager {
let compressed_count = result.history.len();
if result.created_timelines {
session_guard.last_compressed_message_at = Some(chrono::Utc::now().timestamp_millis());
let _ = session_guard.persist_session_meta().await;
if let Err(e) = session_guard.persist_session_meta().await {
tracing::warn!(error = %e, "Failed to persist compression marker after /compact");
}
}
session_guard.clear_history();
for msg in result.history {
@ -1443,6 +1452,9 @@ impl SessionManager {
let retry_result = session_guard.compressor.compress_if_needed(raw).await?;
if retry_result.created_timelines {
session_guard.last_compressed_message_at = Some(chrono::Utc::now().timestamp_millis());
if let Err(e) = session_guard.persist_session_meta().await {
tracing::warn!(error = %e, "Failed to persist compression marker on retry");
}
}
let mut retry = retry_result.history;
retry.insert(0, ChatMessage::system(system_prompt));