Guard discovery using evaluated action inputs (#31998)
### Description
Pass the inputs evaluated for the current invocation to the input-discovery guard, together with the action's scheduling dependencies. Previously pruned inputs restored on the action are evaluated after discovery, before the execution guard protects them.
### Motivation
A pruning action resets its original input set, while ActionExecutionFunction initially evaluates only inputs restored from its action cache. After a rewind switches the synchronizer to fine-grained locks, discovery can therefore try to expand a pruned runfiles tree whose metadata has not been requested. This crashes in RemoteRewoundActionSynchronizer.lockKeysFor, as observed while rebuilding a kernel with remote caching [1]. The existing metadata invariant remains enforced.
The crash stack from [1]:
```text
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ActionLookupData{actionLookupKey=ActionTemplateExpansionKey{actionLookupKey=ConfiguredTargetKey{label=//test/kernel:kernel_6_6_build, config=BuildConfigurationKey[0358dac2367b24cc5bcd0c1c1892392ded9fb1c9afaef15f1292bc073297b5a5]}, actionIndex=148}, actionIndex=36}' (requested by nodes 'File:[[<execution_root>]bazel-out/x86_64-unknown-linux-musl-fastbuild/bin]test/kernel/kernel_6_6_build.scans3')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.runCore(AbstractParallelEvaluator.java:555)
at com.google.devtools.build.lib.concurrent.QuiescingTask.exec(QuiescingTask.java:78)
at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException: File:[[<execution_root>]bazel-out/rbe_x86_64_linux-opt-exec/bin]external/pahole+/pahole.runfiles
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:975)
at com.google.devtools.build.lib.remote.RemoteRewoundActionSynchronizer.lockKeysFor(RemoteRewoundActionSynchronizer.java:411)
at com.google.devtools.build.lib.remote.RemoteRewoundActionSynchronizer.lambda$inputKeysFor$0(RemoteRewoundActionSynchronizer.java:395)
at com.google.common.collect.Iterators$6.transform(Iterators.java:830)
at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:51)
at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:51)
at com.google.common.collect.Iterators$ConcatenatedIterator.hasNext(Iterators.java:1421)
at com.github.benmanes.caffeine.cache.LocalLoadingCache.loadSequentially(LocalLoadingCache.java:72)
at com.github.benmanes.caffeine.cache.LocalLoadingCache.getAll(LocalLoadingCache.java:65)
at com.google.devtools.build.lib.remote.RemoteRewoundActionSynchronizer.lockArtifactsForConsumption(RemoteRewoundActionSynchronizer.java:369)
at com.google.devtools.build.lib.remote.RemoteRewoundActionSynchronizer.enterInputDiscovery(RemoteRewoundActionSynchronizer.java:288)
at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.discoverInputs(SkyframeActionExecutor.java:1064)
at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.checkCacheAndExecuteIfNeeded(ActionExecutionFunction.java:778)
at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.computeInternal(ActionExecutionFunction.java:355)
at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.compute(ActionExecutionFunction.java:207)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.runCore(AbstractParallelEvaluator.java:474)
... 5 more
```
The regression uses ordinary unused_inputs_list, a declared tool with an unused runfiles tree, a changed source, and an evicted remote blob. It forces rewinding before rediscovery and checks recovery with and without a disk cache. The existing synchronizer test continues to verify scheduling-dependency producer protection independently of the passed input set.
### Build API Changes
No
### Checklist
- [x] I have added tests for the new use cases.
- [x] I have updated the input-discovery contract and synchronization proof.
### Release Notes
RELNOTES: Fix a crash when input pruning and remote action rewinding interact with runfiles trees.
[1]: https://github.com/aya-rs/aya/actions/runs/39850538176/job/120075173645
Written and submitted by Codex on behalf of Tamir Duberstein.
Closes #31998
COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/bazel/pull/31998 from tamird:codex/pruned-input-discovery-locks 4244111d58f0a07584ccf3d4a1c52925d747c18b
PiperOrigin-RevId: 1007136610
Change-Id: I8bd94abad3244e72861b1cc1200452e6830d3000
{Fast, Correct} - Choose two
Build and test software of any size, quickly and reliably.
Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.
One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.
Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.
Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.
To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.
See CONTRIBUTING.md