mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Implement environment-bound exec plumbing
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -239,6 +239,7 @@ use codex_core::state_db::reconcile_rollout;
|
||||
use codex_core::windows_sandbox::WindowsSandboxLevelExt;
|
||||
use codex_core::windows_sandbox::WindowsSandboxSetupMode as CoreWindowsSandboxSetupMode;
|
||||
use codex_core::windows_sandbox::WindowsSandboxSetupRequest;
|
||||
use codex_exec_server::Environment;
|
||||
use codex_feedback::CodexFeedback;
|
||||
use codex_login::ServerOptions as LoginServerOptions;
|
||||
use codex_login::ShutdownHandle;
|
||||
@@ -1553,6 +1554,7 @@ impl CodexMessageProcessor {
|
||||
|
||||
let CommandExecParams {
|
||||
command,
|
||||
environment_id,
|
||||
process_id,
|
||||
tty,
|
||||
stream_stdin,
|
||||
@@ -1566,6 +1568,24 @@ impl CodexMessageProcessor {
|
||||
size,
|
||||
sandbox_policy,
|
||||
} = params;
|
||||
let configured_environment_id = Environment::default_environment_id(
|
||||
self.config.experimental_exec_server_url.as_deref(),
|
||||
);
|
||||
let environment_id = match environment_id {
|
||||
Some(environment_id) if environment_id != configured_environment_id => {
|
||||
let error = JSONRPCErrorError {
|
||||
code: INVALID_REQUEST_ERROR_CODE,
|
||||
message: format!(
|
||||
"unsupported environmentId `{environment_id}`; configured environment is `{configured_environment_id}`"
|
||||
),
|
||||
data: None,
|
||||
};
|
||||
self.outgoing.send_error(request, error).await;
|
||||
return;
|
||||
}
|
||||
Some(environment_id) => environment_id,
|
||||
None => configured_environment_id,
|
||||
};
|
||||
|
||||
if size.is_some() && !tty {
|
||||
let error = JSONRPCErrorError {
|
||||
@@ -1751,6 +1771,7 @@ impl CodexMessageProcessor {
|
||||
.start(StartCommandExecParams {
|
||||
outgoing,
|
||||
request_id: request_for_task,
|
||||
environment_id,
|
||||
process_id,
|
||||
exec_request,
|
||||
started_network_proxy: started_network_proxy_for_task,
|
||||
@@ -1830,6 +1851,7 @@ impl CodexMessageProcessor {
|
||||
let ThreadStartParams {
|
||||
model,
|
||||
model_provider,
|
||||
environment_id,
|
||||
service_tier,
|
||||
cwd,
|
||||
approval_policy,
|
||||
@@ -1846,6 +1868,21 @@ impl CodexMessageProcessor {
|
||||
ephemeral,
|
||||
persist_extended_history,
|
||||
} = params;
|
||||
let configured_environment_id = Environment::default_environment_id(
|
||||
self.config.experimental_exec_server_url.as_deref(),
|
||||
);
|
||||
if let Some(environment_id) = environment_id
|
||||
&& environment_id != configured_environment_id
|
||||
{
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!(
|
||||
"unsupported environmentId `{environment_id}`; configured environment is `{configured_environment_id}`"
|
||||
),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
let mut typesafe_overrides = self.build_thread_config_overrides(
|
||||
model,
|
||||
model_provider,
|
||||
@@ -2077,6 +2114,7 @@ impl CodexMessageProcessor {
|
||||
|
||||
let response = ThreadStartResponse {
|
||||
thread: thread.clone(),
|
||||
environment_id: config_snapshot.environment_id,
|
||||
model: config_snapshot.model,
|
||||
model_provider: config_snapshot.model_provider_id,
|
||||
service_tier: config_snapshot.service_tier,
|
||||
@@ -3400,6 +3438,7 @@ impl CodexMessageProcessor {
|
||||
|
||||
let ThreadResumeParams {
|
||||
thread_id,
|
||||
environment_id,
|
||||
history,
|
||||
path,
|
||||
model,
|
||||
@@ -3415,6 +3454,21 @@ impl CodexMessageProcessor {
|
||||
personality,
|
||||
persist_extended_history,
|
||||
} = params;
|
||||
let configured_environment_id = Environment::default_environment_id(
|
||||
self.config.experimental_exec_server_url.as_deref(),
|
||||
);
|
||||
if let Some(environment_id) = environment_id
|
||||
&& environment_id != configured_environment_id
|
||||
{
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!(
|
||||
"unsupported environmentId `{environment_id}`; configured environment is `{configured_environment_id}`"
|
||||
),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
let thread_history = if let Some(history) = history {
|
||||
let Some(thread_history) = self
|
||||
@@ -3549,9 +3603,9 @@ impl CodexMessageProcessor {
|
||||
thread_status,
|
||||
/*has_live_in_progress_turn*/ false,
|
||||
);
|
||||
|
||||
let response = ThreadResumeResponse {
|
||||
thread,
|
||||
environment_id: configured_environment_id,
|
||||
model: session_configured.model,
|
||||
model_provider: session_configured.model_provider_id,
|
||||
service_tier: session_configured.service_tier,
|
||||
@@ -3902,6 +3956,7 @@ impl CodexMessageProcessor {
|
||||
async fn thread_fork(&mut self, request_id: ConnectionRequestId, params: ThreadForkParams) {
|
||||
let ThreadForkParams {
|
||||
thread_id,
|
||||
environment_id,
|
||||
path,
|
||||
model,
|
||||
model_provider,
|
||||
@@ -3916,6 +3971,21 @@ impl CodexMessageProcessor {
|
||||
ephemeral,
|
||||
persist_extended_history,
|
||||
} = params;
|
||||
let configured_environment_id = Environment::default_environment_id(
|
||||
self.config.experimental_exec_server_url.as_deref(),
|
||||
);
|
||||
if let Some(environment_id) = environment_id
|
||||
&& environment_id != configured_environment_id
|
||||
{
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
format!(
|
||||
"unsupported environmentId `{environment_id}`; configured environment is `{configured_environment_id}`"
|
||||
),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
let (rollout_path, source_thread_id) = if let Some(path) = path {
|
||||
(path, None)
|
||||
@@ -4156,6 +4226,7 @@ impl CodexMessageProcessor {
|
||||
|
||||
let response = ThreadForkResponse {
|
||||
thread: thread.clone(),
|
||||
environment_id: configured_environment_id,
|
||||
model: session_configured.model,
|
||||
model_provider: session_configured.model_provider_id,
|
||||
service_tier: session_configured.service_tier,
|
||||
@@ -7309,6 +7380,7 @@ async fn handle_pending_thread_resume_request(
|
||||
}
|
||||
|
||||
let ThreadConfigSnapshot {
|
||||
environment_id,
|
||||
model,
|
||||
model_provider_id,
|
||||
service_tier,
|
||||
@@ -7321,6 +7393,7 @@ async fn handle_pending_thread_resume_request(
|
||||
} = pending.config_snapshot;
|
||||
let response = ThreadResumeResponse {
|
||||
thread,
|
||||
environment_id,
|
||||
model,
|
||||
model_provider: model_provider_id,
|
||||
service_tier,
|
||||
@@ -8419,6 +8492,7 @@ mod tests {
|
||||
fn collect_resume_override_mismatches_includes_service_tier() {
|
||||
let request = ThreadResumeParams {
|
||||
thread_id: "thread-1".to_string(),
|
||||
environment_id: None,
|
||||
history: None,
|
||||
path: None,
|
||||
model: None,
|
||||
@@ -8435,6 +8509,7 @@ mod tests {
|
||||
persist_extended_history: false,
|
||||
};
|
||||
let config_snapshot = ThreadConfigSnapshot {
|
||||
environment_id: "local".to_string(),
|
||||
model: "gpt-5".to_string(),
|
||||
model_provider_id: "openai".to_string(),
|
||||
service_tier: Some(codex_protocol::config_types::ServiceTier::Flex),
|
||||
|
||||
@@ -89,6 +89,7 @@ struct CommandControlRequest {
|
||||
pub(crate) struct StartCommandExecParams {
|
||||
pub(crate) outgoing: Arc<OutgoingMessageSender>,
|
||||
pub(crate) request_id: ConnectionRequestId,
|
||||
pub(crate) environment_id: String,
|
||||
pub(crate) process_id: Option<String>,
|
||||
pub(crate) exec_request: ExecRequest,
|
||||
pub(crate) started_network_proxy: Option<StartedNetworkProxy>,
|
||||
@@ -149,6 +150,7 @@ impl CommandExecManager {
|
||||
let StartCommandExecParams {
|
||||
outgoing,
|
||||
request_id,
|
||||
environment_id,
|
||||
process_id,
|
||||
exec_request,
|
||||
started_network_proxy,
|
||||
@@ -158,7 +160,6 @@ 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(),
|
||||
@@ -801,6 +802,7 @@ mod tests {
|
||||
connection_id: ConnectionId(1),
|
||||
request_id: codex_app_server_protocol::RequestId::Integer(42),
|
||||
},
|
||||
environment_id: "test-env".to_string(),
|
||||
process_id: Some("proc-42".to_string()),
|
||||
exec_request: windows_sandbox_exec_request(),
|
||||
started_network_proxy: None,
|
||||
@@ -834,6 +836,7 @@ mod tests {
|
||||
.start(StartCommandExecParams {
|
||||
outgoing: Arc::new(OutgoingMessageSender::new(tx)),
|
||||
request_id: request_id.clone(),
|
||||
environment_id: "test-env".to_string(),
|
||||
process_id: Some("proc-99".to_string()),
|
||||
exec_request: windows_sandbox_exec_request(),
|
||||
started_network_proxy: None,
|
||||
@@ -883,6 +886,7 @@ mod tests {
|
||||
.start(StartCommandExecParams {
|
||||
outgoing: Arc::new(OutgoingMessageSender::new(tx)),
|
||||
request_id: request_id.clone(),
|
||||
environment_id: "test-env".to_string(),
|
||||
process_id: Some("proc-100".to_string()),
|
||||
exec_request: ExecRequest {
|
||||
command: vec!["sh".to_string(), "-lc".to_string(), "sleep 30".to_string()],
|
||||
|
||||
@@ -54,7 +54,7 @@ impl FsApi {
|
||||
) -> Result<FsReadFileResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
path = ?params.path,
|
||||
"fs/readFile"
|
||||
);
|
||||
let bytes = self
|
||||
@@ -73,7 +73,7 @@ impl FsApi {
|
||||
) -> Result<FsWriteFileResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
path = ?params.path,
|
||||
"fs/writeFile"
|
||||
);
|
||||
let bytes = STANDARD.decode(params.data_base64).map_err(|err| {
|
||||
@@ -94,7 +94,7 @@ impl FsApi {
|
||||
) -> Result<FsCreateDirectoryResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
path = ?params.path,
|
||||
"fs/createDirectory"
|
||||
);
|
||||
self.file_system
|
||||
@@ -115,7 +115,7 @@ impl FsApi {
|
||||
) -> Result<FsGetMetadataResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
path = ?params.path,
|
||||
"fs/getMetadata"
|
||||
);
|
||||
let metadata = self
|
||||
@@ -137,7 +137,7 @@ impl FsApi {
|
||||
) -> Result<FsReadDirectoryResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
path = ?params.path,
|
||||
"fs/readDirectory"
|
||||
);
|
||||
let entries = self
|
||||
@@ -163,7 +163,7 @@ impl FsApi {
|
||||
) -> Result<FsRemoveResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
path = %params.path,
|
||||
path = ?params.path,
|
||||
"fs/remove"
|
||||
);
|
||||
self.file_system
|
||||
@@ -185,8 +185,8 @@ impl FsApi {
|
||||
) -> Result<FsCopyResponse, JSONRPCErrorError> {
|
||||
tracing::debug!(
|
||||
environment_id = %self.environment_id,
|
||||
source_path = %params.source_path,
|
||||
destination_path = %params.destination_path,
|
||||
source_path = ?params.source_path,
|
||||
destination_path = ?params.destination_path,
|
||||
"fs/copy"
|
||||
);
|
||||
self.file_system
|
||||
|
||||
@@ -814,6 +814,7 @@ mod tests {
|
||||
.request(ClientRequest::ThreadStart {
|
||||
request_id: RequestId::Integer(2),
|
||||
params: ThreadStartParams {
|
||||
environment_id: None,
|
||||
ephemeral: Some(true),
|
||||
..ThreadStartParams::default()
|
||||
},
|
||||
|
||||
@@ -63,8 +63,8 @@ use codex_core::default_client::get_codex_user_agent;
|
||||
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_feedback::CodexFeedback;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::W3cTraceContext;
|
||||
|
||||
@@ -195,6 +195,7 @@ impl TracingHarness {
|
||||
ClientRequest::ThreadStart {
|
||||
request_id: RequestId::Integer(request_id),
|
||||
params: ThreadStartParams {
|
||||
environment_id: None,
|
||||
ephemeral: Some(true),
|
||||
..ThreadStartParams::default()
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user