diff --git a/src/agents/sandbox/fs-bridge-mutation-helper.ts b/src/agents/sandbox/fs-bridge-mutation-helper.ts index 52942e45a84..39372dfd586 100644 --- a/src/agents/sandbox/fs-bridge-mutation-helper.ts +++ b/src/agents/sandbox/fs-bridge-mutation-helper.ts @@ -170,16 +170,24 @@ export const SANDBOX_PINNED_MUTATION_PYTHON = [ " temp_name = None", " try:", " temp_name, temp_fd = create_temp_file(dst_parent_fd, dst_basename)", + " total_written = 0", " while True:", " chunk = os.read(src_fd, 65536)", " if not chunk:", " break", - " os.write(temp_fd, chunk)", + " written = os.write(temp_fd, chunk)", + " if written != len(chunk):", + " raise OSError(errno.EIO, 'short write to sandbox temp file: wrote ' + str(written) + ' of ' + str(len(chunk)) + ' bytes (fakeowner or network fs may be dropping writes)', dst_basename)", + " total_written += written", " try:", " os.fchmod(temp_fd, stat.S_IMODE(src_stat.st_mode))", " except AttributeError:", " pass", " os.fsync(temp_fd)", + " # Verify bytes were actually persisted — fakeowner/network mounts can silently drop writes.", + " stat_result = os.fstat(temp_fd)", + " if stat_result.st_size != total_written:", + " raise OSError(errno.EIO, 'sandbox temp file size mismatch after write: expected ' + str(total_written) + ' bytes but got ' + str(stat_result.st_size) + ' (fakeowner or network fs may be silently dropping writes)', dst_basename)", " os.close(temp_fd)", " temp_fd = None", " os.replace(temp_name, dst_basename, src_dir_fd=dst_parent_fd, dst_dir_fd=dst_parent_fd)",