kb://infrastructure/cargo-j4-disciplinestable2026-05-21

Cargo -j 4 discipline on blal.de

infrastructurecargorustserver-safetyci-discipline

All cargo invocations on blal.de are capped at -j 4 (build parallelism) and --test-threads=4 (test parallelism). Sub-agents that touch Rust must additionally scope to a single crate (-p CRATE --lib).

Why

blal.de has 12 threads and 62 GB RAM. Default cargo is -j $(nproc) = 12. Each rustc on heavy crates (alice-core, agents-memory, agents-tools) peaks at 2-4 GB. With 15+ parallel rustc processes the host hit load 672 on 2026-05-16 and froze. Recovery was pkill -9 rustc + wait + resume.

A separate incident on 2026-05-20 saw cargo test --workspace from a sub-agent inflate one worktree's target/ to 60 GB and trigger the 95% disk alert (kb://incidents/2026-05-21-target-disk-95-percent).

The rules

cargo build / check  →  -j 4
cargo test           →  --test-threads=4   (and -j 4 if the test triggers a build)
sub-agent Rust work  →  cargo test -p <crate> --lib -j 4 -- --test-threads=4
                        cargo check -p <crate> -j 4
                        NEVER cargo test --workspace

Concurrency limits

  • Maximum 3 cargo-heavy agents concurrent on this server
  • Disk gates: - > 85% disk → max 1 cargo-heavy agent - 75-85% → max 2 - < 75% → max 3
  • Before any parallel overnight wave: 1. du -sh ~/projects/org-openalicelabs/openalice-wt-*/target → find > 5 GB targets 2. Remove obsolete worktrees (git worktree remove --force) 3. Confirm disk < 75% before dispatching

Sub-agent prompt template

When dispatching any Rust sub-agent, the prompt must include:

CRITICAL DISK CONSTRAINT:
- NEVER run `cargo test --workspace` or anything that compiles across crates.
- Use `cargo test -p <SINGLE-CRATE> --lib -j 4 -- --test-threads=4` only.
- Use `cargo check -p <crate> -j 4` for early compile verification.
- If `target/` grows past 5 GB, `cargo clean -p <crate>` and continue narrower.
- Cap `-j 4` always.
- If you need to compile something downstream to validate, STOP and report —
  do not widen the build.

Monitor

Arm df --output=pcent /home/blal to alert at 90% before dispatching parallel agents. On alert, cargo clean the worktrees of any agents that have already committed.

Bound to this server

If the lab migrates to a 32+ thread host with more disk, the cap revisits. Until then, the -j 4 rule is non-negotiable.