Skip to content

fix: delete build cache with its function, site or runtime - #14761

Merged
ChiragAgg5k merged 4 commits into
mainfrom
fix/build-cache-cleanup
Oct 22, 2026
Merged

ChiragAgg5k merged 4 commits into
mainfrom
fix/build-cache-cleanup

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Site deployment screenshots leave platform file rows behind.

Path Before After
Delete deployment / site (Deletes worker) object deleted, row in bucket_<screenshots> kept object and row deleted
Deployment deleted while capture runs (Screenshots worker) objects + rows written, never referenced capture bails before writing; anything already written is removed on failure

Tests (SitesConsoleClientTest, screenshots group):

  • testDeleteDeploymentScreenshots: screenshot rows 404 after the deployment is deleted
  • testDeleteDeploymentDuringScreenshotCapture: no screenshot rows remain when the deployment is deleted mid-capture

Related: appwrite-labs/cloud#6628

…untime

Builds keep a package-manager cache per resource and runtime image. Pin
that deleting a function or site, or changing its runtime, removes the
cache those builds wrote. Deployments::resourceCachePath() names that
path, and a unit test holds it to the path storage() hands the build.
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/build-cache-cleanup (after).

Metric Before After Change
🚀 Requests/sec 203.75 205.29 ⚪ +0.8%
⏱️ Latency P50 86.45 ms 83.6 ms ⚪ -3.3%
⏱️ Latency P95 191.3 ms 193.65 ms ⚪ +1.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 83.6 193.65 12,654 205.29 +2.35
Account 150.03 270.42 666 11.08 -16.49
TablesDB 82.4 155.07 6,882 112.95 -2.86
Storage 75.42 200.05 3,330 56.96 +24.75
Functions 109.41 221.98 1,776 31.35 +5.94

Top API waits (after)

API request Max wait (ms)
functions.create 993.81
functions.variables.update 689.7
functions.variables.create 624.22
functions.variables.delete 537.17
storage.buckets.create 503.72

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
node-20 is listed as node-20.0, so the update was refused before it
could reach the cache.
@ChiragAgg5k
ChiragAgg5k force-pushed the fix/build-cache-cleanup branch from 748900f to 083f984 Compare October 22, 2026 09:42
The cache key hashes project, resource and runtime image, and only a
project delete removed the cache directory. Deleting a function or site
left its cache behind, and changing the runtime stranded the previous
image's cache where no later build or delete looks.

The deletes worker now removes the resource's current cache, and the
function and site update endpoints remove the previous cache when the
runtime image changes. The key stays as it is, so existing caches keep
working.
@ChiragAgg5k
ChiragAgg5k marked this pull request as ready for review October 22, 2026 10:15
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Stale docblock now misdocuments deleteBuildCache (Deletes.php:1655) — The PR inserted deleteBuildCache after the old @param Device $device / @param Document $deployment docblock instead of replacing it, so deleteBuildCache (which takes $deviceForBuilds, $project, $resource) carries a docblock describing deleteBuildFiles' parameters (src/Appwrite/Platform/Workers/Deletes.php:1655-1663).

This PR introduces per-resource build-cache reclamation: a new resourceCachePath() derives the deterministic cache key previously written by builds, and both the Functions/Sites update flows and the deletes worker now remove the cache left behind when a runtime changes or a resource is deleted.

Files Change
src/Appwrite/Deployment/Deployments.php Adds resourceCachePath() mirroring the build storage() key derivation.
src/Appwrite/Platform/Modules/Compute/Base.php Adds deleteStaleBuildCache() called from update actions when the runtime image changes.
src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php, src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php Capture the pre-update snapshot and invoke stale-cache cleanup.
src/Appwrite/Platform/Workers/Deletes.php Adds deleteBuildCache() wired into deleteFunction/deleteSite.
tests/unit/Deployment/*, tests/e2e/Services/{Functions,Sites}/* Unit contract tests for path derivation and e2e assertions that caches are removed after updates and deletes.

Reviewed commit: d62378f

@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This pull request resolves build-cache paths from each resource’s runtime image and removes the corresponding cache when a function or site is deleted or its runtime changes. It adds coverage for cache-path identity and cleanup, and the latest updates keep the function and site update actions compatible with callers that do not provide a builds device.

Latest changes: The newest commits make the builds device nullable and optional in both update actions, skipping stale-cache cleanup when a direct caller omits it to preserve backward compatibility.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 9
File Change
src/Appwrite/Deployment/Deployments.php Derives a resource’s build-cache path using its project, identity, and runtime image.
src/Appwrite/Platform/Modules/Compute/Base.php Adds best-effort stale-cache cleanup, safely skipping it when no builds device is supplied.
src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php Cleans the prior function cache after updates and keeps the builds-device argument optional.
src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php Cleans the prior site cache after updates and keeps the builds-device argument optional.
src/Appwrite/Platform/Workers/Deletes.php Removes a function or site’s build cache during resource deletion.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Covers build-cache cleanup when deleting a function and changing its runtime.
tests/e2e/Services/Sites/SitesCustomServerTest.php Covers build-cache cleanup when deleting a site and changing its build runtime.
tests/unit/Deployment/Storage.php Adds a test helper for resolving a resource’s build-cache path.
tests/unit/Deployment/StorageTest.php Checks that resource cache paths match build paths and vary by runtime and resource identity.

Reviewed the commits since d62378f · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

The build device was a new required parameter on the function and site
update actions, so a subclass calling parent::action() with the previous
argument list would fail on every update. Make it optional and last;
without it the stale cache is left as before.
@ChiragAgg5k
ChiragAgg5k merged commit d61aa63 into main Oct 22, 2026
65 checks passed
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
fix: delete build cache with its function, site or runtime
(cherry picked from commit d61aa63)
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.

1 participant