Skip to content

[NO-JIRA] bazel-reap: reclaim idle lgtm-mono container Bazel output bases (>6h idle) - #1075

Merged
johnnymo87 merged 3 commits into
mainfrom
disk-cleanup-lgtm-mono-bazel
Dec 2, 2026
Merged

johnnymo87 merged 3 commits into
mainfrom
disk-cleanup-lgtm-mono-bazel

Conversation

@johnnymo87

@johnnymo87 johnnymo87 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Why

The lgtm-mono container runs bazel with its output root at ~/.local/state/lgtm/mono/bazel, on host disk. It creates one 3-5 GB output base per food-truck/mono PR worktree. The service frees a base only when its PR merges. Neither the nightly cleanup nor bazel-reap knows about this root, so the base of any unmerged PR stays forever. The root reached 36 GB within 30 minutes of mono moving to the container (lgtm-oqw2.77). Jonathan approved the policy: reap a base after more than 6 h idle, only when nothing is using it, by rename-then-delete.

What

bazel-reap gets a "container" tier that runs after the existing tiers and shares their per-pass budget.

  • Candidates: only direct 32-hex children of the root. cache/, install/ and symlinks are skipped.
  • Idle: the newest mtime of command.log, server/ and DO_NOT_BUILD_HERE must be at least 6 h old. A base with none of those files is kept.
  • Liveness: checked with the host /proc probe, not server.pid.txt, because that pid is in the container's namespace. Verified live: the container's server JVMs hold server/jvm.out open at the same path, and the probe reports in_use.
  • Deletion: rename to _reaping-*, then delete. Leftovers from an earlier pass, or from the service's own merge-time reaper, are finished off. Dry-run is honoured.
  • Under disk pressure (root at 80% or more, the existing threshold), the window drops to the 30 min that the pressure tier already applies to the old service's lgtm-pr-* bases, which these replace one for one. In the 45 minutes after mono moved, 21 bases of 3.4 GB appeared while the box sat at 82%. This goes beyond the approved 6 h rule only to match what the old service's bases already got.

The previous tier's early exit 0 on a missing ~/.cache/bazel base now skips to the container pass instead.

Verification

  • test-bazel-reaper.sh passes 98/0, with 11 new container tests, including one where only an open fd holds the base.
  • checks.bazel-reaper-tests builds.
  • The cloudbox toplevel evaluates.
  • Adversarial review found no blocking issues. Its fixes are in the second commit.

… ~/.local/state/lgtm/mono/bazel

The lgtm-mono docker container (the lgtm review service) runs Bazel with
--output_user_root=/home/dev/.local/state/lgtm/mono/bazel, bind-mounted at the
same path inside the container. It creates one output base (3-5 GB) per
food-truck/mono PR worktree (/home/dev/projects/mono/.worktrees/lgtm-pr-<N>).
The service frees a base only when its PR merges, so unmerged or closed PRs
leave bases behind forever, and bursts can fill the root disk.

Adds a container-root pass to bazel-reap:
- Root seam BAZEL_REAP_CONTAINER_BASE (default ~/.local/state/lgtm/mono/bazel);
  missing root is a clean no-op.
- Policy: reap when idle >= 6h (seam BAZEL_REAP_CONTAINER_IDLE_MIN, default 360),
  regardless of disk pressure.
- Candidates: direct children named exactly 32 lowercase hex chars; skips
  cache/, install/, _reaping-*, and non-hex.
- Server liveness: server.pid.txt is ignored (pid is in container namespace).
  Uses /proc probe (bazelReapInUsePy) on host to check cwd and open fds.
  Probe failure ("error") keeps the base. Live-verified against lgtm-mono JVM.
- Idle age: newest mtime among <base>/command.log, <base>/server/, and
  <base>/DO_NOT_BUILD_HERE. If none exists, keep.
- Deletion: rename-then-delete (_reaping-<name>.*), retries stale _reaping-*
  dirs (including those left by lgtm-mono's merge reaper). Honours DRY_RUN.
- Shared per-pass budget MAX_PER_PASS.
- 9 new regression tests in users/dev/test-bazel-reaper.sh (66 -> 91 passing).
  Updated anti-vacuity pin in flake.nix bazel-reaper-tests check.
Skip symlinks (chmod -R would follow one to its target); test the real
live signal (an open fd in the base, not a cwd); say plainly the tier
bounds accumulation and is not burst relief.

Refs: lgtm-oqw2.77
@johnnymo87
johnnymo87 enabled auto-merge (squash) December 2, 2026 20:40
…e lgtm-pr-* 30m window

Measured the hour food-truck/mono moved into the container: 21 bases of
3.4 GB in 45 minutes, one per new PR head, box at 82%. The old service's
lgtm-pr-* bases (which these replace one for one) were already reaped at
30 min idle under pressure; the container tier now matches that, and keeps
6 h otherwise.

Refs: lgtm-oqw2.77
@johnnymo87
johnnymo87 merged commit e0195da into main Dec 2, 2026
2 checks passed
@johnnymo87
johnnymo87 deleted the disk-cleanup-lgtm-mono-bazel branch December 2, 2026 21:35
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