Skip to content

[8.8.0] Materialize (chains of) symlinks in remote repos via prefetching - #30035

Merged
iancha1992 merged 1 commit into
bazelbuild:release-8.8.0from
fmeum:rrcc-8.7.0-31
Jul 14, 2026
Merged

iancha1992 merged 1 commit into
bazelbuild:release-8.8.0from
fmeum:rrcc-8.7.0-31

Conversation

@fmeum

@fmeum fmeum commented Jun 26, 2026 •

Copy link
Copy Markdown
Collaborator

When using the remote repo contents cache, repo materialization now uses the same code path as local action input prefetching for symlinks. This ensures that each symlink is only materialized once and that there are no races in case symlinking is not atomic (on Windows with default settings). Along the way, remove unreachable code from UploadManifest.

Furthermore, when a remotely cached repo is partially materialized since it contains action inputs, Skyframe provides the metadata of these inputs after following all symlinks as it does for all source files. Since (chains of) symlinks need to be preserved and materialized in the same way as if the repo rule ran locally or was fully materialized as a dependency of another repo rule, AbstractActionInputPrefetcher is changed to walk the full chain of symlinks behind a prefetched external repo path and replant every link verbatim on the host file system.

This proves very difficult to get right for repos with symlinks pointing into the main repo as such symlinks would cross over into the host filesystem. For this reason such symlinks now exclude a repo from being cached remotely. Note that the local repo contents cache already doesn't cache such repos. Since main repo files are readily available, this is considered a minor loss in usefulness only.

This PR combines the backports of #28683 and #29767 into a single commit, subsuming #30028: the symlink-materialization tests added upstream in #28683 only pass on 8.x once the chain-walk change from #29767 is in place, since repo files are materialized lazily through RemoteExternalOverlayFileSystem rather than fully on disk as on master.

