Skip to content

fix: skip gitops-managed projects in filesystem cleanup (#2266)#2354

Merged
kmendell merged 2 commits intogetarcaneapp:mainfrom
GiulioSavini:fix/gitops-cleanup-skip-managed-projects
Apr 12, 2026
Merged

fix: skip gitops-managed projects in filesystem cleanup (#2266)#2354
kmendell merged 2 commits intogetarcaneapp:mainfrom
GiulioSavini:fix/gitops-cleanup-skip-managed-projects

Conversation

@GiulioSavini
Copy link
Copy Markdown
Contributor

@GiulioSavini GiulioSavini commented Apr 12, 2026

Summary

  • cleanupDBProjects was 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).
  • After removing a Git-Sync link, DeleteSync clears GitOpsManagedBy before the next cleanup run — so even a brief window where the directory is empty caused the record to be deleted with no recovery path.
  • Fix: add a guard at the top of the cleanup loop that skips any project with GitOpsManagedBy set, since its lifecycle belongs to the gitops system, not the filesystem scanner.

Closes #2266

Test plan

  • Configure a project with Git-Sync enabled
  • Stop the git-sync job so the compose file is absent from disk
  • Trigger a filesystem scan (or wait for the periodic cleanup)
  • Verify the project still appears in the UI (was previously deleted)
  • Remove the Git-Sync link; verify the project record persists after the next cleanup pass

🤖 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 cleanupDBProjects that skips any project with a non-empty GitOpsManagedBy, 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.

Fix All in Codex

Prompt To Fix All 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.

Reviews (1): Last reviewed commit: "fix: skip gitops-managed projects in fil..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

…#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.
@kmendell
Copy link
Copy Markdown
Member

kmendell commented Apr 12, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 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 != "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Fix in Codex

@kmendell kmendell merged commit 85397c7 into getarcaneapp:main Apr 12, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 Bug: Git-Sync hides linked projects permanently

2 participants