core: add Session::history_snapshot and use in compact task to avoid external state locking

This commit is contained in:
jimmyfraiture
2025-09-24 17:31:30 +01:00
parent d36bae194b
commit 55abf54a7d
2 changed files with 6 additions and 4 deletions

View File

@@ -750,6 +750,11 @@ impl Session {
}
}
pub(crate) async fn history_snapshot(&self) -> Vec<ResponseItem> {
let state = self.state.lock().await;
state.history_snapshot()
}
async fn update_token_usage_info(
&self,
sub_id: &str,

View File

@@ -151,10 +151,7 @@ async fn run_compact_task_inner(
if remove_task_on_completion {
sess.remove_task(&sub_id).await;
}
let history_snapshot = {
let state = sess.state.lock().await;
state.history_snapshot()
};
let history_snapshot = sess.history_snapshot().await;
let summary_text = get_last_assistant_message_from_turn(&history_snapshot).unwrap_or_default();
let user_messages = collect_user_messages(&history_snapshot);
let initial_context = sess.build_initial_context(turn_context.as_ref());