Skip to content

Tell a running agent when the disk is low (disk-low-notify hook) - #1414

Merged
GLinnik21 merged 5 commits into
mainfrom
disk-low-notify
Nov 16, 2026
Merged

GLinnik21 merged 5 commits into
mainfrom
disk-low-notify

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

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 -rf of build trees.

Until now nothing told a live agent: make's disk preflight evicts silently before a build, and build-gc-auto.sh starts tools/build-gc.sh --auto only at SessionEnd.

What it does

.claude/hooks/disk-low-notify.py, registered for PostToolUse and PostToolUseFailure (matcher Bash):

  • Fast path: one statvfs on the checkout's volume and a substring scan of stdin. No JSON parse and no subprocess when there is room.
  • Thresholds: the same as tools/disk-budget.py: the comfort line PLX_GC_MIN_FREE_GIB (20) and the reserve PLX_MIN_FREE_MB (3072). A test reads disk-budget.py's defaults so the two cannot drift.
  • low (free space below the comfort line): detaches the MAIN checkout's build-gc.sh --auto, the way build-gc-auto.sh does, and adds a note.
  • critical (below the reserve, or a failed command's error says the filesystem is full while this volume is below the comfort line): a stronger note, and the same reclaim.
  • elsewhere (a failure reports a full filesystem while this volume has room): a note only. Nothing is launched and "critical" is not used.
  • Note format: the additionalContext is 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-line systemMessage goes to the human. A subagent gets a variant meant for its report to the caller.
  • Throttle: once per session per level, again on a 5 GiB drop or after 30 minutes. A machine-wide launch dedup of 10 minutes sits on top of build-gc's own --auto lock. State is written atomically.
  • Safety: fail-open (any error exits 0 with no output). PLX_DISK_NOTIFY=off disables it.
  • Limit: hooks run only after tool calls; there is no timer event, so an idle session is not warned until its next call.

Wiring

  • .claude/settings.json: the two registrations.
  • ci/check-python-steps.txt: the new test as a step.
  • AGENTS.md: one sentence in the make disk bullet.

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 correct
  • python3 .claude/hooks/build-gc-auto-test.py: OK
  • ci/test_ci_split.py, ci/test_ci_workflows.py, ci/test_managed_targets.py, ci/test_agent_files.py: OK
  • Smoke runs with a stubbed launcher covered three cases: the elsewhere note, a critical note with one launch, and a successful grep ENOSPC that printed nothing.
  • make check is left to CI.

Known gap: .claude/settings.json is in CI's MUST_NOT_TRIGGER list, 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

GLinnik21 and others added 5 commits November 16, 2026 22:04
…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]>
@GLinnik21
GLinnik21 merged commit 6adf1bf into main Nov 16, 2026
9 checks passed
@GLinnik21
GLinnik21 deleted the disk-low-notify branch November 16, 2026 19:38
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