mirror of
https://github.com/openai/codex.git
synced 2026-04-27 16:15:09 +00:00
Reuse guardian session across approvals (#14668)
## Summary - reuse a guardian subagent session across approvals so reviews keep a stable prompt cache key and avoid one-shot startup overhead - clear the guardian child history before each review so prior guardian decisions do not leak into later approvals - include the `smart_approvals` -> `guardian_approval` feature flag rename in the same PR to minimize release latency on a very tight timeline - add regression coverage for prompt-cache-key reuse without prior-review prompt bleed ## Request - Bug/enhancement request: internal guardian prompt-cache and latency improvement request --------- Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
committed by
GitHub
parent
ba463a9dc7
commit
6fdeb1d602
@@ -22,6 +22,7 @@ pub enum ContextSnapshotRenderMode {
|
||||
pub struct ContextSnapshotOptions {
|
||||
render_mode: ContextSnapshotRenderMode,
|
||||
strip_capability_instructions: bool,
|
||||
strip_agents_md_user_context: bool,
|
||||
}
|
||||
|
||||
impl Default for ContextSnapshotOptions {
|
||||
@@ -29,6 +30,7 @@ impl Default for ContextSnapshotOptions {
|
||||
Self {
|
||||
render_mode: ContextSnapshotRenderMode::RedactedText,
|
||||
strip_capability_instructions: false,
|
||||
strip_agents_md_user_context: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +45,11 @@ impl ContextSnapshotOptions {
|
||||
self.strip_capability_instructions = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn strip_agents_md_user_context(mut self) -> Self {
|
||||
self.strip_agents_md_user_context = true;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_request_input_snapshot(
|
||||
@@ -88,6 +95,12 @@ pub fn format_response_items_snapshot(items: &[Value], options: &ContextSnapshot
|
||||
{
|
||||
return None;
|
||||
}
|
||||
if options.strip_agents_md_user_context
|
||||
&& role == "user"
|
||||
&& text.starts_with("# AGENTS.md instructions for ")
|
||||
{
|
||||
return None;
|
||||
}
|
||||
return Some(format_snapshot_text(text, options));
|
||||
}
|
||||
let Some(content_type) =
|
||||
@@ -451,6 +464,33 @@ mod tests {
|
||||
assert_eq!(rendered, "00:message/developer:<PERMISSIONS_INSTRUCTIONS>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_agents_md_user_context_omits_agents_fragment_from_user_messages() {
|
||||
let items = vec![json!({
|
||||
"type": "message",
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "input_text",
|
||||
"text": "# AGENTS.md instructions for /tmp/example\n\n<INSTRUCTIONS>\n- test\n</INSTRUCTIONS>"
|
||||
},
|
||||
{
|
||||
"type": "input_text",
|
||||
"text": "<environment_context>\n <cwd>/tmp/example</cwd>\n</environment_context>"
|
||||
}
|
||||
]
|
||||
})];
|
||||
|
||||
let rendered = format_response_items_snapshot(
|
||||
&items,
|
||||
&ContextSnapshotOptions::default()
|
||||
.render_mode(ContextSnapshotRenderMode::RedactedText)
|
||||
.strip_agents_md_user_context(),
|
||||
);
|
||||
|
||||
assert_eq!(rendered, "00:message/user:<ENVIRONMENT_CONTEXT:cwd=<CWD>>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redacted_text_mode_normalizes_environment_context_with_subagents() {
|
||||
let items = vec![json!({
|
||||
|
||||
Reference in New Issue
Block a user