mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Thread environment ids through app-server routing slice
Derive stable environment bindings for standalone fs and command/exec paths while keeping the local executor path intact for the default environment. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -67,9 +67,12 @@ struct ConnectionProcessId {
|
||||
#[derive(Clone)]
|
||||
enum CommandExecSession {
|
||||
Active {
|
||||
environment_id: String,
|
||||
control_tx: mpsc::Sender<CommandControlRequest>,
|
||||
},
|
||||
UnsupportedWindowsSandbox,
|
||||
UnsupportedWindowsSandbox {
|
||||
environment_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
enum CommandControl {
|
||||
@@ -155,6 +158,7 @@ impl CommandExecManager {
|
||||
output_bytes_cap,
|
||||
size,
|
||||
} = params;
|
||||
let environment_id = environment_id_from_cwd(exec_request.cwd.as_path());
|
||||
if process_id.is_none() && (tty || stream_stdin || stream_stdout_stderr) {
|
||||
return Err(invalid_request(
|
||||
"command/exec tty or streaming requires a client-supplied processId".to_string(),
|
||||
@@ -195,7 +199,9 @@ impl CommandExecManager {
|
||||
}
|
||||
sessions.insert(
|
||||
process_key.clone(),
|
||||
CommandExecSession::UnsupportedWindowsSandbox,
|
||||
CommandExecSession::UnsupportedWindowsSandbox {
|
||||
environment_id: environment_id.clone(),
|
||||
},
|
||||
);
|
||||
}
|
||||
let sessions = Arc::clone(&self.sessions);
|
||||
@@ -259,9 +265,17 @@ impl CommandExecManager {
|
||||
}
|
||||
sessions.insert(
|
||||
process_key.clone(),
|
||||
CommandExecSession::Active { control_tx },
|
||||
CommandExecSession::Active {
|
||||
environment_id: environment_id.clone(),
|
||||
control_tx,
|
||||
},
|
||||
);
|
||||
}
|
||||
tracing::debug!(
|
||||
environment_id = %environment_id,
|
||||
process_id = %process_key.process_id.error_repr(),
|
||||
"command/exec start"
|
||||
);
|
||||
let spawned = if tty {
|
||||
codex_utils_pty::spawn_pty_process(
|
||||
program,
|
||||
@@ -389,13 +403,28 @@ impl CommandExecManager {
|
||||
};
|
||||
|
||||
for control in controls {
|
||||
if let CommandExecSession::Active { control_tx } = control {
|
||||
let _ = control_tx
|
||||
.send(CommandControlRequest {
|
||||
control: CommandControl::Terminate,
|
||||
response_tx: None,
|
||||
})
|
||||
.await;
|
||||
match control {
|
||||
CommandExecSession::Active {
|
||||
environment_id,
|
||||
control_tx,
|
||||
} => {
|
||||
tracing::debug!(
|
||||
environment_id = %environment_id,
|
||||
"command/exec connection closed"
|
||||
);
|
||||
let _ = control_tx
|
||||
.send(CommandControlRequest {
|
||||
control: CommandControl::Terminate,
|
||||
response_tx: None,
|
||||
})
|
||||
.await;
|
||||
}
|
||||
CommandExecSession::UnsupportedWindowsSandbox { environment_id } => {
|
||||
tracing::debug!(
|
||||
environment_id = %environment_id,
|
||||
"command/exec connection closed for windows sandbox"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,10 +447,26 @@ impl CommandExecManager {
|
||||
))
|
||||
})?
|
||||
};
|
||||
let CommandExecSession::Active { control_tx } = session else {
|
||||
return Err(invalid_request(
|
||||
"command/exec/write, command/exec/terminate, and command/exec/resize are not supported for windows sandbox processes".to_string(),
|
||||
));
|
||||
let control_tx = match session {
|
||||
CommandExecSession::Active {
|
||||
environment_id,
|
||||
control_tx,
|
||||
} => {
|
||||
tracing::debug!(
|
||||
environment_id = %environment_id,
|
||||
"command/exec control"
|
||||
);
|
||||
control_tx
|
||||
}
|
||||
CommandExecSession::UnsupportedWindowsSandbox { environment_id } => {
|
||||
tracing::debug!(
|
||||
environment_id = %environment_id,
|
||||
"command/exec control rejected for windows sandbox"
|
||||
);
|
||||
return Err(invalid_request(
|
||||
"command/exec/write, command/exec/terminate, and command/exec/resize are not supported for windows sandbox processes".to_string(),
|
||||
));
|
||||
}
|
||||
};
|
||||
let (response_tx, response_rx) = oneshot::channel();
|
||||
let request = CommandControlRequest {
|
||||
@@ -917,11 +962,12 @@ mod tests {
|
||||
connection_id: request_id.connection_id,
|
||||
process_id: InternalProcessId::Client("proc-11".to_string()),
|
||||
};
|
||||
manager
|
||||
.sessions
|
||||
.lock()
|
||||
.await
|
||||
.insert(process_id, CommandExecSession::UnsupportedWindowsSandbox);
|
||||
manager.sessions.lock().await.insert(
|
||||
process_id,
|
||||
CommandExecSession::UnsupportedWindowsSandbox {
|
||||
environment_id: "test-env".to_string(),
|
||||
},
|
||||
);
|
||||
|
||||
let err = manager
|
||||
.write(
|
||||
@@ -953,11 +999,12 @@ mod tests {
|
||||
connection_id: request_id.connection_id,
|
||||
process_id: InternalProcessId::Client("proc-12".to_string()),
|
||||
};
|
||||
manager
|
||||
.sessions
|
||||
.lock()
|
||||
.await
|
||||
.insert(process_id, CommandExecSession::UnsupportedWindowsSandbox);
|
||||
manager.sessions.lock().await.insert(
|
||||
process_id,
|
||||
CommandExecSession::UnsupportedWindowsSandbox {
|
||||
environment_id: "test-env".to_string(),
|
||||
},
|
||||
);
|
||||
|
||||
let err = manager
|
||||
.terminate(
|
||||
@@ -990,7 +1037,10 @@ mod tests {
|
||||
connection_id: request_id.connection_id,
|
||||
process_id: process_id.clone(),
|
||||
},
|
||||
CommandExecSession::Active { control_tx },
|
||||
CommandExecSession::Active {
|
||||
environment_id: "test-env".to_string(),
|
||||
control_tx,
|
||||
},
|
||||
);
|
||||
|
||||
tokio::spawn(async move {
|
||||
|
||||
@@ -28,12 +28,20 @@ use std::sync::Arc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct FsApi {
|
||||
environment_id: String,
|
||||
file_system: Arc<dyn ExecutorFileSystem>,
|
||||
}
|
||||
|
||||
impl Default for FsApi {
|
||||
fn default() -> Self {
|
||||
Self::new(Environment::default_environment_id(None))
|
||||
}
|
||||
}
|
||||
|
||||
impl FsApi {
|
||||
pub(crate) fn new(environment_id: String) -> Self {
|
||||
Self {
|
||||
environment_id,
|
||||
file_system: Arc::new(Environment::default().get_filesystem()),
|
||||
}
|
||||
}
|
||||
@@ -44,6 +52,11 @@ impl FsApi {
|
||||
&self,
|
||||
params: FsReadFileParams,
|
||||
) -> Result<FsReadFileResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
"fs/readFile"
|
||||
);
|
||||
let bytes = self
|
||||
.file_system
|
||||
.read_file(¶ms.path)
|
||||
@@ -58,6 +71,11 @@ impl FsApi {
|
||||
&self,
|
||||
params: FsWriteFileParams,
|
||||
) -> Result<FsWriteFileResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
"fs/writeFile"
|
||||
);
|
||||
let bytes = STANDARD.decode(params.data_base64).map_err(|err| {
|
||||
invalid_request(format!(
|
||||
"fs/writeFile requires valid base64 dataBase64: {err}"
|
||||
@@ -74,6 +92,11 @@ impl FsApi {
|
||||
&self,
|
||||
params: FsCreateDirectoryParams,
|
||||
) -> Result<FsCreateDirectoryResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
"fs/createDirectory"
|
||||
);
|
||||
self.file_system
|
||||
.create_directory(
|
||||
¶ms.path,
|
||||
@@ -90,6 +113,11 @@ impl FsApi {
|
||||
&self,
|
||||
params: FsGetMetadataParams,
|
||||
) -> Result<FsGetMetadataResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
"fs/getMetadata"
|
||||
);
|
||||
let metadata = self
|
||||
.file_system
|
||||
.get_metadata(¶ms.path)
|
||||
@@ -107,6 +135,11 @@ impl FsApi {
|
||||
&self,
|
||||
params: FsReadDirectoryParams,
|
||||
) -> Result<FsReadDirectoryResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
"fs/readDirectory"
|
||||
);
|
||||
let entries = self
|
||||
.file_system
|
||||
.read_directory(¶ms.path)
|
||||
@@ -128,6 +161,11 @@ impl FsApi {
|
||||
&self,
|
||||
params: FsRemoveParams,
|
||||
) -> Result<FsRemoveResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
"fs/remove"
|
||||
);
|
||||
self.file_system
|
||||
.remove(
|
||||
¶ms.path,
|
||||
@@ -145,6 +183,12 @@ impl FsApi {
|
||||
&self,
|
||||
params: FsCopyParams,
|
||||
) -> Result<FsCopyResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
source_path = %params.source_path,
|
||||
destination_path = %params.destination_path,
|
||||
"fs/copy"
|
||||
);
|
||||
self.file_system
|
||||
.copy(
|
||||
¶ms.source_path,
|
||||
|
||||
@@ -64,6 +64,7 @@ use codex_core::default_client::set_default_client_residency_requirement;
|
||||
use codex_core::default_client::set_default_originator;
|
||||
use codex_core::models_manager::collaboration_mode_presets::CollaborationModesConfig;
|
||||
use codex_feedback::CodexFeedback;
|
||||
use codex_exec_server::Environment;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::W3cTraceContext;
|
||||
@@ -255,7 +256,9 @@ impl MessageProcessor {
|
||||
analytics_events_client,
|
||||
);
|
||||
let external_agent_config_api = ExternalAgentConfigApi::new(config.codex_home.clone());
|
||||
let fs_api = FsApi::default();
|
||||
let fs_api = FsApi::new(Environment::default_environment_id(
|
||||
config.experimental_exec_server_url.as_deref(),
|
||||
));
|
||||
|
||||
Self {
|
||||
outgoing,
|
||||
|
||||
Reference in New Issue
Block a user