fix: skip gitops-managed projects in filesystem cleanup (#2266)#2354
Merged
kmendell merged 2 commits intogetarcaneapp:mainfrom Apr 12, 2026
Merged
Conversation
…#2266) The periodic cleanupDBProjects scan was deleting DB records for projects linked via Git-Sync whenever their compose file was absent from disk (e.g. after an SSH/clone failure or immediately after removing the link). Because the gitops reconciler clears GitOpsManagedBy before the delete, the next cleanup sweep then permanently removes the record with no way to recover. Guard the cleanup loop: if a project has GitOpsManagedBy set, skip it entirely — its lifecycle belongs to the gitops system, not the filesystem scanner.
Member
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
| // Skip projects whose lifecycle is owned by the gitops system. | ||
| // Their compose files may not exist on disk yet (e.g. during a sync | ||
| // or after an SSH/clone failure) and should never be deleted here. | ||
| if p.GitOpsManagedBy != nil && *p.GitOpsManagedBy != "" { |
Contributor
There was a problem hiding this comment.
Inconsistent whitespace guard vs. the parallel check
The existing check for the same field at line 397 uses strings.TrimSpace(*proj.GitOpsManagedBy) != "", but this new guard compares directly against "". Since GitOpsManagedBy values are always UUIDs in practice this will never differ, but for defensive consistency it's worth aligning the two.
Suggested change
| if p.GitOpsManagedBy != nil && *p.GitOpsManagedBy != "" { | |
| if p.GitOpsManagedBy != nil && strings.TrimSpace(*p.GitOpsManagedBy) != "" { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: backend/internal/services/project_service.go
Line: 1012
Comment:
**Inconsistent whitespace guard vs. the parallel check**
The existing check for the same field at line 397 uses `strings.TrimSpace(*proj.GitOpsManagedBy) != ""`, but this new guard compares directly against `""`. Since `GitOpsManagedBy` values are always UUIDs in practice this will never differ, but for defensive consistency it's worth aligning the two.
```suggestion
if p.GitOpsManagedBy != nil && strings.TrimSpace(*p.GitOpsManagedBy) != "" {
```
How can I resolve this? If you propose a fix, please make it concise.
kmendell
approved these changes
Apr 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cleanupDBProjectswas permanently deleting DB records for projects linked via Git-Sync whenever the compose file was missing from disk (e.g. after an SSH/clone failure, or during a sync cycle where files haven't been written yet).DeleteSyncclearsGitOpsManagedBybefore the next cleanup run — so even a brief window where the directory is empty caused the record to be deleted with no recovery path.GitOpsManagedByset, since its lifecycle belongs to the gitops system, not the filesystem scanner.Closes #2266
Test plan
🤖 Generated with Claude Code
Disclaimer Greptiles Reviews use AI, make sure to check over its work.
To better help train Greptile on our codebase, if the comment is useful and valid Like the comment, if its not helpful or invalid Dislike
To have Greptile Re-Review the changes, mention
greptileai.Greptile Summary
Adds a guard in
cleanupDBProjectsthat skips any project with a non-emptyGitOpsManagedBy, preventing the filesystem cleanup loop from permanently deleting gitops-managed projects when their compose files are temporarily absent (e.g. during a sync cycle or after an SSH/clone failure). The fix is minimal and correctly scoped; it aligns with how the same field is guarded in other parts of the service.Confidence Score: 5/5
Safe to merge — the fix is minimal, targeted, and correct; only a cosmetic style inconsistency remains.
All findings are P2 (style/consistency). The logic itself correctly addresses the described bug and is consistent with the codebase's existing handling of GitOpsManagedBy.
No files require special attention.
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: skip gitops-managed projects in fil..." | Re-trigger Greptile