Summary
Recursive cache results are memoized only by NodeContext, but each memoized Lazy<Task<CacheResult>> captures whether outputs should be materialized.
Impact
With MSBuildCacheGetResultsForUnqueriedDependencies=true, a recursive query that does not require outputs can populate the memoized result first. A later direct query for the same node reuses that cache hit without materializing required files, allowing MSBuild to proceed with missing reference assemblies or other outputs.
Evidence
src/Common/MSBuildCachePluginBase.cs stores recursive results in ConcurrentDictionary<NodeContext, Lazy<Task<CacheResult>>>. materializeOutputs is not part of the key or separately tracked. The implementation comments assume the node will not later be queried directly, while the setting is documented for builds that are not executed in graph order.
Suggested fix
Separate result lookup from materialization state. A direct caller requiring outputs should be able to materialize a previously memoized non-materialized hit without repeating fingerprint/cache lookup. Alternatively, include the materialization requirement in memoization while preventing duplicate result mutation.
Acceptance criteria
- A recursive non-materializing hit followed by a direct query materializes outputs exactly once.
- The fix covers out-of-order dependency queries and multi-targeting inner builds.
- Default and non-recursive behavior remains unchanged.
- A deterministic concurrency/order test covers the regression.
Summary
Recursive cache results are memoized only by
NodeContext, but each memoizedLazy<Task<CacheResult>>captures whether outputs should be materialized.Impact
With
MSBuildCacheGetResultsForUnqueriedDependencies=true, a recursive query that does not require outputs can populate the memoized result first. A later direct query for the same node reuses that cache hit without materializing required files, allowing MSBuild to proceed with missing reference assemblies or other outputs.Evidence
src/Common/MSBuildCachePluginBase.csstores recursive results inConcurrentDictionary<NodeContext, Lazy<Task<CacheResult>>>.materializeOutputsis not part of the key or separately tracked. The implementation comments assume the node will not later be queried directly, while the setting is documented for builds that are not executed in graph order.Suggested fix
Separate result lookup from materialization state. A direct caller requiring outputs should be able to materialize a previously memoized non-materialized hit without repeating fingerprint/cache lookup. Alternatively, include the materialization requirement in memoization while preventing duplicate result mutation.
Acceptance criteria