Skip to main content

Module build_cache

Module build_cache 

Source
Expand description

Clearing agents’ cargo build caches and warning when a disk runs low (docs/specs/SPEC_BUILD_CACHE_CLEANUP_2026_10_26.md).

Three hosts nearly filled their disks in two days from agents’ target folders. On one of them 67% of 1 TB of targets was target/<profile>/incremental, and 90% of that was the agentmux_srv crate: every change to a dependency gives the crate a new incremental directory (about 10 GB) and the old one is never reused or collected.

Three things are done here, none of which can break a build (the worst case of a wrong guess is a slower incremental rebuild):

  • Orphans: in each incremental folder, the newest few directories per crate are kept and older ones idle for a day are removed.
  • A finished task: the agent’s own clones lose all their incremental folders.
  • Abandoned clones: a clone nobody built in for days loses its whole target (when a task finishes, or the disk is low).

A clone with a cargo, rustc, linker or test process running in it is never touched. Every removal is logged, naming the workspace. This file is the file-system and policy part; build_cache_service.rs runs it on a schedule and sends the warnings.

Structs§

Policy
What is cleared, and when the disk warning fires.
Removed
One removal.
Report
What a pass over one workspace did.
TargetSize
A clone’s target size and how much of it is incremental.

Enums§

Why
What a pass is for; it goes in the log.

Constants§

KEY_ENABLED
Settings keys (in the settings file’s free-form part).
KEY_ORPHANS
KEY_ORPHAN_IDLE_HOURS
KEY_ORPHAN_KEEP
KEY_STALE_DAYS
KEY_WARN_FREE_GB
KEY_WARN_FREE_PCT

Functions§

build_running_in
Whether a build seems to be running in clone: a process whose working directory, executable or command line is inside it and which is a compiler, linker, cargo or something run from the target folder. Looks at the machine’s processes now.
clones_in
Every cargo clone in an agent’s workspace: the workspace itself or a folder directly in it that has a Cargo.toml and a target folder.
dir_size
The size of everything under p, in bytes.
disk_of
The free and total bytes of the disk that holds path.
human
“193 GB”, “4.7 GB”, “820 MB”.
incremental_roots
The incremental folders of a target: target/<profile>/incremental and, for a cross build, target/<triple>/<profile>/incremental.
last_build
When something was last built in target: the newest change among the target, its profile folders and the folders cargo writes to on every build.
log_path
Where removals are logged (AGENTMUX_BUILD_CACHE_LOG overrides it, for tests).
orphans_in
The incremental directories under root to remove: per crate, everything beyond the newest keep that has been idle for idle as of now.
run_pass
One pass over the clones of workspace.
snapshot_processes
A snapshot of the machine’s processes, for build_running_in.
target_sizes
The size of every clone’s target in workspace, largest first.