Repository navigation
Tell a running agent when the disk is low (disk-low-notify hook) - #1414
Merged
Merged
Conversation
…ady running A new PostToolUse + PostToolUseFailure hook on Bash (.claude/hooks/disk-low-notify.py) adds a factual note, and a one-line systemMessage for the owner, when free space on the checkout's volume is under tools/disk-budget.py's comfort line (PLX_GC_MIN_FREE_GIB) or reserve (PLX_MIN_FREE_MB), or a command's output reports "No space left on device". It detaches `tools/build-gc.sh --auto` from the main checkout, the way the SessionEnd hook does, so an agent that hears about low disk is also told the sanctioned cleanup is already running instead of improvising an rm -rf. The common case is one statvfs and a substring scan of stdin. Throttled per session and level (plus a 5 GiB drop or 30 minutes), the reclaim launch deduped for 10 minutes machine-wide. The test pins the default thresholds to disk-budget.py's constants and never starts the real build-gc. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ep to the manifest's end The note replays on --resume, possibly days later, so its stamp carries the date. The reclaim's live-tree check is worded as tools/build-gc.sh --evict and docs/disk-budget.md state it (a live builder, an open file or a touch inside the idle window skips a tree). The new test step goes at the END of ci/check-python-steps.txt, where its header says new steps go. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… another volume to its owner The "No space left on device" / ENOSPC / quota match counts only in a PostToolUseFailure's `error`: a grep or cat that exits 0 with the phrase in its output stays silent. When a failure carries the phrase while the checkout's volume is at or above the comfort line, another volume may be full: the note is given, build-gc.sh --auto is not started (it frees space on this volume), and the systemMessage says "a command reported a full filesystem; this volume has N GiB free" without the word critical. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A parser that copes with 5000-deep JSON no longer trips over it in the hook (the full-disk text is read from `error` only), so the response-shaped case runs above the thresholds and a separate case nests the `error` field itself. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e reclaim is not started The per-session state and the launch stamp are written to a temp file beside the target and renamed over it, so a concurrent hook never reads a truncated file. The AGENTS.md sentence claimed the reclaim was started whenever a command printed "No space left on device"; it is started only below the comfort line or the reserve, and the same error while the volume has room gets a note only. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
A running agent now hears about low disk inside its session, and hears that the sanctioned reclaim is already running, so it has no reason to improvise an
rm -rfof build trees.Until now nothing told a live agent:
make's disk preflight evicts silently before a build, andbuild-gc-auto.shstartstools/build-gc.sh --autoonly at SessionEnd.What it does
.claude/hooks/disk-low-notify.py, registered for PostToolUse and PostToolUseFailure (matcherBash):statvfson the checkout's volume and a substring scan of stdin. No JSON parse and no subprocess when there is room.tools/disk-budget.py: the comfort linePLX_GC_MIN_FREE_GIB(20) and the reservePLX_MIN_FREE_MB(3072). A test readsdisk-budget.py's defaults so the two cannot drift.build-gc.sh --auto, the waybuild-gc-auto.shdoes, and adds a note.additionalContextis written as factual statements, timestamped, because it is replayed rather than re-run on resume. This follows the hooks reference, which warns that imperative system-style text can trip prompt-injection defences. A one-linesystemMessagegoes to the human. A subagent gets a variant meant for its report to the caller.--autolock. State is written atomically.PLX_DISK_NOTIFY=offdisables it.Wiring
.claude/settings.json: the two registrations.ci/check-python-steps.txt: the new test as a step.make diskbullet.Verification
Run on the committed tree:
python3 .claude/hooks/disk-low-notify-test.py:disk-low-notify: 154/154 cases correct(also on /usr/bin/python3 3.9.6)python3 .claude/hooks/tv-lock-notify-test.py:tv-lock-notify: 100/100 cases correctpython3 .claude/hooks/build-gc-auto-test.py:OKci/test_ci_split.py,ci/test_ci_workflows.py,ci/test_managed_targets.py,ci/test_agent_files.py:OKgrep ENOSPCthat printed nothing.make checkis left to CI.Known gap:
.claude/settings.jsonis in CI'sMUST_NOT_TRIGGERlist, so a later PR that edits only the hook registrations starts no CI run. Left alone: changing it touches the workflow paths.🤖 Generated with Claude Code