Auto-clean task worktrees and monitor disk pressure#535
Open
Conversation
- Reduce DefaultWorktreeCleanupMaxAge from 7 days to 24 hours so closed task worktrees are reclaimed before a batch of reel-heavy tasks can fill the disk. - Run the stale-worktree cleanup every 10 minutes (was 1 hour) so tasks that cross the grace period are reclaimed within minutes, not an hour. - Trigger cleanup immediately when a task transitions to done/archived. No-op under the default grace period, but reclaims disk fast when a user sets worktree_cleanup_max_age to a short value or zero. - Add GetDiskStats (syscall.Statfs) plus DefaultDiskWarnPercent (85%) and DefaultDiskRefusePercent (90%) constants. New settings disk_warn_percent and disk_refuse_percent allow overrides. - The executor now samples disk usage every 5 minutes. Above the warn threshold it logs a warning; above refuse it force-cleans stale worktrees ignoring the grace period. - Before starting new tasks, refuse and move them to blocked with a clear message when disk >= refuse threshold. Prevents the silent SQLite I/O errors that jammed the daemon on 2026-04-20. - Expose `ty worktrees disk` to view current usage and thresholds. 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.
Summary
Today's incident (2026-04-20) filled the agent server's disk to 100% after ~13 Boston reel iterations, causing SQLite I/O errors and a stuck task in a retry loop. Root cause: each TaskYou worktree is ~500MB (node_modules + binary outputs), and the default cleanup grace period was 7 days with an hourly check.
This PR tightens cleanup and adds disk-pressure handling so the daemon can't silently fill disk again.
DefaultWorktreeCleanupMaxAge). Satisfies the "max 24h" acceptance criterion.done/archivedkicks offcleanupStaleWorktreesimmediately. Respects the grace period; valuable when users set it to 0 for immediate removal.syscall.Statfs. NewGetDiskStats, thresholdsDefaultDiskWarnPercent=85,DefaultDiskRefusePercent=90, overridable viadisk_warn_percent/disk_refuse_percentsettings.blockedwith a clear message (pointing toty worktrees cleanup --max-age 0) instead of erroring silently.ty worktrees diskcommand to inspect usage and thresholds.Test plan
go build ./...cleango vet ./...cleango test ./...all suites passinternal/executor/disk_test.gocovers Statfs success, missing path, threshold refusal logic, and config fallbackDefaultWorktreeCleanupMaxAgeabove 48h🤖 Generated with Claude Code