mirror of
https://github.com/openai/codex.git
synced 2026-10-23 15:32:54 +00:00
## What changed - Include `environmentInfo` in the exec-server `initialize` response and seed the Rust client's metadata cache from it. - Fall back to one lazy `environment/info` request when connecting to older servers that omit initialization metadata, then share the cached result across client clones and session recovery. - Keep app-server `environment/info` requests uncached so they continue to probe the executor. ## Testing - Cover initialization metadata, the legacy-server fallback, shared caching, accepted WebSocket environments, and repeated uncached app-server probes. GitOrigin-RevId: 380132d9db183998d73e8c6b0954e4d70c7e8406
79 lines
2.7 KiB
Rust
79 lines
2.7 KiB
Rust
use super::*;
|
|
use std::time::Duration;
|
|
|
|
#[derive(Clone)]
|
|
pub(crate) struct EnvironmentRequestProcessor {
|
|
environment_manager: Arc<EnvironmentManager>,
|
|
}
|
|
|
|
impl EnvironmentRequestProcessor {
|
|
pub(crate) fn new(environment_manager: Arc<EnvironmentManager>) -> Self {
|
|
Self {
|
|
environment_manager,
|
|
}
|
|
}
|
|
|
|
pub(crate) async fn environment_add(
|
|
&self,
|
|
params: EnvironmentAddParams,
|
|
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
|
self.environment_manager
|
|
.upsert_environment(
|
|
params.environment_id,
|
|
params.exec_server_url,
|
|
params.connect_timeout_ms.map(Duration::from_millis),
|
|
)
|
|
.map_err(|err| invalid_request(err.to_string()))?;
|
|
Ok(Some(EnvironmentAddResponse {}.into()))
|
|
}
|
|
|
|
pub(crate) async fn environment_info(
|
|
&self,
|
|
params: EnvironmentInfoParams,
|
|
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
|
let environment_id = params.environment_id;
|
|
let environment = self
|
|
.environment_manager
|
|
.get_environment(&environment_id)
|
|
.ok_or_else(|| invalid_request(format!("unknown environment id `{environment_id}`")))?;
|
|
let info = environment.force_info().await.map_err(|err| {
|
|
internal_error(format!(
|
|
"failed to get info for environment `{environment_id}`: {err}"
|
|
))
|
|
})?;
|
|
Ok(Some(
|
|
EnvironmentInfoResponse {
|
|
shell: EnvironmentShellInfo {
|
|
name: info.shell.name,
|
|
path: info.shell.path,
|
|
},
|
|
cwd: info.cwd,
|
|
}
|
|
.into(),
|
|
))
|
|
}
|
|
|
|
pub(crate) async fn environment_status(
|
|
&self,
|
|
params: EnvironmentStatusParams,
|
|
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
|
let environment_id = params.environment_id;
|
|
let (status, error) = match self
|
|
.environment_manager
|
|
.get_environment_status(&environment_id)
|
|
.await
|
|
{
|
|
Some(EnvironmentObservedStatus::Ready) => (EnvironmentStatusKind::Ready, None),
|
|
Some(EnvironmentObservedStatus::Pending) => (EnvironmentStatusKind::Pending, None),
|
|
Some(EnvironmentObservedStatus::Disconnected { error }) => {
|
|
(EnvironmentStatusKind::Disconnected, Some(error))
|
|
}
|
|
None => (
|
|
EnvironmentStatusKind::Unknown,
|
|
Some(format!("unknown environment id `{environment_id}`")),
|
|
),
|
|
};
|
|
Ok(Some(EnvironmentStatusResponse { status, error }.into()))
|
|
}
|
|
}
|