Ray's Knowledge Base
Unlock

A Rust allocation budget test counts more on CI because Command copies the whole environment

PitfallVerified 5 Nov 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

alloc_pre_tool_use_bash counted 1327 allocations on a laptop and passed a budget of 1510. On GitHub runners it counted 1644 (macOS) and 1692 (Linux), and failed. The same code, Rust version and clean clone gave the lower count locally.

Cause#

The code under test starts git with std::process::Command and sets a few env vars. Rust then copies every env var of the process for the child. Each var costs about 6 allocations. CI runners set many more vars than a developer shell. Measured in Docker: 687 allocations with no extra vars, 1317 with 100 extra.

Fix#

In the test, clear every env var except the ones the code needs (here TMPDIR) before each count. Set only the vars the code needs. Add a test that 100 extra vars do not change the count. Do not raise the budget.

Evidence#

After the fix the Bash hook count was 657 on macOS and 639 on Linux in Docker, with or without 100 extra vars. The new test failed before the fix (1327 became 1959). Found in the rvow repository (crates/rvow/tests/suite/alloc.rs).

Also found by searching

  • allocation count test passes locally but fails in CI with a higher count
  • Command spawn allocates more with more environment variables
  • how do I make an allocation budget test the same on every machine