4.6 KiB
Project cascade deletion (Fanyu)
Project deletion now uses a persisted task in project_deletion_tasks, independent of the project record. A preview digest, exact project name and reason are required. Active Runs additionally require explicit stop confirmation.
Order and recovery
Before acquiring the deletion task or stopping writers, initialize the Kubernetes
client with the API's K8S_NAMESPACE, K8S_IMAGE_PULL_SECRET_NAME,
WORKSPACE_PVC_NAME, and WORKSPACE_MOUNT_PATH. Do not substitute blank or dummy
PVC values. Initialization failure returns project_deletion_configuration_invalid
without starting cleanup. The background executor repeats this preflight.
- Save the task and lock the project. Pause Capture intake and refuse new project/workflow/human-task writes.
- Stop owned Run Kubernetes Jobs/Pods and verify absence. Wait for Run execution leases and API-side slicing/submission writers to settle.
- Delete only the confirmed Run workspaces and workflow-generated object prefixes. Verify storage deletion; errors are not ignored.
- Cascade business records and remove the project last.
- Keep the deletion task, receipts and errors. Closing the dialog does not cancel it. After an interruption the lease expires; an administrator can retry from deletion history. Concurrent retries cannot own the same task.
The workspace object-store mapping is explicit:
PROJECT_DELETION_WORKSPACE_CONNECTION_IDPROJECT_DELETION_WORKSPACE_BUCKET
Only system/runs/<validated Run ID>/ is considered a Run workspace. Shared system/, models, backups, raw Capture input roots, accounts, suppliers, public templates and the global trash are retained. Ambiguous/shared paths stop deletion. Previously orphaned directories lacking project/Run ownership are not swept by this feature.
Batch deletion
The project list supports selecting up to 20 projects and opening one batch confirmation dialog. Each row shows its own preview, retained inputs, blockers, progress and retry control. No project-name or reason text entry is required in the batch UI; the confirmed preview name/digest and an explicit-action reason are sent using the existing single-project contract. Active Runs still require the stop checkbox.
POST /api/project-deletions/batch accepts projects[] containing projectId
and the single-project confirmation fields. Admission is checked independently
per project, including organization, preview digest and deletion lease. The
response contains results[] with each project's HTTP status and task/error.
One failure does not cancel other admissions. Tasks are persisted independently;
closing the dialog does not cancel admitted cleanup. A retry of the same selection
reuses existing task IDs, and completed projects are not deleted again. Deletion
history remains the recovery entry after a lost response or API interruption.
Each project's cleanup count has a progress bar, and the batch footer keeps the overall step progress visible while scrolling long manifests. Percentages use completed targets divided by all targets, not bytes or elapsed time. Failed tasks retain their completed steps; 100% requires the final completed task status.
Batch validation includes partial failure, cross-organization rejection, duplicate selection, admin role checks, repeat requests, and isolated browser checks of three projects followed by retrying only the failed one.
Manual acceptance
Use a disposable project, not production source data:
- Open project deletion; check counts, exact generated paths and retained input roots.
- Submit a wrong name or omit reason: deletion must not start.
- With active processing, omit stop confirmation: deletion must not start.
- Confirm deletion, close the dialog, reopen “删除记录”: the same task and progress remain visible.
- Simulate a storage permission failure in an isolated test connection: project remains locked, failure is visible, no success is reported.
- Restore permission and retry: completed steps remain recorded, remaining cleanup finishes.
- Confirm project/Run/human records and owned output directories are gone; original Capture files and other projects remain.
- Interrupt the API during deletion in an isolated environment: after lease expiry, retry the retained task.
Validation scope: automated fixtures use temporary directories, an in-memory store, injected runtime/storage failures, and the real Kubernetes client against an isolated HTTP fixture. Tests cover configuration propagation, missing PVC rejection, already-absent resources, failure/retry, and raw-input preservation. Real production deletion requires explicit user authorization. Storage deletion is irreversible unless independently backed up.