Repository navigation
clean: reclaim finished agent checkouts hourly - #41
Merged
Merged
Conversation
kixelated
added a commit
to moq-dev/moq
that referenced
this pull request
Nov 5, 2026
Finished T3 and Claude Code checkouts reclaim their managed targets from the dotfiles cleaner on an hourly timer. That work is kixelated/dotfiles#41. Delete this quest. Co-Authored-By: Grok 4.7 <noreply@x.ai>
Scan ~/worktrees and release a managed target when its T3 thread, quest checkout, or Claude Code transcript is finished. A live session, a non-terminal run, an unknown t3-* path, or a process in the target keeps it. Idle time is not a signal. Closed pull-request heads count as abandoned work. The hourly timer replaces the manual-only service. Co-Authored-By: Grok 4.7 <noreply@x.ai>
kixelated
force-pushed
the
agent-disk-budget
branch
from
November 6, 2026 16:34
0e67f79 to
fdbe6f8
Compare
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.
Problem
On 2026-11-04 the desktop root disk filled three times, down to 244 MB and then to 5-14 GB, while parallel agent builds ran. Managed mbx targets were about 430 GiB across roughly 420 checkouts. Almost all of that sat on
~/worktrees/moq/t3-*checkouts. Cleaning targets that had been idle for more than six hours freed about 150 GiB, and only 2 of 742 T3 worktrees were at a merged pull-request head.The cleaner did not scan
~/worktrees, and after the 15-minute timer was removed it ran only when someone started it. kixelated/dotfiles#36 keeps a target until its checkout is gone. This change is what removes a finished checkout, or its target, so that retention rule can release the disk.Approach
The hourly
worktree-clean.timerruns the existing oneshot. It is persistent, with a ten-minute randomized delay. A 15-minute timer spent more time fetching and calling GitHub than the disk needed. An hour matches how these targets accumulate.~/worktreesis a scan root, next to~/work,~/.codex/worktrees,~/.worktrees, and/tmp.A checkout is finished only when an owner signal says so:
completed,failed,cancelled,interrupted,rolled_back) and every session isstoppedor absent. One non-terminal run or any other session status keeps the path. A path with no terminal run and no archived thread is still being created.phaseisreleasedandrunsis empty. Any other phase, a supervised run, or an unreadable registry keeps a.worktreescheckout.*.jsonl) exists for that.claude/worktreespath. No transcript falls through to the git rules.An unknown
t3-*directory under aworktreespath stays, including when the T3 database cannot be read. A database or registry error is not treated as finished. Idle time, mtime, and T3'sworktreeAfterDaysare not signals.Git completion still applies to ordinary worktrees. A closed pull request's head is abandoned work, so its history qualifies. Commits after that head do not. A detached HEAD still needs a surviving local branch or tag, including when the agent signal says the checkout is finished. Branches are not deleted.
A finished, clean, idle checkout is removed with
git worktree remove, which already runsmbx cache remove. A finished checkout that is dirty or untracked stays, andmbx cache removeruns for its managed workspace targets after a fresh process check. A process in the checkout or the target keeps both./tmpis still scanned only for registered worktrees. Age does not delete test scratch such as/tmp/moq-test-*. On 2026-11-05/tmpis its own filesystem (/dev/nvme0n1p1, 627G free of 954G). Aduof/tmpshowed about 159G, of which/tmp/moq-test-1000was 78G of failed-test evidence. mbx attributed 0 managed-target bytes to/tmp.Impact
Read-only classification on 2026-11-05, using this gate and an mbx project snapshot from the same day. This did not delete anything.
~/worktrees/*and~/work/*: 873 finished, 15 busy, 295 untracked. Finished paths accounted for about 76.6 GiB of managed targets. Busy paths accounted for about 3.6 GiB.~/worktrees/moq/t3-cced8ddf(1.2 GiB, run in progress) and~/worktrees/moq.pro/t3-00f61769(2.4 GiB, run in progress). This session's checkoutt3-825df977is busy and had no managed target in the snapshot.t3-fb8bc7d835.5 GiB,t3-384cf58d12.8 GiB,t3-762e4a0512.7 GiB,t3-e9c7666c11.4 GiB.~/work/*/.claude/worktrees: 279 directories, 33 with a transcript and no managed-target bytes, 246 with no transcript. The 5.10 GiB checkoutagent-a42ff81308526f267has no transcript, so it stays unless git can prove completion.~/work/*/.worktrees: 7 released, 4 busy, 9 untracked, and no managed-target bytes in the snapshot.Action-cache figures overlap across checkouts, so they are not added to these totals. The 76.6 GiB figure is the managed-target upper bound the gate would allow. The cleaner still keeps a dirty tree and anything a process has open. The timer has not run for a day on this host because this PR does not install over the live dotfiles.
python3 -B -m unittest discover -s tests -vpassed, 92 tests.systemd-analyze --user verifyaccepted the service and the timer.Alternatives
Routing T3 checkouts through
quest worktreewould give one supervisor, but T3 owns~/worktreesand recreates a missing worktree. Quest only supervises.worktrees/checkouts it created. Extending this cleaner reclaims the checkouts T3 already has.Reclaiming on idle time, or on T3's one-day
worktreeAfterDays, would delete a checkout whose owner is between turns. The same-day targets above would also sit until the next day.Leaving cleanup manual keeps the disk full until someone notices. A 15-minute timer is more GitHub and fetch load than this disk needs.
Changing
target.keepbelongs to #36. This PR does not editmbx/config.toml. An explicitmbx cache removeafter a finished signal is the removal #36's retention allows.Follow-ups
Choices made without asking
quest worktree.OnCalendar=hourly,Persistent=true,RandomizedDelaySec=10min), not 15 minutes and not idle-time reclaim.t3-*paths stay./tmpand do not change mbxtarget.keephere.(Written by Grok 4.7 with high effort)