Lightweight coding agent that runs in your terminal
Rust
Fix token estimate during compaction (#9337)
Eric Traut1fc72c647fd5
diff --git a/codex-rs/core/src/context_manager/history.rs b/codex-rs/core/src/context_manager/history.rsindex 4ee2e252c4..2279beef20 100644--- a/codex-rs/core/src/context_manager/history.rs+++ b/codex-rs/core/src/context_manager/history.rs@@ -97,7 +97,11 @@ impl ContextManager {}| ResponseItem::Compaction {encrypted_content: content,- } => estimate_reasoning_length(content.len()) as i64,+ } => {+ let reasoning_bytes = estimate_reasoning_length(content.len());+ i64::try_from(approx_tokens_from_byte_count(reasoning_bytes))+ .unwrap_or(i64::MAX)+ }item => {let serialized = serde_json::to_string(item).unwrap_or_default();i64::try_from(approx_token_count(&serialized)).unwrap_or(i64::MAX)