Repository navigation
fix(upload): delete expired uploads on a timer, not only after uploads - #651
Merged
Merged
Conversation
Expired upload folders were only removed by a background task that ran after a later successful upload, so on a quiet server uploaded source code could stay on disk indefinitely. Add a FastAPI lifespan that sweeps expired uploads once at startup and then every VIBEGRAPH_UPLOAD_CLEANUP_INTERVAL_SECONDS (default 300) until shutdown. The sweep runs in a worker thread, a failed sweep is logged and does not stop later ones, and shutdown cancels and awaits the task. Invalid, zero or negative interval values fall back to the default. The per-upload cleanup and the one-hour retention are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No test failed when the sweep ran on the event loop thread, and a sweep that swallowed CancelledError only made the suite hang at random. Add two tests: one checks that the cleanup runs in a worker thread, the other cancels the task while a sweep is running and expects it to stop. Also reword the README line so "every 5 minutes" clearly refers to the running server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
madara88645
marked this pull request as ready for review
October 23, 2026 20:50
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Expired upload folders (
vibegraph_upload_*in the system temp dir) were only deleted by a background task that ran after a later successful upload. On a quiet server, uploaded source code could stay on disk indefinitely, and the README privacy section said so.This PR adds a timed cleanup, so expired uploads are deleted even when no further upload arrives.
New behavior
create_app()now passes a FastAPIlifespan(Starlette 1.x has noon_event):cleanup_expired_upload_dirs) before the app serves requests, then starts one asyncio task,upload-cleanup.UPLOAD_CLEANUP_INTERVAL_SECONDS.asyncio.to_thread), so filesystem work never blocks the event loop.Upload cleanup failed) and later sweeps still run. Cancellation is not swallowed.cleanup_expired_upload_dirskeeps its signature and behavior.uvicorn app:appin Dockerfile and Dockerfile.fly),serve.pyandmain.py startall use the sameappobject, so they all get the lifespan.TestClient(app)withoutwithdo not run the lifespan, and requests work exactly as before.Guarantee: while the server is running, an upload is deleted within about one hour (retention) plus the interval (5 minutes by default). If the process is stopped (Fly stops idle machines), nothing runs while it is stopped. The sweep runs again on the next start, before requests are served.
Config
VIBEGRAPH_UPLOAD_CLEANUP_INTERVAL_SECONDS, default300.abc,1.5, an empty string,0or-5log a warning and fall back to300. So a typo can neither switch the sweep off nor turn it into a busy loop.VIBEGRAPH_UPLOAD_RETENTION_SECONDS, default3600) is unchanged..env.example.How verified
tests/test_upload_cleanup_schedule.py(14 tests, about 1 s):CancelledError.python -X dev -m uvicorn app:app, a privateTMPDIR, a short interval and an artificially slow delete:/api/healthstayed under 13 ms while a 3 s sweep ran;Out of scope
🤖 Generated with Claude Code