From 3856a896eab595e865f67eaa736d3cdf2a9f6fbb Mon Sep 17 00:00:00 2001 From: diwu-sf Date: Thu, 20 Mar 2025 12:21:36 -0700 Subject: [PATCH] fix file chunking corruption (#7338) --- .../impl/action_execution/action_execution_client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openhands/runtime/impl/action_execution/action_execution_client.py b/openhands/runtime/impl/action_execution/action_execution_client.py index bcdbe2be15..0432c74665 100644 --- a/openhands/runtime/impl/action_execution/action_execution_client.py +++ b/openhands/runtime/impl/action_execution/action_execution_client.py @@ -1,5 +1,4 @@ import os -import shutil import tempfile import threading from abc import abstractmethod @@ -149,7 +148,10 @@ class ActionExecutionClient(Runtime): with tempfile.NamedTemporaryFile( suffix='.zip', delete=False ) as temp_file: - shutil.copyfileobj(response.raw, temp_file, length=16 * 1024) + for chunk in response.iter_content(chunk_size=16 * 1024): + if chunk: # filter out keep-alive new chunks + temp_file.write(chunk) + temp_file.flush() return Path(temp_file.name) except requests.Timeout: raise TimeoutError('Copy operation timed out')