From fa0e2ba87c87f75c54fca2407944a34a68ced625 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 20 Apr 2026 07:15:05 -0700 Subject: [PATCH] Avoid false shell snapshot cleanup warnings (#18441) ## Why Fresh app-server thread startup can create a shell snapshot through a temp file and then promote it to the final snapshot path. The previous implementation briefly wrapped the temp path in `ShellSnapshot`, so after a successful rename its `Drop` attempted to delete the old temp path and could log a false `ENOENT` warning. Fixes #17549. ## What changed - Validate the temp snapshot path directly before promotion. - Rename the temp path directly to the final snapshot path. - Keep explicit cleanup of the temp path on validation or finalization failures. --- codex-rs/core/src/shell_snapshot.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/codex-rs/core/src/shell_snapshot.rs b/codex-rs/core/src/shell_snapshot.rs index e0e037b20..40cb4a960 100644 --- a/codex-rs/core/src/shell_snapshot.rs +++ b/codex-rs/core/src/shell_snapshot.rs @@ -151,20 +151,15 @@ impl ShellSnapshot { temp_path.display() ); - let temp_snapshot = Self { - path: temp_path.clone(), - cwd: session_cwd.clone(), - }; - - if let Err(err) = validate_snapshot(shell, &temp_snapshot.path, session_cwd).await { + if let Err(err) = validate_snapshot(shell, &temp_path, session_cwd).await { tracing::error!("Shell snapshot validation failed: {err:?}"); - remove_snapshot_file(&temp_snapshot.path).await; + remove_snapshot_file(&temp_path).await; return Err("validation_failed"); } - if let Err(err) = fs::rename(&temp_snapshot.path, &path).await { + if let Err(err) = fs::rename(&temp_path, &path).await { tracing::warn!("Failed to finalize shell snapshot: {err:?}"); - remove_snapshot_file(&temp_snapshot.path).await; + remove_snapshot_file(&temp_path).await; return Err("write_failed"); }