Skip to content

Add MainThread.SetCustomImplementation for custom platform backends - #34230

Closed
Redth wants to merge 9 commits into
net11.0from
dev/redth/fix-34101
Closed

Redth wants to merge 9 commits into
net11.0from
dev/redth/fix-34101

Conversation

@Redth

@Redth Redth commented Feb 25, 2026

Copy link
Copy Markdown
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description

Fixes #34101

On custom platform backends (e.g. Linux/GTK), MainThread.BeginInvokeOnMainThread() and MainThread.InvokeOnMainThreadAsync() throw NotImplementedInReferenceAssemblyException because there is no platform-specific partial class implementation for the netstandard TFM.

This PR adds a public MainThread.SetCustomImplementation() method that allows custom backends to register their own IsMainThread and BeginInvokeOnMainThread implementations.

Changes

  • MainThread.shared.cs: Added static callback fields and SetCustomImplementation(Func<bool>, Action<Action>) public method
  • MainThread.netstandard.cs: Modified to check for custom callbacks before throwing NotImplementedInReferenceAssemblyException
  • PublicAPI.Unshipped.txt: Added new public API entry for all targets
  • MainThread_Tests.cs: Added 6 unit tests covering the new functionality

Usage

Custom platform backends can register their implementation during startup:

MainThread.SetCustomImplementation(
    isMainThread: () => /* check if on UI thread */,
    beginInvokeOnMainThread: action => /* dispatch to UI thread */);

For example, a GTK backend might use:

MainThread.SetCustomImplementation(
    isMainThread: () => GLib.MainContext.Default.IsOwner,
    beginInvokeOnMainThread: action => GLib.Idle.Add(() => { action(); return false; }));

On standard platforms (iOS, Android, Windows, MacCatalyst), the existing platform-specific implementations continue to be used unchanged.

Fixes #34101. On custom platform backends (e.g. Linux/GTK), MainThread
throws NotImplementedInReferenceAssemblyException because there is no
platform-specific partial class implementation. This adds a public
SetCustomImplementation method that allows custom backends to provide
their own IsMainThread and BeginInvokeOnMainThread implementations.

Changes:
- Add SetCustomImplementation(Func<bool>, Action<Action>) to MainThread
- Modify MainThread.netstandard.cs to use custom callbacks before throwing
- Add unit tests verifying the new functionality
- Update PublicAPI.Unshipped.txt for all targets

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 25, 2026 02:01

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.

Pull request overview

Adds an opt-in mechanism for custom platform backends (e.g., Linux/GTK) to provide MainThread behavior when the portable (*.netstandard.cs) implementation would otherwise throw, addressing the “custom backend throws NotImplementedInReferenceAssemblyException” scenario.

Changes:

  • Added MainThread.SetCustomImplementation(Func<bool>, Action<Action>) and backing delegate fields.
  • Updated the netstandard MainThread implementation to use the custom delegates when present.
  • Added PublicAPI entries across TFMs and introduced new unit tests for the custom-implementation behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/Essentials/src/MainThread/MainThread.shared.cs Adds public API + stores delegates for custom main-thread detection/dispatch.
src/Essentials/src/MainThread/MainThread.netstandard.cs Uses custom delegates before throwing the reference-assembly exception.
src/Essentials/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt Adds new API entry (but has BOM/format concerns).
src/Essentials/src/PublicAPI/net/PublicAPI.Unshipped.txt Adds new API entry (but has BOM/format concerns).
src/Essentials/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt Adds new API entry (format appears inconsistent with shipped conventions).
src/Essentials/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt Adds new API entry (format appears inconsistent with shipped conventions).
src/Essentials/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt Adds new API entry (format appears inconsistent with shipped conventions).
src/Essentials/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt Adds new API entry (format appears inconsistent with shipped conventions).
src/Essentials/src/PublicAPI/net-android/PublicAPI.Unshipped.txt Adds new API entry (format appears inconsistent with shipped conventions).
src/Essentials/test/UnitTests/MainThread_Tests.cs Adds unit tests validating custom-implementation behavior and argument validation.

@@ -1 +1,2 @@
#nullable enable
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

PublicAPI formatting here is inconsistent with the rest of this TFM's shipped APIs (which use the ~static prefix and omit nullable ! annotations for MainThread members). As written, this entry likely won't match the API as generated from the current (nullable-oblivious) source. Update the entry to the correct PublicAPI format for this assembly (likely ~static ... without !).

Suggested change
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void
~static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool> isMainThread, System.Action<System.Action> beginInvokeOnMainThread) -> void

Copilot uses AI. Check for mistakes.
@@ -1 +1,2 @@
#nullable enable
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

PublicAPI formatting here is inconsistent with the rest of this TFM's shipped APIs (which use the ~static prefix and omit nullable ! annotations for MainThread members). As written, this entry likely won't match the API as generated from the current (nullable-oblivious) source. Update the entry to the correct PublicAPI format for this assembly (likely ~static ... without !).

Suggested change
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void
~static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool> isMainThread, System.Action<System.Action> beginInvokeOnMainThread) -> void

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +25
s_isMainThreadImplementation = isMainThread ?? throw new ArgumentNullException(nameof(isMainThread));
s_beginInvokeOnMainThreadImplementation = beginInvokeOnMainThread ?? throw new ArgumentNullException(nameof(beginInvokeOnMainThread));

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

