Skip to content

feat: reap stale/failed upload orphans (scoped #65)#101

Merged
ravirajsinh45 merged 4 commits into
mainfrom
feat/reap-stale-uploads
Jul 7, 2026
Merged

feat: reap stale/failed upload orphans (scoped #65)#101
ravirajsinh45 merged 4 commits into
mainfrom
feat/reap-stale-uploads

Conversation

@ravirajsinh45

Copy link
Copy Markdown
Contributor

Summary

Stacked on the storage-usage branch. A scoped slice of #65: reclaim storage from stuck/failed
uploads — the leak the committed-only storage cap (#98) can't see.

What it does

Hourly Celery beat reap_stale_uploads:

  • Aborts stale, still-open S3 multipart uploads (ListMultipartUploads, Initiated older than
    STALE_UPLOAD_TIMEOUT_HOURS, default 24) — the only way to reach stuck multiparts, since the
    UploadId is not stored in the DB.
  • Soft-deletes uploading/failed versions older than the cutoff and best-effort deletes their
    S3 objects (raw + processed/HLS prefix + thumbnail). DB rows stay for No garbage collection for soft-deleted assets / orphaned S3 objects / expired share links #65's retention GC.

New: settings.stale_upload_timeout_hours; s3_service.list_stale_multipart_uploads + delete_prefix.
Logic split into a testable _reap_stale_uploads(db) (mutates, no commit) + a task wrapper (session +
commit).

Out of scope (stays in #65): soft-deleted-asset cascade GC, ShareLink.expires_at enforcement, a
general orphan sweeper, retention window, manual purge endpoint.

Testing

  • Full backend suite: 95 passed; 5 new tests — S3 helpers, reaper mock-unit (soft-delete + best-effort
    S3 deletes), and a real-DB selection test (old uploading/failed reaped; recent/ready untouched).

Stacked on chore/storage-usage-tests-and-alignment; retarget as the stack merges.

@ravirajsinh45 ravirajsinh45 force-pushed the feat/reap-stale-uploads branch from 7f1545e to d9f4484 Compare July 7, 2026 03:07
@ravirajsinh45 ravirajsinh45 force-pushed the chore/storage-usage-tests-and-alignment branch from 9fac2a6 to ee28017 Compare July 7, 2026 04:28
ravirajsinh45 added a commit that referenced this pull request Jul 7, 2026
@ravirajsinh45 ravirajsinh45 force-pushed the feat/reap-stale-uploads branch from d9f4484 to 9916b6b Compare July 7, 2026 04:28
@ravirajsinh45 ravirajsinh45 force-pushed the chore/storage-usage-tests-and-alignment branch from ee28017 to f5e87a5 Compare July 7, 2026 05:26
ravirajsinh45 added a commit that referenced this pull request Jul 7, 2026
@ravirajsinh45 ravirajsinh45 force-pushed the feat/reap-stale-uploads branch from 9916b6b to b304e70 Compare July 7, 2026 05:26
@ravirajsinh45 ravirajsinh45 force-pushed the chore/storage-usage-tests-and-alignment branch from f5e87a5 to 43e578c Compare July 7, 2026 05:46
@ravirajsinh45 ravirajsinh45 changed the base branch from chore/storage-usage-tests-and-alignment to main July 7, 2026 05:50
…eclaim orphan versions)

- _reap_stale_uploads(db) soft-deletes uploading/failed versions older than the
  configurable cutoff and best-effort deletes their S3 objects; reap_stale_uploads()
  task wraps session lifecycle + commit. Registered hourly in beat_schedule.
- Shared real_db fixture moved to conftest.py (used by storage-usage + reaper tests).
@ravirajsinh45 ravirajsinh45 force-pushed the feat/reap-stale-uploads branch from b304e70 to 872907e Compare July 7, 2026 05:50
@ravirajsinh45 ravirajsinh45 merged commit 0a0e5a6 into main Jul 7, 2026
4 checks passed
@ravirajsinh45 ravirajsinh45 deleted the feat/reap-stale-uploads branch July 7, 2026 05:53
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