From 4e7089a8abe7669680729de82d319f1258bd1896 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Fri, 24 Oct 2025 11:16:45 -0700 Subject: [PATCH] default --- codex-rs/core/src/codex.rs | 14 ++++++-------- codex-rs/core/src/conversation_history.rs | 19 ++++--------------- codex-rs/core/src/state/session.rs | 7 ++----- codex-rs/protocol/src/protocol.rs | 2 +- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index d67da9b5fb..1a3be60534 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -542,7 +542,7 @@ impl Session { ); // Create the mutable state for the Session. - let state = SessionState::new(session_configuration.clone(), config.model_context_window); + let state = SessionState::new(session_configuration.clone()); let services = SessionServices { mcp_connection_manager, @@ -876,7 +876,7 @@ impl Session { turn_context: &TurnContext, rollout_items: &[RolloutItem], ) -> CodexResult> { - let mut history = ConversationHistory::new(turn_context.client.get_model_context_window()); + let mut history = ConversationHistory::new(); for item in rollout_items { match item { RolloutItem::ResponseItem(response_item) => { @@ -1543,8 +1543,7 @@ pub(crate) async fn run_task( // For normal turns, continue recording to the session history as before. let is_review_mode = turn_context.is_review_mode; - let mut review_thread_history: ConversationHistory = - ConversationHistory::new(turn_context.client.get_model_context_window()); + let mut review_thread_history: ConversationHistory = ConversationHistory::new(); if is_review_mode { // Seed review threads with environment context so the model knows the working directory. review_thread_history @@ -2570,7 +2569,7 @@ mod tests { original_config_do_not_use: Arc::clone(&config), }; - let state = SessionState::new(session_configuration.clone(), config.model_context_window); + let state = SessionState::new(session_configuration.clone()); let services = SessionServices { mcp_connection_manager: McpConnectionManager::default(), @@ -2638,7 +2637,7 @@ mod tests { original_config_do_not_use: Arc::clone(&config), }; - let state = SessionState::new(session_configuration.clone(), config.model_context_window); + let state = SessionState::new(session_configuration.clone()); let services = SessionServices { mcp_connection_manager: McpConnectionManager::default(), @@ -2861,8 +2860,7 @@ mod tests { turn_context: &TurnContext, ) -> CodexResult<(Vec, Vec)> { let mut rollout_items = Vec::new(); - let mut live_history = - ConversationHistory::new(turn_context.client.get_model_context_window()); + let mut live_history = ConversationHistory::new(); let initial_context = session.build_initial_context(turn_context); for item in &initial_context { diff --git a/codex-rs/core/src/conversation_history.rs b/codex-rs/core/src/conversation_history.rs index 6a31d638d0..17b7cd7226 100644 --- a/codex-rs/core/src/conversation_history.rs +++ b/codex-rs/core/src/conversation_history.rs @@ -17,12 +17,7 @@ pub(crate) struct ConversationHistory { } impl ConversationHistory { - pub(crate) fn new(model_context_window: Option) -> Self { - let token_info = model_context_window.map(|context_window| TokenUsageInfo { - total_token_usage: TokenUsage::default(), - last_token_usage: TokenUsage::default(), - model_context_window: Some(context_window), - }); + pub(crate) fn new() -> Self { let tokenizer = match Tokenizer::try_default() { Ok(tokenizer) => Some(tokenizer), Err(error) => { @@ -32,7 +27,7 @@ impl ConversationHistory { }; Self { items: Vec::new(), - token_info, + token_info: Some(TokenUsageInfo::default()), tokenizer, } } @@ -408,12 +403,6 @@ impl ConversationHistory { } } -impl Default for ConversationHistory { - fn default() -> Self { - Self::new(None) - } -} - #[inline] fn error_or_panic(message: String) { if cfg!(debug_assertions) || env!("CARGO_PKG_VERSION").contains("alpha") { @@ -460,7 +449,7 @@ mod tests { } fn create_history_with_items(items: Vec) -> ConversationHistory { - let mut h = ConversationHistory::new(None); + let mut h = ConversationHistory::new(); h.record_items(items.iter()).unwrap(); h } @@ -477,7 +466,7 @@ mod tests { #[test] fn filters_non_api_messages() { - let mut h = ConversationHistory::default(); + let mut h = ConversationHistory::new(); // System message is not an API message; Other is ignored. let system = ResponseItem::Message { id: None, diff --git a/codex-rs/core/src/state/session.rs b/codex-rs/core/src/state/session.rs index 9510385d48..6f20557643 100644 --- a/codex-rs/core/src/state/session.rs +++ b/codex-rs/core/src/state/session.rs @@ -18,13 +18,10 @@ pub(crate) struct SessionState { impl SessionState { /// Create a new session state mirroring previous `State::default()` semantics. - pub(crate) fn new( - session_configuration: SessionConfiguration, - model_context_window: Option, - ) -> Self { + pub(crate) fn new(session_configuration: SessionConfiguration) -> Self { Self { session_configuration, - history: ConversationHistory::new(model_context_window), + history: ConversationHistory::new(), latest_rate_limits: None, } } diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index add8b7d6aa..48f6404368 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -575,7 +575,7 @@ pub struct TokenUsage { pub total_tokens: i64, } -#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)] +#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS, Default)] pub struct TokenUsageInfo { /// The total token usage for the session. accumulated from all turns. pub total_token_usage: TokenUsage,