Skip to content

[build] Fix concurrent SDK version generation. Fixes #26685 - #26687

Merged
rolfbjarne merged 5 commits into
mainfrom
dev/rolf/fix-sdkversions-race
Sep 24, 2026
Merged

rolfbjarne merged 5 commits into
mainfrom
dev/rolf/fix-sdkversions-race

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Multi-target assembly-preparer builds can invoke the same Make recipes concurrently. The shared SdkVersions.cs.tmp file can be truncated by another invocation, causing a false regeneration error, while writing ProductConstants.cs directly can expose incomplete source to a compiler.

Generate both files through process-specific temporary files and atomically publish completed output. Clean up temporary files on exit and ignore leftovers from interrupted builds. Genuine SdkVersions.cs changes still fail the build with the existing instruction to commit the regenerated file.

Let Make own incremental dependency tracking instead of the incorrect and incomplete MSBuild input/output paths. Track the shared recipes and version configuration as Make prerequisites, and quote the project directory passed to make.

Fixes #26685

🤖 Pull request created by Copilot

rolfbjarne and others added 2 commits September 23, 2026 15:14
Multi-target assembly-preparer builds can invoke the same Make recipes concurrently. Use process-specific temporary files and atomically publish completed output so one invocation cannot truncate another invocation’s temporary file or expose partially written ProductConstants.cs to a compiler. Clean up temporary files on exit while preserving the error requiring genuine SdkVersions.cs changes to be committed.

Let Make own incremental dependency tracking instead of the incorrect and incomplete MSBuild input/output paths. Track the shared recipes and version configuration as Make prerequisites, and quote the project directory passed to make.

Fixes #26685

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Extend the generated-source ignore rules to cover the PID-suffixed temporary files used by concurrent generation. The recipes normally remove these files on exit, but an abrupt process termination can bypass cleanup; any leftovers should remain ignored just like the previous shared temporary file.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 23, 2026 13:31

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.

Copilot review overview

🟡 Changes recommended

Resolve the shared temporary-file race and add a concurrent-generation regression test.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes concurrent SDK/version file generation during multi-target builds.

Changes:

  • Uses process-specific temporary files and atomic publication.
  • Moves incremental dependency tracking to Make.
  • Ignores temporary leftovers and quotes the project path.
File Summary
tools/​common/​Make.common Updates generation and dependency handling; shared temporary-file concurrency and test-coverage issues remain.
tools/​common/​.gitignore Ignores generated temporary files.
tools/​assembly-preparer/​assembly-preparer.csproj Delegates generated-file tracking to Make.

Comment thread tools/common/Make.common Resolved
The generated-source targets consume Make.config.inc, whose writer still used one shared temporary file and removed the published configuration before replacement. Concurrent Make invocations could therefore interfere before reaching the already-protected C# generators.

Use a process-specific temporary file, clean it on exit, and preserve the published configuration until the existing atomic rename replaces it. Ignore interrupted-generation leftovers and make the configuration depend on its generator script so changes to that script trigger regeneration.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 23, 2026 13:40

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.

Copilot review overview

🔵 Needs a closer look

Unresolved shell portability and Make dependency issues may break or stale generated version output.

Review effort: Lite
Findings: None

Resolved since last review (1)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Add Make.versions prerequisite to prevent stale generated version metadata

Make.config:40

❌ bug — create-make-config.sh reads ./Make.versions when computing the commit distances, but this target does not depend on $(TOP)/Make.versions. After a version change, Make can therefore reuse a stale Make.config.inc, and the generated constants consume outdated version metadata. Add $(TOP)/Make.versions to this prerequisite list.

[!NOTE]
This review comment was generated by GitHub Copilot.

Low severity Use POSIX trap syntax for /bin/sh compatibility

tools/​common/​Make.common:8

❌ error — This recipe now uses Bash's EXIT trap, but Make does not select Bash for recipe execution; on Linux the default /bin/sh is commonly dash, which rejects EXIT and aborts before generating SdkVersions.cs. Use the POSIX 0 trap (or explicitly run the recipe under Bash) so the Linux build path remains valid.

