Synced from Hive. This page is pulled from hivecommons/hive@v5 during the docs build. Edit the canonical source in the Hive repository.

Data janitor

Every hive keeps its state on one persistent volume mounted at /data. On hosted hives that volume is a CephFS RWX PVC (50 GiB). Two costs grow with it:

  • Bytes. They fill the shared Ceph pool that other tenants also use.
  • File count. CRI-O relabels the whole volume for SELinux before every new pod starts. With many files, the relabel times out under load (context deadline exceeded ... stage container volume configuration), and the pod does not start.

The data janitor (src/pkg/datajanitor, #20927) keeps /data bounded without operator action. It is on by default.

What it removes

Each run applies these rules. A rule only selects data the hive owns and can regenerate. Its retention is measured from the newest write anywhere inside the item, so an item still being written to is never selected.

RuleSelectsDefault retention
worktreesLinked git worktrees under /data/home/* and /data/agents/*/* clones. A worktree qualifies only when its branch is merged into origin/HEAD or its upstream branch was deleted ([gone]), it has no uncommitted work (no modified tracked files and no new untracked files; ignored build output does not count), and it is not locked or detached. Metadata for worktrees whose directory is already gone is cleared with git worktree prune.7 days
cachesIndividual files in /data/home/.cache/go-build, /data/home/.cache/pip, /data/home/.npm/_cacache and /data/home/go/pkg/mod/cache/download, plus extra_cache_dirs.14 days
tmpFiles in /data/tmp and /data/home/tmp, plus extra_tmp_dirs, and the empty directories they leave.3 days
logsRotated logs only (*.log.N, *.gz, or a date in the name) in data.logs_dir and /data/agents/*/.bob/.bob-errors. The file a process is writing to is never selected. The retention is never shorter than governor.logging.max_age_days.14 days
transcriptsCLI transcripts (*.jsonl) in data.claude_sessions_dir. The default matches the token scanners’ 30-day window, so dashboard token history is not cut short.30 days
orphan_agentsWorkspace directories under /data/agents of agents the operator removed: names in removed_agents (replicas such as guide-2 count as guide) that are not configured again. An unrecognised name alone is never treated as an orphan. Interactive homes under /data/home/agents, which hold CLI credentials and memory, are never swept.14 days

The janitor also runs the older session-state and agent-home prunes (src/pkg/sessionprune) on the same schedule. Before this change those prunes ran once at startup only, because their loop stopped as soon as it was wired. They run in dry-run mode too: they predate the janitor and are not part of its dry-run contract.

The hourly workspace sweep (HIVE_WORKSPACE_CLEANUP_*, pkg/dashboard/workspace_cleanup.go) is separate and unchanged. It removes non-git scratch entries from agent workspaces after 2 hours.

What it never removes

Every selected path is checked against a protection list before removal. A path is refused when it is, is inside, or contains any of these:

  • hive.yaml, config.env, /data/.hive, /data/agent-configs
  • credentials: /data/secrets, /data/vaults, the GitHub App key and user tokens, /data/home/.claude/.credentials.json, /data/home/.claude.json, /data/home/.config, /data/home/.codex, /data/home/.gemini, /data/home/.ssh, /data/home/.gitconfig, /data/home/.git-credentials
  • beads (/data/beads), the knowledge store (/data/knowledge), policies, skills, snapshots, contributors and hub (/data/saas) state
  • anything in extra_protected_paths

Live user-session worktrees under /data/session-sandbox are skipped. They have their own sweeper that knows which sessions are alive. Shared crux state beside the agent workspaces (/data/agents/sandbox, sandbox-runs, sandbox-review-spools, gates, runs, signals, checkouts) is protected.

Rules never follow symlinks. A rule root with a symlink anywhere below /data is skipped. Only regular files and symlinks are selected, never sockets, FIFOs or device files.

The orphan rule has two extra safety checks:

  • It acts only on tombstoned agents (removed_agents). With none, it does nothing.
  • It skips a whole root when it would remove more than orphan_max_fraction_percent of the agent directories there. A directory that holds anything named like a credential (auth.json, .credentials.json, *.pem, *.key) is never removed by the orphan rule.

Size guard

Every size_guard_check_minutes, the janitor measures /data. On CephFS this reads the ceph.dir.rbytes and ceph.dir.rfiles xattrs, which is two cheap reads. Elsewhere it uses statfs (used blocks and inodes of the volume holding /data). Only if statfs fails does it walk the tree, up to 2,000,000 entries.

Capacity comes from capacity_bytes if that is set. Otherwise it is the subvolume quota (ceph.quota.max_bytes), and failing that, statfs.

When usage reaches size_guard_percent (80% by default), the guard:

  1. runs the janitor immediately, unless any run finished within size_guard_cooldown_minutes;
  2. raises a yellow dashboard banner (data-janitor-size-guard) until usage falls back under the threshold;
  3. reports guard_tripped to the hub in the heartbeat, which raises a data-volume-full warning in the hub’s fleet alerts.

Where to see it

GET /api/status has a data_janitor block:

"data_janitor": {
  "enabled": true,
  "dry_run": false,
  "interval_seconds": 21600,
  "usage": {"bytes": 7340032000, "files": 412000, "capacity_bytes": 53687091200,
            "percent": 13.7, "source": "cephfs", "measured_at": "..."},
  "size_guard": {"threshold_percent": 80, "tripped": false},
  "last_run": {"trigger": "schedule", "freed_bytes": 1048576000, "freed_files": 52000,
               "freed_dirs": 900, "failed": 0, "pruned_repos": 1,
               "rules": {"caches": {"selected": 50000, "removed": 50000, "freed_bytes": 900000000,
                                    "freed_files": 50000, "examples": ["..."]}}},
  "runs": 4,
  "total_freed_bytes": 2147483648,
  "total_freed_files": 104000
}

Each run that frees something logs one data janitor run complete line with the same totals. A refused candidate logs data janitor: refused candidate with the reason.

Configuration

All keys live under data.janitor in hive.yaml. Each one is optional, and a retention of 0 turns that rule off.

KeyDefaultMeaning
enabledtrueRun the janitor. Env HIVE_DATA_JANITOR_ENABLED overrides.
dry_runfalseSelect and report without deleting. Env HIVE_DATA_JANITOR_DRY_RUN overrides.
interval_minutes360Time between scheduled runs.
worktree_retention_days7See worktrees.
cache_retention_days14See caches.
tmp_retention_days3See tmp.
log_retention_days14See logs.
transcript_retention_days30See transcripts.
orphan_agent_retention_days14See orphan_agents.
orphan_max_fraction_percent50Maximum share of one root’s agent directories the orphan rule may remove in one run.
size_guard_percent80Fill level that triggers an immediate run and the warnings. 0 disables the guard.
size_guard_check_minutes15How often the guard measures /data.
size_guard_cooldown_minutes60Minimum time between guard-triggered runs.
capacity_bytes0Capacity override. 0 reads the CephFS quota, then statfs.
extra_cache_dirs[]Extra cache trees, trimmed file by file.
extra_tmp_dirs[]Extra scratch trees.
extra_protected_paths[]Extra paths that are never removed.

To try the janitor safely on a hive, set HIVE_DATA_JANITOR_DRY_RUN=true, wait for a run (one runs at startup), and read data_janitor.last_run on /api/status.

Hub: slots and deprovision

The hub handles the volumes of pool slots and deleted hives (src/pkg/hub/storage_hygiene.go):

  • Deprovision frees the volume. Before it deletes the namespace of a dynamic-storage hive, the hub sets the bound PV’s reclaim policy to Delete (only when that PV’s claimRef is this hive’s hive-data claim) and deletes the PVC. This also applies when an owner deletes their own hive. Without that step, a Retain storage class would keep the CephFS subvolume, and its bytes, after the hive is gone.
  • Stale unclaimed slots are reported. An unclaimed slot whose reported /data (measured within HIVE_HUB_SLOT_DATA_MAX_AGE, 6h) is over HIVE_HUB_SLOT_DATA_STALE_BYTES (2 GiB) raises a slot-data-stale info alert.
  • Idle stale slots are reset. Once such a slot has sat unclaimed for HIVE_HUB_SLOT_RESET_MIN_IDLE (24h), the hourly lane marks it resetting (which the claim paths never pick), waits a few seconds, re-reads it, and only if it is still resetting removes its record and deprovisions it, which deletes its PVC. A claim that raced the mark wins, and the reset backs off. The pool replenisher then seeds a fresh slot with a clean volume. At most HIVE_HUB_SLOT_RESETS_PER_RUN (1) slots are reset per cluster per pass. Set HIVE_HUB_SLOT_STORAGE_RESET_ENABLED=false to report without resetting.

A slot qualifies only when it meets every one of these conditions: status available, owned by a hub admin, org prefixed available-, no vanity URL, and no claim in flight. Customer hives are never reset automatically.