feat: add suffix to shell snapshot name (#14938)

https://github.com/openai/codex/issues/14906
This commit is contained in:
jif-oai
2026-03-17 17:59:27 +00:00
committed by GitHub
Unverified
parent f26ad3c92c
commit d484bb57d9
2 changed files with 80 additions and 13 deletions
+18 -9
View File
@@ -120,13 +120,13 @@ impl ShellSnapshot {
ShellType::PowerShell => "ps1",
_ => "sh",
};
let path = codex_home
.join(SNAPSHOT_DIR)
.join(format!("{session_id}.{extension}"));
let nonce = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map(|duration| duration.as_nanos())
.unwrap_or(0);
let path = codex_home
.join(SNAPSHOT_DIR)
.join(format!("{session_id}.{nonce}.{extension}"));
let temp_path = codex_home
.join(SNAPSHOT_DIR)
.join(format!("{session_id}.tmp-{nonce}"));
@@ -510,12 +510,9 @@ pub async fn cleanup_stale_snapshots(codex_home: &Path, active_session_id: Threa
let file_name = entry.file_name();
let file_name = file_name.to_string_lossy();
let (session_id, _) = match file_name.rsplit_once('.') {
Some((stem, ext)) => (stem, ext),
None => {
remove_snapshot_file(&path).await;
continue;
}
let Some(session_id) = snapshot_session_id_from_file_name(&file_name) else {
remove_snapshot_file(&path).await;
continue;
};
if session_id == active_session_id {
continue;
@@ -556,6 +553,18 @@ async fn remove_snapshot_file(path: &Path) {
}
}
fn snapshot_session_id_from_file_name(file_name: &str) -> Option<&str> {
let (stem, extension) = file_name.rsplit_once('.')?;
match extension {
"sh" | "ps1" => Some(
stem.split_once('.')
.map_or(stem, |(session_id, _generation)| session_id),
),
_ if extension.starts_with("tmp-") => Some(stem),
_ => None,
}
}
#[cfg(test)]
#[path = "shell_snapshot_tests.rs"]
mod tests;