Skip to content

Skip remote content upload when the remote cache is read-only - #178

Merged
David Federman (dfederm) merged 3 commits into
microsoft:mainfrom
tubolets:fix/skip-remote-content-upload-when-readonly
Aug 28, 2026
Merged

David Federman (dfederm) merged 3 commits into
microsoft:mainfrom
tubolets:fix/skip-remote-content-upload-when-readonly

Conversation

@tubolets

Copy link
Copy Markdown
Contributor

RemoteCacheIsReadOnly suppresses content hash list publication but not content upload, so a read-only client uploads content that no later build can ever retrieve — nothing references it. It costs egress, storage and build time for no benefit.

CasCacheClient holds both the raw _remoteCacheSession and the _twoLevelCacheSession built from TwoLevelCacheConfiguration. AddNodeAsync uploads content through the raw session without consulting the flag, while the content hash list goes through the two-level session, which honours it.

Changes

  • Capture RemoteCacheIsReadOnly from the passed TwoLevelCacheConfiguration and skip the remote upload block when it is set. This also elides the remote PinBulkAsync calls, which were made only to decide what to upload.
  • Read path is unchanged.

Validation

  • dotnet build MSBuildCache.sln -c Release: succeeded, 0 warnings, 0 errors
  • dotnet test MSBuildCache.sln -c Release --no-build: 547/550 passed. The 3 net472 failures are a pre-existing The tools version "Current" is unrecognized environment issue in MSBuildCachePluginBaseTests; an unmodified checkout fails the same 3.

No unit test added: there is no mock ICacheSession in Common.Tests to build an AddNodeAsync harness on, and CasCacheClientTests currently only covers the static GetAddNodeResult helper. Happy to add a mock session and a regression test if you'd like it in this PR.

Fixes: #177

CasCacheClient holds two sessions: the raw _remoteCacheSession and the
_twoLevelCacheSession built from TwoLevelCacheConfiguration. When adding a
node, content was uploaded directly through _remoteCacheSession without
consulting RemoteCacheIsReadOnly, while the content hash list that would
reference that content is published through _twoLevelCacheSession, which does
honor it.

The result is that a read-only client uploads content that can never be
retrieved: no content hash list ever points at it, so no subsequent build can
hit on it. The upload only costs egress, storage and build time, and leaves
unreferenced blobs behind for lifecycle policies to collect.

Guard the upload block on the read-only flag, which also elides the remote
pin calls that were only made to decide what to upload.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@dfederm David Federman (dfederm) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Just 1 comment to add a regression test, but otherwise looks great!

Adds RecordingCacheSession / RecordingCache, minimal ICacheSession and ICache
implementations that count the calls made against them, and two tests driving
CasCacheClient.AddNodeInternalAsync:

- AddNodeDoesNotUploadContentWhenRemoteCacheIsReadOnly asserts the remote
  session sees no PinAsync, PutStreamAsync or PutFileAsync calls, while the node
  metadata and content hash list are still written to the local cache.
- AddNodeUploadsContentWhenRemoteCacheIsWritable asserts the remote session is
  still pinned and uploaded to when the remote cache is writable, so the guard
  is conditional rather than unconditional.

The first test fails without the accompanying fix:
Expected:<0>. Actual:<1>. 'actual' expression: 'remoteSession.PinCallCount'.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tubolets

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="WiseTech Global"

@dfederm

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
@dfederm
David Federman (dfederm) merged commit 54bcfb2 into microsoft:main Aug 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants