Skip to content

fix(sites): delete screenshot rows with their deployment - #14764

Merged
ChiragAgg5k merged 5 commits into
mainfrom
fix/screenshot-rows
Oct 22, 2026
Merged

ChiragAgg5k merged 5 commits into
mainfrom
fix/screenshot-rows

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
Capture finishes between the delete action's read and delete Deletes worker gets a snapshot without the IDs read under the same row lock (forUpdate) the worker's update takes
Object unlink fails row deleted, object untracked row kept while the object exists

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

Deleting a deployment removes the screenshot objects but keeps their
file rows, and a deployment deleted while its capture runs still gets
both files and rows written afterwards.
@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/screenshot-rows (after).

Metric Before After Change
🚀 Requests/sec 215.4 218.19 ⚪ +1.3%
⏱️ Latency P50 79.24 ms 78.42 ms ⚪ -1%
⏱️ Latency P95 195.56 ms 190.14 ms ⚪ -2.8%
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 78.42 190.14 13,680 218.19 -5.41
Account 155.67 312.96 720 12.06 +36.25
TablesDB 76.45 150.06 7,440 120.4 -4.75
Storage 70.65 162.64 3,600 60.15 -13.32
Functions 116.44 217.51 1,920 32.9 -8.87

Top API waits (after)

API request Max wait (ms)
account.name.update 578.02
tablesdb.rows.create 435.7
account.prefs.update 378.69
account.get 362.75
functions.variables.update 357.39

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
The Deletes worker removed the screenshot objects but kept their file
rows in the platform screenshots bucket, so every deleted deployment or
site left two unreachable rows behind.

A deployment deleted while its capture ran was worse: the worker still
wrote both objects and rows, then found no deployment to attach them to.
It now re-checks the deployment before writing, and removes anything it
already wrote whenever the capture fails before the deployment takes
ownership of the screenshots.
@ChiragAgg5k
ChiragAgg5k marked this pull request as ready for review October 22, 2026 10:06
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Polling test asserts before waiting, never breaks on success (SitesConsoleClientTest.php:243) — The polling loop in testDeleteDeploymentDuringScreenshotCapture calls assertSame(0, $files['body']['total']) inside the loop body (tests/e2e/Services/Sites/SitesConsoleClientTest.php:244), unlike assertEventually, which catches assertion failures and retries.

This PR wires screenshot artifacts into the deployment deletion lifecycle: when a deployment (or function) is deleted, the Deletes worker now removes the stored screenshot files from storage and deletes their corresponding rows from the screenshots bucket collection, then proceeds with the usual deployment cleanup. A new e2e test in the Sites console suite confirms that after a deployment delete, the screenshot files are no longer listed in storage while the DB row is removed.

Files Change
src/Appwrite/Platform/Workers/Deletes.php Deletes worker now removes screenshot files from storage and their bucket rows during deployment/function deletion.
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Screenshot capture worker adjustments supporting the new cleanup path.
tests/e2e/Services/Sites/SitesConsoleClientTest.php E2E test asserting screenshots are cleaned up after deployment deletion.

Reviewed commit: d6b0112

@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental recovery path preserves a committed deletion's screenshot snapshot and refreshes it before retrying an uncommitted delete.

The pull request cleans up screenshot storage objects and platform file rows when site deployments are deleted, and removes captures that fail because their deployment disappears. Deployment deletion reads the row under the same lock as screenshot updates so the queued cleanup includes the latest screenshot IDs. E2E tests cover cleanup after deletion and deletion during capture.

Latest changes: The new commit retains the last locked deployment snapshot across a transaction failure, then rereads and retries deletion under the row lock when the delete did not commit.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Tracks screenshot files during capture and cleans up stored objects and rows when capture fails or its deployment is gone.
src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php Locks and snapshots the deployment before deletion, preserving or refreshing that snapshot across transaction failures.
src/Appwrite/Platform/Workers/Deletes.php Deletes deployment screenshot objects and their platform rows, retaining rows if object deletion fails.
tests/e2e/Services/Sites/SitesConsoleClientTest.php Adds E2E coverage for screenshot cleanup after deployment deletion and deletion during capture.

Reviewed the commits since e86564f · 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 A · See the inline comments. Summary

@luxor-code-review luxor-code-review Bot 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.

Adds deployment screenshot cleanup to the Deletes worker plus an e2e test verifying screenshot persistence after deployment deletion.

Key findings

Deleting a deployment read it, then deleted it. A capture finishing in
between wrote its screenshot IDs to a row the Deletes worker never saw,
so the worker's files were orphaned after it handed them over. The read
now happens under the row lock the screenshots worker's update takes:
either the IDs are in the snapshot, or the update finds no row and the
worker removes its own files.

A deleted site's Deletes worker can likewise read a deployment before
the capture updates it, so the worker keeps ownership of its files when
the site update finds no site.

A screenshot row is now kept while its object still exists, so a failed
unlink leaves the object findable instead of untracked.
…ction

The TransactionException fallback deleted the deployment but enqueued the
copy read before the transaction, which can miss screenshot IDs a capture
wrote in between. It now keeps the last locked read when the delete had
committed, and otherwise locks, re-reads and deletes, enqueuing that copy.

@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

@ChiragAgg5k
ChiragAgg5k merged commit 5b95b1f into main Oct 22, 2026
45 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/screenshot-rows branch October 22, 2026 15:04
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
fix(sites): delete screenshot rows with their deployment

(cherry picked from commit 5b95b1f)
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