Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Move Guardian thread context into `guardianv2` configuration (#43104)

felixxia-oaie4ce83419b41
diff --git a/codex-rs/app-server/tests/suite/v2/guardian_v2.rs b/codex-rs/app-server/tests/suite/v2/guardian_v2.rs
index cdbaed21bf..bbc85476d6 100644
--- a/codex-rs/app-server/tests/suite/v2/guardian_v2.rs
+++ b/codex-rs/app-server/tests/suite/v2/guardian_v2.rs
@@ -774,9 +774,9 @@ async fn guardian_v2_routes_scoped_tool_approvals(
};
let guardian_scope_config = match scope {
GuardianToolScope::AllTools => {
- "\n\n[features.guardianv2]\nenabled = true\n\n[features.guardianv2.review_scope]\ncomputer_use_only = false"
+ "\n\n[features.guardianv2.review_scope]\ncomputer_use_only = false"
}
- GuardianToolScope::ComputerUseOnly { .. } => "\n\n[features.guardianv2]\nenabled = true",
+ GuardianToolScope::ComputerUseOnly { .. } => "",
};
let tool_approval_mode = if node_repl_review_required {
"auto"
@@ -792,12 +792,9 @@ async fn guardian_v2_routes_scoped_tool_approvals(
analytics_server.uri(),
))
.with_extra_config(&format!(
- "[mcp_servers.{server_name}]\nurl = \"{mcp_server_url}/mcp\"\ndefault_tools_approval_mode = \"{tool_approval_mode}\"\n\n[analytics]\nenabled = true\n\n[otel]\nmetrics_exporter = {{ otlp-http = {{ endpoint = \"{responses_url}/metrics\", protocol = \"json\" }} }}{guardian_scope_config}"
+ "[mcp_servers.{server_name}]\nurl = \"{mcp_server_url}/mcp\"\ndefault_tools_approval_mode = \"{tool_approval_mode}\"\n\n[analytics]\nenabled = true\n\n[otel]\nmetrics_exporter = {{ otlp-http = {{ endpoint = \"{responses_url}/metrics\", protocol = \"json\" }} }}\n\n[features.guardianv2]\nenabled = true\nthread_context = {thread_context_enabled}{guardian_scope_config}"
))
.enable_feature(Feature::GuardianApproval);
- if thread_context_enabled {
- mock_config = mock_config.enable_feature(Feature::GuardianThreadContext);
- }
if lifecycle.has_user_input() || lifecycle.has_root_user_input() {
mock_config = mock_config.enable_feature(Feature::DefaultModeRequestUserInput);
}
diff --git a/codex-rs/app-server/tests/suite/v2/guardian_v2_history_tests.rs b/codex-rs/app-server/tests/suite/v2/guardian_v2_history_tests.rs
index dc94f46b0d..d1c99b4b01 100644
--- a/codex-rs/app-server/tests/suite/v2/guardian_v2_history_tests.rs
+++ b/codex-rs/app-server/tests/suite/v2/guardian_v2_history_tests.rs
@@ -273,6 +273,10 @@ async fn guardians_retain_evidence_after_compaction_and_discard_it_after_rollbac
});
let (mcp_url, mcp_server) = start_mcp_server(/*sensitive_action*/ None).await?;
let codex_home = TempDir::new()?;
+ let thread_context_enabled = match context_path {
+ ContextPath::Legacy => false,
+ ContextPath::ThreadOwned => true,
+ };
let mut mock_config = MockResponsesConfig::new(&responses_url)
.with_provider_name("OpenAI")
.with_provider_config("requires_openai_auth = true\nsupports_websockets = false")
@@ -284,15 +288,11 @@ async fn guardians_retain_evidence_after_compaction_and_discard_it_after_rollbac
.disable_feature(Feature::RemoteCompactionV2)
.disable_feature(Feature::TokenBudget)
.with_extra_config(&format!(
- "[mcp_servers.{TEST_SERVER_NAME}]\nurl = \"{mcp_url}/mcp\"\ndefault_tools_approval_mode = \"prompt\"\n\n[features.guardianv2]\nenabled = true\npersist_scores = true\nreuse_parent_compaction = {reuse_parent_compaction}\n\n[features.guardianv2.review_scope]\ncomputer_use_only = false"
+ "[mcp_servers.{TEST_SERVER_NAME}]\nurl = \"{mcp_url}/mcp\"\ndefault_tools_approval_mode = \"prompt\"\n\n[features.guardianv2]\nenabled = true\nthread_context = {thread_context_enabled}\npersist_scores = true\nreuse_parent_compaction = {reuse_parent_compaction}\n\n[features.guardianv2.review_scope]\ncomputer_use_only = false"
));
if matches!(context_path, ContextPath::ThreadOwned) {
mock_config = mock_config.disable_feature(Feature::GuardianReuseParentCompaction);
}
- mock_config = match context_path {
- ContextPath::Legacy => mock_config.disable_feature(Feature::GuardianThreadContext),
- ContextPath::ThreadOwned => mock_config.enable_feature(Feature::GuardianThreadContext),
- };
mock_config.write(codex_home.path())?;
let config = load_default_config_for_test(&codex_home).await;
let models = [
diff --git a/codex-rs/config/src/schema.rs b/codex-rs/config/src/schema.rs
index 550f0c3d54..fd144796ee 100644
--- a/codex-rs/config/src/schema.rs
+++ b/codex-rs/config/src/schema.rs
@@ -77,6 +77,10 @@ pub fn features_schema(schema_gen: &mut SchemaGenerator) -> Schema {
);
continue;
}
+ if feature.id == codex_features::Feature::GuardianThreadContext {
+ // This setting is already part of the guardianv2 feature table.
+ continue;
+ }
if feature.id == codex_features::Feature::GuardianV2 {
validation.properties.insert(
feature.key.to_string(),
diff --git a/codex-rs/core/config.schema.json b/codex-rs/core/config.schema.json
index d66fa6a104..095a2bcc59 100644
--- a/codex-rs/core/config.schema.json
+++ b/codex-rs/core/config.schema.json
@@ -774,9 +774,6 @@
"guardian_reuse_parent_compaction": {
"type": "boolean"
},
- "guardian_thread_context": {
- "type": "boolean"
- },
"guardianv2": {
"$ref": "#/definitions/FeatureToml_for_GuardianV2ConfigToml"
},
@@ -1561,6 +1558,10 @@
"minimum": 0.0,
"type": "number"
},
+ "thread_context": {
+ "description": "Use thread-owned context for sync and async Guardian. Defaults to false. Independent of the Guardian v2 `enabled` toggle.",
+ "type": "boolean"
+ },
"transcript": {
"$ref": "#/definitions/GuardianV2TranscriptConfigToml"
}
@@ -6165,9 +6166,6 @@
"guardian_reuse_parent_compaction": {
"type": "boolean"
},
- "guardian_thread_context": {
- "type": "boolean"
- },
"guardianv2": {
"$ref": "#/definitions/FeatureToml_for_GuardianV2ConfigToml"
},
diff --git a/codex-rs/ext/guardian-v2/src/async_scorer/extension_tests.rs b/codex-rs/ext/guardian-v2/src/async_scorer/extension_tests.rs
index 5f8f7dc03e..85daa63ea7 100644
--- a/codex-rs/ext/guardian-v2/src/async_scorer/extension_tests.rs
+++ b/codex-rs/ext/guardian-v2/src/async_scorer/extension_tests.rs
@@ -2087,7 +2087,7 @@ async fn assert_luna_pool_context(thread_context_enabled: bool) -> Result<()> {
conversation_history,
r#"{"path":"README.md"}"#,
Some(TEST_GUARDIAN_POLICY),
- &format!("[features]\nguardian_thread_context = {thread_context_enabled}\n"),
+ &format!("[features.guardianv2]\nthread_context = {thread_context_enabled}\n"),
/*model_defaults*/ None,
)
.await?;
@@ -2558,7 +2558,7 @@ async fn assert_compaction_approval_policy(thread_context_enabled: bool) -> Resu
skip_if_no_network!(Ok(()));
let fixture = GuardianFailureFixture::with_config(&format!(
- "[features]\nguardian_thread_context = {thread_context_enabled}\n"
+ "[features.guardianv2]\nthread_context = {thread_context_enabled}\n"
))
.await?;
let thread_store = fixture.test.codex.thread_extension_data();
@@ -3350,7 +3350,7 @@ async fn legacy_contributor_can_disable_parent_compaction_reuse() -> Result<()>
oversized_compaction,
user_instruction("Inspect the repository guidelines."),
];
- let configuration = "[features]\nguardian_thread_context = false\n\n[features.guardianv2]\nenabled = true\nreuse_parent_compaction = false\nmax_parent_compaction_tokens = 256\n";
+ let configuration = "[features.guardianv2]\nthread_context = false\nenabled = true\nreuse_parent_compaction = false\nmax_parent_compaction_tokens = 256\n";
let (request, test, _registry) = sample_configured_conversation_history(
conversation_history,
r#"{"path":"README.md"}"#,
diff --git a/codex-rs/features/src/feature_configs.rs b/codex-rs/features/src/feature_configs.rs
index 32d3cbaf0e..b933b03615 100644
--- a/codex-rs/features/src/feature_configs.rs
+++ b/codex-rs/features/src/feature_configs.rs
@@ -129,6 +129,10 @@ pub struct GuardianV2ConfigToml {
/// Route Guardian review and classification through the unmetered Codex endpoints.
#[serde(skip_serializing_if = "Option::is_none")]
pub free_guardian: Option<bool>,
+ /// Use thread-owned context for sync and async Guardian. Defaults to false.
+ /// Independent of the Guardian v2 `enabled` toggle.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub thread_context: Option<bool>,
/// Persist reviewed actions and risk scores to rollout files for debugging.
#[serde(skip_serializing_if = "Option::is_none")]
pub persist_scores: Option<bool>,
diff --git a/codex-rs/features/src/lib.rs b/codex-rs/features/src/lib.rs
index 660e415238..83d16523af 100644
--- a/codex-rs/features/src/lib.rs
+++ b/codex-rs/features/src/lib.rs
@@ -815,6 +815,11 @@ impl FeaturesToml {
if let Some(enabled) = self.guardianv2.as_ref().and_then(FeatureToml::enabled) {
entries.insert(Feature::GuardianV2.key().to_string(), enabled);
}
+ if let Some(FeatureToml::Config(config)) = &self.guardianv2
+ && let Some(enabled) = config.thread_context
+ {
+ entries.insert(Feature::GuardianThreadContext.key().to_string(), enabled);
+ }
if let Some(enabled) = self.multi_agent_v2.as_ref().and_then(FeatureToml::enabled) {
entries.insert(Feature::MultiAgentV2.key().to_string(), enabled);
}
@@ -1544,7 +1549,7 @@ pub const FEATURES: &[FeatureSpec] = &[
},
FeatureSpec {
id: Feature::GuardianThreadContext,
- key: "guardian_thread_context",
+ key: "guardianv2.thread_context",
stage: Stage::UnderDevelopment,
default_enabled: false,
},
diff --git a/codex-rs/features/src/tests.rs b/codex-rs/features/src/tests.rs
index 93ab6dc6d7..90c7b40efa 100644
--- a/codex-rs/features/src/tests.rs
+++ b/codex-rs/features/src/tests.rs
@@ -163,19 +163,18 @@ fn guardian_v2_feature_config_preserves_boolean_toggle() {
}
#[test]
-fn guardian_thread_context_resolves_boolean_config_and_profile_overrides() {
+fn guardian_thread_context_resolves_nested_config_and_profile_overrides() {
+ let enabled_context = "[guardianv2]\nthread_context = true";
+ let disabled_context = "[guardianv2]\nthread_context = false";
for (base, profile, enabled) in [
("", "", false),
- ("guardian_thread_context = false", "", false),
- ("guardian_thread_context = true", "", true),
+ (disabled_context, "", false),
+ (enabled_context, "", true),
+ (enabled_context, disabled_context, false),
+ (disabled_context, enabled_context, true),
(
- "guardian_thread_context = true",
- "guardian_thread_context = false",
- false,
- ),
- (
- "guardian_thread_context = false",
- "guardian_thread_context = true",
+ "[guardianv2]\nenabled = false\nthread_context = true",
+ "",
true,
),
] {
@@ -238,6 +237,7 @@ max_recent_non_user_entries = 12
Some(FeatureToml::Config(crate::GuardianV2ConfigToml {
enabled: Some(true),
free_guardian: Some(true),
+ thread_context: None,
persist_scores: Some(true),
classifier_instructions: Some("Review this action".to_owned()),
review_threshold: Some(0.65),