Skip to content

testing: shared nested cache root (closes #14777) - #14799

Merged
TrapsterDK merged 5 commits into
mainfrom
shared-nested-cache-root
Nov 24, 2026
Merged

TrapsterDK merged 5 commits into
mainfrom
shared-nested-cache-root

Conversation

@TrapsterDK

@TrapsterDK TrapsterDK commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #14776

  • DX_NESTED_SHARED (exported by setup-bazel through $GITHUB_ENV as $RUNNER_TEMP/dx-nested, with --sandbox_writable_path, and inherited only by nested_bazel_test) gives every nested server one shared --install_base (keyed by the Bazel binary) and a --disk_cache with a 2 GB GC limit. The repository cache and --repo_contents_cache are shared per cache set, so an offline test never finds a download its own set lacks. Output bases stay per test.
  • Cache-set entries are placed once with a uniquely named staging file and a rename (symlink on Unix, hard link on Windows); an entry another test placed first counts as placed, and a dangling entry is replaced.
  • The whole root is bounded at 6 GB (DX_NESTED_SHARED_LIMIT overrides); Bazel has no size GC for the repository or repo contents cache. Each test registers a lease (a locked file under <root>/leases) naming its install base, repository cache and repo contents cache. Under a short exclusive lock on the root, a starting test moves the least recently used entries no running lease holds into <root>/_trash, then deletes them outside the lock; a stopped delete leaves only trash, which the next lease empties. A running lease holds its install base, its whole repository cache and the repo contents entries used since it started. Install bases age by their directory mtime, which the Bazel client stamps per start. Harness cases: an over-limit root evicts the stale entry first; trash left by a stopped delete is emptied and the repositories are still reused.
  • nested_bazel_test(caches = "private") opts out; cold_start_test uses it. Record mode is always private. Unset, nothing changes.
  • New harness cases: with a shared root the second test does not extract the install base and fetches no repository; without it every test extracts and fetches.

Timing, Linux x86_64 on a loaded, CPU-capped local machine (seconds, unset → warm shared root): go_prebuilt_guard 249 → 87, java_prebuilt_guard 181 → 89. nested_smoke.txt lines scaled by that ratio: 44 → 16, 32 → 16. The other lines are not measurable here: the harness, adopt-polyglot and release consumers fail on the stale consumer locks of #13353; apple is macOS only; cpp_rust and cold_start do not use the shared root.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus

@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

/evidence platforms=["macos_arm64","windows_x86_64"] task=test scope=//tools/testing/nested:dx_nested_test //tools/testing:nested_bazel_harness_test

@github-actions

Copy link
Copy Markdown
Contributor

Evidence started on shared-nested-cache-root: https://github.com/devhusdk/rules_dx/actions/runs/45313459120

@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

/evidence platforms=["macos_arm64","windows_x86_64"] task=test scope=//tools/testing/nested:dx_nested_test //tools/testing:nested_bazel_harness_test

@github-actions

Copy link
Copy Markdown
Contributor

Evidence started on shared-nested-cache-root: https://github.com/devhusdk/rules_dx/actions/runs/45318376491

TrapsterDK and others added 4 commits November 24, 2026 06:04
With DX_NESTED_SHARED set, every nested server shares the install base,
the repository cache, the repo contents cache and a 4 GB disk cache
under that root; output bases stay per test. setup-bazel points it at
$RUNNER_TEMP/dx-nested. Cache-set entries land with one rename, so
concurrent tests see no entry or a whole one. nested_bazel_test(caches =
"private") and record mode stay off the root; cold_start_test opts out.
Unset, nothing changes.

Part of #14776

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
… caches with a set

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
A starting test takes the root's exclusive lock when no other test holds it and
evicts the least recently used install bases, fetched repositories and
downloads until the root fits; running tests hold a shared lock. The disk cache
GC limit drops to 2 GB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
@TrapsterDK
TrapsterDK force-pushed the shared-nested-cache-root branch from d90f401 to b4df89c Compare November 24, 2026 05:07
@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

/evidence platforms=["macos_arm64","windows_x86_64"] task=test scope=//tools/testing/nested:dx_nested_test //tools/testing:nested_bazel_harness_test

@github-actions

Copy link
Copy Markdown
Contributor

Evidence started on shared-nested-cache-root: https://github.com/devhusdk/rules_dx/actions/runs/45332432381

@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

Review: changes requested (head b4df89c)

1. tools/testing/nested/src/shared.rs:94: eviction deletes in place, so an interrupted delete can corrupt the shared root. remove_dir_all runs directly on repo-contents/<hash>. That directory holds <uuid>/ and <uuid>.recorded_inputs, and Bazel trusts any entry whose .recorded_inputs exists. If the removal stops partway, the .recorded_inputs file can survive next to a half-deleted <uuid>/ tree, and every later test with the same predeclared hash reuses that broken repo. Two ways it stops partway: the evicting test is killed, or a Windows file is still open. On Windows, release() skips when a test fails, so that test's server stays alive until the reaper sweeps, while the next test can already take the exclusive lock. Fix: rename the entry into <bucket>/repo-contents/_trash/<unique> first, then delete it, and skip the entry if the rename fails. That is how Bazel's own repo contents GC does it.

2. .github/actions/setup-bazel/action.yml:73: test --test_env=DX_NESTED_SHARED=… changes the key of every test action in every job that uses setup-bazel. Nothing outside dx_nested reads the variable. The gate even excludes resources:nested_bazel:1, so its whole test set loses cached results and local runs never hit CI results, for no benefit. This can be avoided: export DX_NESTED_SHARED through $GITHUB_ENV, keep --sandbox_writable_path (it is not part of the key), and add env_inherit = ["DX_NESTED_SHARED"] to the rust_test in nested_bazel_test (tools/testing/hermetic/defs.bzl:223). Then only the nested tests' keys change.

3. shared.rs:48: an over-limit root makes starting tests wait instead of trimming it. With nested_bazel=2, whenever the root is over the limit and another nested test holds the shared lock, a starting test waits up to min(180 s, the other test's remaining time). If the wait runs out, it starts without evicting, so in a busy job the root can stay above 6 GB. There is no deadlock or lock leak (flock and LockFileEx are released on exit, one Server per process). Separately, the root now stays on the runner for the whole job, where TEST_TMPDIR used to be removed per test. macOS runners already hit ENOSPC. Consider also trimming when a lease is dropped.

4. shared.rs:130, low: install bases always count as used now, because Bazel stamps future mtimes. So a stale install base, for example after the outer repo is refetched and the key changes, is evicted only after every repository entry.

5. tools/testing/nested_smoke.txt, low: the go/java values (16/16) are scaled estimates, not measurements, which test-budget.md requires. The harness line stays at 33, but the harness now runs the probe 5 times, each cold-extracting an install base.

Checked and fine: concurrent first extraction of a shared install base (Bazel 9 extracts into a CreateSiblingTempDir directory, renames it, and takes a shared <install_base>.lock); atomic placement with unique staging names; dangling-link replacement; no new unsafe; library errors are propagated; no Starlark # comments; no tag, timeout or allowlist changes.

CI (run 45331102118): no failure is caused by this PR. The gate excludes resources:nested_bazel:1, and the nested jobs were skipped, so the new harness cases have no CI evidence yet.

  • check windows_x86_64 / windows_arm64: the format phase flags files this PR does not touch (tools/testing/own_cc_tool.rs, tools/testing/consumer/cold_start_test.rs, tools/testing/hermetic/src/tests.rs, apple/tests/cell_tests.bzl, …). They are already unformatted on main 964ec32 (checked with rustfmt) and show up because this PR widens the affected set. Formatting them here, as was done for plain_fixture.rs, clears that part. The lint phase then fails with os error 206 (known "filename too long").
  • coverage windows_x86_64 / windows_arm64: os error 206 (known).
  • check macos_arm64: the runner ran out of disk. The same happened on run 45321288857, whose branch does not have this change.
  • coverage linux_x86_64: the outer Bazel ran out of Java heap (exit 33), which aborted 35 results, e.g. //cc/tests/fixtures/hello:toolchain_action_tests_compile_llvm. //erlang/tests/fixtures/negative/undeclared_header:nif_header_hidden_test also failed to build. Both happen on run 45319681152 as well.
  • coverage linux_arm64: out-of-memory abort of //android/tests:native_library_tests_floor_level_test.
  • coverage macos_arm64: out of disk while extracting the rust wasm toolchain, so //rust/tests/fixtures/consumer_wasm:acquisition failed analysis and //apple/tests:entry_and_srcs_test was aborted.
  • check linux_x86_64: cancelled at the 60-minute limit (known). check linux_arm64: cancelled.

🤖 Generated with Claude Code

…ed root

Eviction renames an entry into `<root>/_trash` and deletes it after the
root lock is released, so a stopped delete never leaves a half-deleted
repository next to its `.recorded_inputs`; the next lease empties the
trash. Each test registers a lease naming its install base, repository
cache and repo contents cache; a starting test evicts only entries no
running lease holds, so it trims the root without waiting. Install bases
age by their own directory mtime, which the Bazel client stamps per start.

setup-bazel exports DX_NESTED_SHARED through GITHUB_ENV and only
nested_bazel_test inherits it, so other test actions keep their keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

/evidence platforms=["linux_x86_64","windows_x86_64","macos_arm64"] task=test scope=//tools/testing/nested/... //tools/testing:nested_bazel_harness_test //tools/testing/consumer:go_prebuilt_guard_test //tools/testing/consumer:java_prebuilt_guard_test

@github-actions

Copy link
Copy Markdown
Contributor

Evidence started on shared-nested-cache-root: https://github.com/devhusdk/rules_dx/actions/runs/45347598008

@TrapsterDK
TrapsterDK merged commit 2072935 into main Nov 24, 2026
27 of 43 checks passed
@TrapsterDK
TrapsterDK deleted the shared-nested-cache-root branch November 24, 2026 07:49
TrapsterDK added a commit that referenced this pull request Nov 24, 2026
… (follow-up to #14799) (#14812)

* testing: age shared cache entries by their files, not their directory

Counting an entry directory's own mtime made a freshly created directory
with old files look recently used, so the over-limit harness case evicted
the install base instead of the stale repository. Only install bases age
by their directory, which the Bazel client stamps per start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus

* testing: close test files before evicting on Windows

A directory holding an open file cannot be renamed on Windows, so the
install base test kept its entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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