Repository navigation
⚡️ Feature Request: Optimistic concurrency control for Swarm stack source edits #5192
loong95
started this conversation in
Feature requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Feature Description
Add optimistic concurrency control to Swarm stack source edits, so saving an editor page that was loaded earlier cannot silently overwrite changes made by someone else in the meantime.
Problem It Solves
PATCH /agents/{id}/swarm/stacks/{name}/sourcehas no version, hash, or ETag check. The handler only looks at which JSON keys were submitted and merges those fields over the currently saved source (UpdateStackSourceinbackend/internal/swarm/children/stacks/service.go):composeContent,overrideContent, andenvContentare replaced wholesale when present.filesreplaces the entire auxiliary file set, andCleanupRemovedFiles(backend/pkg/projects/fs_writer.go) deletes any file on disk that is not in the submitted list.The editor (
frontend/src/routes/(app)/swarm/stacks/new/+page.svelte) builds the payload withchangedFields()against the snapshot loaded when the page was opened, and never revalidates it. So:.env) and saves.filesarray) is written over B's changes. No warning, no 409, and the audit event only recordsstack.source.updatewith the stack name, so there is no trail of what was replaced. Saving also redeploys the stack withprune: true, so the overwrite takes effect immediately.The worst case is
files: touching any workspace file submits the whole file list, so files B created after A's page load are deleted.Proposed Solution
Return a source revision from
GET .../sourceand require it onPATCH:revision(orhash) toSwarmStackSource: a SHA-256 over the canonical source set (compose, override,.env, and auxiliary files sorted by path).PATCHaccepts abaseRevision. Before writing, recompute the hash of the current saved source; on mismatch return409 Conflictwith the current revision, and ideally the current source or changed paths.composeContentdoes not block a.env-only save.Standard HTTP preconditions (
ETag+If-Matchon the source resource) would achieve the same result.Alternatives Considered
filespath can delete other people's files.Additional Context
main(checked 2026-12-01).backend/internal/swarm/children/stacks/handler.go—UpdateSwarmStackSourceInput,SubmittedFields()backend/internal/swarm/children/stacks/service.go—UpdateStackSource,upsertStackSource,CleanupRemovedFilesfrontend/src/lib/utils/payload.ts—changedFieldsfrontend/src/routes/(app)/swarm/stacks/new/+page.svelte—handleSaveStackSourcemain; I can test a branch and provide logs once there is something to try.Would you be willing to work on this feature?
All reactions