8.x adaptation: AbstractActionInputPrefetcher on 8.x resolves input paths via the Bazel 8.x-specific resolveExecPath(execPath) helper (which avoids evaluating the WORKSPACE-named exec root when possible) and exposes the exec root through the execRoot() method rather than an execRoot field, so the new symlink handling is expressed in those terms. Because execRoot() is not available during external repository materialization, external repo paths are detected via a new isUnderExternalRepoRoot helper (mirroring DirectoryTracker.setWritable) instead of !inputPath.startsWith(execRoot()); both getSymlinks and plantSymlink use it. The chain-walking is re-expressed on the exec-path-based symlink model (resolveExecPath, execRoot(), FileArtifactValue#getMaterializationExecPath) rather than the master model (getResolvedPath, execRoot field): the Symlink record becomes (Path linkPath, PathFragment targetPath) as upstream, but the materialization case resolves getMaterializationExecPath() through resolveExecPath instead of reading getResolvedPath(); the loop guard throws FileSymlinkLoopException(PathFragment) (the 8.x constructor); the symlink target of an unresolved symlink artifact is read from UnresolvedSymlinkArtifactValue#getSymlinkTarget (8.x has no FileArtifactValue#getUnresolvedSymlinkTarget); and the 8.x CacheNotFoundException rewinding onErrorResumeNext is preserved.

On the repo side, 8.x has no RepositoryUtils or merged RepositoryFetchFunction, so the ReplantSymlinksResult record and the main-repo-symlink exclusion are applied to RepositoryFunction.replantSymlinks and the RepositoryDelegatorFunction caching path (where remote caching is now gated on safeForRemoteCache() and local caching on safeForLocalCache()). VendorManager keeps its existing private replantSymlinks, so the upstream call-signature change there does not apply.

Depends on the replant prerequisite (#28582) backported in #30034.

Fixes #28575.
Fixes #29656.
Fixes #29515.

Closes #28683.

PiperOrigin-RevId: 893359962
Change-Id: If0eb64e41858a4b9298c2609d83160b0ecbfd451
(cherry picked from commit 90eb56e)

Closes #29767.

PiperOrigin-RevId: 936532134
Change-Id: I48b63f6fd2d5f57e139175e3ed578d65f6abbd08
(cherry picked from commit c310e3e)

@fmeum
fmeum force-pushed the rrcc-8.7.0-31 branch 2 times, most recently from ac118f6 to 2cdd82a Compare June 26, 2026 14:09
@fmeum fmeum changed the title [8.8.0] Materialize chains of symlinks in remote repos [8.8.0] Materialize (chains of) symlinks in remote repos via prefetching Jul 9, 2026
@fmeum
fmeum requested review from coeuvre and tjgq July 12, 2026 15:57
@fmeum
fmeum marked this pull request as ready for review July 12, 2026 15:57
@fmeum
fmeum requested a review from a team as a code owner July 12, 2026 15:57
@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Core Skyframe, bazel query, BEP, options parsing, bazelrc team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Jul 12, 2026
@fmeum

fmeum commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

Should be merged after #30034

@iancha1992

Copy link
Copy Markdown
Contributor

@fmeum Could you please resolve the conflicts?

When using the remote repo contents cache, repo materialization now uses
the same code path as local action input prefetching for symlinks. This
ensures that each symlink is only materialized once and that there are no
races in case symlinking is not atomic (on Windows with default settings).
Along the way, remove unreachable code from `UploadManifest`.

Furthermore, when a remotely cached repo is partially materialized since it
contains action inputs, Skyframe provides the metadata of these inputs
after following all symlinks as it does for all source files. Since (chains
of) symlinks need to be preserved and materialized in the same way as if
the repo rule ran locally or was fully materialized as a dependency of
another repo rule, `AbstractActionInputPrefetcher` is changed to walk the
full chain of symlinks behind a prefetched external repo path and replant
every link verbatim on the host file system.

This proves very difficult to get right for repos with symlinks pointing
into the main repo as such symlinks would cross over into the host
filesystem. For this reason such symlinks now exclude a repo from being
cached remotely. Note that the local repo contents cache already doesn't
cache such repos. Since main repo files are readily available, this is
considered a minor loss in usefulness only.

This commit combines the backports of bazelbuild#28683 and bazelbuild#29767 into one: the
symlink-materialization tests added upstream in bazelbuild#28683 only pass on 8.x
once the chain-walk change from bazelbuild#29767 is in place, since repo files are
materialized lazily through `RemoteExternalOverlayFileSystem` rather than
fully on disk as on master.

8.x adaptation: `AbstractActionInputPrefetcher` on 8.x resolves input paths
via the Bazel 8.x-specific `resolveExecPath(execPath)` helper (which avoids
evaluating the WORKSPACE-named exec root when possible) and exposes the
exec root through the `execRoot()` method rather than an `execRoot` field,
so the new symlink handling is expressed in those terms. Because
`execRoot()` is not available during external repository materialization,
external repo paths are detected via a new `isUnderExternalRepoRoot`
helper (mirroring `DirectoryTracker.setWritable`) instead of
`!inputPath.startsWith(execRoot())`; both `getSymlinks` and `plantSymlink`
use it. The chain-walking is re-expressed on the exec-path-based symlink
model (`resolveExecPath`, `execRoot()`,
`FileArtifactValue#getMaterializationExecPath`) rather than the master
model (`getResolvedPath`, `execRoot` field): the `Symlink` record becomes
`(Path linkPath, PathFragment targetPath)` as upstream, but the
materialization case resolves `getMaterializationExecPath()` through
`resolveExecPath` instead of reading `getResolvedPath()`; the loop guard
throws `FileSymlinkLoopException(PathFragment)` (the 8.x constructor); the
symlink target of an unresolved symlink artifact is read from
`UnresolvedSymlinkArtifactValue#getSymlinkTarget` (8.x has no
`FileArtifactValue#getUnresolvedSymlinkTarget`); and the 8.x
`CacheNotFoundException` rewinding `onErrorResumeNext` is preserved.

On the repo side, 8.x has no `RepositoryUtils` or merged
`RepositoryFetchFunction`, so the `ReplantSymlinksResult` record and the
main-repo-symlink exclusion are applied to
`RepositoryFunction.replantSymlinks` and the `RepositoryDelegatorFunction`
caching path (where remote caching is now gated on `safeForRemoteCache()`
and local caching on `safeForLocalCache()`). `VendorManager` keeps its
existing private `replantSymlinks`, so the upstream call-signature change
there does not apply.

Depends on the replant prerequisite (bazelbuild#28582) backported in the preceding
slot.

Fixes bazelbuild#28575.
Fixes bazelbuild#29656.
Fixes bazelbuild#29515.

Closes bazelbuild#28683.

PiperOrigin-RevId: 893359962
Change-Id: If0eb64e41858a4b9298c2609d83160b0ecbfd451
(cherry picked from commit 90eb56e)

Closes bazelbuild#29767.

PiperOrigin-RevId: 936532134
Change-Id: I48b63f6fd2d5f57e139175e3ed578d65f6abbd08
(cherry picked from commit c310e3e)
@iancha1992
iancha1992 enabled auto-merge July 13, 2026 21:34
@fmeum

fmeum commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@iancha1992 Done

@iancha1992
iancha1992 added this pull request to the merge queue Jul 14, 2026
Merged via the queue into bazelbuild:release-8.8.0 with commit f051d1a Jul 14, 2026
46 checks passed
@github-actions github-actions Bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Jul 14, 2026
@fmeum
fmeum deleted the rrcc-8.7.0-31 branch July 14, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Core Skyframe, bazel query, BEP, options parsing, bazelrc 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.

3 participants