Skip to content

πŸ› janitor: prune idle Claude CLI session scratch under the temp directory - #18349

Merged
hivecommons-hive[bot] merged 1 commit into
v6from
feat/janitor-claude-tmp
Nov 16, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
v6from
feat/janitor-claude-tmp

Conversation

@hanthor

@hanthor hanthor commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Problem

The Claude CLI keeps per-session scratch in <tmp>/claude-<uid>/<project>/<session>/: task output, scratchpads, and whatever an agent clones or builds there. Nothing removes it when the session ends.

It lives in the container's writable layer, not on /data, so none of the janitor's existing classes see it, and it fills the node's root disk rather than the data volume.

On a Docker Compose host running two v6 spokes:

  • school grew 17 GiB and reef grew 22.6 GiB of container writable layer, almost all of it /tmp/claude-*/-data-agents-<agent>/<session>.
  • That filled the 100 GB root disk. Every other service on the host then failed. One, an OAuth broker, returned 500 for every request because it couldn't write its database.
  • About 490 of those session directories had no write in the last 6 hours.

Change

  • sessionprune.PruneClaudeTmp(tmpRoot, maxAge, now, logger) removes claude-*/<project>/<session> directories whose newest write anywhere inside is older than maxAge.
    • It reuses pruneHomeTarget, so it never follows symlinks, keeps a directory on any stat or walk failure, and only looks at that exact depth.
    • It never removes project or user directories, or anything else in /tmp.
  • DefaultTmpRetentionHours = 24. A resumed session loses only its scratch; its transcript lives under the agent home.
  • It is wired into the existing janitor goroutine: it runs at startup and then every 6 hours, beside runAgentHomePrune. It logs claude tmp prune complete only when it removed something.
  • Changelog fragment, plus a line in docs/diskpressure-recovery-runbook.md.

Tests

tmpprune_test.go covers:

  • An idle session is removed.
  • A session with a recent write deep inside an old tree is kept.
  • Paths outside the claude-*/<project>/<session> shape are kept.
  • Symlinks are never followed, at either the user or the session level.
  • An empty root, a missing root and maxAge <= 0 are no-ops.

go test ./pkg/sessionprune/ ./cmd/hive/, go vet, gofmt and go build ./cmd/hive/ all pass.

πŸ€– Generated with Claude Code

…tory

The Claude CLI keeps per-session scratch in <tmp>/claude-<uid>/<project>/
<session>/ and never removes it. It lives in the container's writable
layer, not on /data, so no existing janitor class saw it. On one Docker
host two spokes reached 17 GiB and 22 GiB and filled the root disk.

PruneClaudeTmp removes each session directory whose newest write anywhere
inside is older than 24 hours, reusing the home sweep's symlink-safe
newest-write rule, and runs on the janitor's existing 6-hour tick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: James Reilly <jreilly1821@gmail.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 16, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hanthor for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#18341 🌱 chore: top up v6 from v5 (2026-11-15, fourth) same files src/cmd/hive/main.go

@github-actions

Copy link
Copy Markdown
Contributor

Mutation testing

Head 3c1fa0b0d.

6 mutant(s) in changed files are not reached by any test (NOT COVERED). A maintainer may apply the mutation/acknowledged label to accept this.

File Line Mutation
src/cmd/hive/main.go 1493 ARITHMETIC_BASE
src/cmd/hive/sessionprunewire.go 93 CONDITIONALS_NEGATION
src/cmd/hive/sessionprunewire.go 97 CONDITIONALS_BOUNDARY
src/cmd/hive/sessionprunewire.go 97 CONDITIONALS_BOUNDARY
src/cmd/hive/sessionprunewire.go 97 CONDITIONALS_NEGATION
src/cmd/hive/sessionprunewire.go 97 CONDITIONALS_NEGATION

Verdict: uncovered (#17349).

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness review at 3c1fa0b: no blocker. The prune reuses pruneHomeTarget and newestModTime (homeprune.go:128, prune.go:123), which are symlink-safe and keep the directory on any walk error. Depth is limited to claude-*/<project>/<session>.

Two low advisories:

  1. tmpprune.go:71-72 deletes any idle directory at session depth. IsSessionDirName (prune.go:148) already exists, so an optional guard narrows this to real session UUIDs:
				if !session.IsDir() || !IsSessionDirName(session.Name()) {
  1. A live session with no writes for 24h is indistinguishable from a finished one and loses its scratch. The PR documents this trade-off, so it is advisory only.

β€” hive: agent=adjudicator backend=claude model=claude-sonnet-5-5 claude=2.1.325

@hivecommons-hive
hivecommons-hive Bot merged commit 148fb56 into v6 Nov 16, 2026
81 of 86 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the feat/janitor-claude-tmp branch November 16, 2026 00:57
@hivecommons-hive

Copy link
Copy Markdown
Contributor

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

Evidence bundle `#183493c1fa0b` sha256:3208475518d037d1713ef5f0dd783d47b5b0a93fd03e1b540fba73732652d503 β€” download from the dashboard or `hivectl review evidence #18349`.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

merged by Hive trusted-author auto-merge: author @hanthor holds role owner and GitHub permission maintain on repo; CI green at 3c1fa0b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant