diff --git a/codex-rs/app-server/src/request_processors.rs b/codex-rs/app-server/src/request_processors.rs index 9e4dd01ed6..3e9abc5e17 100644 --- a/codex-rs/app-server/src/request_processors.rs +++ b/codex-rs/app-server/src/request_processors.rs @@ -209,6 +209,7 @@ use codex_app_server_protocol::ThreadDecrementElicitationResponse; use codex_app_server_protocol::ThreadDeleteParams; use codex_app_server_protocol::ThreadDeleteResponse; use codex_app_server_protocol::ThreadDeletedNotification; +use codex_app_server_protocol::ThreadEnvironment; use codex_app_server_protocol::ThreadForkParams; use codex_app_server_protocol::ThreadForkResponse; use codex_app_server_protocol::ThreadGoal; @@ -616,11 +617,11 @@ pub(crate) fn apply_live_thread_settings( loaded_thread: &CodexThread, config_snapshot: &ThreadConfigSnapshot, ) { - thread.daybreak_program_propagation_enrolled = - Some(loaded_thread.daybreak_program_propagation_enrolled()); - thread.model = Some(config_snapshot.model.clone()); - thread.reasoning_effort = config_snapshot.reasoning_effort.clone(); - thread.environments = Some( + apply_thread_view_settings( + thread, + loaded_thread, + config_snapshot.model.clone(), + config_snapshot.reasoning_effort.clone(), config_snapshot .environment_selections() .iter() @@ -629,6 +630,20 @@ pub(crate) fn apply_live_thread_settings( ); } +fn apply_thread_view_settings( + thread: &mut Thread, + loaded_thread: &CodexThread, + model: String, + reasoning_effort: Option, + environments: Vec, +) { + thread.daybreak_program_propagation_enrolled = + Some(loaded_thread.daybreak_program_propagation_enrolled()); + thread.model = Some(model); + thread.reasoning_effort = reasoning_effort; + thread.environments = Some(environments); +} + fn resolve_request_cwd(cwd: Option) -> Result, JSONRPCErrorError> { cwd.map(|cwd| { AbsolutePathBuf::relative_to_current_dir(path_utils::normalize_for_native_workdir(cwd)) diff --git a/codex-rs/app-server/src/request_processors/thread_enrichment.rs b/codex-rs/app-server/src/request_processors/thread_enrichment.rs index 7ca32ea0f3..840a91b2b4 100644 --- a/codex-rs/app-server/src/request_processors/thread_enrichment.rs +++ b/codex-rs/app-server/src/request_processors/thread_enrichment.rs @@ -1,9 +1,10 @@ -use super::apply_live_thread_settings; +use super::apply_thread_view_settings; use super::thread_input::can_accept_direct_input; use crate::thread_status::ThreadWatchManager; use crate::thread_status::resolve_thread_status; use codex_app_server_protocol::SessionSource; use codex_app_server_protocol::Thread; +use codex_app_server_protocol::ThreadEnvironment; use codex_app_server_protocol::ThreadStatus; use codex_core::ThreadManager; use codex_protocol::ThreadId; @@ -55,8 +56,22 @@ async fn enrich_loaded_thread( let Ok(loaded_thread) = thread_manager.get_thread(thread_id).await else { return; }; - let config_snapshot = loaded_thread.configured_snapshot().await; - apply_live_thread_settings(thread, &loaded_thread, &config_snapshot); + let settings = loaded_thread.thread_view_settings().await; + apply_thread_view_settings( + thread, + &loaded_thread, + settings.model, + settings.reasoning_effort, + settings + .environments + .into_iter() + .map(|env| ThreadEnvironment { + environment_id: env.environment_id, + cwd: env.cwd.into(), + runtime_workspace_roots: env.workspace_roots.into_iter().map(Into::into).collect(), + }) + .collect(), + ); if !matches!( &thread.source, SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. }) @@ -85,6 +100,6 @@ async fn enrich_loaded_thread( } thread.can_accept_direct_input = Some(can_accept_direct_input( loaded_thread.multi_agent_version(), - &config_snapshot.session_source, + &settings.session_source, )); } diff --git a/codex-rs/app-server/tests/suite/v2/thread_environments.rs b/codex-rs/app-server/tests/suite/v2/thread_environments.rs index 6329b3c0ad..c0f179465e 100644 --- a/codex-rs/app-server/tests/suite/v2/thread_environments.rs +++ b/codex-rs/app-server/tests/suite/v2/thread_environments.rs @@ -37,14 +37,20 @@ async fn thread_environments_follow_the_loaded_thread_selection() -> Result<()> .with_codex_home(home.path()) .build_initialized() .await?; - let selection = first.auto_env_params()?; + let mut selection = first.auto_env_params()?; + let cwd = &first.auto_env()?.selection().cwd; + let roots = vec![cwd.join("src")?.into(), cwd.join("docs")?.into()]; + selection.runtime_workspace_roots = Some(roots.clone()); let expected = Some(vec![ThreadEnvironment { - environment_id: selection.environment_id, + environment_id: selection.environment_id.clone(), cwd: selection.cwd.clone(), - runtime_workspace_roots: vec![selection.cwd], + runtime_workspace_roots: roots, }]); let request = first - .send_thread_start_request_with_auto_env(ThreadStartParams::default()) + .send_thread_start_request(ThreadStartParams { + environments: Some(vec![selection]), + ..Default::default() + }) .await?; let started: ThreadStartResponse = timeout(DEFAULT_READ_TIMEOUT, first.read_response(request)).await??; diff --git a/codex-rs/core/src/codex_thread.rs b/codex-rs/core/src/codex_thread.rs index 0e8a49fd5a..8421fe034f 100644 --- a/codex-rs/core/src/codex_thread.rs +++ b/codex-rs/core/src/codex_thread.rs @@ -105,6 +105,33 @@ use codex_rollout::state_db::StateDbHandle; static LIVE_THREADS: Gauge = Gauge::new("core.threads.live"); +/// The live settings needed to display a thread list or search result. +#[derive(Debug, PartialEq)] +pub struct ThreadViewSettings { + pub model: String, + pub reasoning_effort: Option, + pub environments: Vec, + pub session_source: SessionSource, +} + +/// The selected workspace for display, without the environment's execution config. +#[derive(Debug, PartialEq)] +pub struct ThreadEnvironmentView { + pub environment_id: String, + pub cwd: PathUri, + pub workspace_roots: Vec, +} + +impl From<&TurnEnvironmentSelection> for ThreadEnvironmentView { + fn from(selection: &TurnEnvironmentSelection) -> Self { + Self { + environment_id: selection.environment_id.clone(), + cwd: selection.cwd.clone(), + workspace_roots: selection.workspace_roots.clone(), + } + } +} + #[derive(Clone, Debug)] pub struct ThreadConfigSnapshot { /// Trusted host country inherited by future turns. @@ -1500,6 +1527,11 @@ impl CodexThread { self.session.configured_snapshot().await } + /// Reads display settings without materializing an execution permission profile. + pub async fn thread_view_settings(&self) -> ThreadViewSettings { + self.session.thread_view_settings().await + } + pub async fn config_snapshot(&self) -> ThreadConfigSnapshot { self.session.thread_config_snapshot().await } diff --git a/codex-rs/core/src/lib.rs b/codex-rs/core/src/lib.rs index e03033386b..e3e1d9ac23 100644 --- a/codex-rs/core/src/lib.rs +++ b/codex-rs/core/src/lib.rs @@ -65,6 +65,8 @@ pub use codex_thread::GuardianAuthorizationVersion; pub use codex_thread::GuardianRootMessage; pub use codex_thread::GuardianRootSnapshot; pub use codex_thread::ThreadConfigSnapshot; +pub use codex_thread::ThreadEnvironmentView; +pub use codex_thread::ThreadViewSettings; pub use codex_thread::TurnAdmissionState; pub use guardian::GuardianInferenceContext; pub use guardian::ScoreAuthorization as GuardianScoreAuthorization; diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs index fb8bcb5ccf..6b4794dc98 100644 --- a/codex-rs/core/src/session/mod.rs +++ b/codex-rs/core/src/session/mod.rs @@ -2405,6 +2405,18 @@ impl Session { configuration.thread_config_snapshot(configuration.environments.clone()) } + pub(crate) async fn thread_view_settings(&self) -> crate::ThreadViewSettings { + let state = self.state.lock().await; + let configuration = &state.session_configuration; + let collaboration = &configuration.step_settings.collaboration_mode; + crate::ThreadViewSettings { + model: collaboration.model().to_string(), + reasoning_effort: collaboration.reasoning_effort(), + environments: configuration.environments.iter().map(Into::into).collect(), + session_source: configuration.session_source.clone(), + } + } + pub(crate) async fn thread_config_snapshot(&self) -> ThreadConfigSnapshot { self.resume_config_snapshot().await.0 } diff --git a/codex-rs/core/src/session/step_activation_tests.rs b/codex-rs/core/src/session/step_activation_tests.rs index 4e0ed09979..b432ff0c16 100644 --- a/codex-rs/core/src/session/step_activation_tests.rs +++ b/codex-rs/core/src/session/step_activation_tests.rs @@ -444,6 +444,24 @@ async fn thread_metadata_and_goal_recording_do_not_resolve_the_selected_model() assert_eq!(local.model, MODEL_B); assert_eq!(local.service_tier.as_deref(), Some("unsupported")); + let view = tokio::select! { + settings = session.thread_view_settings() => settings, + _ = lookup.started.notified() => panic!("list settings requested model info"), + }; + assert_eq!( + view, + crate::ThreadViewSettings { + model: local.model.clone(), + reasoning_effort: local.reasoning_effort.clone(), + environments: local + .environment_selections() + .iter() + .map(Into::into) + .collect(), + session_source: local.session_source.clone(), + }, + ); + let update = UserGoalUpdate::Set { objective: Some("Keep the existing tests".into()), status: None,