mirror of
https://github.com/openai/codex.git
synced 2026-10-18 17:18:52 +00:00
Add in-memory shell snapshots to unified exec (#39957)
## What changed - Add the under-development `shell_snapshot_v2` feature and advertise executor support through environment capabilities. - Use executor-managed, in-memory snapshots for eligible direct `bash`, `zsh`, and `sh` login commands, while applying the configured shell environment policy and avoiding duplicate automatic startup-file effects. - Keep file-backed snapshots available for user-shell commands and fall back to the existing execution path when in-memory snapshots are unsupported or inapplicable. ## Testing - Cover policy filtering, snapshot reuse without snapshot files, automatic startup files, local and remote execution, and legacy user-shell snapshots. GitOrigin-RevId: 4ad6cdf13824913ac8c393ba38b9844230677579
This commit is contained in:
@@ -172,9 +172,17 @@ impl ShellSnapshotCache {
|
||||
.collect::<String>();
|
||||
let state_variables = state_variables.join(" ");
|
||||
let shell_start = prepared.command.len() - params.argv.len();
|
||||
prepared.command[shell_start + 1] = "-c".to_string();
|
||||
// Automatic startup files run before the restoration script and could
|
||||
// reintroduce environment variables that the snapshot already filtered.
|
||||
let (shell_flag, startup) = match shell_type {
|
||||
ShellType::Bash => ("-pc", "set +o privileged\n"),
|
||||
ShellType::Zsh => ("-fc", "setopt RCS\n"),
|
||||
ShellType::Sh => ("-c", ""),
|
||||
ShellType::PowerShell | ShellType::Cmd => unreachable!(),
|
||||
};
|
||||
prepared.command[shell_start + 1] = shell_flag.to_string();
|
||||
prepared.command[shell_start + 2] = format!(
|
||||
"if ! eval \"unset {state_variables}\n{state_expansion}\" >/dev/null; then printf 'failed to restore shell snapshot\\n' >&2; fi\n{}",
|
||||
"{startup}if ! eval \"unset {state_variables}\n{state_expansion}\" >/dev/null; then printf 'failed to restore shell snapshot\\n' >&2; fi\n{}",
|
||||
params.argv[2]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user