mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
core: remove redundant TurnContext and Prompt fields (#28638)
## Why `TurnContext` had accumulated dead fields and cached projections of values already owned by its per-turn `Config` or `ModelInfo`. Keeping both copies made ownership unclear and allowed artificial split-brain states, such as a compatibility hash differing from the model metadata it came from. `Prompt` similarly carried a write-only personality after personality selection had already been materialized into its base instructions. This makes the canonical owner explicit: configuration-backed values come from `config`, model-derived values come from `model_info`, and prompts contain only data consumed by request construction. ## What changed - Remove the unused `ghost_snapshot`, `codex_self_exe`, and `thread_source` fields. - Remove duplicate `comp_hash`, `truncation_policy`, `features`, `shell_environment_policy`, `codex_linux_sandbox_exe`, `compact_prompt`, and `tool_mode` fields. - Read those values directly from `TurnContext::config` or `TurnContext::model_info` at their consumers. - Remove the write-only `Prompt::personality` field and its constructor assignments. - Preserve review-turn inheritance of the parent turn's shell policy, Linux sandbox executable, and compact prompt through the review config. ## Testing - `cargo check -p codex-core --tests`
This commit is contained in:
1 parent
cb15c64760
commit
172b2218a5
42 files changed
+225
-245
No files matched your search
@@ -82,7 +82,11 @@ impl ToolArgumentDiffConsumer for ApplyPatchArgumentDiffConsumer {
|
||||
call_id: String,
|
||||
diff: &str,
|
||||
) -> Option<EventMsg> {
|
||||
if !turn.features.enabled(Feature::ApplyPatchStreamingEvents) {
|
||||
if !turn
|
||||
.config
|
||||
.features
|
||||
.enabled(Feature::ApplyPatchStreamingEvents)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ async fn to_extension_call(invocation: &ToolInvocation) -> ExtensionToolCall {
|
||||
call_id: invocation.call_id.clone(),
|
||||
tool_name: invocation.tool_name.clone(),
|
||||
model: invocation.turn.model_info.slug.clone(),
|
||||
truncation_policy: invocation.turn.truncation_policy,
|
||||
truncation_policy: invocation.turn.model_info.truncation_policy.into(),
|
||||
conversation_history,
|
||||
turn_item_emitter: Arc::new(CoreTurnItemEmitter {
|
||||
session: Arc::downgrade(&invocation.session),
|
||||
@@ -315,7 +315,7 @@ mod tests {
|
||||
let weak_turn = Arc::downgrade(&turn);
|
||||
let turn_id = turn.sub_id.clone();
|
||||
let model = turn.model_info.slug.clone();
|
||||
let truncation_policy = turn.truncation_policy;
|
||||
let truncation_policy = turn.model_info.truncation_policy.into();
|
||||
let expected_sandbox_cwds = turn
|
||||
.environments
|
||||
.turn_environments
|
||||
|
||||
@@ -156,7 +156,7 @@ impl McpHandler {
|
||||
tool_input: result.tool_input,
|
||||
wall_time: started.elapsed(),
|
||||
original_image_detail_supported: can_request_original_image_detail(&turn.model_info),
|
||||
truncation_policy: turn.truncation_policy,
|
||||
truncation_policy: turn.model_info.truncation_policy.into(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,9 +115,10 @@ impl ListMcpResourceTemplatesHandler {
|
||||
}
|
||||
}
|
||||
.await;
|
||||
let truncation_policy = turn.model_info.truncation_policy.into();
|
||||
|
||||
match payload_result {
|
||||
Ok(payload) => match serialize_function_output(payload, turn.truncation_policy) {
|
||||
Ok(payload) => match serialize_function_output(payload, truncation_policy) {
|
||||
Ok(output) => {
|
||||
let content = function_call_output_content_items_to_text(&output.body)
|
||||
.unwrap_or_default();
|
||||
|
||||
@@ -113,9 +113,10 @@ impl ListMcpResourcesHandler {
|
||||
}
|
||||
}
|
||||
.await;
|
||||
let truncation_policy = turn.model_info.truncation_policy.into();
|
||||
|
||||
match payload_result {
|
||||
Ok(payload) => match serialize_function_output(payload, turn.truncation_policy) {
|
||||
Ok(payload) => match serialize_function_output(payload, truncation_policy) {
|
||||
Ok(output) => {
|
||||
let content = function_call_output_content_items_to_text(&output.body)
|
||||
.unwrap_or_default();
|
||||
|
||||
@@ -96,9 +96,10 @@ impl ReadMcpResourceHandler {
|
||||
})
|
||||
}
|
||||
.await;
|
||||
let truncation_policy = turn.model_info.truncation_policy.into();
|
||||
|
||||
match payload_result {
|
||||
Ok(payload) => match serialize_function_output(payload, turn.truncation_policy) {
|
||||
Ok(payload) => match serialize_function_output(payload, truncation_policy) {
|
||||
Ok(output) => {
|
||||
let content = function_call_output_content_items_to_text(&output.body)
|
||||
.unwrap_or_default();
|
||||
|
||||
@@ -228,7 +228,6 @@ fn build_agent_shared_config(turn: &TurnContext) -> Result<Config, FunctionCallE
|
||||
.or_else(|| turn.model_info.default_reasoning_level.clone());
|
||||
config.model_reasoning_summary = Some(turn.reasoning_summary);
|
||||
config.developer_instructions = turn.developer_instructions.clone();
|
||||
config.compact_prompt = turn.compact_prompt.clone();
|
||||
apply_spawn_agent_runtime_overrides(&mut config, turn)?;
|
||||
|
||||
Ok(config)
|
||||
@@ -263,8 +262,6 @@ pub(crate) fn apply_spawn_agent_runtime_overrides(
|
||||
FunctionCallError::RespondToModel(format!("approval_policy is invalid: {err}"))
|
||||
})?;
|
||||
config.approvals_reviewer = turn.config.approvals_reviewer;
|
||||
config.permissions.shell_environment_policy = turn.shell_environment_policy.clone();
|
||||
config.codex_linux_sandbox_exe = turn.codex_linux_sandbox_exe.clone();
|
||||
#[allow(deprecated)]
|
||||
let turn_cwd = turn.cwd.clone();
|
||||
config.cwd = turn_cwd;
|
||||
|
||||
@@ -4467,17 +4467,19 @@ async fn build_agent_spawn_config_uses_turn_context_values() {
|
||||
text: "base".to_string(),
|
||||
};
|
||||
turn.developer_instructions = Some("dev".to_string());
|
||||
turn.compact_prompt = Some("compact".to_string());
|
||||
turn.shell_environment_policy = ShellEnvironmentPolicy {
|
||||
let mut config = (*turn.config).clone();
|
||||
config.compact_prompt = Some("compact".to_string());
|
||||
config.permissions.shell_environment_policy = ShellEnvironmentPolicy {
|
||||
use_profile: true,
|
||||
..ShellEnvironmentPolicy::default()
|
||||
};
|
||||
config.codex_linux_sandbox_exe = Some(PathBuf::from("/bin/echo"));
|
||||
turn.config = Arc::new(config);
|
||||
let temp_dir = tempfile::tempdir().expect("temp dir");
|
||||
#[allow(deprecated)]
|
||||
{
|
||||
turn.cwd = temp_dir.abs();
|
||||
}
|
||||
turn.codex_linux_sandbox_exe = Some(PathBuf::from("/bin/echo"));
|
||||
#[allow(deprecated)]
|
||||
let turn_cwd = turn.cwd.clone();
|
||||
let sandbox_policy = pick_allowed_sandbox_policy(
|
||||
@@ -4506,9 +4508,6 @@ async fn build_agent_spawn_config_uses_turn_context_values() {
|
||||
expected.model_reasoning_effort = turn.reasoning_effort.clone();
|
||||
expected.model_reasoning_summary = Some(turn.reasoning_summary);
|
||||
expected.developer_instructions = turn.developer_instructions.clone();
|
||||
expected.compact_prompt = turn.compact_prompt.clone();
|
||||
expected.permissions.shell_environment_policy = turn.shell_environment_policy.clone();
|
||||
expected.codex_linux_sandbox_exe = turn.codex_linux_sandbox_exe.clone();
|
||||
#[allow(deprecated)]
|
||||
{
|
||||
expected.cwd = turn.cwd.clone();
|
||||
@@ -4544,9 +4543,6 @@ async fn build_agent_resume_config_clears_base_instructions() {
|
||||
expected.model_reasoning_effort = turn.reasoning_effort.clone();
|
||||
expected.model_reasoning_summary = Some(turn.reasoning_summary);
|
||||
expected.developer_instructions = turn.developer_instructions.clone();
|
||||
expected.compact_prompt = turn.compact_prompt.clone();
|
||||
expected.permissions.shell_environment_policy = turn.shell_environment_policy.clone();
|
||||
expected.codex_linux_sandbox_exe = turn.codex_linux_sandbox_exe.clone();
|
||||
#[allow(deprecated)]
|
||||
{
|
||||
expected.cwd = turn.cwd.clone();
|
||||
|
||||
@@ -80,7 +80,12 @@ async fn run_exec_like(args: RunExecLikeArgs) -> Result<FunctionToolOutput, Func
|
||||
};
|
||||
let fs = turn_environment.environment.get_filesystem();
|
||||
|
||||
let explicit_env_overrides = turn.shell_environment_policy.r#set.clone();
|
||||
let explicit_env_overrides = turn
|
||||
.config
|
||||
.permissions
|
||||
.shell_environment_policy
|
||||
.r#set
|
||||
.clone();
|
||||
let exec_permission_approvals_enabled =
|
||||
session.features().enabled(Feature::ExecPermissionApprovals);
|
||||
let requested_additional_permissions = additional_permissions.clone();
|
||||
@@ -223,7 +228,9 @@ async fn run_exec_like(args: RunExecLikeArgs) -> Result<FunctionToolOutput, Func
|
||||
let post_tool_use_response = out
|
||||
.as_ref()
|
||||
.ok()
|
||||
.map(|output| crate::tools::format_exec_output_str(output, turn.truncation_policy))
|
||||
.map(|output| {
|
||||
crate::tools::format_exec_output_str(output, turn.model_info.truncation_policy.into())
|
||||
})
|
||||
.map(JsonValue::String);
|
||||
let content = emitter
|
||||
.finish(event_ctx, out, /*applied_patch_delta*/ None)
|
||||
|
||||
@@ -100,7 +100,10 @@ impl ShellCommandHandler {
|
||||
cwd,
|
||||
expiration: params.timeout_ms.into(),
|
||||
capture_policy: ExecCapturePolicy::ShellTool,
|
||||
env: create_env(&turn_context.shell_environment_policy, Some(thread_id)),
|
||||
env: create_env(
|
||||
&turn_context.config.permissions.shell_environment_policy,
|
||||
Some(thread_id),
|
||||
),
|
||||
network: turn_context.network.clone(),
|
||||
sandbox_permissions: params.sandbox_permissions.unwrap_or_default(),
|
||||
windows_sandbox_level: turn_context.windows_sandbox_level,
|
||||
|
||||
@@ -83,7 +83,7 @@ async fn shell_command_handler_to_exec_params_uses_session_shell_and_turn_contex
|
||||
#[allow(deprecated)]
|
||||
let expected_cwd = turn_context.resolve_path(workdir.clone());
|
||||
let expected_env = create_env(
|
||||
&turn_context.shell_environment_policy,
|
||||
&turn_context.config.permissions.shell_environment_policy,
|
||||
Some(session.thread_id),
|
||||
);
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ impl ExecCommandHandler {
|
||||
chunk_id: String::new(),
|
||||
wall_time: std::time::Duration::ZERO,
|
||||
raw_output: output.into_text().into_bytes(),
|
||||
truncation_policy: turn.truncation_policy,
|
||||
truncation_policy: turn.model_info.truncation_policy.into(),
|
||||
max_output_tokens,
|
||||
process_id: None,
|
||||
exit_code: None,
|
||||
@@ -310,7 +310,7 @@ impl ExecCommandHandler {
|
||||
chunk_id: generate_chunk_id(),
|
||||
wall_time: output.duration,
|
||||
raw_output: output_text.into_bytes(),
|
||||
truncation_policy: turn.truncation_policy,
|
||||
truncation_policy: turn.model_info.truncation_policy.into(),
|
||||
max_output_tokens,
|
||||
// Sandbox denial is terminal, so there is no live
|
||||
// process for write_stdin to resume.
|
||||
|
||||
@@ -75,7 +75,7 @@ impl WriteStdinHandler {
|
||||
input: &args.chars,
|
||||
yield_time_ms: args.yield_time_ms,
|
||||
max_output_tokens: args.max_output_tokens,
|
||||
truncation_policy: turn.truncation_policy,
|
||||
truncation_policy: turn.model_info.truncation_policy.into(),
|
||||
})
|
||||
.await
|
||||
.map_err(|err| {
|
||||
|
||||
@@ -195,7 +195,7 @@ impl ViewImageHandler {
|
||||
DEFAULT_IMAGE_DETAIL
|
||||
};
|
||||
|
||||
let image_url = if turn.features.enabled(Feature::ResizeAllImages) {
|
||||
let image_url = if turn.config.features.enabled(Feature::ResizeAllImages) {
|
||||
// The history insertion path owns image decoding and resizing when this is enabled.
|
||||
data_url_from_bytes("application/octet-stream", &file_bytes)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user