mirror of
https://github.com/openai/codex.git
synced 2026-11-18 07:00:27 +00:00
Bound MCP descriptions separately from Guardian action JSON (#44493)
## Why MCP tool and connector descriptions were included in required action JSON, consuming review input budget even though they are optional metadata. ## What changed Move `tool_description` and `connector_description` into an optional, explicitly untrusted `guardian_tool_descriptions` fragment. Limit each description to 400 estimated tokens, escape closing tags, and allow budget enforcement to omit the fragment while retaining the required action JSON. Preserve nested arguments such as `arguments.description` and mention tool descriptions in the budget omission notice. ## Testing Add regression coverage for oversized descriptions, escaped closing markers, and budget eviction without changing action arguments. Update MCP approval and elicitation tests to verify descriptions appear separately from the action JSON. GitOrigin-RevId: 30734567c2ebc4b180110276c83d79ddb315ceab
This commit is contained in:
1 parent
102fc57e4a
commit
9688359977
15 files changed
+229
-10
No files matched your search
@@ -14,6 +14,8 @@ pub struct PlannedAction {
|
||||
pub json: String,
|
||||
pub kind: PlannedActionKind,
|
||||
pub reason: Option<String>,
|
||||
/// Host-rendered, bounded untrusted metadata; the action JSON remains required.
|
||||
pub tool_descriptions: Option<String>,
|
||||
}
|
||||
|
||||
// Action JSON and reasons can contain credentials; diagnostics expose only the kind.
|
||||
|
||||
@@ -227,7 +227,18 @@ impl CollectedContext {
|
||||
)
|
||||
}
|
||||
ContextSection::PlannedAction(planned) => {
|
||||
(11, "planned_action", text_content(planned.render(action)))
|
||||
let mut items = planned
|
||||
.render(action)
|
||||
.into_iter()
|
||||
.map(|text| Budgeted::required(ContentItem::InputText { text }))
|
||||
.collect::<Vec<_>>();
|
||||
if let Some(text) = planned.tool_descriptions {
|
||||
items.push(Budgeted::optional(
|
||||
ContentItem::InputText { text },
|
||||
BudgetPriority::ToolDescription,
|
||||
));
|
||||
}
|
||||
(11, "planned_action", SectionDelivery::UserContent(items))
|
||||
}
|
||||
};
|
||||
sections.push((position, SectionOutput { id, delivery }));
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::composition::SectionOutput;
|
||||
/// Eviction priority within a profile; older items at the same priority go first.
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub(crate) enum BudgetPriority {
|
||||
ToolDescription,
|
||||
Commentary,
|
||||
Tool,
|
||||
Image,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use super::*;
|
||||
use crate::budget::section_tokens;
|
||||
use crate::composition::user_message;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn text(value: &str) -> ContentItem {
|
||||
@@ -11,6 +12,53 @@ fn text(value: &str) -> ContentItem {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn planned_action_budget_omits_descriptions_without_changing_arguments() {
|
||||
let action = crate::PlannedAction {
|
||||
json: r#"{"tool":"write_record","arguments":{"description":"required payload"}}"#
|
||||
.to_owned(),
|
||||
kind: crate::PlannedActionKind::Command,
|
||||
reason: None,
|
||||
tool_descriptions: Some("optional tool description ".repeat(/*n*/ 100)),
|
||||
};
|
||||
let required = action.render(crate::ActionPresentation::SyncFull);
|
||||
let context = crate::CollectedContext {
|
||||
sections: vec![crate::ContextSection::PlannedAction(action)],
|
||||
}
|
||||
.compose(
|
||||
crate::ContextPresentation::SyncFull {
|
||||
session_id: "review",
|
||||
},
|
||||
crate::RenderedTranscript {
|
||||
items: Vec::new(),
|
||||
omission_note: None,
|
||||
truncations: Vec::new(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let mut required_items = required.iter().map(|item| text(item)).collect::<Vec<_>>();
|
||||
required_items.push(text("evidence omitted"));
|
||||
let budget = crate::estimate_input_tokens(&user_message(required_items.clone())) + 100;
|
||||
let selected = context
|
||||
.enforce_budget(
|
||||
RequestBudget {
|
||||
max_input_tokens: budget,
|
||||
existing_context_tokens: 0,
|
||||
},
|
||||
"evidence omitted".to_owned(),
|
||||
)
|
||||
.unwrap();
|
||||
// The sync preamble is also required and remains ahead of the action.
|
||||
let messages = selected.into_messages();
|
||||
let ResponseItem::Message { content, .. } = &messages[0] else {
|
||||
panic!("expected user evidence");
|
||||
};
|
||||
assert_eq!(
|
||||
&content[content.len() - required_items.len()..],
|
||||
required_items
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn budget_reserves_existing_context_and_preserves_required_messages() {
|
||||
let trusted = crate::PreviousReviews::try_from_fragments(vec!["verified review".to_owned()])
|
||||
|
||||
@@ -207,6 +207,7 @@ fn reused_registry_preserves_section_identity_and_source_roles() {
|
||||
denied_globs: vec!["**/*.key".into()],
|
||||
};
|
||||
let action = super::PlannedAction {
|
||||
tool_descriptions: None,
|
||||
json: r#"{"tool":"read_file","path":"debug-secret.json"}"#.into(),
|
||||
kind: super::PlannedActionKind::Command,
|
||||
reason: Some("debug-secret reason".into()),
|
||||
|
||||
Reference in new issue
Block a user