diff --git a/codex-rs/core/src/context/world_state/additional_context.rs b/codex-rs/core/src/context/world_state/additional_context.rs index e61f3b641a..465c283613 100644 --- a/codex-rs/core/src/context/world_state/additional_context.rs +++ b/codex-rs/core/src/context/world_state/additional_context.rs @@ -26,7 +26,7 @@ use serde::Deserialize; use std::collections::BTreeMap; use std::collections::HashMap; -const MAX_ADDITIONAL_CONTEXT_VALUE_TOKENS: usize = 1_000; +const MAX_ADDITIONAL_CONTEXT_VALUE_TOKENS: usize = 10_000; const MAX_DERIVED_TOOL_NAME_CHARS: usize = 128; /// A delivered client submission replaces the active sources. Extension inputs only update their own keys. diff --git a/codex-rs/core/tests/suite/additional_context.rs b/codex-rs/core/tests/suite/additional_context.rs index 515b33303d..3f7fa537e2 100644 --- a/codex-rs/core/tests/suite/additional_context.rs +++ b/codex-rs/core/tests/suite/additional_context.rs @@ -888,7 +888,7 @@ async fn additional_context_values_are_truncated_before_model_input( ) -> Result<()> { skip_if_no_network!(Ok(())); - const MAX_EXPECTED_EXTERNAL_CONTEXT_TEXT_BYTES: usize = 5 * 1024; + const MAX_EXPECTED_EXTERNAL_CONTEXT_TEXT_BYTES: usize = 40 * 1024; let server = start_mock_server().await; let request = mount_sse_once( @@ -906,8 +906,8 @@ async fn additional_context_values_are_truncated_before_model_input( }) .build_with_auto_env(&server) .await?; - let long_browser_value = format!("browser-head-{}browser-tail", "b".repeat(40_000)); - let long_automation_value = format!("automation-head-{}automation-tail", "a".repeat(40_000)); + let long_browser_value = format!("browser-head-{}browser-tail", "b".repeat(80_000)); + let long_automation_value = format!("automation-head-{}automation-tail", "a".repeat(80_000)); let untruncated_browser_fragment = format!("{long_browser_value}"); let untruncated_automation_fragment = @@ -953,7 +953,7 @@ async fn additional_context_values_are_truncated_before_model_input( }; assert!(automation_text.starts_with(&format!( "automation-head-{}", - "a".repeat(1024) + "a".repeat(19_000) ))); assert!(automation_text.contains("tokens truncated")); assert!(automation_text.ends_with("automation-tail")); @@ -974,14 +974,14 @@ async fn additional_context_values_are_truncated_before_model_input( assert_eq!(outputs[0]["name"], "browser_info"); assert_eq!(outputs[0]["namespace"], "agent"); let body = outputs[0]["output"].as_str().expect("text output"); - assert!(body.starts_with(&format!("browser-head-{}", "b".repeat(1024)))); + assert!(body.starts_with(&format!("browser-head-{}", "b".repeat(19_000)))); assert!(body.ends_with("browser-tail")); assert!(body.contains("tokens truncated")); assert!(body.len() <= MAX_EXPECTED_EXTERNAL_CONTEXT_TEXT_BYTES); let mut hidden_edit = long_automation_value.clone(); - hidden_edit.replace_range(20_000..20_001, "c"); + hidden_edit.replace_range(40_000..40_001, "c"); let mut changed_middle = long_browser_value.clone(); - changed_middle.replace_range(20_000..20_001, "c"); + changed_middle.replace_range(40_000..40_001, "c"); let changed_prefix = changed_middle.replacen("browser-head", "browser-view", 1); for (value, expected_count) in [(changed_middle, 1), (changed_prefix, 2)] { let next = mount_sse_once(&server, sse(vec![ev_completed("updated-context")])).await; @@ -1045,7 +1045,7 @@ async fn additional_context_values_are_truncated_before_model_input( assert_eq!(user_text, "summarize context"); assert!(external_text.starts_with(&format!( "browser-head-{}", - "b".repeat(1024) + "b".repeat(19_000) ))); assert!(external_text.contains("tokens truncated")); assert!(external_text.ends_with("browser-tail")); @@ -1097,32 +1097,32 @@ async fn additional_context_metrics_record_submitted_sizes_and_truncation( "application_limit", application, None, - "a".repeat(4_000), + "a".repeat(40_000), false, ), ( "application_over", application, None, - "a".repeat(4_001), + "a".repeat(40_001), true, ), ( "opaque_named_limit", untrusted, Some("browser_limit"), - "b".repeat(4_000), + "b".repeat(40_000), false, ), ( "opaque_named_over", untrusted, Some("browser_over"), - "b".repeat(4_001), + "b".repeat(40_001), true, ), // Size is measured in UTF-8 bytes; the unnamed entry must not acquire a key-derived label. - ("opaque_unnamed", untrusted, None, "é".repeat(2_001), true), + ("opaque_unnamed", untrusted, None, "é".repeat(20_001), true), ("opaque_empty", untrusted, None, String::new(), false), ]; let values = cases @@ -1242,7 +1242,7 @@ async fn additional_context_metrics_record_submitted_sizes_and_truncation( expected_counts.insert(tags.clone(), 2); // The marker is outside the retained-text budget, so a truncated value can grow. let after_bytes = if truncated { - 4_000 + "…1 tokens truncated…".len() + 40_000 + "…1 tokens truncated…".len() } else { value.len() }; diff --git a/codex-rs/core/tests/suite/compact.rs b/codex-rs/core/tests/suite/compact.rs index 36f86666be..d72ff03ab1 100644 --- a/codex-rs/core/tests/suite/compact.rs +++ b/codex-rs/core/tests/suite/compact.rs @@ -1139,12 +1139,13 @@ async fn additional_context_survives_compaction(remote: bool) -> Result<()> { let untrusted = |value: &str| { AdditionalContextEntry::new(value.to_owned(), AdditionalContextKind::Untrusted) }; + let app = "🧭".repeat(10_000); let mut context = BTreeMap::from([ ("page".to_owned(), untrusted("old selection")), ("removed".to_owned(), untrusted("closed tab")), ( "app".to_owned(), - AdditionalContextEntry::new("editor".to_owned(), AdditionalContextKind::Application), + AdditionalContextEntry::new(app.clone(), AdditionalContextKind::Application), ), ]); let submit = async |prompt: &str, context| -> Result<()> { @@ -1183,9 +1184,9 @@ async fn additional_context_survives_compaction(remote: bool) -> Result<()> { let app_messages = follow_up .message_input_texts("developer") .into_iter() - .filter(|text| text == "editor") + .filter(|text| text.starts_with("")) .collect::>(); - assert_eq!(app_messages, ["editor"]); + assert_eq!(app_messages, [format!("{app}")]); // The context belongs to the compacted window, before the preserved second prompt. let input = follow_up.input(); let second_prompt = input diff --git a/codex-rs/otel/src/metrics/names.rs b/codex-rs/otel/src/metrics/names.rs index 6b4d1be30e..25162dcf1e 100644 --- a/codex-rs/otel/src/metrics/names.rs +++ b/codex-rs/otel/src/metrics/names.rs @@ -99,11 +99,11 @@ pub const THREAD_STARTED_METRIC: &str = "codex.thread.started"; pub const ADDITIONAL_CONTEXT_COUNT_METRIC: &str = "codex.additional_context"; /// UTF-8 value bytes before/after truncation, excluding message wrappers; after includes the marker. pub const ADDITIONAL_CONTEXT_VALUE_BYTES_METRIC: &str = "codex.additional_context.value_bytes"; -/// Logarithmic byte buckets through 4 MiB, with a 4 KiB boundary near the truncation cap. +/// Logarithmic byte buckets through 4 MiB, with boundaries near the previous and current truncation caps. pub static ADDITIONAL_CONTEXT_VALUE_BYTES_BUCKETS: LazyLock> = LazyLock::new(|| { let mut buckets = context_log_buckets(/*max_exponent*/ 22.0) .into_iter() - .chain([4096.0]) + .chain([4096.0, 40_960.0]) .collect::>(); buckets.sort_by(f64::total_cmp); buckets.dedup(); diff --git a/codex-rs/otel/tests/suite/send.rs b/codex-rs/otel/tests/suite/send.rs index 9da64701d0..9b4a6e739f 100644 --- a/codex-rs/otel/tests/suite/send.rs +++ b/codex-rs/otel/tests/suite/send.rs @@ -140,7 +140,7 @@ fn histogram_uses_explicit_bucket_boundaries() -> Result<()> { #[test] fn additional_context_histogram_bounds_truncated_observations() -> Result<()> { let (metrics, exporter) = build_metrics_with_defaults(&[])?; - let samples = [4_024, 4_027, 4_043]; + let samples = [40_024, 40_027, 40_043]; for value in samples { metrics.histogram_with_boundaries( ADDITIONAL_CONTEXT_VALUE_BYTES_METRIC, @@ -155,12 +155,12 @@ fn additional_context_histogram_bounds_truncated_observations() -> Result<()> { &latest_metrics(&exporter), ADDITIONAL_CONTEXT_VALUE_BYTES_METRIC, ); - assert_eq!((sum, count), (12_094.0, 3)); + assert_eq!((sum, count), (120_094.0, 3)); assert_eq!(counts.iter().sum::(), count); assert_eq!(counts.last(), Some(&0)); for (upper_bound, bucket_count) in bounds.iter().zip(&counts) { assert!( - *bucket_count == 0 || *upper_bound <= 4_096.0, + *bucket_count == 0 || *upper_bound <= 40_960.0, "post-truncation observations landed in a bucket ending at {upper_bound} bytes" ); }