Skip to content

C# and C/C++: Make autobuild script selection deterministic. - #23276

Draft
michaelnebel wants to merge 4 commits into
github:mainfrom
michaelnebel:michaelnebel-deterministic-csharp-build-script
Draft

michaelnebel wants to merge 4 commits into
github:mainfrom
michaelnebel:michaelnebel-deterministic-csharp-build-script

Conversation

@michaelnebel

@michaelnebel michaelnebel commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The non-determinism showed itself during a QA run (It picked different scripts in the different runs) when the autobuilder attempted to build the code from https://github.com/aspnet/AspNetKatana.

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 5f16783f73dd714209747a538cff208b85215817

Dimension Assessment Rationale
Change confidence 9/10 ↑ C# and C++ autobuilder suites pass on .NET 11; regression tests cover permutations, depth, Windows candidate ordering, and no candidates.
↓ No real-world build or CI result has been inspected.
Diagnosis confidence 9.5/10 ↑ The original code preserved filesystem enumeration order for equal-depth candidates; regression cases fail before the fix.
Evidence fit 4/10 ↑ The reported differing script choices are consistent with the identified ordering defect.
↓ The linked job logs are SAML-protected and could not be inspected.

Summary

  • Select the shallowest build script with OrderBy, ThenBy, and FirstOrDefault, breaking ties by ordinal path order while retaining existing candidate matching. .NET optimizes selection to a linear-time minimum scan without sorting.
  • Store candidates in a backing array and expose candidate paths through a get-only projection, in no guaranteed order.
  • Cover different file and directory enumeration orders, depth priority, Windows script candidates, and an empty candidate set. The shared rule is used by both C# and C++ autobuilders.
  • Add fix change notes under both languages; the C/C++ note also calls out the shared C# impact.

Validation

  • dotnet test csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/Semmle.Autobuild.CSharp.Tests.csproj (.NET 11): 41 passed.
  • dotnet test csharp/autobuilder/Semmle.Autobuild.Cpp.Tests/Semmle.Autobuild.Cpp.Tests.csproj (.NET 11): 2 passed.
  • The Bazel test attempt could not analyze the target because the local @semmle_code repository lacks git_info.

The reported example job logs could not be inspected because access requires SAML authorization: successful run and failed run.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the C# label Nov 27, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
michaelnebel and others added 2 commits November 27, 2026 11:17
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@michaelnebel michaelnebel changed the title Make autobuild script selection deterministic C# and C/C++: Make autobuild script selection deterministic. Nov 27, 2026
@michaelnebel
michaelnebel requested an adaptive review from Copilot November 27, 2026 13:43

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.

🟢 Approval recommended

No active review issues are reported for the deterministic build-script selection change.

No open issues 🎉

What changed in this PR

This PR makes build-script selection deterministic in the shared C# and C/C++ autobuilder, preventing filesystem enumeration order from changing which script runs.

Changes:

  • Preserve shallowest-script priority and break ties using ordinal path order.
  • Store candidates in a backing array and expose their paths through a get-only projection.
  • Add regression tests for enumeration order, depth, Windows candidates, and no candidates, plus change notes for both languages.
File Description
csharp/​ql/​lib/​change-notes/​2026-11-27-deterministic-build-script.md Documents deterministic C# script selection.
csharp/​autobuilder/​Semmle.Autobuild.Shared/​BuildCommandAutoRule.cs Adds deterministic tie-breaking and array-backed candidate storage.
csharp/​autobuilder/​Semmle.Autobuild.CSharp.Tests/​BuildScripts.cs Tests ordering, depth priority, Windows candidates, and empty results.
cpp/​ql/​lib/​change-notes/​2026-11-27-deterministic-build-script.md Documents the shared C# and C/C++ autobuilder fix.

Review effort: Balanced (adaptive)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants