mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Prewarm shell snapshots for eligible turns (#42137)
## Why Shell Snapshot V2 previously captured the login-shell environment lazily when a command started, adding that work to the command path. ## What changed - Start one asynchronous snapshot capture after turn hooks accept the turn, so eligible local `exec_command` calls can reuse it without blocking the model. - Use the turn's resolved tools, permissions, sandbox, environment, and shell configuration, and skip prewarming for unsupported or network-managed cases. - Cancel outstanding prewarming during shutdown. Keep failed speculative captures retryable by real commands without consuming their retry budget. ## Testing Added coverage for non-blocking capture and reuse, failure recovery, sandbox and permission isolation, shutdown cancellation, hook-stopped turns, eligibility gates, and concurrent capture retries. GitOrigin-RevId: ff24a4f0328c06653e09d03fd0a3db1eccd65030
This commit is contained in:
@@ -71,6 +71,8 @@ use crate::rpc::internal_error;
|
||||
use crate::rpc::invalid_params;
|
||||
use crate::rpc::invalid_request;
|
||||
use crate::rpc_server_requests::RpcServerRequestSender;
|
||||
#[cfg(unix)]
|
||||
use crate::shell_snapshot::CapturePurpose;
|
||||
use crate::telemetry::ExecServerTelemetry;
|
||||
use crate::telemetry::ProcessMetricGuard;
|
||||
|
||||
@@ -355,7 +357,12 @@ impl LocalProcess {
|
||||
#[cfg(unix)]
|
||||
self.inner
|
||||
.shell_snapshots
|
||||
.prepare(¶ms, &mut prepared, &self.inner.telemetry)
|
||||
.prepare(
|
||||
¶ms,
|
||||
&mut prepared,
|
||||
&self.inner.telemetry,
|
||||
CapturePurpose::Execution,
|
||||
)
|
||||
.await?;
|
||||
if prepared.command.is_empty() {
|
||||
return Err(invalid_params("argv must not be empty".to_string()));
|
||||
@@ -753,6 +760,39 @@ impl ExecBackend for LocalProcess {
|
||||
fn start(&self, params: ExecParams) -> ExecBackendFuture<'_> {
|
||||
Box::pin(LocalProcess::start(self, params))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn prewarm_shell_snapshot(&self, params: ExecParams) -> ExecProcessFuture<'_, ()> {
|
||||
Box::pin(async move {
|
||||
if params.enforce_managed_network
|
||||
|| params.managed_network.is_some()
|
||||
|| params.network_proxy.is_some()
|
||||
{
|
||||
return Err(ExecServerError::Protocol(
|
||||
"shell snapshot prewarming does not support managed networking".to_string(),
|
||||
));
|
||||
}
|
||||
let mut prepared = prepare_exec_request(
|
||||
¶ms,
|
||||
child_env(¶ms),
|
||||
self.runtime_paths.as_ref(),
|
||||
/*network_policy_decider*/ None,
|
||||
/*network_policy_audit_observer*/ None,
|
||||
)
|
||||
.await
|
||||
.map_err(map_handler_error)?;
|
||||
self.inner
|
||||
.shell_snapshots
|
||||
.prepare(
|
||||
¶ms,
|
||||
&mut prepared,
|
||||
&self.inner.telemetry,
|
||||
CapturePurpose::Prewarm,
|
||||
)
|
||||
.await
|
||||
.map_err(map_handler_error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl LocalExecProcess {
|
||||
|
||||
Reference in New Issue
Block a user