[!NOTE]
This review comment was generated by GitHub Copilot.

This issue also appears on line 56 of the same file.

Copilot AI review requested due to automatic review settings September 23, 2026 13:56

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.

Copilot review overview

🟡 Changes recommended

Make.config does not list Make.versions as a prerequisite, allowing stale version data.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)

Comment thread Make.config Resolved
Add Make.versions to the Make.config.inc prerequisites because create-make-config.sh uses its history to calculate per-platform NuGet commit distances. This ensures version updates refresh the cached metadata before the generated-source recipes consume it, while unchanged builds remain incremental.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 23, 2026 14:04
@vs-mobiletools-engineering-service2

This comment has been minimized.

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.

Copilot review overview

🔵 Needs a closer look

Address the missing Git revision prerequisites and non-portable trap ... EXIT usage.

Review effort: Lite
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Version generation misses HEAD changes in reused checkouts

Make.config:40

❌ bug — create-make-config.sh computes the NuGet commit distances from git blame ... HEAD and git rev-list ... HEAD, but this prerequisite list only tracks the checked-in configuration and script. In a reused checkout, advancing HEAD without changing Make.config or Make.versions leaves Make.config.inc up to date, so SdkVersions.cs/ProductConstants.cs can retain stale version data. Add appropriate Git revision/index prerequisites (the version-generation rules in dotnet/Makefile:112 track both) or another revision marker, after GIT_DIRECTORY has been resolved for worktrees.

[!NOTE]
This review comment was generated by GitHub Copilot.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 6df0ea155215603133a01b583c94440eeb32ca07 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #6df0ea1] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 269 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 7 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 25 tests passed. [attempt 4] Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 25 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Golden Gate (27): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: 6df0ea155215603133a01b583c94440eeb32ca07 [PR build]

@rolfbjarne
rolfbjarne merged commit 8918122 into main Sep 24, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/fix-sdkversions-race branch September 24, 2026 10:30
rolfbjarne added a commit that referenced this pull request Oct 15, 2026
#26685 (#26869)

Multi-target assembly-preparer builds can invoke the same Make recipes concurrently. The shared SdkVersions.cs.tmp file can be truncated by another invocation, causing a false regeneration error, while writing ProductConstants.cs directly can expose incomplete source to a compiler.

Generate both files through process-specific temporary files and atomically publish completed output. Clean up temporary files on exit and ignore leftovers from interrupted builds. Genuine SdkVersions.cs changes still fail the build with the existing instruction to commit the regenerated file.

Let Make own incremental dependency tracking instead of the incorrect and incomplete MSBuild input/output paths. Track the shared recipes and version configuration as Make prerequisites, and quote the project directory passed to make.

Fixes #26685

🤖 Pull request created by Copilot

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rolf Bjarne Kvinge <rokvin@microsoft.com>

Backport of #26687.
rolfbjarne added a commit that referenced this pull request Oct 15, 2026
#26685 (#26879)

Multi-target assembly-preparer builds can invoke the same Make recipes concurrently. The shared SdkVersions.cs.tmp file can be truncated by another invocation, causing a false regeneration error, while writing ProductConstants.cs directly can expose incomplete source to a compiler.

Generate both files through process-specific temporary files and atomically publish completed output. Clean up temporary files on exit and ignore leftovers from interrupted builds. Genuine SdkVersions.cs changes still fail the build with the existing instruction to commit the regenerated file.

Let Make own incremental dependency tracking instead of the incorrect and incomplete MSBuild input/output paths. Track the shared recipes and version configuration as Make prerequisites, and quote the project directory passed to make.

Fixes #26685

🤖 Pull request created by Copilot

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rolf Bjarne Kvinge <rokvin@microsoft.com>

Backport of #26687.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] BuildSdkVersions races on shared SdkVersions.cs.tmp during multi-target builds

4 participants