Garbage-collect the TEE container volume to stop /app/.data from filling up#5
Open
mpjunior92 wants to merge 16 commits intoGajesh2007:masterfrom
Open
Garbage-collect the TEE container volume to stop /app/.data from filling up#5mpjunior92 wants to merge 16 commits intoGajesh2007:masterfrom
/app/.data from filling up#5mpjunior92 wants to merge 16 commits intoGajesh2007:masterfrom
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Context
The Sovra TEE VM's 100 GB
pd-ssdmounted at/app/.datais running out of space, and EigenCloud's platform constraints make resizing the persistent disk impractical. This PR adds an application-level garbage collector so the container reclaims its own disk as it runs.Goals
/app/.datafrom filling up under normal operation.posts.jsonandcartoons.jsonare the product, never swept.Non-goals
Architecture
Two complementary mechanisms, both in-process. No new services.
1. Write-through cache. When R2 is enabled, local media files are deleted after the publish pipeline persists them with a CDN URL. Editor / Twitter upload / video producer still read the files locally during generation — cleanup fires only at end-of-publish, not inside the uploader helpers. When R2 is disabled, files stay put; the frontend serves them via fastify static routes.
2. Janitor. Runs every hour. Each sweep performs, in order:
events.jsonlexceeds 50 MB, keep the last 10,000 lines and rotate atomically..datamount is >70% full, run an aggressive sweep using a 1-day threshold. When R2 is disabled, also null outimageUrl/videoUrlfields inposts.jsonfor any file that was just deleted — the frontend renders a placeholder instead of a 404.JSON stores, cache files, and the agent keypair are never touched.
3. Startup disk audit. One-shot directory walk logged at boot: total size, per-subdir breakdown, top-10 largest files. Emits as a structured
[disk-audit] …line so Datadog can surface the real culprit on the next restart.Config
A single
gcblock, all fields overridable. Safe rollback lever: setGC_ENABLED=falseto disable both the write-through cleanup and the janitor.gc.enabledtrue(GC_ENABLED=falsedisables)gc.sweepIntervalMs1h(5sin TEST_MODE)gc.initialDelayMs60s(2sin TEST_MODE)gc.mediaMaxAgeMs7 daysgc.mediaPressureAgeMs1 daygc.diskPressureThreshold0.70gc.eventLogMaxBytes50 MBgc.eventLogKeepLines10,000Error handling
Each step in a sweep is wrapped in a try/catch that logs and continues — one branch failing never blocks the others.
unlink/statENOENT is swallowed silently (files vanish concurrently).statfsfailure skips the pressure check for that cycle. Event-log rotation writes to a temp file then atomic-renames; there is a small race where events written during the rename may be lost — acceptable, documented in code.When R2 upload fails, the local file is preserved (same as before this PR). The janitor's age sweep is the backstop — orphaned local files get reclaimed in 7 days.
Testing
posts.jsonURL null-out (with cross-subdir basename collision coverage),cleanupLocalIfOnR2no-op when R2 is off.events.jsonland aged media, waits one janitor cycle, asserts rotation landed under the threshold and pressure behavior is correct. Runs locally in ~10s (the Docker image build is the main cost). Invoked viabun run test:e2e.bun run typecheckclean.Rollout plan
ecloud compute app upgrade "Sovra Agent".[disk-audit]log line → confirms which subdir or file is actually dominating the disk.[janitor] rotated events.jsonl: X → Y bytesshould appear.GC_ENABLED=falsein the env and redeploy.