Repository navigation
fix(deletes): clear build output of deployments deleted mid-build - #14927
Conversation
Deleting a deployment while it builds let the build keep running and write its artifact after the deletes worker had already run, with no row left to own it. The delete endpoints now cancel an unfinished build, the jobs worker removes the build directory when a callback arrives for a deleted deployment, and deletes remove the whole per-deployment build directory rather than only buildPath. Local recursive deletes no longer follow symbolic links, since builds can write into the directory being removed.
|
Review complete. 🟠 1 high · 🟡 1 medium 📍 Findings outside the diff (2) — 🟠 1 high · 🟡 1 medium — defects on lines GitHub can't attach comments to🟠 High — TOCTOU: symlink swap can still escape // packages/storage/src/Device/Local.php
517 $path = realpath($this->getRoot() . DIRECTORY_SEPARATOR . $path);
518
519 if ($path === false || ! is_dir($path)) {
520 return false;
521 }
522
523 $files = $this->scanDirectory($path);
🟡 Medium — Cancel skipped on storage-delete failure and violates contract · Delete.php:132–144 · // src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php
132 if (!empty($deployment->getAttribute('sourcePath', ''))) {
133 if (!($deviceForSites->delete($deployment->getAttribute('sourcePath', '')))) {
134 throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from storage');
135 }
136 }
137
138 // A build still running would write its output after the deletes worker has cleared it.
139 if (!\in_array($deployment->getAttribute('status'), ['ready', 'failed', 'canceled'], true)) {
140 try {
141 $deployments->cancel($deployment->getId());
142 } catch (\Throwable) {
143 }The delete actions call 🧹 Nitpicks (1) — 🟢 1 low
This PR hardens deletion of deployment build directories:
Reviewed commit: 40b585f |
🔵 Tier A · Mergeable after minor fixes
The PR cancels unfinished deployments on deletion and removes the deployment-scoped build directory both during deletion and when a late build callback arrives. Local recursive deletion unlinks symlinks without traversing their targets, with E2E and storage/deployment regression coverage. The latest changes move late-callback cleanup outside event deduplication and add coverage for idempotent cleanup and symlink refusal. Latest changes: The newest commits move deleted-deployment cleanup after the callback lock so redeliveries retry it even when the dedupe marker remains, and add a deployment-directory cleanup regression test.
Fix with agent prompt### Issue 1
tests/unit/Platform/Modules/Functions/Workers/ActivateRulesTest.php:177
**Keep worker retry coverage out of the unit suite**
This directly invokes `Jobs::action()` with stubbed dependencies, adding a unit test for worker behavior. The repository guidance says not to unit-test workers and to cover their behavior through E2E, so this retry scenario belongs in the worker's E2E coverage instead.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 10
⏳ Still open from earlier reviews · 1
✅ Fixed since the last review · 1
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The callback's dedupe key is saved before the cleanup runs, so a cleanup that failed was skipped as already processed on redelivery and its output stayed orphaned. Release the key and fail the callback instead.
Purging the dedupe marker on a failed cleanup still lost the retry when the cache itself was down. The cleanup now runs after the deduplicated handler, so every delivery of a callback for a deleted deployment retries it whatever the marker says, and Jobs.php no longer touches the dedupe block. Coverage moves from a worker unit test to the Deployments library, per the test guidance.
What does this PR do?
Deleting a deployment while it builds leaves the build artifact in storage with no row owning it.
Three fixes:
deleteBuildDirectory()usesdeletePath($deploymentId)(the per-deployment directory, notdirname(buildPath), so a buildPath in another layout never widens the delete). Builds can write into that directory on the local device, soLocal::delete(..., true)andLocal::deletePath()now unlink symbolic links instead of recursing into their targets.Jobs.phponly appends to the end ofaction()and leaves the dedupe block alone, so it does not overlap #14914.Test Plan
FunctionsCustomServerTest::testDeleteDeploymentDuringBuild: delete a deployment mid-build (commands: sleep 10), wait past the build, assertlistFiles({deploymentId})is[].DeploymentsTest::testDeleteBuildDirectoryReportsWhetherAnythingIsLeft: deletes the whole directory, reports success when nothing is left (so a retry succeeds), and refuses a symlinked directory.LocalTest::testRecursiveDeleteDoesNotFollowSymlinks:delete()/deletePath()on a directory holding a symlink leave the link target intact.The retry after a failed cleanup lives in the worker and has no E2E: a storage failure cannot be forced from an E2E test.
Related: appwrite-labs/cloud#6628