mirror of
https://github.com/openai/codex.git
synced 2026-12-04 00:51:02 +00:00
Preserve request-level reasoning effort for memory and title workers (#46531)
## Why Memory consolidation and ephemeral title generation need to use their selected request-level reasoning effort even when managed settings enable reasoning-effort overrides. ## What changed - Exempt current and legacy memory consolidation sessions and ephemeral `thread_title` threads from reasoning-effort overrides. - Tag temporary title threads with `thread_title` and keep them excluded from agents overview refreshes. Recap threads retain the `system` tag. - Preserve override behavior for persisted `thread_title` threads and other ephemeral threads. ## Testing Extend regression coverage to verify request effort, omission of effort updates from exempt workers' requests, preservation of inherited history, title thread tagging, and overview filtering. GitOrigin-RevId: 8dbc2eb13509f9c80f90d5798a56ea33fad2a0bc
This commit is contained in:
@@ -91,6 +91,7 @@ use codex_protocol::protocol::Event as ProtocolEvent;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::InternalSessionSource;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use codex_protocol::protocol::W3cTraceContext;
|
||||
use codex_rollout_trace::InferenceTraceAttempt;
|
||||
use codex_rollout_trace::InferenceTraceContext;
|
||||
@@ -494,10 +495,16 @@ impl ModelClient {
|
||||
let auth_env_telemetry =
|
||||
collect_auth_env_telemetry(model_provider.info(), codex_api_key_env_enabled);
|
||||
let include_attestation = model_provider.supports_attestation();
|
||||
// Reviewers use their own request-level effort even when managed requirements
|
||||
// pin the parent's feature on. Share this decision with update injection and pinning.
|
||||
// Fixed-effort workers use request-level effort even when managed requirements
|
||||
// pin the feature on. Share this decision with update injection and pinning.
|
||||
let memory_consolidation = matches!(
|
||||
&session_source,
|
||||
SessionSource::Internal(InternalSessionSource::MemoryConsolidation)
|
||||
| SessionSource::SubAgent(SubAgentSource::MemoryConsolidation)
|
||||
);
|
||||
let reasoning_effort_override_enabled = reasoning_effort_override_enabled
|
||||
&& !crate::guardian::is_basic_session_source(&session_source);
|
||||
&& !crate::guardian::is_basic_session_source(&session_source)
|
||||
&& !memory_consolidation;
|
||||
Self {
|
||||
state: Arc::new(ModelClientState {
|
||||
thread_id,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! Only trusted harness items establish overrides. Replay preserves startup prewarm's
|
||||
//! baseline while it is retained.
|
||||
//! Successful compaction retires the overrides and allows a fresh request baseline.
|
||||
//! Synchronous Guardian reviewers always use their selected request-level effort.
|
||||
//! Fixed-effort workers always use their selected request-level effort.
|
||||
//! Unsupported models use selected request effort without rewriting saved updates.
|
||||
|
||||
use super::session::Session;
|
||||
|
||||
@@ -1618,6 +1618,14 @@ impl Session {
|
||||
&initial_history,
|
||||
);
|
||||
let codex_responses_headers = thread_extension_data.get::<crate::CodexResponsesHeaders>();
|
||||
// Ephemeral title requests use request-level effort even when managed settings
|
||||
// enable overrides. The client-supplied tag selects cache behavior, not permissions.
|
||||
let title_request = config.ephemeral && matches!(
|
||||
session_configuration.thread_source.as_ref(),
|
||||
Some(ThreadSource::Feature(feature)) if feature == "thread_title"
|
||||
);
|
||||
let reasoning_effort_override_enabled =
|
||||
config.features.enabled(Feature::ReasoningEffortOverride) && !title_request;
|
||||
let services = SessionServices {
|
||||
// Start with an empty connection set. The initialized set is
|
||||
// published after SessionConfigured so MCP events follow it.
|
||||
@@ -1681,7 +1689,7 @@ impl Session {
|
||||
session_configuration.originator.clone(),
|
||||
config.model_verbosity,
|
||||
config.features.enabled(Feature::ContentItemKinds),
|
||||
config.features.enabled(Feature::ReasoningEffortOverride),
|
||||
reasoning_effort_override_enabled,
|
||||
config.features.enabled(Feature::EnableRequestCompression),
|
||||
config.features.enabled(Feature::RuntimeMetrics),
|
||||
Self::build_model_client_beta_features_header(config.as_ref()),
|
||||
|
||||
@@ -77,21 +77,36 @@ fn message(role: &str, text: &str) -> Value {
|
||||
})
|
||||
}
|
||||
|
||||
#[test_case(SessionSource::Internal(InternalSessionSource::Guardian); "internal guardian")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Other("guardian".to_string())); "legacy guardian")]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum WorkerOverrides {
|
||||
Enabled,
|
||||
Disabled,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum WorkerHistory {
|
||||
Persisted,
|
||||
Ephemeral,
|
||||
}
|
||||
|
||||
#[test_case(SessionSource::Internal(InternalSessionSource::Guardian), ThreadSource::GuardianReview, WorkerHistory::Persisted, WorkerOverrides::Disabled; "internal guardian")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::Other("guardian".to_string())), ThreadSource::GuardianReview, WorkerHistory::Persisted, WorkerOverrides::Disabled; "legacy guardian")]
|
||||
#[test_case(SessionSource::Internal(InternalSessionSource::MemoryConsolidation), ThreadSource::MemoryConsolidation, WorkerHistory::Persisted, WorkerOverrides::Disabled; "memory consolidation")]
|
||||
#[test_case(SessionSource::SubAgent(SubAgentSource::MemoryConsolidation), ThreadSource::MemoryConsolidation, WorkerHistory::Persisted, WorkerOverrides::Disabled; "legacy memory consolidation")]
|
||||
#[test_case(SessionSource::Cli, ThreadSource::Feature("thread_title".to_string()), WorkerHistory::Ephemeral, WorkerOverrides::Disabled; "ephemeral thread title")]
|
||||
#[test_case(SessionSource::Cli, ThreadSource::Feature("thread_title".to_string()), WorkerHistory::Persisted, WorkerOverrides::Enabled; "persisted thread title")]
|
||||
#[test_case(SessionSource::Cli, ThreadSource::Feature("system".to_string()), WorkerHistory::Ephemeral, WorkerOverrides::Enabled; "other ephemeral thread")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn sync_guardian_ignores_managed_reasoning_override(
|
||||
async fn worker_reasoning_overrides_follow_effective_client_policy(
|
||||
session_source: SessionSource,
|
||||
thread_source: ThreadSource,
|
||||
history: WorkerHistory,
|
||||
overrides: WorkerOverrides,
|
||||
) -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = responses::start_mock_server().await;
|
||||
let mut mocks = Vec::new();
|
||||
for id in [
|
||||
"parent-medium",
|
||||
"parent-high",
|
||||
"reviewer-low",
|
||||
"reviewer-high",
|
||||
] {
|
||||
for id in ["parent-medium", "parent-high", "worker-low", "worker-high"] {
|
||||
mocks.push(
|
||||
responses::mount_sse_once(&server, responses::sse(vec![responses::ev_completed(id)]))
|
||||
.await,
|
||||
@@ -119,12 +134,13 @@ async fn sync_guardian_ignores_managed_reasoning_override(
|
||||
let parent = Arc::clone(&test.codex);
|
||||
parent.shutdown_and_wait().await?;
|
||||
|
||||
// Fork real parent history, including its trusted effort updates, into a reviewer.
|
||||
let config = test.config.clone();
|
||||
// Fork real parent history while managed requirements keep the feature enabled.
|
||||
let mut config = test.config.clone();
|
||||
config.ephemeral = history == WorkerHistory::Ephemeral;
|
||||
assert!(config.features.enabled(Feature::ReasoningEffortOverride));
|
||||
let mut options = StartThreadOptions::new(config);
|
||||
options.session_source = Some(session_source);
|
||||
options.thread_source = Some(ThreadSource::GuardianReview);
|
||||
options.thread_source = Some(thread_source);
|
||||
let forked = test
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
@@ -144,7 +160,7 @@ async fn sync_guardian_ignores_managed_reasoning_override(
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
test.submit_text_turn("review an action").await?;
|
||||
test.submit_text_turn("perform the worker task").await?;
|
||||
}
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
|
||||
@@ -161,24 +177,50 @@ async fn sync_guardian_ignores_managed_reasoning_override(
|
||||
Value::from("medium"),
|
||||
Value::from("medium"),
|
||||
Value::from("low"),
|
||||
Value::from("high"),
|
||||
Value::from(if overrides == WorkerOverrides::Enabled {
|
||||
"low"
|
||||
} else {
|
||||
"high"
|
||||
}),
|
||||
],
|
||||
);
|
||||
let inherited_updates = vec![
|
||||
effort_update(ReasoningEffort::Medium),
|
||||
effort_update(ReasoningEffort::High),
|
||||
];
|
||||
let mut worker_updates = inherited_updates.clone();
|
||||
let expected_worker_requests = if overrides == WorkerOverrides::Enabled {
|
||||
worker_updates.push(effort_update(ReasoningEffort::Low));
|
||||
let first = worker_updates.clone();
|
||||
worker_updates.push(effort_update(ReasoningEffort::High));
|
||||
vec![first, worker_updates.clone()]
|
||||
} else {
|
||||
vec![vec![], vec![]]
|
||||
};
|
||||
assert_eq!(
|
||||
requests.iter().map(effort_updates).collect::<Vec<_>>(),
|
||||
vec![
|
||||
vec![effort_update(ReasoningEffort::Medium)],
|
||||
inherited_updates.clone(),
|
||||
vec![],
|
||||
vec![],
|
||||
],
|
||||
[
|
||||
vec![
|
||||
vec![effort_update(ReasoningEffort::Medium)],
|
||||
inherited_updates.clone(),
|
||||
],
|
||||
expected_worker_requests
|
||||
]
|
||||
.concat(),
|
||||
);
|
||||
// Reviewers neither append new updates nor erase inherited durable history.
|
||||
for thread in [&parent, &test.codex] {
|
||||
// Fixed-effort workers neither append updates nor erase inherited live or durable history.
|
||||
for (thread, expected) in [(&parent, inherited_updates), (&test.codex, worker_updates)] {
|
||||
let context_updates = thread
|
||||
.conversation_history_snapshot()
|
||||
.await
|
||||
.items()
|
||||
.filter(|item| matches!(item, ResponseItem::ConfigurationUpdate { .. }))
|
||||
.map(|item| serde_json::to_value(item).expect("serialize context update"))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(context_updates, expected);
|
||||
if thread.config_snapshot().await.ephemeral {
|
||||
continue;
|
||||
}
|
||||
let saved_updates = thread
|
||||
.load_history(/*include_archived*/ false)
|
||||
.await?
|
||||
@@ -192,7 +234,7 @@ async fn sync_guardian_ignores_managed_reasoning_override(
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(saved_updates, inherited_updates);
|
||||
assert_eq!(saved_updates, expected);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -622,6 +622,15 @@ async fn finish_overview_refresh(
|
||||
|
||||
#[tokio::test]
|
||||
async fn hidden_system_thread_does_not_refresh_shared_overview() {
|
||||
check_hidden_thread_does_not_refresh_shared_overview("system").await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn hidden_title_thread_does_not_refresh_shared_overview() {
|
||||
check_hidden_thread_does_not_refresh_shared_overview("thread_title").await;
|
||||
}
|
||||
|
||||
async fn check_hidden_thread_does_not_refresh_shared_overview(source: &str) {
|
||||
let mut app = make_test_app().await;
|
||||
let app_server = crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref())
|
||||
.await
|
||||
@@ -648,7 +657,7 @@ async fn hidden_system_thread_does_not_refresh_shared_overview() {
|
||||
ThreadStatus::Idle,
|
||||
);
|
||||
thread.ephemeral = true;
|
||||
thread.thread_source = Some(ThreadSource::Feature("system".to_string()));
|
||||
thread.thread_source = Some(ThreadSource::Feature(source.to_string()));
|
||||
|
||||
app.handle_app_server_event(
|
||||
&app_server,
|
||||
@@ -679,7 +688,7 @@ async fn hidden_system_thread_does_not_refresh_shared_overview() {
|
||||
"Persisted system thread",
|
||||
ThreadStatus::Idle,
|
||||
);
|
||||
thread.thread_source = Some(ThreadSource::Feature("system".to_string()));
|
||||
thread.thread_source = Some(ThreadSource::Feature(source.to_string()));
|
||||
|
||||
app.handle_app_server_event(
|
||||
&app_server,
|
||||
|
||||
@@ -124,7 +124,7 @@ impl App {
|
||||
&& started.thread.ephemeral
|
||||
&& matches!(
|
||||
started.thread.thread_source.as_ref(),
|
||||
Some(ThreadSource::Feature(feature)) if feature == "system"
|
||||
Some(ThreadSource::Feature(feature)) if matches!(feature.as_str(), "system" | "thread_title")
|
||||
)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -17,6 +17,7 @@ use crate::temporary_structured_request::TemporaryStructuredThreadOptions;
|
||||
use crate::temporary_structured_request::run_temporary_structured_turn;
|
||||
use crate::temporary_structured_request::start_temporary_thread;
|
||||
use crate::temporary_structured_request::unsubscribe_temporary_thread;
|
||||
use codex_app_server_protocol::ThreadSource;
|
||||
use codex_app_server_protocol::Turn;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_context_fragments::ContextualUserFragment;
|
||||
@@ -222,6 +223,7 @@ impl App {
|
||||
config.cwd.display().to_string()
|
||||
};
|
||||
let options = TemporaryStructuredThreadOptions {
|
||||
thread_source: ThreadSource::Feature("system".to_string()),
|
||||
model,
|
||||
model_provider: config.model_provider_id.clone(),
|
||||
cwd,
|
||||
|
||||
@@ -453,6 +453,7 @@ async fn temporary_recap_threads_disable_memories_and_remote_mcp_servers() -> Re
|
||||
|
||||
let config = app.chat_widget.config_ref();
|
||||
let options = crate::temporary_structured_request::TemporaryStructuredThreadOptions {
|
||||
thread_source: codex_app_server_protocol::ThreadSource::Feature("system".to_string()),
|
||||
model: app.chat_widget.current_model().to_string(),
|
||||
model_provider: config.model_provider_id.clone(),
|
||||
cwd: config.cwd.display().to_string(),
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::temporary_structured_request::start_temporary_thread;
|
||||
use crate::temporary_structured_request::unsubscribe_temporary_thread;
|
||||
use codex_app_server_protocol::ServerNotification;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_app_server_protocol::ThreadSource;
|
||||
use codex_app_server_protocol::UserInput;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::models::MessagePhase;
|
||||
@@ -100,6 +101,7 @@ impl App {
|
||||
let effort = (model == THREAD_TITLE_MODEL).then_some(ReasoningEffort::Low);
|
||||
let config = self.chat_widget.config_ref();
|
||||
let options = TemporaryStructuredThreadOptions {
|
||||
thread_source: ThreadSource::Feature("thread_title".to_string()),
|
||||
model,
|
||||
model_provider: config.model_provider_id.clone(),
|
||||
cwd: config.cwd.display().to_string(),
|
||||
|
||||
@@ -20,6 +20,7 @@ use codex_app_server_client::AppServerEvent;
|
||||
use codex_app_server_protocol::ItemCompletedNotification;
|
||||
use codex_app_server_protocol::ServerNotification;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_app_server_protocol::ThreadSource;
|
||||
use codex_app_server_protocol::Turn;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_app_server_protocol::UserInput;
|
||||
@@ -345,6 +346,15 @@ async fn check_thread_title_generation(scenario: TitleScenario) -> color_eyre::R
|
||||
app.handle_event(&mut tui, &mut app_server, *event).await?;
|
||||
}
|
||||
TitleDriveEvent::Server(event) => {
|
||||
if let AppServerEvent::ServerNotification(notification) = &event
|
||||
&& let ServerNotification::ThreadStarted(started) = notification.as_ref()
|
||||
&& started.thread.ephemeral
|
||||
{
|
||||
assert_eq!(
|
||||
started.thread.thread_source,
|
||||
Some(ThreadSource::Feature("thread_title".to_string())),
|
||||
);
|
||||
}
|
||||
if let AppServerEvent::ServerNotification(notification) = &event
|
||||
&& let ServerNotification::TurnCompleted(completed) = notification.as_ref()
|
||||
&& Some(&completed.thread_id) == temporary_thread_id.as_ref()
|
||||
|
||||
@@ -35,6 +35,7 @@ const STRUCTURED_RESPONSE_MAX_BYTES: usize = 8 * 1024;
|
||||
|
||||
/// Preserve the visible thread's provider, permissions, and external-tool isolation.
|
||||
pub(crate) struct TemporaryStructuredThreadOptions {
|
||||
pub(crate) thread_source: ThreadSource,
|
||||
pub(crate) model: String,
|
||||
pub(crate) model_provider: String,
|
||||
pub(crate) cwd: String,
|
||||
@@ -51,6 +52,7 @@ pub(crate) async fn start_temporary_thread(
|
||||
options: TemporaryStructuredThreadOptions,
|
||||
) -> color_eyre::Result<ThreadStartResponse> {
|
||||
let TemporaryStructuredThreadOptions {
|
||||
thread_source,
|
||||
model,
|
||||
model_provider,
|
||||
cwd,
|
||||
@@ -140,7 +142,7 @@ pub(crate) async fn start_temporary_thread(
|
||||
permissions: custom_permission_profile.clone(),
|
||||
runtime_workspace_roots: Some(Vec::new()),
|
||||
ephemeral: Some(true),
|
||||
thread_source: Some(ThreadSource::Feature("system".to_string())),
|
||||
thread_source: Some(thread_source),
|
||||
environments: Some(Vec::new()),
|
||||
dynamic_tools: Some(Vec::new()),
|
||||
selected_capability_roots: Some(Vec::new()),
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::test_support::PathBufExt;
|
||||
use codex_app_server_protocol::ItemCompletedNotification;
|
||||
use codex_app_server_protocol::ServerNotification;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_app_server_protocol::ThreadSource;
|
||||
use codex_app_server_protocol::Turn;
|
||||
use codex_app_server_protocol::TurnCompletedNotification;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
@@ -74,6 +75,7 @@ async fn preserves_custom_permissions_and_disables_required_mcp_servers() -> col
|
||||
let response = start_temporary_thread(
|
||||
&app_server.request_handle(),
|
||||
TemporaryStructuredThreadOptions {
|
||||
thread_source: ThreadSource::Feature("thread_title".to_string()),
|
||||
model: "gpt-5.2".to_string(),
|
||||
model_provider: config.model_provider_id.clone(),
|
||||
cwd: config.cwd.display().to_string(),
|
||||
@@ -88,11 +90,13 @@ async fn preserves_custom_permissions_and_disables_required_mcp_servers() -> col
|
||||
response.active_permission_profile.map(|profile| profile.id),
|
||||
response.model_provider,
|
||||
response.thread.ephemeral,
|
||||
response.thread.thread_source,
|
||||
),
|
||||
(
|
||||
Some("title-restricted".to_string()),
|
||||
config.model_provider_id,
|
||||
true,
|
||||
Some(ThreadSource::Feature("thread_title".to_string())),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user