Skip to content

fix: remove import copies on project delete and refused imports - #14759

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/imports-cleanup
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/imports-cleanup

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Import copies in /storage/imports/app-<projectId>/ could outlive everything that names them.

Leak Fix
Project delete removed uploads, sites, functions, builds and cache roots, but not imports deleteProject also deletes the project's imports root (same guard: empty project ID is refused before any device is built)
CSV/JSON import copied the file, then validated database/collection; a 404 left a copy no migration names Validate database, type and collection before copying
Separate-topology appwrite-worker-deletes had no imports volume Mount appwrite-imports
$deviceForImports = new TelemetryDevice($telemetry, getDevice(APP_STORAGE_IMPORTS . '/app-' . $projectId));
$deviceForImports->delete($deviceForImports->getRoot(), true);

Tests (E2E, pushed before the fix to show red):

  • MigrationsBase::testRefusedImportLeavesNoCopy: CSV and JSON import into a missing database returns 404 and leaves no *_<fileId>.* copy.
  • ProjectsConsoleClientTest::testDeleteProjectRemovesPendingImports: a pending import file is gone after the project is deleted.

Related: appwrite-labs/cloud#6628

…eletes

A refused CSV/JSON import and a project deleted before its import runs both leave the copied file in the imports directory with no migration to remove it.
@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • 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/imports-cleanup (after).

Metric Before After Change
🚀 Requests/sec 217.84 225.74 ⚪ +3.6%
⏱️ Latency P50 77.77 ms 77.62 ms ⚪ -0.2%
⏱️ Latency P95 190.06 ms 174.31 ms 🟢 -8.3%
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 77.62 174.31 13,851 225.74 -15.75
Account 139.67 260.55 729 12.14 -29.81
TablesDB 76.83 146.42 7,533 124.19 -1.57
Storage 68.58 159.14 3,645 62.29 -7.58
Functions 103.93 191.56 1,944 34.03 -32.82

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 445.88
tablesdb.rows.update 411.98
functions.create 365.54
account.name.update 361.49
account.prefs.update 309.88

Project delete cleared every per-project storage root except imports, so a file waiting for its migration outlived the project. The CSV and JSON import endpoints copied the file before checking the database and collection, so a refused request left a copy that no migration names and nothing would remove. Validate first, delete the imports root with the other roots, and mount the imports volume on the separate deletes worker so it can reach it.
@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ChiragAgg5k
ChiragAgg5k marked this pull request as ready for review October 22, 2026 09:27
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Staged import copy leaks in APP_STORAGE_IMPORTS on post-copy failure · Create.php:176–180 · unchanged line

// src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php
176	        } elseif (!$deviceForFiles->copy($path, $newPath, $deviceForMigrations)) {
177	            throw new \Exception('Unable to copy file');
178	        }
179	
180	        $fileSize = $deviceForMigrations->getFileSize($newPath);

Both import actions copy the uploaded file into the migrations device, but if $dbForProject->createDocument('migrations', ...) or $publisherForMigrations->enqueue(...) throws afterwards, nothing deletes the staged copy (CSV/Imports/Create.php:176). The copy can be a fully decrypted/decompressed plaintext for encrypted or compressed uploads. The orphaned file persists in APP_STORAGE_IMPORTS forever, since no maintenance task sweeps that device and project deletion only helps if the project still exists.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Silent false from Local::delete skips imports cleanup error log (Deletes.php:1094) — The new imports cleanup relies on catch (Throwable) to report deletion failure, but Local::delete() signals failure by returning false, not throwing (packages/storage/src/Device/Local.php:480).

The change hardens the CSV/JSON migration import endpoints by moving the database and collection lookup ahead of the file copy, so a bad target no longer leaves a staged copy on disk, and introduces lifecycle cleanup for the new imports storage device. Docker wiring gains the matching appwrite-imports volume and APP_STORAGE_IMPORTS environment, and e2e suites are extended to cover the new validation errors.

Files Change
src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php, src/.../JSON/Imports/Create.php Move database/collection existence validation before the file copy/decryption step in both import endpoints
src/Appwrite/Platform/Workers/Deletes.php Delete the project's /storage/imports/app-{projectId} directory during project-deletion cleanup
docker-compose.yml Add the appwrite-imports volume and APP_STORAGE_IMPORTS env wiring to the compose stack
tests/e2e/Services/Migrations/MigrationsBase.php, tests/e2e/Services/Projects/ProjectsConsoleClientTest.php Extend e2e coverage for import validation ordering and project-deletion cleanup

Reviewed commit: 837fd45

@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The changed code and surrounding call paths show the import validations run before copy, and the cleanup is guarded and available in the separate deletes-worker topology.

This change removes a project's temporary migration-import directory during project cleanup, validates database and collection targets before CSV/JSON imports copy files, and mounts the imports volume in the separate deletes worker. It also adds E2E coverage for refused imports and project deletion with a pending import file.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
docker-compose.yml Mounts the imports volume in the separate deletes worker.
src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php Validates the target database, supported CSV database type, and collection before copying the file.
src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php Validates the target database and collection before copying the file.
src/Appwrite/Platform/Workers/Deletes.php Deletes the project's imports storage directory during project cleanup.
tests/e2e/Services/Migrations/MigrationsBase.php Adds coverage that refused CSV and JSON imports leave no copy.
tests/e2e/Services/Projects/ProjectsConsoleClientTest.php Adds coverage that project deletion removes pending import files.

Reviewed 837fd45 · 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

@ChiragAgg5k
ChiragAgg5k merged commit f8bd84f into main Oct 22, 2026
118 of 120 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/imports-cleanup branch October 22, 2026 11:00
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
fix: remove import copies on project delete and refused imports
(cherry picked from commit f8bd84f)
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