Conversation
Remove project and environment references atomically during deletion, and sanitize legacy orphaned assignments on read.
Use a transaction-scoped organization advisory lock for provider creation, updates, and resource deletion so validation cannot race cleanup. Add concurrent-writer and cross-organization regression coverage.
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.
What is this PR about?
Fixes orphaned Secret Vault assignment IDs when projects or environments are deleted. Cleanup now runs in the same database transaction as deletion, is scoped to the owning organization, and shares a transaction-scoped organization advisory lock with provider validation and writes before updating JSONB assignments. Existing orphaned data is sanitized in provider read responses without causing writes, so affected providers can be edited and saved again while strict assignment validation remains intact.
Checklist
canarybranch.Local verification used the documented Dokploy setup with a migrated PostgreSQL 16 database. I exercised the production services for both project and environment deletion, verified the stored JSONB assignments, injected legacy orphaned IDs, confirmed reads did not mutate storage, and successfully saved the sanitized provider. I also forced concurrent create/update requests to wait behind deletion, confirmed the wait in PostgreSQL pg_locks, and verified both rejected stale assignments after deletion committed.
Automated checks:
pnpm exec biome check packages/server/src/services/vault-provider.ts packages/server/src/services/project.ts packages/server/src/services/environment.ts apps/dokploy/__test__/env/vault-orphaned-assignments.test.tspnpm --filter=@dokploy/server typecheckpnpm --filter=dokploy typecheckpnpm --filter=dokploy test --run __test__/env/vault-orphaned-assignments.test.ts(8 passed)pnpm --filter=dokploy test --run __test__/env(154 passed)pnpm dokploy:buildI also ran the full test suite: 1,015 tests passed and 5 were skipped. The remaining 22 failures are in unrelated Windows/platform-dependent tests that invoke POSIX executables such as
/bin/bash,sh,rm, andcommand, require symlink privileges, or expected a running Docker daemon. The new regression suite passed in that run.Issues related (if applicable)
Closes #5425
Screenshots (if applicable)
Not applicable; this is a backend data-integrity fix.
The PR is not yet safe to merge because concurrent provider creation or updates can persist assignments to a resource after its deletion commits.
Summary
This PR cleans vault assignments as part of project and environment deletion transactions and sanitizes legacy orphaned assignments in provider read responses.
Reviews (1) ? Last reviewed commit: "fix(vault): clean assignments after reso..."