mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
add parent-id to guardian context (#17194)
adding parent codex session id to guardian prompt
This commit is contained in:
@@ -158,6 +158,10 @@ pub(crate) async fn build_guardian_prompt_items(
|
||||
push_text(format!("{prefix}{entry}\n"));
|
||||
}
|
||||
push_text(headings.transcript_end.to_string());
|
||||
push_text(format!(
|
||||
"Reviewed Codex session id: {}\n",
|
||||
session.conversation_id
|
||||
));
|
||||
if let Some(note) = omission_note {
|
||||
push_text(format!("\n{note}\n"));
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -17,6 +17,7 @@ use crate::config_loader::Sourced;
|
||||
use crate::test_support;
|
||||
use codex_config::config_toml::ConfigToml;
|
||||
use codex_network_proxy::NetworkProxyConfig;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::approvals::NetworkApprovalProtocol;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::models::ContentItem;
|
||||
@@ -54,6 +55,11 @@ use std::time::Duration;
|
||||
use tempfile::TempDir;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
fn fixed_guardian_parent_session_id() -> ThreadId {
|
||||
ThreadId::from_string("11111111-1111-4111-8111-111111111111")
|
||||
.expect("fixed parent session id should be a valid UUID")
|
||||
}
|
||||
|
||||
async fn guardian_test_session_and_turn(
|
||||
server: &wiremock::MockServer,
|
||||
) -> (Arc<Session>, Arc<TurnContext>) {
|
||||
@@ -64,6 +70,7 @@ async fn guardian_test_session_and_turn_with_base_url(
|
||||
base_url: &str,
|
||||
) -> (Arc<Session>, Arc<TurnContext>) {
|
||||
let (mut session, mut turn) = crate::codex::make_session_and_context().await;
|
||||
session.conversation_id = fixed_guardian_parent_session_id();
|
||||
let mut config = (*turn.config).clone();
|
||||
config.model_provider.base_url = Some(format!("{base_url}/v1"));
|
||||
config.user_instructions = None;
|
||||
@@ -850,6 +857,7 @@ async fn guardian_review_request_layout_matches_model_visible_request_snapshot()
|
||||
.await;
|
||||
|
||||
let (mut session, mut turn) = crate::codex::make_session_and_context().await;
|
||||
session.conversation_id = fixed_guardian_parent_session_id();
|
||||
let temp_cwd = TempDir::new()?;
|
||||
let mut config = (*turn.config).clone();
|
||||
config.cwd = temp_cwd.abs();
|
||||
@@ -913,6 +921,44 @@ async fn guardian_review_request_layout_matches_model_visible_request_snapshot()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn build_guardian_prompt_items_includes_parent_session_id() -> anyhow::Result<()> {
|
||||
let (session, _) = crate::codex::make_session_and_context().await;
|
||||
let prompt = build_guardian_prompt_items(
|
||||
&session,
|
||||
/*retry_reason*/ None,
|
||||
GuardianApprovalRequest::Shell {
|
||||
id: "shell-1".to_string(),
|
||||
command: vec!["git".to_string(), "status".to_string()],
|
||||
cwd: PathBuf::from("/repo"),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
additional_permissions: None,
|
||||
justification: None,
|
||||
},
|
||||
GuardianPromptMode::Full,
|
||||
)
|
||||
.await?;
|
||||
let prompt_text = prompt
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|item| match item {
|
||||
codex_protocol::user_input::UserInput::Text { text, .. } => text,
|
||||
codex_protocol::user_input::UserInput::Image { .. } => String::new(),
|
||||
_ => String::new(),
|
||||
})
|
||||
.collect::<String>();
|
||||
|
||||
assert!(
|
||||
prompt_text.contains(&format!(
|
||||
">>> TRANSCRIPT END\nReviewed Codex session id: {}\n",
|
||||
session.conversation_id
|
||||
)),
|
||||
"guardian prompt should expose the parent session id immediately after the transcript end"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
Reference in New Issue
Block a user