From 026ad6e3f9cd89936e94da57a839c1bab2454cfa Mon Sep 17 00:00:00 2001 From: jimmyfraiture Date: Wed, 1 Oct 2025 11:01:25 +0100 Subject: [PATCH] Process comment --- codex-rs/core/src/client.rs | 38 ++++++++++++++++++++++++++++++++++--- codex-rs/core/src/config.rs | 2 ++ codex-rs/tui/src/lib.rs | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index 9e0c1c0430..2b2c802564 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -113,9 +113,12 @@ impl ModelClient { } pub fn get_auto_compact_token_limit(&self) -> Option { - self.config.model_auto_compact_token_limit.or_else(|| { - get_model_info(&self.config.model_family).and_then(|info| info.auto_compact_token_limit) - }) + match self.config.model_auto_compact_token_limit { + Some(limit) if limit <= crate::config::AUTO_COMPACT_DISABLED => None, + Some(limit) => Some(limit), + None => get_model_info(&self.config.model_family) + .and_then(|info| info.auto_compact_token_limit), + } } /// Dispatches to either the Responses or Chat implementation depending on @@ -912,7 +915,11 @@ fn try_parse_retry_after(err: &Error) -> Option { #[cfg(test)] mod tests { use super::*; + use crate::built_in_model_providers; + use crate::config::ConfigOverrides; + use crate::config::ConfigToml; use serde_json::json; + use tempfile::TempDir; use tokio::sync::mpsc; use tokio_test::io::Builder as IoBuilder; use tokio_util::io::ReaderStream; @@ -998,6 +1005,31 @@ mod tests { ) } + #[test] + fn auto_compaction_disabled_when_limit_sentinel() { + let codex_home = TempDir::new().expect("tempdir"); + let mut config = Config::load_from_base_config_with_overrides( + ConfigToml::default(), + ConfigOverrides::default(), + codex_home.path().to_path_buf(), + ) + .expect("load default config"); + config.model_auto_compact_token_limit = Some(crate::config::AUTO_COMPACT_DISABLED); + + let provider = built_in_model_providers()["openai"].clone(); + let client = ModelClient::new( + Arc::new(config), + None, + otel_event_manager(), + provider, + None, + ReasoningSummaryConfig::default(), + ConversationId::new(), + ); + + assert!(client.get_auto_compact_token_limit().is_none()); + } + // ──────────────────────────── // Tests from `implement-test-for-responses-api-sse-parser` // ──────────────────────────── diff --git a/codex-rs/core/src/config.rs b/codex-rs/core/src/config.rs index af595b495d..b77a6cf9b5 100644 --- a/codex-rs/core/src/config.rs +++ b/codex-rs/core/src/config.rs @@ -45,6 +45,8 @@ use toml_edit::Table as TomlTable; const OPENAI_DEFAULT_MODEL: &str = "gpt-5-codex"; const OPENAI_DEFAULT_REVIEW_MODEL: &str = "gpt-5-codex"; pub const GPT_5_CODEX_MEDIUM_MODEL: &str = "gpt-5-codex"; +/// Sentinel value signalling auto-compaction should be fully disabled. +pub const AUTO_COMPACT_DISABLED: i64 = -1; /// Maximum number of bytes of the documentation that will be embedded. Larger /// files are *silently truncated* to this size so we do not take up too much of diff --git a/codex-rs/tui/src/lib.rs b/codex-rs/tui/src/lib.rs index 07c7b1262b..aa56ff5137 100644 --- a/codex-rs/tui/src/lib.rs +++ b/codex-rs/tui/src/lib.rs @@ -171,7 +171,7 @@ pub async fn run_main( }; if cli.disable_auto_compaction { - config.model_auto_compact_token_limit = None; + config.model_auto_compact_token_limit = Some(codex_core::config::AUTO_COMPACT_DISABLED); } // we load config.toml here to determine project state.