bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Crash (IllegalArgumentException "cannot relativize") when a remote-execution input from --experimental_remote_repo_contents_cache is missing from the remote CAS

Open jeffwall-curlewlabs opened this issue 1 month ago • 3 comments

Description of the bug:

With --experimental_remote_repo_contents_cache, Bazel 9.3.0 crashes with an internal error, not a lost-input recovery, when an action input that comes from a repository served by the remote repo contents cache is reported missing by FindMissingBlobs before remote execution.

FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ActionLookupData0{actionLookupKey=ConfiguredTargetKey{label=//pkg:test, config=BuildConfigurationKey[...]}, actionIndex=0}' (requested by nodes ...)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:552)
	...
Caused by: java.lang.IllegalArgumentException: Path '<output_base>/external/+browser+website_chromium_darwin_arm64/LICENSE.headless_shell' is not under '<output_base>/execroot/_main', cannot relativize
	at com.google.devtools.build.lib.vfs.PathFragment.relativeTo(PathFragment.java:378)
	at com.google.devtools.build.lib.remote.common.RemotePathResolver$DefaultRemotePathResolver.localPathToExecPath(RemotePathResolver.java:112)
	at com.google.devtools.build.lib.remote.RemoteExecutionCache.lambda$uploadFile$0(RemoteExecutionCache.java:224)
	...
	at com.google.devtools.build.lib.remote.RemoteExecutionCache.uploadFile(RemoteExecutionCache.java:214)
	at com.google.devtools.build.lib.remote.merkletree.MerkleTree$Uploadable.upload(MerkleTree.java:193)
	at com.google.devtools.build.lib.remote.RemoteExecutionCache.uploadBlob(RemoteExecutionCache.java:297)
	at com.google.devtools.build.lib.remote.RemoteExecutionCache.lambda$maybeCreateUploadTask$5(RemoteExecutionCache.java:381)
	...
	at com.google.devtools.build.lib.remote.RemoteExecutionCache.lambda$findMissingBlobs$5(RemoteExecutionCache.java:442)
	...

What happens, reading the 9.3.0 source:

  1. The repository +browser+website_chromium_darwin_arm64 (a plain http_archive) is served by the remote repo contents cache, so its files exist only in the remote external overlay file system; the on-disk <output_base>/external/<repo>/ contains only REPO.bazel.
  2. An action that takes one of the repo's files as input is executed remotely. FindMissingBlobs reports that file's blob missing from the remote CAS.
  3. RemoteExecutionCache.uploadFile finds the file is not available locally and takes the branch commented "the remote input was determined to exist ... but reported to be missing ... possibly because it was evicted in the interim". To build the CacheNotFoundException it calls remotePathResolver.localPathToExecPath(path).
  4. DefaultRemotePathResolver.localPathToExecPath is localPath.relativeTo(execRoot). The path is under <output_base>/external/..., not under <output_base>/execroot/_main, so relativeTo throws IllegalArgumentException and the server crashes (exit code 37).

So the lost-input path that exists for exactly this situation cannot handle an input whose local path is in the remote-repo overlay under <output_base>/external. Even if the exception were built correctly, it is not clear that action rewinding / lost-input handling can recover a lost input belonging to a remote-cached repository (that would need the repository to be re-fetched and re-uploaded), so the expected behavior may need more than the path fix.

How the state arose in our case: the repo's cache entry was answered by the local --disk_cache, not by the remote cache. RemoteRepoContentsCacheImpl.buildContext reads with CachePolicy.ANY_CACHE, and the disk cache held the repo's action-cache entry from an earlier fetch. The remote CAS had since lost 3 of the repo's 23 blobs. A disk-cache hit does not go through the remote server's completeness checking, so Bazel accepted a repository the remote CAS no longer fully held, and the first remote action that needed a lost file crashed the server. Asked directly (fresh output base, --disk_cache=), the remote cache (Buildbarn) correctly rejected the entry:

GetActionResult NOT_FOUND: Object 1-09d2153b56e27616a5402096aaccaf0f363a42c6a3a6bf085f204956eaf2eb9b-1741976- referenced by the action result is not present in the Content Addressable Storage

That fetch then re-uploaded the missing blobs and the crash stopped. The failure was deterministic until then: it reproduced on two different client machines, including one starting from an empty output base, because each machine's disk cache held the same entry.

Expected behavior: a missing input from a remote-cached repository should not crash the server. Ideally Bazel re-fetches the repository (or treats the cached repository as invalid) and continues, or at minimum fails the build with a normal error. Separately, it may be worth considering whether a disk-cache hit for a remote repo contents cache entry should be trusted when the files will later be needed from the remote CAS.

Which category does this issue belong to?

Remote Execution

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

We have not reduced this to a minimal repository yet. The shape, from what we observed:

  1. Remote execution with a remote cache (we use Buildbarn), plus --disk_cache=<dir>, and the startup option --experimental_remote_repo_contents_cache with --repo_contents_cache=.
  2. An http_archive repository whose files are inputs to a remotely executed action, e.g. a filegroup(srcs = glob(["**"])) used as test data.
  3. Build once so the repository is uploaded to the remote repo contents cache and its action-cache entry is written through to the disk cache.
  4. Delete one of the repository's file blobs from the remote CAS (eviction, in our case).
  5. With a fresh output base and the same disk cache, build a target whose remotely executed action needs that file (and is not an action-cache hit). The server crashes with the trace above.

Relevant flags from the failing invocation:

startup: --experimental_remote_repo_contents_cache
--remote_cache=grpc://...
--remote_executor=grpc://...
--disk_cache=<dir>
--repo_contents_cache=
--remote_download_outputs=minimal
--remote_upload_local_results

Which operating system are you running Bazel on?

Linux x86_64 client (Ubuntu); the action executed remotely on a macOS arm64 worker.

What is the output of bazel info release?

release 9.3.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

Private repository.

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

Not known to be a regression; we have only seen it on 9.3.0.

Have you found anything relevant by searching the web?

No existing issue found searching for "cannot relativize" together with remote repo contents cache / localPathToExecPath.

Any other information, logs or outputs that you want to share?

Source references at the 9.3.0 tag:

  • src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionCache.java, uploadFile: the !isAvailableLocally branch that calls localPathToExecPath.
  • src/main/java/com/google/devtools/build/lib/remote/common/RemotePathResolver.java, DefaultRemotePathResolver.localPathToExecPath: relativeTo(execRoot).
  • src/main/java/com/google/devtools/build/lib/remote/RemoteRepoContentsCacheImpl.java, buildContext: lookups read with CachePolicy.ANY_CACHE.

jeffwall-curlewlabs avatar Oct 21 '26 22:10 jeffwall-curlewlabs

@bazel-io fork 9.4.0

fmeum avatar Oct 22 '26 09:10 fmeum

@bazel-io fork 10.0.0

fmeum avatar Oct 22 '26 09:10 fmeum

This will be fixed by https://github.com/bazelbuild/bazel/issues/31258 as it's already fixed at HEAD and in 10.0.0rc1.

fmeum avatar Oct 22 '26 09:10 fmeum