Skip to content

[CI] Prune Roslyn caches before saving snapshots - #135820

Merged
agocke merged 2 commits into
dotnet:mainfrom
agocke:fix/roslyn-cache-pruning
Oct 19, 2026
Merged

agocke merged 2 commits into
dotnet:mainfrom
agocke:fix/roslyn-cache-pruning

Conversation

@agocke

@agocke agocke commented Oct 14, 2026

Copy link
Copy Markdown
Member

Summary

Prune Roslyn's compilation cache after all product and test-build steps, before Azure Pipelines saves the cache snapshot.

  • Use VBCSCompiler -purgecache:<job-start-time> to discard entries not used during this job, retaining reused and newly created entries.
  • Log cache size before and after pruning, available disk space, and the compiler's pruning summary. Surface deletion errors even when the compiler returns exit code zero.
  • Start a new roslyn | v3 snapshot generation without fallback to unpruned v1/v2 snapshots. Preserve the existing platform, leg, and Debug/Release separation.

The final-job hook is conditional on a successful, cache-enabled job. It runs after postBuildSteps, rather than alongside the existing statistics step, because some legs still compile CoreCLR tests after those statistics are collected. Sccache behavior is unchanged.

Motivation

Recent Linux Debug cache saves fail while creating the archive with No space left on device, preventing fresh snapshots from being published.

One sampled Linux Release cache contained 11,430 untouched entries, compared with 288 reused entries and 881 newly stored entries. These are entry counts, not byte measurements or an end-to-end speedup claim, but they show substantial retained history.

This change retains the completed job's working set; it does not impose a hard byte limit. The snapshot-generation change incurs an initial cold Roslyn build for each leg instead of restoring the oversized old snapshots.

Validation

  • Parsed the changed YAML and checked final-step placement and generation-isolated restoration.
  • Exercised the PowerShell and Bash cleanup scripts with the pinned SDK 11.0.100-rc.1.26420.103, using disposable cache fixtures.
  • Confirmed obsolete entries are removed, reused/new entries and staging directories are preserved, invalid timestamps fail without deleting retained entries, and deletion errors are surfaced even when Roslyn exits successfully.
  • The Bash check used Git Bash with the Windows compiler host; Linux/macOS agent execution and full pipeline validation are pending. No full runtime build was run.

Note

This PR description and code changes were prepared with GitHub Copilot.

Cleanup retains entries used or created during the complete job, including test builds.
V3 snapshots do not restore oversized old generations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8cf51af-8686-4700-9b01-cb1db7806f25
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

@agocke
agocke requested a review from sbomer October 14, 2026 22:26
@agocke
agocke marked this pull request as ready for review October 14, 2026 22:27
@agocke
agocke requested a balanced review from Copilot October 14, 2026 23:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Linux/macOS agent execution and end-to-end snapshot saving remain unvalidated.

0 open findings

What changed in this PR

Prunes Roslyn compilation caches before CI snapshot saving to reduce retained cache history and archive disk pressure.

Changes:

  • Adds platform-specific pruning with size, disk-space, and error reporting.
  • Runs pruning after post-build steps for successful, cache-enabled jobs.
  • Starts isolated roslyn | v3 snapshots without restoring older generations.
File Description
eng/​pipelines/​coreclr/​templates/​setup-build-caches.yml Moves cache keys and restoration to generation v3.
eng/​pipelines/​coreclr/​templates/​prune-roslyn-cache.yml Adds Bash and PowerShell pruning steps and diagnostics.
eng/​pipelines/​common/​global-build-job.yml Invokes pruning at the end of the job.

🧠 Review effort: Balanced

Removed comment about starting a new cache generation to avoid restoring unpruned snapshots.
@agocke
agocke requested a review from jjonescz October 17, 2026 02:37
@agocke

agocke commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

/ba-g unrelated diagnostics failures

@agocke
agocke enabled auto-merge (squash) October 17, 2026 02:38
@agocke
agocke merged commit 3a73de9 into dotnet:main Oct 19, 2026
183 of 188 checks passed
@agocke
agocke deleted the fix/roslyn-cache-pruning branch October 19, 2026 08:39
@github-project-automation github-project-automation Bot moved this to Done in AppModel Oct 19, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants