From 49a5b3ff692f784d4655afa35cb71ecd9faa93a4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 19 Mar 2026 02:11:27 +0000 Subject: [PATCH] fix(sandbox): rollback EXDEV dir move on size-check failure to preserve source tree --- src/agents/sandbox/fs-bridge-mutation-helper.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/agents/sandbox/fs-bridge-mutation-helper.ts b/src/agents/sandbox/fs-bridge-mutation-helper.ts index 39372dfd586..19beb8bad26 100644 --- a/src/agents/sandbox/fs-bridge-mutation-helper.ts +++ b/src/agents/sandbox/fs-bridge-mutation-helper.ts @@ -146,6 +146,14 @@ export const SANDBOX_PINNED_MUTATION_PYTHON = [ " try:", " for child in os.listdir(src_dir_fd):", " move_entry(src_dir_fd, child, temp_dir_fd, child)", + " except Exception:", + " # Rollback: move children from temp_dir back to source to preserve original tree.", + " # Without this, a size-check failure on a later child leaves earlier children stranded", + " # in the hidden temp dir and the source partially deleted.", + " for child in os.listdir(temp_dir_fd):", + " move_entry(temp_dir_fd, child, src_dir_fd, child)", + " remove_tree(dst_parent_fd, temp_dir_name)", + " raise", " finally:", " os.close(src_dir_fd)", " os.close(temp_dir_fd)",