Skip to content

[9.3.0] Prefetch the targets of symlinked .bzl files in the RRCC - #30713

Merged
iancha1992 merged 5 commits into
bazelbuild:release-9.3.0from
fmeum:cp-9.3.0-30517
Sep 2, 2026
Merged

iancha1992 merged 5 commits into
bazelbuild:release-9.3.0from
fmeum:cp-9.3.0-30517

Conversation

@fmeum

@fmeum fmeum commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Description

When a repo is injected from the remote repo contents cache, .bzl and REPO.bazel files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so #30031 made the read side resolve symbolic links first, which serves a symlinked .bzl file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. helper.bzl -> real_helper.bzl. A symlink such as helper.bzl -> real_helper.txt resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

Motivation

Loading a .bzl file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching .bzl files during injection is meant to avoid: the loads between .bzl files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to #30031.

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: None

Closes #30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
(cherry picked from commit 61574a9)

This PR also carries the prerequisite commit c37a6a1 ("Improve path validation in remote repository contents cache."), which touches the same injection code path and landed on master first.

Replaces #30579, which bundles the same two commits but does not build on this branch: it hand-authors a new remote_external_overlay_file_system target in src/main/java/com/google/devtools/build/lib/remote/BUILD that depends on //src/main/proto:failure_details_java_proto (the branch uses //src/main/protobuf), so the target does not even analyze, and its test uses EventBusEventHandler, which does not exist on this branch.

9.3.0 adaptation: The src/main/java/com/google/devtools/build/lib/remote/BUILD split is not needed because that package still has a single monolithic remote target here, which already covers RemoteExternalOverlayFileSystem.java; the same goes for the remote_external_overlay_file_system entry in src/test/java/com/google/devtools/build/lib/remote/BUILD, where only the new //src/main/java/com/google/devtools/build/lib/cmdline dep is required. The new test constructs the Reporter as new Reporter(new EventBus()) since EventBusEventHandler was introduced by a master-only refactoring.

Closes #30520

@fmeum
fmeum marked this pull request as ready for review August 13, 2026 16:02
@fmeum
fmeum requested a review from a team as a code owner August 13, 2026 16:02
@fmeum
fmeum requested a review from meisterT August 13, 2026 16:02
@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Aug 13, 2026
@fmeum

fmeum commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

@iancha1992 This replaces #30579

@iancha1992

Copy link
Copy Markdown
Contributor

@fmeum Could you please resolve the merge conflicts? Thanks!

meisterT and others added 2 commits August 25, 2026 14:38
Validate node names in remote tree to ensure they don't contain separators, uplevel references, or absolute paths. Ensure injected paths and symlink targets remain within the repository directory.

PiperOrigin-RevId: 956519847
Change-Id: I0a2a91dd827be37fff78146637c7e55dc9c876df

(cherry picked from commit c37a6a1)
…d#30517)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and `REPO.bazel` files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links first, which serves a symlinked `.bzl` file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as `helper.bzl -> real_helper.txt` resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching `.bzl` files during injection is meant to avoid: the loads between `.bzl` files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
(cherry picked from commit 61574a9)
auto-merge was automatically disabled August 25, 2026 12:43

Head branch was pushed to by a user without write access

@fmeum

fmeum commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

@iancha1992 Resolved

@iancha1992
iancha1992 enabled auto-merge August 25, 2026 18:34
@iancha1992

Copy link
Copy Markdown
Contributor

@fmeum Could you please resolve the merge conflict? Thanks!

auto-merge was automatically disabled September 1, 2026 19:28

Head branch was pushed to by a user without write access

@fmeum

fmeum commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@iancha1992 done

@iancha1992
iancha1992 enabled auto-merge September 1, 2026 21:58
@iancha1992
iancha1992 added this pull request to the merge queue Sep 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Sep 2, 2026
@iancha1992
iancha1992 added this pull request to the merge queue Sep 2, 2026
Merged via the queue into bazelbuild:release-9.3.0 with commit 4d5d4ce Sep 2, 2026
41 checks passed
@github-actions github-actions Bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Remote-Exec Issues and PRs for the Execution (Remote) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants