Description
When project creation fails during workspace initialization, the API endpoint in codeframe/ui/server.py:321-324 performs a rollback by deleting the database record:
except Exception as e:
# Cleanup: delete project if workspace creation fails
app.state.db.delete_project(project_id)
raise HTTPException(status_code=500, detail=f"Workspace creation failed: {str(e)}")
However, this only cleans up the database - it doesn't explicitly clean up the filesystem workspace if it was partially created.
Current Behavior
- The
WorkspaceManager has cleanup logic in its exception handler (manager.py:67-69), which uses shutil.rmtree(workspace_path, ignore_errors=True)
- If the
WorkspaceManager cleanup fails or is interrupted, orphaned workspace directories could accumulate
- The API endpoint doesn't verify that workspace cleanup succeeded
Proposed Solution
Add explicit workspace cleanup in the API endpoint's exception handler:
except Exception as e:
# Cleanup: delete project and workspace if creation fails
app.state.db.delete_project(project_id)
# Explicitly clean up workspace directory if it exists
workspace_path = Path(app.state.workspace_root) / str(project_id)
if workspace_path.exists():
try:
shutil.rmtree(workspace_path)
logger.info(f"Cleaned up orphaned workspace: {workspace_path}")
except Exception as cleanup_error:
logger.error(f"Failed to clean up workspace {workspace_path}: {cleanup_error}")
raise HTTPException(status_code=500, detail=f"Workspace creation failed: {str(e)}")
Related
Identified in PR #6 code review - Project Schema Refactoring
Description
When project creation fails during workspace initialization, the API endpoint in
codeframe/ui/server.py:321-324performs a rollback by deleting the database record:However, this only cleans up the database - it doesn't explicitly clean up the filesystem workspace if it was partially created.
Current Behavior
WorkspaceManagerhas cleanup logic in its exception handler (manager.py:67-69), which usesshutil.rmtree(workspace_path, ignore_errors=True)WorkspaceManagercleanup fails or is interrupted, orphaned workspace directories could accumulateProposed Solution
Add explicit workspace cleanup in the API endpoint's exception handler:
Related
Identified in PR #6 code review - Project Schema Refactoring