Skip to content

Commit 2fa9487

Browse files
committed
fix(api): delete repo entry when size check or analysis fails
Previously, repos were added to DB before size check, leaving orphan 'pending' entries when rejected. Now we: - Delete repo if analysis fails (return 500) - Delete repo if size check fails (return 403) - No more pending cards for rejected repos
1 parent 39eed6b commit 2fa9487

1 file changed

Lines changed: 32 additions & 18 deletions

File tree

backend/routes/repos.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,24 @@ async def add_repository(
8181
# Fail CLOSED if analysis failed (security: don't allow unknown-size repos)
8282
if not analysis.success:
8383
logger.error(
84-
"Repo analysis failed - blocking indexing",
84+
"Repo analysis failed - removing repo",
8585
user_id=user_id,
8686
repo_id=repo["id"],
8787
error=analysis.error
8888
)
89-
return {
90-
"repo_id": repo["id"],
91-
"status": "added",
92-
"indexing_blocked": True,
93-
"analysis": analysis.to_dict(),
94-
"message": f"Repository added but analysis failed: {analysis.error}. Please try re-indexing later."
95-
}
89+
# Clean up: delete the repo we just created
90+
try:
91+
repo_manager.delete_repo(repo["id"])
92+
except Exception as del_err:
93+
logger.warning("Failed to cleanup failed analysis repo", error=str(del_err))
94+
95+
raise HTTPException(
96+
status_code=500,
97+
detail={
98+
"error": "ANALYSIS_FAILED",
99+
"message": f"Repository analysis failed: {analysis.error}"
100+
}
101+
)
96102

97103
# Check repo size against tier limits
98104
size_check = user_limits.check_repo_size(
@@ -102,22 +108,30 @@ async def add_repository(
102108
)
103109

104110
if not size_check.allowed:
105-
# Repo added but too large - return warning with upgrade CTA
111+
# Repo too large - delete the entry and return error
106112
logger.info(
107-
"Repo too large for user tier",
113+
"Repo too large for user tier - removing",
108114
user_id=user_id,
109115
repo_id=repo["id"],
110116
file_count=analysis.file_count,
117+
estimated_functions=analysis.estimated_functions,
111118
tier=size_check.tier
112119
)
113-
return {
114-
"repo_id": repo["id"],
115-
"status": "added",
116-
"indexing_blocked": True,
117-
"analysis": analysis.to_dict(),
118-
"limit_check": size_check.to_dict(),
119-
"message": size_check.message
120-
}
120+
# Clean up: delete the repo we just created
121+
try:
122+
repo_manager.delete_repo(repo["id"])
123+
except Exception as del_err:
124+
logger.warning("Failed to cleanup rejected repo", error=str(del_err))
125+
126+
raise HTTPException(
127+
status_code=403,
128+
detail={
129+
"error": "REPO_TOO_LARGE",
130+
"analysis": analysis.to_dict(),
131+
"limit_check": size_check.to_dict(),
132+
"message": size_check.message
133+
}
134+
)
121135

122136
return {
123137
"repo_id": repo["id"],

0 commit comments

Comments
 (0)