mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Expose loaded thread environments in app-server responses (#42386)
## What changed - Add the experimental `Thread.environments` field with each selected environment's ID, working directory, and runtime workspace roots. - Populate the field from live thread state in start, resume, read, list, and unarchive responses. Use `null` for unloaded threads and an empty list when a loaded thread has no environment selection. - Document that the field reports selection rather than connection status and does not affect executor selection or resume behavior. ## Testing - Cover selection updates, unloaded and resumed threads, loaded pathless unarchives, and clients that subscribe after environment connection notifications. GitOrigin-RevId: a6daa06aff7089d7c5a1e4c7d03109b41f12fa3c
This commit is contained in:
committed by
copyberry
parent
cff76fa96f
commit
2b554fd3f9
@@ -3,7 +3,7 @@ use crate::error_code::invalid_request;
|
||||
use crate::notification_media::without_notification_media;
|
||||
use crate::outgoing_message::ClientRequestResult;
|
||||
use crate::outgoing_message::ThreadScopedOutgoingMessageSender;
|
||||
use crate::request_processors::apply_live_model_settings;
|
||||
use crate::request_processors::apply_live_thread_settings;
|
||||
use crate::request_processors::populate_thread_turns_from_history;
|
||||
use crate::request_processors::thread_from_stored_thread;
|
||||
use crate::request_processors::thread_settings_from_config_snapshot;
|
||||
@@ -1287,7 +1287,7 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
}
|
||||
};
|
||||
|
||||
apply_live_model_settings(&mut response.thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut response.thread, &config_snapshot);
|
||||
outgoing.send_response(request_id, response).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,12 +605,19 @@ use crate::thread_state::ThreadStateManager;
|
||||
use token_usage_replay::restored_token_usage_turn_id;
|
||||
use token_usage_replay::send_thread_token_usage_update_to_connection;
|
||||
|
||||
pub(crate) fn apply_live_model_settings(
|
||||
pub(crate) fn apply_live_thread_settings(
|
||||
thread: &mut Thread,
|
||||
config_snapshot: &ThreadConfigSnapshot,
|
||||
) {
|
||||
thread.model = Some(config_snapshot.model.clone());
|
||||
thread.reasoning_effort = config_snapshot.reasoning_effort.clone();
|
||||
thread.environments = Some(
|
||||
config_snapshot
|
||||
.environment_selections()
|
||||
.iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
fn resolve_request_cwd(cwd: Option<PathBuf>) -> Result<Option<AbsolutePathBuf>, JSONRPCErrorError> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::apply_live_model_settings;
|
||||
use super::apply_live_thread_settings;
|
||||
use super::thread_input::can_accept_direct_input;
|
||||
use crate::thread_status::ThreadWatchManager;
|
||||
use crate::thread_status::resolve_thread_status;
|
||||
@@ -44,7 +44,7 @@ pub(super) async fn enrich_loaded_threads<T>(
|
||||
return;
|
||||
};
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
apply_live_model_settings(thread, &config_snapshot);
|
||||
apply_live_thread_settings(thread, &config_snapshot);
|
||||
if !matches!(
|
||||
&thread.source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. })
|
||||
|
||||
@@ -1994,7 +1994,7 @@ impl ThreadRequestProcessor {
|
||||
if let Ok(loaded_thread) = self.thread_manager.get_thread(thread_uuid).await {
|
||||
thread.session_id = loaded_thread.session_configured().session_id.to_string();
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
apply_live_model_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
}
|
||||
self.attach_thread_name(thread_uuid, &mut thread).await;
|
||||
thread.status = resolve_thread_status(
|
||||
@@ -2049,6 +2049,10 @@ impl ThreadRequestProcessor {
|
||||
let (mut thread, _) =
|
||||
thread_from_stored_thread(stored_thread, fallback_provider.as_str(), &self.config.cwd);
|
||||
|
||||
if let Ok(loaded_thread) = self.thread_manager.get_thread(thread_id).await {
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
}
|
||||
thread.status = resolve_thread_status(
|
||||
self.thread_watch_manager
|
||||
.loaded_status_for_thread(&thread.id)
|
||||
@@ -2985,7 +2989,7 @@ impl ThreadRequestProcessor {
|
||||
} else {
|
||||
fallback_thread
|
||||
};
|
||||
apply_live_model_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
self.apply_thread_read_store_fields(thread_id, &mut thread, include_turns, loaded_thread)
|
||||
.await?;
|
||||
Ok(thread)
|
||||
@@ -4284,7 +4288,7 @@ impl ThreadRequestProcessor {
|
||||
);
|
||||
thread_summary.session_id = existing_thread.session_configured().session_id.to_string();
|
||||
thread_summary.thread_source = config_snapshot.thread_source.clone().map(Into::into);
|
||||
apply_live_model_settings(&mut thread_summary, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread_summary, &config_snapshot);
|
||||
thread_summary.can_accept_direct_input = Some(can_accept_direct_input(
|
||||
existing_thread.multi_agent_version(),
|
||||
&config_snapshot.session_source,
|
||||
@@ -4649,7 +4653,7 @@ impl ThreadRequestProcessor {
|
||||
)),
|
||||
};
|
||||
let mut thread = thread?;
|
||||
apply_live_model_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
thread.can_accept_direct_input = Some(can_accept_direct_input);
|
||||
thread.id = thread_id.to_string();
|
||||
thread.session_id = session_id;
|
||||
@@ -5147,7 +5151,7 @@ impl ThreadRequestProcessor {
|
||||
));
|
||||
thread.session_id = session_configured.session_id.to_string();
|
||||
thread.thread_source = config_snapshot.thread_source.clone().map(Into::into);
|
||||
apply_live_model_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
if thread.path.is_none() {
|
||||
thread.project_id = inherited_project_id.clone();
|
||||
}
|
||||
@@ -5908,6 +5912,7 @@ pub(crate) fn thread_from_stored_thread(
|
||||
let thread_id = thread.thread_id.to_string();
|
||||
let thread = Thread {
|
||||
id: thread_id.clone(),
|
||||
environments: None,
|
||||
extra: None,
|
||||
session_id: thread_id,
|
||||
forked_from_id: thread.forked_from_id.map(|id| id.to_string()),
|
||||
@@ -6096,6 +6101,13 @@ fn build_thread_from_snapshot(
|
||||
let now = time::OffsetDateTime::now_utc().unix_timestamp();
|
||||
Thread {
|
||||
id: thread_id.to_string(),
|
||||
environments: Some(
|
||||
config_snapshot
|
||||
.environment_selections()
|
||||
.iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
),
|
||||
extra: None,
|
||||
session_id,
|
||||
forked_from_id: None,
|
||||
|
||||
@@ -198,6 +198,7 @@ mod tests {
|
||||
|
||||
fn test_thread(items: Vec<ThreadItem>) -> Thread {
|
||||
Thread {
|
||||
environments: None,
|
||||
id: "thread-1".to_string(),
|
||||
extra: None,
|
||||
session_id: "session-1".to_string(),
|
||||
|
||||
@@ -259,6 +259,7 @@ pub(crate) fn summary_to_thread(
|
||||
|
||||
let thread_id = conversation_id.to_string();
|
||||
Thread {
|
||||
environments: None,
|
||||
id: thread_id.clone(),
|
||||
extra: None,
|
||||
session_id: thread_id,
|
||||
|
||||
@@ -1469,7 +1469,7 @@ impl TurnRequestProcessor {
|
||||
|
||||
if let Some(mut thread) = stored_thread {
|
||||
let config_snapshot = review_thread.config_snapshot().await;
|
||||
apply_live_model_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
thread.session_id = review_thread.session_configured().session_id.to_string();
|
||||
self.thread_watch_manager
|
||||
.upsert_thread_silently(&thread.id)
|
||||
|
||||
Reference in New Issue
Block a user