diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 8adc2b3858..2a5a7d0203 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -750,6 +750,11 @@ impl Session { } } + pub(crate) async fn history_snapshot(&self) -> Vec { + let state = self.state.lock().await; + state.history_snapshot() + } + async fn update_token_usage_info( &self, sub_id: &str, diff --git a/codex-rs/core/src/codex/compact.rs b/codex-rs/core/src/codex/compact.rs index 88e8a8f433..8d20ccf4bb 100644 --- a/codex-rs/core/src/codex/compact.rs +++ b/codex-rs/core/src/codex/compact.rs @@ -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());