From 2b40a9294384fa8c5ed8d0513e6738ae73861d28 Mon Sep 17 00:00:00 2001 From: tofarr Date: Mon, 10 Feb 2025 18:07:40 +0000 Subject: [PATCH] Fix for issue where temp file is empty (#6669) --- .../impl/action_execution/action_execution_client.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/openhands/runtime/impl/action_execution/action_execution_client.py b/openhands/runtime/impl/action_execution/action_execution_client.py index 7da8c21ff6..7f12824474 100644 --- a/openhands/runtime/impl/action_execution/action_execution_client.py +++ b/openhands/runtime/impl/action_execution/action_execution_client.py @@ -142,11 +142,13 @@ class ActionExecutionClient(Runtime): stream=True, timeout=30, ) as response: - temp_file = tempfile.NamedTemporaryFile(delete=False) - for chunk in response.iter_content(chunk_size=8192): - if chunk: # filter out keep-alive new chunks - temp_file.write(chunk) - return Path(temp_file.name) + with tempfile.NamedTemporaryFile(delete=False) as temp_file: + total_length = 0 + for chunk in response.iter_content(chunk_size=8192): + if chunk: # filter out keep-alive new chunks + total_length += len(chunk) + temp_file.write(chunk) + return Path(temp_file.name) except requests.Timeout: raise TimeoutError('Copy operation timed out')