-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
Description
When git clone fails in _setup_repository(), the temporary directory created with tempfile.mkdtemp() is not cleaned up, leading to a disk space leak.
Location
File: pdd/agentic_change.py:111-132
Root Cause
# Line 112: Creates temp directory
temp_dir = Path(tempfile.mkdtemp(prefix=f"pdd_{repo}_"))
# Lines 120-131: If clone fails, raises exception without cleanup
try:
result = subprocess.run(["gh"] + clone_cmd, ...)
if result.returncode != 0:
raise RuntimeError(...) # Exits without cleaning temp_dir
except Exception as e:
raise RuntimeError(...) # Exits without cleaning temp_dirReproduction
We tested this manually and confirmed the leak:
# Test showed temp directory created but not deleted on clone failure
temp_dir = Path(tempfile.mkdtemp(prefix=f"pdd_{repo}_"))
# ... clone fails ...
# Directory still exists: True ⚠️Scenarios That Trigger The Leak
- Network interruption during clone
- Git authentication failures
- Rate limiting
- Private repositories without proper credentials
- Non-existent repositories (after issue API call succeeds)
- Disk space issues during clone
Proposed Solutions
Option 1: Use TemporaryDirectory context manager (Recommended)
with tempfile.TemporaryDirectory(prefix=f"pdd_{repo}_") as temp_dir_str:
temp_dir = Path(temp_dir_str)
# Clone operation
# Automatic cleanup on any exceptionNote: This requires restructuring the function since the temp directory is deleted when exiting the context.
Option 2: Manual cleanup in exception handlers
temp_dir = Path(tempfile.mkdtemp(prefix=f"pdd_{repo}_"))
try:
# Clone operation
if result.returncode != 0:
shutil.rmtree(temp_dir) # Cleanup before raising
raise RuntimeError(...)
except Exception as e:
shutil.rmtree(temp_dir) # Cleanup before raising
raise RuntimeError(...)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels