Skip to content

Prune idle workspace Gradle caches at startup - #35

Merged
mathewdunne merged 6 commits into
mainfrom
gradle-cache-prune
Nov 18, 2026
Merged

mathewdunne merged 6 commits into
mainfrom
gradle-cache-prune

Conversation

@mathewdunne

Copy link
Copy Markdown
Owner

Why

On 2026-11-16 the prod data disk (50 GB) filled up during a class. Every workspace request then failed with SQLITE_FULL, and students saw "Something went wrong!" and "Run channel disconnected". Each of the 20 workspaces held a 1.2–2.2 GB home/.gradle/caches, mostly a copy of the image's pre-filled cache. Nothing ever removed it, so disk use grew by ~1.5 GB for every student who had ever signed in. As a stopgap the disk was grown to 100 GB and the caches of idle workspaces were cleared by hand.

What

Every time the control plane starts, it deletes home/.gradle/caches for each <dataDir>/users/ws_* workspace that nobody has used in more than GRADLE_CACHE_PRUNE_DAYS days (default 14; 0 turns it off).

  • Folders with no matching workspace in the database count as idle.
  • Workspaces whose code container is running are skipped, checked with docker inspect.
  • Demo mode is skipped, because its caches live in named volumes.
  • The prune runs in the background and doesn't delay boot. It logs one summary line.
  • Each cache is first renamed to caches.pruning-<ts> (an atomic step), then deleted. A container that starts mid-prune therefore sees no caches/ and gets a clean fresh copy from the image. Leftover caches.pruning-* folders are deleted on the next start.

It runs at startup rather than on a timer because the prod VM is stopped between classes, and changing the VM startup script through Terraform would replace the instance. Decision log: docs/decisions/049-startup-gradle-cache-prune.md. Design and plan: docs/superpowers/specs|plans/2026-11-16-gradle-cache-prune*.

Testing

  • bun run typecheck and bun run check are clean.
  • bun run test: 577 pass. bun run test:web: 164 pass.
  • New gradle-cache-prune.test.ts covers:
    • idle vs. recent workspaces, and the exact cutoff
    • orphan folders
    • running workspaces skipped, including when the running check throws
    • leftover cleanup and ignored entries
    • a missing users/ folder
    • a real createApp boot, with pruning on and with 0
  • New config tests cover the default, 0, blank values, and invalid values.

Known limitations

These are minor, and neither loses student data:

  • If the Docker socket can't be reached, a running container looks stopped, so its cache could be pruned. Gradle would then re-download its dependencies.
  • If a container starts in the instant between the running check and the rename, it ends up with no cache and Gradle re-downloads instead of copying from the image.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VMtFpc22vNkYXSGLTHES97

mathewdunne and others added 6 commits November 17, 2026 00:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VMtFpc22vNkYXSGLTHES97
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VMtFpc22vNkYXSGLTHES97
Wire pruneIdleGradleCaches into createApp (real Docker runtime, not demo,
GRADLE_CACHE_PRUNE_DAYS > 0), add isCodeContainerRunning to the Docker
runtime provider, and document the setting and decision 049.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VMtFpc22vNkYXSGLTHES97
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VMtFpc22vNkYXSGLTHES97
- Treat docker inspect failures other than "no such container" as an
  error so the prune skips the workspace instead of assuming it's stopped.
- Keep workspaces whose last_accessed_at is unparseable.
- Re-check idleness right before the rename so a sign-in during the
  running check keeps the cache.
- Log the prune as disabled in demo mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mathewdunne
mathewdunne merged commit e15ad79 into main Nov 18, 2026
1 check passed
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