From 466b4b704fa294db827bc323fce8a899813eaf9a Mon Sep 17 00:00:00 2001 From: Charles Cunningham Date: Sat, 31 Jan 2026 13:01:18 -0800 Subject: [PATCH] Document turn context history reset --- codex-rs/core/src/state/session.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/codex-rs/core/src/state/session.rs b/codex-rs/core/src/state/session.rs index 12ccf6996b..bed23779be 100644 --- a/codex-rs/core/src/state/session.rs +++ b/codex-rs/core/src/state/session.rs @@ -82,6 +82,11 @@ impl SessionState { self.turn_context_history.push(Some(turn_context)); } + /// Trim or left-pad `turn_context_history` to align with the current number of user turns. + /// + /// When history is replaced (e.g., during replay/rollback), we need the last N entries + /// corresponding to the surviving user turns. If the stored list is shorter than the + /// user-turn count, we pad with `None` so indices remain aligned. pub(crate) fn reset_turn_context_history(&mut self, user_turn_count: usize) { let existing_len = self.turn_context_history.len(); if existing_len >= user_turn_count {