SetCustomImplementation mutates s_isMainThreadImplementation before validating beginInvokeOnMainThread. If beginInvokeOnMainThread is null, the method throws but leaves the class in a partially-updated state (IsMainThread may start returning a value instead of throwing). Validate both parameters first (or assign atomically) so the method is exception-safe and does not change state on failure.

Suggested change
s_isMainThreadImplementation = isMainThread ?? throw new ArgumentNullException(nameof(isMainThread));
s_beginInvokeOnMainThreadImplementation = beginInvokeOnMainThread ?? throw new ArgumentNullException(nameof(beginInvokeOnMainThread));
if (isMainThread is null)
throw new ArgumentNullException(nameof(isMainThread));
if (beginInvokeOnMainThread is null)
throw new ArgumentNullException(nameof(beginInvokeOnMainThread));
s_isMainThreadImplementation = isMainThread;
s_beginInvokeOnMainThreadImplementation = beginInvokeOnMainThread;

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +76
// Use reflection to clear the static fields since there's no public reset API
var type = typeof(MainThread);
var isMainThreadField = type.GetField("s_isMainThreadImplementation",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
var beginInvokeField = type.GetField("s_beginInvokeOnMainThreadImplementation",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
isMainThreadField?.SetValue(null, null);
beginInvokeField?.SetValue(null, null);

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

These tests reset MainThread state by reflecting on private field names. This is brittle (renames/ILLink changes can break tests) and bypasses InternalsVisibleTo that the Essentials assembly already provides. Consider adding an internal reset helper on MainThread (accessible to Microsoft.Maui.Essentials.UnitTests) and call that instead of reflection.

Suggested change
// Use reflection to clear the static fields since there's no public reset API
var type = typeof(MainThread);
var isMainThreadField = type.GetField("s_isMainThreadImplementation",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
var beginInvokeField = type.GetField("s_beginInvokeOnMainThreadImplementation",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
isMainThreadField?.SetValue(null, null);
beginInvokeField?.SetValue(null, null);
// Use the internal reset helper on MainThread instead of reflection on private fields
MainThread.Reset();

Copilot uses AI. Check for mistakes.
@@ -1 +1,2 @@
#nullable enable
#nullable enable

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

The first line now contains a BOM character before #nullable enable (shows up as �#nullable enable). This frequently causes PublicAPI tooling diffs/failures. Please remove the BOM so the line is exactly #nullable enable.

Suggested change
#nullable enable
#nullable enable

Copilot uses AI. Check for mistakes.
@@ -1 +1,2 @@
#nullable enable
#nullable enable

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

The first line now contains a BOM character before #nullable enable. This frequently causes PublicAPI tooling diffs/failures. Please remove the BOM so the line is exactly #nullable enable.

Suggested change
#nullable enable
#nullable enable

Copilot uses AI. Check for mistakes.
@@ -1 +1,2 @@
#nullable enable
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

PublicAPI formatting here is inconsistent with the rest of this TFM's shipped APIs (which use the ~static prefix and omit nullable ! annotations for MainThread members). As written, this entry likely won't match the API as generated from the current (nullable-oblivious) source. Update the entry to the correct PublicAPI format for this assembly (likely ~static ... without !).

Suggested change
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void
~static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool> isMainThread, System.Action<System.Action> beginInvokeOnMainThread) -> void

Copilot uses AI. Check for mistakes.
@@ -1 +1,2 @@
#nullable enable
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

PublicAPI formatting here is inconsistent with the rest of this TFM's shipped APIs (which use the ~static prefix and omit nullable ! annotations for MainThread members). As written, this entry likely won't match the API as generated from the current (nullable-oblivious) source. Update the entry to the correct PublicAPI format for this assembly (likely ~static ... without !).

Suggested change
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void
~static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool> isMainThread, System.Action<System.Action> beginInvokeOnMainThread) -> void

Copilot uses AI. Check for mistakes.
@@ -1 +1,2 @@
#nullable enable
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

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

PublicAPI formatting here is inconsistent with the rest of this TFM's shipped APIs (which use the ~static prefix and omit nullable ! annotations for MainThread members). As written, this entry likely won't match the API as generated from the current (nullable-oblivious) source. Update the entry to the correct PublicAPI format for this assembly (likely ~static ... without !).

Suggested change
static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool>! isMainThread, System.Action<System.Action!>! beginInvokeOnMainThread) -> void
~static Microsoft.Maui.ApplicationModel.MainThread.SetCustomImplementation(System.Func<bool> isMainThread, System.Action<System.Action> beginInvokeOnMainThread) -> void

Copilot uses AI. Check for mistakes.
/// </summary>
public static partial class MainThread
{
static Func<bool> s_isMainThreadImplementation;

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.

do we use s_ ?

- Rename s_ prefixed fields to match Essentials naming conventions
- Validate both parameters before assigning for exception safety
- Add internal ResetCustomImplementation() to replace reflection in tests
- Fix PublicAPI format to use ~static prefix matching shipped conventions
- Remove BOM from net/ and netstandard/ PublicAPI.Unshipped.txt files

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34230

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34230"

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment on lines +30 to +31
customIsMainThreadImplementation = isMainThread;
customBeginInvokeOnMainThreadImplementation = beginInvokeOnMainThread;

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

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

The two static fields are assigned non-atomically. If SetCustomImplementation is called on one thread while another thread calls IsMainThread or BeginInvokeOnMainThread, there's a brief window where customIsMainThreadImplementation is set but customBeginInvokeOnMainThreadImplementation is still null. This could cause an inconsistent state where IsMainThread succeeds via the custom implementation but BeginInvokeOnMainThread falls through to PlatformBeginInvokeOnMainThread which still throws NotSupportedOrImplementedException because the second delegate hasn't been assigned yet.

Consider assigning both delegates atomically, for example by storing them as a single tuple or object reference (e.g., a record/struct containing both delegates), so the implementation is swapped in one atomic reference write.

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +32
public static void SetCustomImplementation(Func<bool> isMainThread, Action<Action> beginInvokeOnMainThread)
{
if (isMainThread is null)
throw new ArgumentNullException(nameof(isMainThread));

if (beginInvokeOnMainThread is null)
throw new ArgumentNullException(nameof(beginInvokeOnMainThread));

customIsMainThreadImplementation = isMainThread;
customBeginInvokeOnMainThreadImplementation = beginInvokeOnMainThread;
}

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

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

On standard platform TFMs (Android, iOS, macOS, Windows, Tizen), calling SetCustomImplementation will silently set the static fields but they will never be read — the platform-specific PlatformIsMainThread and PlatformBeginInvokeOnMainThread implementations don't check them. This means the method succeeds without error but has no effect, which could be very confusing for users.

Consider either (1) making the method throw PlatformNotSupportedException on standard platforms (e.g., via a #if or a platform flag), or (2) documenting in the XML doc that this method only takes effect on the netstandard/bare net TFMs and is ignored on standard platforms, or (3) having the platform-specific implementations also check and prefer the custom implementation when set.

Copilot uses AI. Check for mistakes.
@MauiBot

MauiBot commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI Summary

📊 Expand Full Review — 72445e5 · Address PR review feedback
🔍 Pre-Flight — Context & Validation

Issue: #34101 - MainThread.BeginInvokeOnMainThread throws on custom platform backends - Common UI-thread marshaling pattern crashes; Dispatcher works but isn't the documented/recommended path
PR: #34230 - Add MainThread.SetCustomImplementation for custom platform backends
Platforms Affected: Custom platform backends / external TFMs (for example Linux/GTK); standard Android/iOS/Windows/MacCatalyst implementations are not the target scenario
Files Changed: 9 implementation, 1 test

Key Findings

  • The linked issue requests a way for non-standard backends to supply MainThread behavior or a fallback to MAUI Dispatcher; this PR chooses the explicit registration path via MainThread.SetCustomImplementation(Func<bool>, Action<Action>).
  • The PR changes only Essentials MainThread code plus PublicAPI entries and adds one unit-test file; there are no HostApp/UI/device tests in the PR, only unit coverage.
  • Earlier review feedback about PublicAPI formatting, exception safety, and using an internal reset helper appears addressed in the current diff.
  • Two unresolved review threads remain on the latest revision: the delegates are written as two separate static fields (possible transient inconsistency), and the new public API is advertised on standard TFMs even though the PR description says standard platform implementations remain unchanged.
  • No prior agent review artifact with phase output was found in PR comments; this run needs a full fresh review.

Edge Cases From Discussion

  • Concurrent callers could observe IsMainThread using the custom delegate while BeginInvokeOnMainThread still falls back to the platform partial path.
  • Callers on standard TFMs may assume SetCustomImplementation() changes behavior there, but the PR description claims Android/iOS/Windows/MacCatalyst keep using their existing implementations.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #34230 Add a public custom registration API and use it from the netstandard implementation before throwing ⏳ PENDING (Gate) src/Essentials/src/MainThread/MainThread.shared.cs, src/Essentials/src/MainThread/MainThread.netstandard.cs, PublicAPI files, src/Essentials/test/UnitTests/MainThread_Tests.cs Original PR

🚦 Gate — Test Verification

Result: ❌ SKIPPED

Gate Result: ⚠️ SKIPPED

Platform: android
Mode: Full Verification requested, but no applicable HostApp/UI test exists for this PR

  • Tests FAIL without fix: N/A
  • Tests PASS with fix: N/A

Notes

  • PR Add MainThread.SetCustomImplementation for custom platform backends #34230 adds Essentials source changes plus one unit-test file (src/Essentials/test/UnitTests/MainThread_Tests.cs); it does not add or modify TestCases.HostApp / TestCases.Shared.Tests coverage.
  • Per the gate instructions, the fail-without-fix / pass-with-fix HostApp verification cannot be performed here, so gate is skipped instead of fabricated.
  • Supplemental evidence: the targeted MainThread_Tests unit tests ran successfully in the PR state (6/6 passed).

🔧 Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix Single immutable state object published atomically instead of two separate delegate fields ✅ PASS MainThread.shared.cs, MainThread.netstandard.cs, PublicAPI files Simplest safe fix for the torn-publication bug while preserving the PR's API shape
2 try-fix Ordered volatile publication gate using release/acquire semantics across two fields ✅ PASS MainThread.shared.cs, MainThread.netstandard.cs, PublicAPI files Smaller than a wrapper object, but correctness depends on subtle memory-ordering rules
3 try-fix Shared-layer override routing with lock-protected coherent delegate snapshot across all TFMs ✅ PASS MainThread.shared.cs, tests, PublicAPI files Best tested answer to both review concerns: no torn publication and no ignored override on standard TFMs
4 try-fix Replace delegate pair with an interface-based custom implementation object used from shared code ✅ PASS MainThread.shared.cs, tests, PublicAPI files Functionally sound, but adds more API/abstraction than the scenario needs
5 try-fix Unified shared MainThreadImplementation strategy reference initialized by platform bootstrap/static constructors ✅ PASS MainThread.shared.cs, MainThread.netstandard.cs, MainThread.android.cs, MainThread.ios.tvos.watchos.macos.cs, PublicAPI files Coherent architecture, but touches too many files for this bug
6 try-fix AsyncLocal-scoped custom implementation consulted across TFMs ✅ PASS MainThread.shared.cs, MainThread.netstandard.cs, platform partials, PublicAPI files Passes tests, but the semantics are wrong for a backend-wide registration API because state becomes async-flow scoped
PR PR #34230 Public SetCustomImplementation(Func<bool>, Action<Action>) with two separate backing delegate fields used by the netstandard partial ⚠️ Gate skipped; targeted unit tests on PR passed MainThread.shared.cs, MainThread.netstandard.cs, PublicAPI files, MainThread_Tests.cs Original PR; still leaves an atomicity race and an ambiguous cross-TFM contract

Cross-Pollination

Model Round New Ideas? Details
claude-opus-4.6 1 Yes Single immutable state object with atomic publication
claude-sonnet-4.6 1 Yes Release/acquire publication gate across two fields
gpt-5.3-codex 1 Yes Shared-layer override with lock-protected coherent snapshot
gemini-3-pro-preview 1 Yes Interface-based custom implementation object
claude-opus-4.6 2 No NO NEW IDEAS
claude-sonnet-4.6 2 No NO NEW IDEAS
gpt-5.3-codex 2 Yes Unified shared strategy reference initialized by platform bootstrap/static constructors
gemini-3-pro-preview 2 No NO NEW IDEAS
claude-opus-4.6 3 No NO NEW IDEAS
claude-sonnet-4.6 3 No NO NEW IDEAS
gpt-5.3-codex 3 No NO NEW IDEAS
gemini-3-pro-preview 3 Yes Proxy MainThread through IDispatcher / platform application services (not executed because the workflow hit the 3-round cap)

Exhausted: Yes
Selected Fix: Candidate #3 — it is the strongest tested alternative because it addresses both the torn-publication race and the "public but ignored on standard TFMs" concern, while staying smaller and clearer than candidates 4-6.


📋 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Phase Status

Phase Status Notes
Pre-Flight ✅ COMPLETE Issue #34101 targets custom/external TFMs; PR adds Essentials source changes plus unit tests
Gate ⚠️ SKIPPED No applicable HostApp/UI test exists for Android; targeted MainThread_Tests still passed locally
Try-Fix ✅ COMPLETE 6 attempts run, 6 passing candidates, 3 cross-pollination rounds completed
Report ✅ COMPLETE

Summary

The PR solves the original custom-backend gap and its added unit tests pass, but the current implementation still has two design problems: it publishes the custom MainThread delegates through two independent static writes, and it exposes a public API on every TFM even though only the netstandard path observes it. That makes the current fix harder to reason about and potentially misleading for callers on standard platforms.

Root Cause

SetCustomImplementation() currently installs the isMainThread and beginInvokeOnMainThread delegates separately in MainThread.shared.cs, while only MainThread.netstandard.cs reads them back. A concurrent caller can observe half-installed state, and callers on Android/iOS/Windows/MacCatalyst can successfully call the public API without it having any effect because their platform partials bypass the custom delegates entirely.

Fix Quality

The PR's overall direction is good and the test coverage is a solid start, but I do not think the current shape is ready as-is. The best tested alternative was Candidate #3, which moved the override decision into shared code and used a coherent snapshot so both review concerns disappeared in one place. If you want to keep the current narrower behavior, at minimum the delegate installation should still be made atomic (Candidate #1), and the standard-platform semantics should be clarified explicitly instead of remaining implicit.


@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-failed AI could not verify tests catch the bug s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Mar 23, 2026
Redth and others added 4 commits April 1, 2026 19:16
# Conflicts:
#	src/Essentials/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
#	src/Essentials/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
#	src/Essentials/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
#	src/Essentials/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt
#	src/Essentials/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt
#	src/Essentials/src/PublicAPI/net/PublicAPI.Unshipped.txt
#	src/Essentials/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt
- Store both custom callbacks in a single sealed class (CustomMainThreadCallbacks)
  with volatile field for atomic reference swap, fixing the race condition where
  IsMainThread could use the custom impl while BeginInvokeOnMainThread still throws.
- Add <remarks> documenting that SetCustomImplementation only affects netstandard/net
  TFMs and has no effect on standard platform builds (Android, iOS, etc.).
- Validate both parameters before any state mutation (already correct, preserved).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…#34265)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## Summary

Adds a standalone `code-review` skill for reviewing PR code changes with
MAUI-specific domain knowledge, modeled after [dotnet/android's
android-reviewer
skill](https://github.com/dotnet/android/tree/main/.github/skills/android-reviewer).

### What's included

**`.github/skills/code-review/SKILL.md`** (196 lines) — Review workflow:
- Independence-first methodology (read code before PR description to
avoid anchoring bias)
- 6-step workflow: gather context → load rules → independent assessment
→ reconcile with PR narrative → check CI → devil's advocate verdict
- Three verdicts: `LGTM`, `NEEDS_CHANGES`, `NEEDS_DISCUSSION`
- Optional multi-model review for diverse perspectives
- Output constraints: don't pile on, don't flag what CI catches

**`.github/skills/code-review/references/review-rules.md`** (345 lines)
— Domain knowledge:
- **22 sections** of review rules distilled from real FTE code reviews
- **138 PR citations** linking each rule to the PR where the pattern was
identified
- Sourced from **366 PRs**: top 142 most-discussed PRs (2,883 review
comments), 30 reverted PRs, 50 candidate-branch failures, 64 regression
fixes
- Covers: handler lifecycle, memory leaks, safe area, layout, platform
code, Android/iOS/Windows specifics, navigation, CollectionView,
threading, XAML, testing, performance, error handling, API design,
images, gestures, build, accessibility
- §21 Regression Prevention — lessons from reverts and candidate
failures
- §22 Component Risk Table — ranking the most regression-prone
components

### Design decisions

- **Separation of concerns**: SKILL.md = workflow, review-rules.md =
knowledge (follows Android's pattern)
- **Standalone**: Can be invoked directly by users or by other agents.
No coupling to the PR agent pipeline.
- **Data-driven**: Every rule traces to a real PR where a senior
maintainer flagged the pattern. No generic advice.

### Changes to copilot-instructions.md

- Added "Opening PRs" section with required NOTE block template
- Added code-review skill to the skills listing
- Minor reformatting of existing documentation sections

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
@Redth

Redth commented Apr 3, 2026 •

Copy link
Copy Markdown
Member Author

Addressed today’s 2 new Copilot comments and verified with build/tests.

✅ Fixed

  • src/Essentials/src/MainThread/MainThread.shared.cs

    • SetCustomImplementation now throws PlatformNotSupportedException on platform TFMs (ANDROID, IOS, MACCATALYST, TVOS, WATCHOS, WINDOWS, TIZEN) instead of silently storing delegates that are never used there.
    • Updated XML remarks to reflect that platform TFMs throw and only non-platform TFMs (e.g. netstandard/bare net) use custom callbacks.
  • src/Essentials/test/UnitTests/MainThread_Tests.cs

    • Renamed test names from ..._On_NetStandard_... to ..._On_NonPlatform_... for TFM-accurate naming.

✅ Validation run

  • dotnet build src/Essentials/src/Essentials.csproj -f net10.0 --no-restore -v q
  • dotnet build src/Essentials/test/UnitTests/Essentials.UnitTests.csproj --no-restore -v q
  • dotnet test src/Essentials/test/UnitTests/Essentials.UnitTests.csproj --no-build --filter "FullyQualifiedName~MainThread_Tests"
    • Passed: 6, Failed: 0

✅ Push

  • Commit: cd2c87a7ab
  • Branch: dev/redth/fix-34101

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment on lines +46 to +47

customImplementation = new CustomMainThreadCallbacks(isMainThread, beginInvokeOnMainThread);

Copilot AI Apr 4, 2026

Copy link

Choose a reason for hiding this comment

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

SetCustomImplementation is documented as having no effect on standard platform TFMs, but it currently still stores the provided delegates into a static field on all TFMs. On Android/iOS/etc this won’t be used (since platform partials ignore it) but it can still retain captured references for the lifetime of the app. Consider guarding this assignment (e.g., compile-time #if !PLATFORM / runtime check) so it truly no-ops (or throws) on platform TFMs, matching the remarks and avoiding unintended object retention.

Suggested change
customImplementation = new CustomMainThreadCallbacks(isMainThread, beginInvokeOnMainThread);
#if ANDROID || IOS || MACCATALYST || WINDOWS || TIZEN
return;
#else
customImplementation = new CustomMainThreadCallbacks(isMainThread, beginInvokeOnMainThread);
#endif

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +14
public void IsMainThread_On_NetStandard_Without_Custom_Implementation() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => MainThread.IsMainThread);

[Fact]
public void BeginInvokeOnMainThread_On_NetStandard_Without_Custom_Implementation() =>

Copilot AI Apr 4, 2026

Copy link

Choose a reason for hiding this comment

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

These test names say "NetStandard", but Essentials.UnitTests targets $(_MauiDotNetTfm) (bare netX.Y) as well and the updated MainThread.netstandard.cs is compiled for both netstandard and the bare net TFM. Renaming these tests to something like "Portable"/"NonPlatform" (or including both netstandard + net) would make the intent accurate and avoid confusion when reading failures.

Suggested change
public void IsMainThread_On_NetStandard_Without_Custom_Implementation() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => MainThread.IsMainThread);
[Fact]
public void BeginInvokeOnMainThread_On_NetStandard_Without_Custom_Implementation() =>
public void IsMainThread_On_NonPlatform_Without_Custom_Implementation() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => MainThread.IsMainThread);
[Fact]
public void BeginInvokeOnMainThread_On_NonPlatform_Without_Custom_Implementation() =>

Copilot uses AI. Check for mistakes.
- Throw PlatformNotSupportedException from SetCustomImplementation on platform
  TFMs (Android/iOS/MacCatalyst/tvOS/watchOS/Windows/Tizen) to avoid silently
  retaining custom callback references where they are never used.
- Update XML remarks to reflect throw behavior on platform TFMs and clarify
  non-platform TFM applicability.
- Rename two unit tests from NetStandard to NonPlatform for TFM-accurate naming.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

🧪 PR Test Evaluation

Overall Verdict: ✅ Tests are adequate

The PR adds 6 focused unit tests that correctly cover the new MainThread.SetCustomImplementation API, including the happy path, null-argument guards, and the default (no-impl) exception behavior.

👍 / 👎 — Was this evaluation helpful? React to let us know!

📊 Expand Full Evaluation

PR Test Evaluation Report

PR: #34230 — Add MainThread.SetCustomImplementation for non-platform TFMs
Test files evaluated: 1 (src/Essentials/test/UnitTests/MainThread_Tests.cs)
Fix files: 2 (MainThread.shared.cs, MainThread.netstandard.cs)


Overall Verdict

✅ Tests are adequate

The unit tests are the right type for this API and cover the core scenarios well. There are a couple of minor gaps worth noting, but the critical paths are all tested.


1. Fix Coverage — ✅

The fix adds SetCustomImplementation with two code paths on non-platform TFMs:

  • PlatformIsMainThread now returns customImplementation?.IsMainThread() ?? throw ...
  • PlatformBeginInvokeOnMainThread now routes to customImplementation if set

The tests cover:

  • Default behavior without a custom impl (both properties/methods throw NotImplementedInReferenceAssemblyException) ✅
  • Custom IsMainThread callback is invoked ✅
  • Custom BeginInvokeOnMainThread callback is invoked ✅
  • Null argument guards on both parameters ✅

2. Edge Cases & Gaps — ⚠️

Covered:

  • Default exception when no custom implementation is set
  • Custom IsMainThread returning true
  • Custom BeginInvokeOnMainThread executing the action
  • Null argument validation for both parameters

Missing:

  • Replacing the implementation: No test for calling SetCustomImplementation twice — the second call should silently replace the first (the field is volatile). Worth a test to document the intended behavior.
  • BeginInvokeOnMainThread when IsMainThread = true: The shared code short-circuits to action() directly (not via PlatformBeginInvokeOnMainThread) when on the main thread. The existing test sets IsMainThread: () => false. A case where IsMainThread returns true would verify the synchronous fast-path still works with a custom implementation.
  • Platform TFM throws PlatformNotSupportedException: The #if ANDROID || IOS || ... guard throws on real platform TFMs, but this behavior is untested. Existing device tests don't call SetCustomImplementation. (Lower priority — hard to cover in unit tests, and the behavior is simple.)

3. Test Type Appropriateness — ✅

Current: Unit Test (xUnit)
Recommendation: Same — this is the ideal type.

The API is pure logic with no UI, no layout, no native platform context. Unit tests running against the netstandard/net TFM are exactly right, and the fix was designed specifically for non-platform TFMs.


4. Convention Compliance — ✅

  • Uses [Fact] (xUnit) ✅
  • Proper try/finally cleanup via ClearCustomImplementation() / ResetCustomImplementation() ✅
  • No timing hacks, no async anti-patterns ✅
  • No issues flagged by automated checks ✅

5. Flakiness Risk — ✅ Low

All tests are synchronous, deterministic, and self-contained. The try/finally pattern ensures static state is always reset, preventing cross-test pollution.


6. Duplicate Coverage — ✅ No duplicates

Existing device tests in src/Essentials/test/DeviceTests/Tests/MainThread_Tests.cs test real platform behavior (IsMainThread/IsNotOnMainThread). The new unit tests cover the new custom-implementation API, which is an entirely separate concern with no overlap.


7. Platform Scope — ⚠️

The SetCustomImplementation change spans all TFMs via MainThread.shared.cs, but the meaningful behavior change is conditional:

  • Non-platform TFMs (netstandard, net): custom impl is used ← tested by unit tests ✅
  • Platform TFMs (Android, iOS, etc.): throws PlatformNotSupportedException ← untested

The unit test project runs as a non-platform TFM, so the platform-TFM PlatformNotSupportedException path is not exercised. This is a minor gap; the conditional is simple and hard to cover without a device test context.


8. Assertion Quality — ✅

Assertions are specific and meaningful:

  • Assert.Throws(NotImplementedInReferenceAssemblyException)(...) — exact exception type ✅
  • Assert.True(MainThread.IsMainThread) — checks the actual returned value ✅
  • Assert.True(wasCalled) + Assert.True(actionExecuted) — verifies both invocation and delegation ✅
  • Assert.Throws(ArgumentNullException)(...) — correct exception for null args ✅

9. Fix-Test Alignment — ✅

The tests directly call MainThread.SetCustomImplementation, MainThread.IsMainThread, and MainThread.BeginInvokeOnMainThread — the exact API surface modified by the fix. No misalignment.


Recommendations

  1. (Minor) Add a test for calling SetCustomImplementation twice — verify the second call replaces the first, documenting the intended behavior.
  2. (Minor) Add a test where the custom IsMainThread returns true and then call BeginInvokeOnMainThread — confirm the synchronous fast-path in the shared code still executes the action correctly.
  3. (Low priority) Consider whether a device test should verify that SetCustomImplementation throws PlatformNotSupportedException on platform TFMs. Given the simplicity of the #if guard, this is optional.

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • dc.services.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "dc.services.visualstudio.com"

See Network Configuration for more information.

Note

🔒 Integrity filtering filtered 1 item

Integrity filtering activated and filtered the following item during workflow execution.
This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.

🧪 Test evaluation by Evaluate PR Tests

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@PureWeen

PureWeen commented Apr 21, 2026 •

Copy link
Copy Markdown
Member

🔍 Multi-Model Code Review — PR #34230

PR: Add MainThread.SetCustomImplementation for custom platform backends
Author: @Redth | Base: main | Issue: #34101
Reviewers: 3 independent automated reviewers with adversarial consensus


CI Status: ✅ All checks passing

All maui-pr stages (builds, Helix unit tests, integration tests across platforms) are green.


Prior Review Comments

Previous Copilot reviewer and agent feedback has been addressed by the author (atomicity via single CustomMainThreadCallbacks object, PlatformNotSupportedException on platform TFMs, test naming). This review covers the current state of the diff.


Findings

🟡 MODERATE — Branch targeting: new public API on main instead of net11.0

Files: MainThread.shared.cs, all 8 PublicAPI.Unshipped.txt files
Consensus: 3/3 reviewers agree

Per MAUI repo conventions, main is for bug fixes without API changes, and net11.0 is for new features and API changes. This PR introduces a new public API (SetCustomImplementation) confirmed by the PublicAPI.Unshipped.txt additions, but targets main. Even though the motivation is a bug fix for custom backends, the vehicle is a new public method.

Ask: Should this target net11.0, or does the team have explicit sign-off for shipping new API from main?


🟡 MODERATE — ArgumentNullException fires before PlatformNotSupportedException on platform TFMs

File: src/Essentials/src/MainThread/MainThread.shared.cs (lines ~37-48)
Consensus: 3/3 reviewers agree

On platform TFMs (Android, iOS, etc.), the null guards execute before the unconditional PlatformNotSupportedException throw:

if (isMainThread is null)
    throw new ArgumentNullException(...);  // ← fires first on null input
// ...
throw new PlatformNotSupportedException(...);  // ← never reached if null

A caller passing null gets ArgumentNullException instead of PlatformNotSupportedException, implying the method would work with valid arguments. This is misleading for feature-detection patterns.

Suggested fix: Move the #if platform guard before the null checks:

#if ANDROID || IOS || MACCATALYST || TVOS || WATCHOS || WINDOWS || TIZEN
    throw new PlatformNotSupportedException("...");
#else
    ArgumentNullException.ThrowIfNull(isMainThread);
    ArgumentNullException.ThrowIfNull(beginInvokeOnMainThread);
    customImplementation = new CustomMainThreadCallbacks(isMainThread, beginInvokeOnMainThread);
#endif

🟡 MODERATE — Test parallelism risk with shared static state

File: src/Essentials/test/UnitTests/MainThread_Tests.cs
Consensus: 3/3 reviewers agree

Tests mutate the static customImplementation field. xUnit parallelizes across test classes by default. If any other test class in the assembly accesses MainThread.IsMainThread or MainThread.BeginInvokeOnMainThread concurrently, the static state from these tests will leak, causing non-deterministic failures.

The two "without custom implementation" tests (IsMainThread_On_NonPlatform_Without_Custom_Implementation, BeginInvokeOnMainThread_On_NonPlatform_Without_Custom_Implementation) are especially vulnerable — they assert the null initial state but don't call ResetCustomImplementation() first.

Suggested fix: Add [Collection("MainThread")] to serialize with any other MainThread consumers, or add a setup/teardown that resets state before each test.


🟡 MODERATE — No public way to clear the custom implementation

File: src/Essentials/src/MainThread/MainThread.shared.cs — ResetCustomImplementation()
Consensus: 2/3 reviewers agree

ResetCustomImplementation() is internal, meaning consumers on custom platforms (the target audience) cannot unregister during backend teardown, hot-reload, or testing in their own projects. The API is one-directional — you can set but never clear without internal access.

Suggested fix: Either make ClearCustomImplementation() public, or accept null in SetCustomImplementation as a documented "reset" convention.


🟢 MINOR — Inconsistent volatile read pattern between the two platform methods

File: src/Essentials/src/MainThread/MainThread.netstandard.cs
Consensus: 2/3 reviewers agree

PlatformBeginInvokeOnMainThread uses an explicit local snapshot (var impl = customImplementation), while PlatformIsMainThread uses ?. null-conditional. Both are technically safe (C# spec guarantees single evaluation of ?. receiver), but the inconsistency is a maintenance hazard.

Suggested fix: Use the explicit-local pattern in both for consistency.


🟢 MINOR — User-supplied callback exceptions not documented

File: src/Essentials/src/MainThread/MainThread.shared.cs — XML docs
Consensus: 3/3 reviewers agree

If the custom isMainThread or beginInvokeOnMainThread delegate throws, the exception propagates directly to callers. Previously, callers only expected NotImplementedInReferenceAssemblyException. This contract change should be documented.

Suggested fix: Add a <remarks> note: "Exceptions thrown by the provided delegates will propagate to callers of IsMainThread and BeginInvokeOnMainThread."


🟢 MINOR — Silent replacement semantics undocumented

File: src/Essentials/src/MainThread/MainThread.shared.cs
Consensus: 2/3 reviewers agree

Calling SetCustomImplementation twice silently replaces the first. In multi-library scenarios, the last caller wins with no indication of overwrite. Consider logging a diagnostic, or at minimum document this is the intended behavior.


🟢 MINOR — Missing edge-case test coverage

File: src/Essentials/test/UnitTests/MainThread_Tests.cs
Consensus: 3/3 reviewers agree

Three edge cases are untested:

  1. Double-set replacement — calling SetCustomImplementation twice; second should replace first
  2. Callback that throws — exception should propagate to callers
  3. InvokeOnMainThreadAsync with custom impl — the primary async entry point should flow through the custom implementation

ℹ️ Informational — Discarded findings

Finding Source Reason discarded
Missing MACOS in #if guard 1 reviewer (2/3 after adversarial) Factually incorrect: macOS compilation rules are commented out in Essentials.csproj. MACOS is never defined; macOS is handled through MACCATALYST.
Inconsistent snapshot race in BeginInvokeOnMainThread 2/3 agreed Theoretically present but not practically exploitable: SetCustomImplementation is a configure-once-at-startup API. The double-read across IsMainThread → PlatformBeginInvokeOnMainThread cannot produce incorrect behavior in any supported usage pattern.
Async wrapper sync-throw vs faulted Task 2/3 agreed Pre-existing structural issue in InvokeOnMainThreadAsync, not introduced by this PR.
ResetCustomImplementation naming 1/3 only Below consensus threshold.

Test Coverage Assessment

The PR adds 6 unit tests covering the core paths: null guards, custom IsMainThread, custom BeginInvokeOnMainThread, and default exception behavior. Test type (xUnit unit tests) is appropriate for this API-only change. However, 3 edge cases are missing (noted above).


⚠️ Recommended Action: Request Changes

The PR is well-designed architecturally — the immutable CustomMainThreadCallbacks class with volatile reference is the correct lock-free pattern. However, several issues should be addressed before merge:

  1. Clarify branch targeting — confirm with maintainers that new API on main is intentional
  2. Fix exception ordering — move #if guard before null checks on platform TFMs
  3. Harden test isolation — add [Collection] or setup/teardown to prevent xUnit parallelism flakes
  4. Add missing edge-case tests — double-set, callback-throws, async path
  5. Document callback exception propagation — update XML docs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet dotnet deleted a comment from github-actions Bot Apr 21, 2026
@Redth
Redth changed the base branch from main to net11.0 April 21, 2026 20:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Skill Validation Results

❌ Static Checks Failed

Skills checked: 15 | Agents checked: 0

Full validator output
Found 1 skill(s)
[code-review] 📊 code-review: 2,333 BPE tokens [chars/4: 2,447] (detailed ✓), 28 sections, 6 code blocks
✅ All checks passed (1 skill(s))
No agents found in the specified paths: "/home/runner/work/maui/maui/.github/agents"

✅ LLM Evaluation Passed

🔍 Full results and investigation steps

@Redth

Redth commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review — I addressed the actionable items in the latest updates:

  • Retargeted the PR to net11.0, since this introduces a new public API.
  • Moved the platform guard ahead of the argument validation so platform TFMs consistently throw PlatformNotSupportedException.
  • Documented the replacement/reset behavior for the custom implementation, and noted that delegate exceptions propagate to callers.
  • Expanded and hardened the unit tests to cover static-state cleanup, replacement, clear/reset behavior, exception propagation, and the async path.
  • Merged the latest net11.0 changes and resolved the resulting PublicAPI.Unshipped.txt conflicts.

Please take another look when you get a chance.

PureWeen added a commit that referenced this pull request Apr 21, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## Description

The branching instructions in `.github/copilot-instructions.md`
hardcoded `net10.0` as the feature branch for new APIs. This becomes
stale every time a new `netN.0` branch is created (e.g., `net11.0`,
`net12.0`).

This PR replaces the hardcoded version with a dynamic convention: **the
highest `netN.0` branch is the current feature branch for new features
and API changes**. It also includes a discovery command so agents can
programmatically find the right branch.

## Changes

- Removed hardcoded `net10.0 branch` line from Key Technologies section
- Updated Feature branches description to explain the "highest netN.0"
convention
- Replaced hardcoded `net10.0` in Branching section with
version-agnostic pattern and discovery command

## Why

This caused a real issue: during a multi-model code review of PR #34230,
the reviewer incorrectly recommended targeting `net10.0` instead of
`net11.0` because the instructions said `net10.0`. With this change, the
instructions will remain correct as branches evolve.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth

Redth commented Apr 22, 2026

Copy link
Copy Markdown
Member Author

Closing in favour of #35070

@Redth Redth closed this Apr 22, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators May 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-gate-failed AI could not verify tests catch the bug s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

5 participants