Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix for issue where temp file is empty (#6669)

tofarr2b40a9294384
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')