Skip to content

fix: move swarm stacks to be under projects#2234

Open
kmendell wants to merge 1 commit into
mainfrom
fix/update-swarm-layout
Open

fix: move swarm stacks to be under projects#2234
kmendell wants to merge 1 commit into
mainfrom
fix/update-swarm-layout

Conversation

@kmendell
Copy link
Copy Markdown
Member

@kmendell kmendell commented Apr 5, 2026

Checklist

  • This PR is not opened from my fork’s main branch

What This PR Implements

Fixes: #2226

Changes Made

Testing Done

  • Development environment started: ./scripts/development/dev.sh start
  • Frontend verified at http://localhost:3000
  • Backend verified at http://localhost:3552
  • Manual testing completed (describe):
  • No linting errors (e.g., just lint all)
  • Backend tests pass: just test backend

AI Tool Used (if applicable)

AI Tool:
Assistance Level:
What AI helped with:
I reviewed and edited all AI-generated output:
I ran all required tests and manually verified changes:

Additional Context

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

This PR introduces a new "Swarm Stack Projects" concept that persists stack metadata in a database table (swarm_stack_projects) and reorganises the UI so that saved stacks live under the Projects section rather than the Swarm/Stacks runtime view. The change separates "live runtime" (Swarm → Stacks) from "saved compose files" (Projects → Swarm), with a new "Down" action for the runtime view and a full editor in the Projects view.

  • Adds migration 051, the SwarmStackProject model, five new API endpoints (list/get/update/delete stackprojects, down stack), and the SyncStackProjectsFromFileSystem reconciliation loop that keeps the DB in sync with the filesystem on every read.
  • Replaces the old filesystem-traversal listPersistedStackSourcesInternal with DB-backed queries, and introduces GetStackProject/UpsertStackProject/DeleteStackProject service methods consumed by a new SwarmProjectEditor Svelte component.
  • Moves dockerSocketPathInternal and related helpers to a Linux-only build file, eliminating the dead no-op stubs on non-Linux platforms.

Confidence Score: 4/5

Safe to merge with awareness of a known concurrency issue in the upsert path that can surface as opaque 500 errors under concurrent writes to the same stack name.

The core logic is sound and the DB migration, model, and service layer are well-structured. The outstanding concurrency issue in upsertStackProjectRecordInternal (select-then-insert without atomicity) identified in a prior review round remains unaddressed; under concurrent saves to the same stack name it produces a unique-constraint violation that surfaces as a 500. New findings in this pass are non-blocking performance concerns: GetStackProject triggers a full filesystem sync twice per call (once directly, once through GetStackSource), which compounds with UpsertStackProject calling GetStackProject.

backend/internal/services/swarm_service.go — the upsert and GetStackProject/GetStackSource call chain warrant a second look before shipping to production workloads with many stacks or concurrent users.

Fix All in Codex Fix All in Claude Code

Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
backend/internal/services/swarm_service.go:1301-1325
**Redundant full filesystem sync on every `GetStackProject` call**

`GetStackProject` calls `getStackProjectRecordInternal(ctx, …, true)` (triggering `SyncStackProjectsFromFileSystem`), then immediately calls `GetStackSource`, which itself calls `getStackProjectRecordInternal(ctx, …, true)` a second time — causing another full sync. Each sync scans all stack directories, stats compose/env files, parses YAML via `countStackProjectServicesFromComposeInternal`, and runs upsert queries for every stack. With many stacks this doubles the I/O and DB cost of every `GetStackProject` (and by extension `UpsertStackProject`, which calls `GetStackProject`). The second sync is guaranteed to see an already-up-to-date DB since the first sync just ran; passing `sync=false` on the inner call, or reading the compose content directly from `stackProject.Path` instead of delegating to `GetStackSource`, would eliminate the redundancy.

### Issue 2 of 3
backend/internal/services/swarm_service.go:2557-2559
Unnecessary temp copy for `DirName` pointer — the project-style `new(expr)` helper (used elsewhere, e.g. `base.go`) removes the need for the intermediate `dirNameCopy` variable.

```suggestion
	dirName := filepath.Base(stackSourceDir)
	serviceCount, serviceCountErr := s.countStackProjectServicesFromComposeInternal(ctx, environmentID, stackName, stackSourceDir)
```

### Issue 3 of 3
backend/internal/services/swarm_service.go:2571
Update `DirName` to use `new(dirName)` after removing the `dirNameCopy` intermediate variable.

```suggestion
		DirName:       new(dirName),
```

Reviews (5): Last reviewed commit: "fix: move swarm stacks to be under proje..." | Re-trigger Greptile

Context used:

  • Rule used - What: Use the new built-in new function to initi... (source)

@kmendell
Copy link
Copy Markdown
Member Author

kmendell commented Apr 5, 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.

Copy link
Copy Markdown
Member Author

kmendell commented Apr 5, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@getarcaneappbot
Copy link
Copy Markdown
Contributor

getarcaneappbot commented Apr 5, 2026

Container images for this PR have been built successfully!

  • Manager: ghcr.io/getarcaneapp/arcane:pr-2234
  • Agent: ghcr.io/getarcaneapp/arcane-headless:pr-2234

Built from commit fd7fc0f

@kmendell kmendell force-pushed the fix/update-swarm-layout branch from 27ca6c2 to 6b1c9e3 Compare April 5, 2026 22:02
@kmendell kmendell force-pushed the fix/update-swarm-layout branch 5 times, most recently from c11901f to f363865 Compare April 6, 2026 17:15
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 6, 2026

This pull request has merge conflicts. Please resolve the conflicts so the PR can stay up-to-date and reviewed.

@kmendell kmendell force-pushed the fix/update-swarm-layout branch from f363865 to 055d4f0 Compare April 7, 2026 01:21
@kmendell kmendell force-pushed the fix/update-swarm-layout branch from 055d4f0 to d119f3f Compare April 7, 2026 02:22
@kmendell kmendell marked this pull request as ready for review April 7, 2026 02:31
@kmendell kmendell requested a review from a team April 7, 2026 02:31
Comment thread backend/internal/services/swarm_service.go
@kmendell kmendell force-pushed the fix/update-swarm-layout branch 11 times, most recently from 728855a to d512351 Compare April 12, 2026 18:57
@kmendell kmendell force-pushed the fix/update-swarm-layout branch 5 times, most recently from 3407efb to 456e3eb Compare April 19, 2026 17:21
@github-actions
Copy link
Copy Markdown

This pull request has merge conflicts. Please resolve the conflicts so the PR can stay up-to-date and reviewed.

@kmendell kmendell force-pushed the fix/update-swarm-layout branch from 456e3eb to 2b4f240 Compare April 24, 2026 01:38
@kmendell kmendell force-pushed the fix/update-swarm-layout branch 7 times, most recently from 501fc31 to 2969fbb Compare April 28, 2026 17:17
@kmendell kmendell closed this Apr 28, 2026
@kmendell kmendell reopened this Apr 28, 2026
@kmendell kmendell force-pushed the fix/update-swarm-layout branch 2 times, most recently from f4bcd82 to 6e963b8 Compare April 29, 2026 02:52
@github-actions
Copy link
Copy Markdown

This pull request has merge conflicts. Please resolve the conflicts so the PR can stay up-to-date and reviewed.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

This pull request has merge conflicts. Please resolve the conflicts so the PR can stay up-to-date and reviewed.

@kmendell kmendell force-pushed the fix/update-swarm-layout branch from bde4678 to fd7fc0f Compare May 9, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 Bug: Swarm Stack - View Source missing

2 participants