mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Support saved environments when starting Cloud threads (#61956)
## What changed - Add `EnvironmentSelection` to start Cloud threads with either a saved environment ID or a project checkout in the default environment. - Expose saved environment discovery through the authenticated Cloud request handle, rejecting results if the account changes. - Thread environment selection through the app-server client and TUI session startup, and defer executor readiness for either explicit environment choice. ## Testing Extend prewarm request tests to cover saved environment IDs and deferred readiness. Extend TUI session tests to verify saved environment routing without local working-directory or workspace-root overrides. GitOrigin-RevId: 626cec9926dad8f1a89b1a3ee9e4470850ae6a76
This commit is contained in:
committed by
copyberry
parent
50c227a6e2
commit
e9a2a9e115
@@ -312,10 +312,11 @@ async fn activation_preserves_native_settings_and_thread_metadata() {
|
||||
const PREWARM_CODEX_PLUGINS: &[u8] = b"\xe2\x01\x07\x0a\x05codex";
|
||||
|
||||
#[tokio::test]
|
||||
async fn prewarm_defers_readiness_only_for_selected_projects() {
|
||||
async fn prewarm_defers_readiness_for_explicit_environments() {
|
||||
let mut fixture = fixture_responses(vec![
|
||||
response(vec![frame(&[])], tonic::Status::ok("")),
|
||||
response(vec![frame(&[])], tonic::Status::ok("")),
|
||||
response(vec![frame(&[])], tonic::Status::ok("")),
|
||||
])
|
||||
.await;
|
||||
|
||||
@@ -339,14 +340,14 @@ async fn prewarm_defers_readiness_only_for_selected_projects() {
|
||||
.prewarm_thread(
|
||||
/*model*/ None,
|
||||
/*model_provider*/ None,
|
||||
Some(ProjectEnvironment {
|
||||
Some(EnvironmentSelection::Project(ProjectEnvironment {
|
||||
name: "App".to_owned(),
|
||||
cwd: Some("/workspace/acme/app".to_owned()),
|
||||
origin_urls: vec![
|
||||
"git@github.com:acme/app.git".to_owned(),
|
||||
"https://github.com/acme/lib.git".to_owned(),
|
||||
],
|
||||
}),
|
||||
})),
|
||||
)
|
||||
.await,
|
||||
Err(Error::InvalidResponse)
|
||||
@@ -365,6 +366,25 @@ async fn prewarm_defers_readiness_only_for_selected_projects() {
|
||||
]
|
||||
.concat();
|
||||
assert_request(&mut fixture, "Prewarm", &expected).await;
|
||||
|
||||
assert!(matches!(
|
||||
fixture
|
||||
.client
|
||||
.prewarm_thread(
|
||||
/*model*/ None,
|
||||
/*model_provider*/ None,
|
||||
Some(EnvironmentSelection::Saved("ws~asenvcfg_saved".to_owned())),
|
||||
)
|
||||
.await,
|
||||
Err(Error::InvalidResponse)
|
||||
));
|
||||
let expected = [
|
||||
b"\x52\x17\x0a\x15\x0a\x13\x0a\x11ws~asenvcfg_saved".as_slice(),
|
||||
PREWARM_CODEX_PLUGINS,
|
||||
b"\xe8\x01\x01",
|
||||
]
|
||||
.concat();
|
||||
assert_request(&mut fixture, "Prewarm", &expected).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -59,6 +59,7 @@ pub use items::CommandSummary;
|
||||
pub use items::ItemLifecycle;
|
||||
pub use items::ItemStatus;
|
||||
pub use items::ItemSummary;
|
||||
pub use prewarm::EnvironmentSelection;
|
||||
pub use prewarm::ProjectEnvironment;
|
||||
pub use transcript::FileUpdate;
|
||||
pub use transcript::ItemDelta;
|
||||
|
||||
@@ -16,6 +16,13 @@ pub struct ProjectEnvironment {
|
||||
pub cwd: Option<String>,
|
||||
}
|
||||
|
||||
/// An explicit saved environment or the default environment with a project checkout.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum EnvironmentSelection {
|
||||
Saved(String),
|
||||
Project(ProjectEnvironment),
|
||||
}
|
||||
|
||||
pub(super) const DEFAULT_ENVIRONMENT_CONFIG_ID: &str = "asenvcfg_base";
|
||||
|
||||
impl std::fmt::Debug for ProjectEnvironment {
|
||||
@@ -35,24 +42,28 @@ impl Client {
|
||||
model: Option<String>,
|
||||
model_provider: Option<String>,
|
||||
) -> Result<crate::ThreadActivation, Error> {
|
||||
self.prewarm_thread(model, model_provider, /*project*/ None)
|
||||
self.prewarm_thread(model, model_provider, /*environment*/ None)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Prewarm a coding thread, deferring executor readiness for a selected project checkout.
|
||||
/// Prewarm a coding thread, deferring executor readiness for an explicit environment.
|
||||
pub async fn prewarm_thread(
|
||||
&self,
|
||||
model: Option<String>,
|
||||
model_provider: Option<String>,
|
||||
project: Option<ProjectEnvironment>,
|
||||
environment: Option<EnvironmentSelection>,
|
||||
) -> Result<crate::ThreadActivation, Error> {
|
||||
let deferred_environment = project.is_some().then_some(true);
|
||||
let managed = match project {
|
||||
Some(ProjectEnvironment {
|
||||
let deferred_environment = environment.is_some().then_some(true);
|
||||
let managed = match environment {
|
||||
Some(EnvironmentSelection::Saved(id)) => wire::ManagedEnvironment {
|
||||
environment_config_id: Some(id),
|
||||
..Default::default()
|
||||
},
|
||||
Some(EnvironmentSelection::Project(ProjectEnvironment {
|
||||
name,
|
||||
origin_urls,
|
||||
cwd,
|
||||
}) => wire::ManagedEnvironment {
|
||||
})) => wire::ManagedEnvironment {
|
||||
environment_config_id: Some(DEFAULT_ENVIRONMENT_CONFIG_ID.to_owned()),
|
||||
cwd,
|
||||
overrides: Some(wire::EnvironmentOverrides {
|
||||
|
||||
Reference in New Issue
Block a user