mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Allow larger text entries in Guardian context budgets (#65071)
## Why Guardian context delivery can split a text entry across multiple bounded parts. Capping each entry at the size of one part prevented configurations from allocating more room to a single entry, even when the section budget could accommodate it. ## What changed Allow `max_section_entry_tokens` to exceed the per-part delivery limit when it fits within `min_total_section_tokens`. ## Testing Exercise elastic budgeting with a large transcript tool entry and a file image. Verify that the delivered text parts respect the part limit and reassemble into the original text, that the image is preserved, and that the budget estimate covers the delivered message. GitOrigin-RevId: a303180bc90dce1a21fc91cd12e2eded90eaad8e
This commit is contained in:
@@ -228,7 +228,7 @@ impl ElasticBudgetConfig {
|
||||
/// capacity is shared between sections up to each maximum, with both priorities eligible.
|
||||
/// Preparation must cap text entries once, including framing and omission markers,
|
||||
/// before measuring demand. Entries that fit keep their original representation.
|
||||
/// Entry caps cannot exceed the existing text-part delivery allowance.
|
||||
/// A logical entry can span multiple bounded text parts at delivery.
|
||||
/// Exact actions use protected global space. Opaque native payloads and images stay
|
||||
/// whole and use section/global space rather than the text entry cap.
|
||||
/// Effective section minimums stay fixed and must sum to DEFAULT_MAX_INPUT_TOKENS.
|
||||
@@ -246,7 +246,7 @@ pub struct ElasticSectionLimits {
|
||||
}
|
||||
|
||||
impl ElasticSectionLimits {
|
||||
/// Reject empty quotas, oversized entries and minimums that cannot hold one capped entry.
|
||||
/// A section must reserve room for at least one capped entry, which can span text parts.
|
||||
pub fn new(
|
||||
min_total_section_tokens: usize,
|
||||
max_section_entry_tokens: usize,
|
||||
@@ -257,9 +257,6 @@ impl ElasticSectionLimits {
|
||||
if max_section_entry_tokens > min_total_section_tokens {
|
||||
return Err(ElasticSectionLimitsError::EntryExceedsMinimum);
|
||||
}
|
||||
if max_section_entry_tokens > crate::composition::MAX_TEXT_PART_ESTIMATED_TOKENS {
|
||||
return Err(ElasticSectionLimitsError::EntryExceedsDeliveryLimit);
|
||||
}
|
||||
Ok(Self {
|
||||
min_total_section_tokens,
|
||||
max_section_entry_tokens,
|
||||
@@ -326,7 +323,6 @@ impl<'de> serde::Deserialize<'de> for ElasticSectionLimits {
|
||||
pub enum ElasticSectionLimitsError {
|
||||
ZeroTokens,
|
||||
EntryExceedsMinimum,
|
||||
EntryExceedsDeliveryLimit,
|
||||
MaximumBelowMinimum,
|
||||
}
|
||||
|
||||
@@ -340,11 +336,6 @@ impl std::fmt::Display for ElasticSectionLimitsError {
|
||||
.write_str("min_total_section_tokens must be at least max_section_entry_tokens"),
|
||||
Self::MaximumBelowMinimum => formatter
|
||||
.write_str("max_total_section_tokens must be at least min_total_section_tokens"),
|
||||
Self::EntryExceedsDeliveryLimit => write!(
|
||||
formatter,
|
||||
"max_section_entry_tokens must not exceed {}",
|
||||
crate::composition::MAX_TEXT_PART_ESTIMATED_TOKENS
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ fn elastic_section_config_validates_entry_limits() {
|
||||
});
|
||||
let parsed = serde_json::from_value::<ElasticBudgetConfig>(config.clone()).unwrap();
|
||||
assert_eq!(serde_json::to_value(parsed).unwrap(), config);
|
||||
for (minimum, entry_cap) in [(0, cap), (cap, 0), (cap - 1, cap), (cap + 1, cap + 1)] {
|
||||
for (minimum, entry_cap) in [(0, cap), (cap, 0), (cap - 1, cap)] {
|
||||
let mut invalid = config.clone();
|
||||
invalid["sections"]["transcript_tools"]["min_total_section_tokens"] = minimum.into();
|
||||
invalid["sections"]["transcript_tools"]["max_section_entry_tokens"] = entry_cap.into();
|
||||
|
||||
@@ -187,16 +187,19 @@ fn delivery_preserves_arbitrary_message_boundaries_and_rejects_them_for_sync() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_text_and_file_image_delivery_is_lossless_bounded_and_fully_budgeted() {
|
||||
let text = "é🙂\"\n".repeat(/*n*/ 20_000);
|
||||
fn elastic_tool_text_and_file_image_delivery_is_lossless_bounded_and_fully_budgeted() {
|
||||
let text = "é🙂\"\n".repeat(60 * 1024 / 8);
|
||||
let file_image = ImageReference::File {
|
||||
file_id: "file_123".to_owned(),
|
||||
};
|
||||
let context = ComposedContext {
|
||||
sections: vec![SectionOutput {
|
||||
id: "planned_action",
|
||||
id: "conversation_transcript",
|
||||
delivery: SectionDelivery::user_content(vec![
|
||||
Budgeted::required(ContentItem::InputText { text: text.clone() }),
|
||||
Budgeted::optional(
|
||||
ContentItem::InputText { text: text.clone() },
|
||||
BudgetPriority::Tool,
|
||||
),
|
||||
Budgeted::required(ContentItem::InputImage {
|
||||
image: file_image.clone(),
|
||||
detail: Some(ImageDetail::High),
|
||||
@@ -205,6 +208,25 @@ fn long_text_and_file_image_delivery_is_lossless_bounded_and_fully_budgeted() {
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
let limits = crate::ElasticSectionLimits::new(
|
||||
/*min_total_section_tokens*/ 24_000, /*max_section_entry_tokens*/ 24_000,
|
||||
)
|
||||
.unwrap();
|
||||
let config = crate::budget::tests::complete_minimum_budget(crate::ElasticBudgetConfig {
|
||||
sections: [(crate::ElasticSection::TranscriptTools, limits)].into(),
|
||||
..Default::default()
|
||||
});
|
||||
let context = context
|
||||
.prepare_elastic_entries(&config)
|
||||
.unwrap()
|
||||
.enforce_budget(
|
||||
crate::RequestBudget {
|
||||
max_input_tokens: crate::DEFAULT_MAX_INPUT_TOKENS,
|
||||
existing_context_tokens: 0,
|
||||
},
|
||||
"Evidence omitted.".into(),
|
||||
)
|
||||
.unwrap();
|
||||
let estimated = context.estimated_tokens();
|
||||
let messages = context.clone().into_messages();
|
||||
let ResponseItem::Message { content, .. } = &messages[0] else {
|
||||
|
||||
Reference in New Issue
Block a user