mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
[codex] start threads with pending environments
This commit is contained in:
@@ -15,6 +15,8 @@ use std::path::PathBuf;
|
||||
|
||||
use super::ContextualUserFragment;
|
||||
|
||||
const ENVIRONMENT_SHELL_LOADING: &str = "still loading";
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) struct EnvironmentContext {
|
||||
pub(crate) environments: EnvironmentContextEnvironments,
|
||||
@@ -47,11 +49,25 @@ impl EnvironmentContextEnvironment {
|
||||
.map(|environment| Self {
|
||||
id: environment.environment_id.clone(),
|
||||
cwd: environment.cwd.clone(),
|
||||
shell: environment
|
||||
.shell
|
||||
.as_ref()
|
||||
.map(|shell| shell.name().to_string())
|
||||
.unwrap_or_else(|| shell.name().to_string()),
|
||||
shell: if environment.environment.is_remote() {
|
||||
environment
|
||||
.environment
|
||||
.current_info()
|
||||
.map(|info| info.shell.name)
|
||||
.or_else(|| {
|
||||
environment
|
||||
.shell
|
||||
.as_ref()
|
||||
.map(|shell| shell.name().to_string())
|
||||
})
|
||||
.unwrap_or_else(|| ENVIRONMENT_SHELL_LOADING.to_string())
|
||||
} else {
|
||||
environment
|
||||
.shell
|
||||
.as_ref()
|
||||
.map(|shell| shell.name().to_string())
|
||||
.unwrap_or_else(|| shell.name().to_string())
|
||||
},
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ impl ResolvedTurnEnvironments {
|
||||
self.turn_environments.first()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn primary_environment(&self) -> Option<Arc<codex_exec_server::Environment>> {
|
||||
self.primary()
|
||||
.map(|environment| Arc::clone(&environment.environment))
|
||||
@@ -49,6 +50,7 @@ impl ResolvedTurnEnvironments {
|
||||
|
||||
pub(crate) fn primary_filesystem(&self) -> Option<Arc<dyn ExecutorFileSystem>> {
|
||||
self.primary()
|
||||
.filter(|environment| environment.environment.is_ready())
|
||||
.map(|environment| environment.environment.get_filesystem())
|
||||
}
|
||||
|
||||
@@ -61,7 +63,7 @@ impl ResolvedTurnEnvironments {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn resolve_environment_selections(
|
||||
pub(crate) fn resolve_environment_selections(
|
||||
environment_manager: &EnvironmentManager,
|
||||
environments: &[TurnEnvironmentSelection],
|
||||
) -> CodexResult<ResolvedTurnEnvironments> {
|
||||
@@ -80,8 +82,9 @@ pub(crate) async fn resolve_environment_selections(
|
||||
.ok_or_else(|| {
|
||||
CodexErr::InvalidRequest(format!("unknown turn environment id `{environment_id}`"))
|
||||
})?;
|
||||
let shell = match environment.info().await {
|
||||
Ok(info) => match Shell::from_environment_shell_info(info.shell) {
|
||||
environment.start_loading_info();
|
||||
let shell = match environment.current_info() {
|
||||
Some(info) => match Shell::from_environment_shell_info(info.shell) {
|
||||
Ok(shell) => Some(shell),
|
||||
Err(err) => {
|
||||
tracing::warn!(
|
||||
@@ -90,10 +93,7 @@ pub(crate) async fn resolve_environment_selections(
|
||||
None
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
tracing::warn!("failed to get info for environment `{environment_id}`: {err}");
|
||||
None
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
turn_environments.push(TurnEnvironment {
|
||||
environment_id,
|
||||
@@ -205,7 +205,6 @@ url = "ws://127.0.0.1:8765"
|
||||
},
|
||||
],
|
||||
)
|
||||
.await
|
||||
.expect_err("duplicate environment id should fail");
|
||||
|
||||
assert!(err.to_string().contains("duplicate"));
|
||||
@@ -224,7 +223,6 @@ url = "ws://127.0.0.1:8765"
|
||||
cwd: selected_cwd,
|
||||
}],
|
||||
)
|
||||
.await
|
||||
.expect("environment selections should resolve");
|
||||
|
||||
assert_eq!(
|
||||
@@ -262,7 +260,6 @@ url = "ws://127.0.0.1:8765"
|
||||
cwd: cwd.clone(),
|
||||
}],
|
||||
)
|
||||
.await
|
||||
.expect("local environment should resolve");
|
||||
let remote_environment = Arc::new(
|
||||
Environment::create_for_tests(Some("ws://127.0.0.1:8765".to_string()))
|
||||
|
||||
@@ -528,10 +528,7 @@ impl Codex {
|
||||
.startup_warnings
|
||||
.extend(user_instruction_provider_warnings);
|
||||
// TODO(anp) assemble instructions from multiple environments
|
||||
let primary_environment = environment_selections.primary_environment();
|
||||
let primary_fs = primary_environment
|
||||
.as_ref()
|
||||
.map(|environment| environment.get_filesystem());
|
||||
let primary_fs = environment_selections.primary_filesystem();
|
||||
let loaded_agents_md =
|
||||
load_project_instructions(&mut config, user_instructions, primary_fs.as_deref()).await;
|
||||
|
||||
|
||||
@@ -444,7 +444,6 @@ async fn warm_plugins_and_skills_for_session_init(
|
||||
environment_manager.as_ref(),
|
||||
&environments,
|
||||
)
|
||||
.await
|
||||
.ok()
|
||||
.and_then(|resolved| resolved.primary_filesystem());
|
||||
let plugins_input = config.plugins_config_input();
|
||||
@@ -1118,7 +1117,6 @@ impl Session {
|
||||
sess.services.environment_manager.as_ref(),
|
||||
session_configuration.environment_selections(),
|
||||
)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
CodexErr::InvalidRequest(err.to_string().replace(
|
||||
"unknown turn environment id",
|
||||
|
||||
@@ -414,12 +414,16 @@ pub(crate) async fn run_turn(
|
||||
async fn turn_diff_display_roots(turn_context: &TurnContext) -> Vec<(String, PathBuf)> {
|
||||
let mut display_roots = Vec::new();
|
||||
for turn_environment in &turn_context.environments.turn_environments {
|
||||
let root = get_git_repo_root_with_fs(
|
||||
turn_environment.environment.get_filesystem().as_ref(),
|
||||
&turn_environment.cwd,
|
||||
)
|
||||
.await
|
||||
.unwrap_or_else(|| turn_environment.cwd.clone())
|
||||
let root = if turn_environment.environment.is_ready() {
|
||||
get_git_repo_root_with_fs(
|
||||
turn_environment.environment.get_filesystem().as_ref(),
|
||||
&turn_environment.cwd,
|
||||
)
|
||||
.await
|
||||
.unwrap_or_else(|| turn_environment.cwd.clone())
|
||||
} else {
|
||||
turn_environment.cwd.clone()
|
||||
}
|
||||
.into_path_buf();
|
||||
display_roots.push((turn_environment.environment_id.clone(), root));
|
||||
}
|
||||
|
||||
@@ -704,7 +704,6 @@ impl Session {
|
||||
self.services.environment_manager.as_ref(),
|
||||
session_configuration.environment_selections(),
|
||||
)
|
||||
.await
|
||||
.unwrap_or_else(|err| {
|
||||
warn!("failed to resolve turn environments: {err}");
|
||||
ResolvedTurnEnvironments::default()
|
||||
@@ -748,6 +747,7 @@ impl Session {
|
||||
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
|
||||
let skills_input = skills_load_input_from_config(&per_turn_config, effective_skill_roots);
|
||||
let fs = primary_turn_environment
|
||||
.filter(|turn_environment| turn_environment.environment.is_ready())
|
||||
.map(|turn_environment| turn_environment.environment.get_filesystem());
|
||||
let skills_outcome = Arc::new(
|
||||
self.services
|
||||
|
||||
@@ -1382,8 +1382,7 @@ impl ThreadManagerState {
|
||||
}
|
||||
}
|
||||
let environment_selections =
|
||||
resolve_environment_selections(self.environment_manager.as_ref(), &environments)
|
||||
.await?;
|
||||
resolve_environment_selections(self.environment_manager.as_ref(), &environments)?;
|
||||
let user_instructions = self
|
||||
.user_instructions_for_spawn(&session_source, parent_thread_id, forked_from_thread_id)
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user