microsoft / microsoft/MSBuildCache

Materialize outputs after recursively memoized cache hits

Open
#167 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
64
Forks
24
Avg merge
1d 14h
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read src/Common/MSBuildCachePluginBase.cs, focusing on the ConcurrentDictionary<NodeContext, Lazy<Task>> recursive result path and how materializeOutputs is handled. Trace recursive and direct queries, then add a deterministic concurrency/order test covering out-of-order dependency queries and multi-targeting inner builds. Done means a non-materializing recursive hit causes required outputs to materialize exactly once while default and non-recursive behavior remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.