0170. Optional object caching for native tests
- Status: Accepted for opt-in local test execution; timing acceptance pending. Historical native-cache capacity below is superseded by ADR-0236.
- Date: 2026-11-06
- Plan: M0.12
- Review: Compiler and backend; independent test/tooling review
Context
The second speed round reduced Rust and repeated fixture work, but a passing fresh-cache Rust run still took about19 minutes. Generated C and sanitizer compilation dominate. ADR-0067's executable cache does not cover direct test compiler calls, has a256MiB cap, and deliberately keys the full environment. Tests also shadow and mutate headers; a source-only artifact key is insufficient.
Decision
Offer an explicit fast-test command using local ccache4.14.2.
Bootstrap the pinned macOS archive into private
target/test-ccache storage with its published SHA256;
keep normal gcc-only commands available. No global installation is
required.
An opt-in CC wrapper accepts known system gcc/clang invocations and release flags. It compiles declared C inputs at their original paths, then links afresh with the required sanitizer, thread and PIE flags. Unknown flags, configured wrappers, debug builds and unsupported input shapes use the original compiler invocation. Do not normalize Harness source paths or enable ccache sloppiness. Use preprocessor mode so newly shadowing headers are observed; preserve compiler warning/failure checks.
For recognized compiler/test-generated C in owned Harness
temporary directories, the fast runner may assign
content-addressed build-input paths before invoking ccache. An
identical C file at a fresh temporary path was observed missing
the cache, including plain builds. Snapshot exact C and local
header bytes into a private temporary image, with closed quoted
includes and no explicit C file-observing constructs. Ordinary
inputs and unsupported cases retain their original paths. Preserve
all embedded .hn source locations. Bound active
images with striped ownership locks and remove validated owned
images after compilation; retain unexpected or modified files.
This assigns identities to generated build artifacts rather than
changing emitted program text or weakening cache keys.
Force a private configuration with local storage, no remote backend, content compiler checks, and no hard links/clones. Bind a framed SHA256 of the complete selected compiler environment, cwd, compiler bytes/version and wrapper bytes as an extra ccache input. Cache controls and private Rust/reporting controls are removed from the actual compiler environment too, including Codex's per-command ID so separate invocations can reuse objects. Other environment values remain inputs. The prefix validates the environment digest before exec. Launch it with the same absolute Python as the wrapper: a PATH-selected pyenv shim was observed changing PATH and hook variables.
Forward cancellation to owned subprocess groups and reap them
before cleaning private staging files. Preserve compiler signals.
Check cache ownership and permissions; keep pre-existing
mismatching tools/artifacts. The fast runner sets
HARNESS_NO_CACHE=1 because ADR-0067 does not
dependency-track custom CC wrappers. Its cache policy remains
unchanged. Key unit tests supply an explicit root to construct
keys without enabling executable reuse for other unit tests.
Report actual object hits/misses and cold/warm wall time,
including Cargo discovery/build, for all default Rust targets and
explicit plugin acceptance. Queue profiling runs per target
directory.
Alternatives considered
- Custom preprocessed artifact store — would duplicate dependency, diagnostic, path, corruption and concurrency handling. The narrow ccache prototype already passes header mutation/shadow/deletion and source-location parity checks.
- Fewer sanitizer cases or weaker durability — would lose useful acceptance coverage. Retain existing cases and variants.
- Required new compiler/tool — normal validation continues to support gcc with the repository's existing Python and Rust tools.
Consequences
Repeat local runs can reuse native object work while preserving fresh links and full test coverage. Cold runs still perform compilation; the ten-minute target must be measured rather than inferred from cache hits. Literal compiler calls that ignore CC and source paths observed by macros can remain cache misses. The wrapper is a local test tool, not a production compiler/cache API change. Compiler subprogram, SDK and library replacement is not a universally qualified cache contract; retain the ordinary gate and report the toolchain actually used.
References: ccache configuration and modes, original-source compilation on misses, pinned release.