[codex] allow disabling environment context injection (#16745)

This adds an `include_environment_context` config/profile flag that
defaults on, and guards both initial injection and later environment
updates to allow skipping injection of `<environment_context>`.
This commit is contained in:
Thibault Sottiaux
2026-04-03 18:06:52 -07:00
committed by GitHub
parent 8d19646861
commit 91ca49e53c
8 changed files with 134 additions and 33 deletions
+7
View File
@@ -4495,6 +4495,7 @@ fn test_precedence_fixture_with_o3_profile() -> std::io::Result<()> {
guardian_developer_instructions: None,
include_permissions_instructions: true,
include_apps_instructions: true,
include_environment_context: true,
compact_prompt: None,
commit_attribution: None,
forced_chatgpt_workspace_id: None,
@@ -4639,6 +4640,7 @@ fn test_precedence_fixture_with_gpt3_profile() -> std::io::Result<()> {
guardian_developer_instructions: None,
include_permissions_instructions: true,
include_apps_instructions: true,
include_environment_context: true,
compact_prompt: None,
commit_attribution: None,
forced_chatgpt_workspace_id: None,
@@ -4781,6 +4783,7 @@ fn test_precedence_fixture_with_zdr_profile() -> std::io::Result<()> {
guardian_developer_instructions: None,
include_permissions_instructions: true,
include_apps_instructions: true,
include_environment_context: true,
compact_prompt: None,
commit_attribution: None,
forced_chatgpt_workspace_id: None,
@@ -4909,6 +4912,7 @@ fn test_precedence_fixture_with_gpt5_profile() -> std::io::Result<()> {
guardian_developer_instructions: None,
include_permissions_instructions: true,
include_apps_instructions: true,
include_environment_context: true,
compact_prompt: None,
commit_attribution: None,
forced_chatgpt_workspace_id: None,
@@ -5799,10 +5803,12 @@ async fn prompt_instruction_blocks_can_be_disabled_from_config_and_profiles() ->
codex_home.path().join(CONFIG_TOML_FILE),
r#"include_permissions_instructions = false
include_apps_instructions = false
include_environment_context = false
profile = "chatty"
[profiles.chatty]
include_permissions_instructions = true
include_environment_context = true
"#,
)?;
@@ -5814,6 +5820,7 @@ include_permissions_instructions = true
assert!(config.include_permissions_instructions);
assert!(!config.include_apps_instructions);
assert!(config.include_environment_context);
Ok(())
}
+11
View File
@@ -286,6 +286,9 @@ pub struct Config {
/// Whether to inject the `<apps_instructions>` developer block.
pub include_apps_instructions: bool,
/// Whether to inject the `<environment_context>` user block.
pub include_environment_context: bool,
/// Compact prompt override.
pub compact_prompt: Option<String>,
@@ -1195,6 +1198,9 @@ pub struct ConfigToml {
/// Whether to inject the `<apps_instructions>` developer block.
pub include_apps_instructions: Option<bool>,
/// Whether to inject the `<environment_context>` user block.
pub include_environment_context: Option<bool>,
/// Optional path to a file containing model instructions that will override
/// the built-in instructions for the selected model. Users are STRONGLY
/// DISCOURAGED from using this field, as deviating from the instructions
@@ -2472,6 +2478,10 @@ impl Config {
.include_apps_instructions
.or(cfg.include_apps_instructions)
.unwrap_or(true);
let include_environment_context = config_profile
.include_environment_context
.or(cfg.include_environment_context)
.unwrap_or(true);
let guardian_developer_instructions = guardian_developer_instructions_from_requirements(
config_layer_stack.requirements_toml(),
);
@@ -2640,6 +2650,7 @@ impl Config {
commit_attribution,
include_permissions_instructions,
include_apps_instructions,
include_environment_context,
// The config.toml omits "_mode" because it's a config file. However, "_mode"
// is important in code to differentiate the mode from the store implementation.
cli_auth_credentials_store_mode: cfg.cli_auth_credentials_store.unwrap_or_default(),
+1
View File
@@ -51,6 +51,7 @@ pub struct ConfigProfile {
pub include_apply_patch_tool: Option<bool>,
pub include_permissions_instructions: Option<bool>,
pub include_apps_instructions: Option<bool>,
pub include_environment_context: Option<bool>,
pub experimental_use_unified_exec_tool: Option<bool>,
pub experimental_use_freeform_apply_patch: Option<bool>,
pub tools_view_image: Option<bool>,