Repository navigation
[Windows] Resume NavigationPage outside native completion callbacks - #40802
Conversation
…llbacks Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@dalexsoto stamp |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
A critical navigation race can send A’s completion event to B and suppress B’s later event; notifications must use each request’s captured destination and be covered by a dispatcher-controlled regression test.
1 open issue
What changed in this PR
This PR changes shared NavigationPage completion handling to avoid resuming callers inside native completion callbacks. It targets a suspected cause of the Windows navigation-test crash; the crash fix remains unconfirmed pending Windows validation.
Changes:
- Uses
RunContinuationsAsynchronouslyfor the active navigation request. - Adds a unit test checking that
NavigatedTodoes not reenter the native completion callback.
| File | Description |
|---|---|
src/Controls/tests/Core.UnitTests/NavigationPageLifecycleTests.cs |
Adds a manually completed navigation test for callback reentrancy. |
src/Controls/src/Core/NavigationPage/NavigationPage.cs |
Queues navigation continuations and documents the native-callback rationale. |
Review effort: Balanced
| var currentNavRequestTaskSource = new TaskCompletionSource<object>(); | ||
| // Native completion can run inside Loaded; do not resume callers that may close | ||
| // the window or navigate again until that native callback has returned. | ||
| var currentNavRequestTaskSource = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously); |
|
Validated head c4da77a in build 1704212: NavigationPage passes in both Windows Controls jobs (16 passed, 0 failed, 3 existing skips each). Both genuine TRX files explicitly mark SettingTitleIconImageSourceDoesntCrash Passed (148 ms packaged, 189 ms unpackaged). The unpackaged Shell SearchHandlerFocusTracksDetachment COMException remains a separate, unresolved failure; this is not a full-CI-green claim. |
Preserve synchronous native callback ordering on iOS and other platforms while retaining the WinUI reentrancy fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@dalexsoto stamp |
This comment has been minimized.
This comment has been minimized.
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
The deferred continuation can let a later push change CurrentPage before completion events fire, causing the completed page to miss NavigatedTo and the next page to receive premature, incorrect lifecycle events.
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Correction/validation update: e9964a9 limits deferral to Windows and passes both Windows Controls jobs in 1704232. iOS General still fails the same 17 tests (log 736), despite restoring main’s non-Windows code. The iOS compiler invocation confirms IOS, not WINDOWS. Runtime comparison found different iOS 27.2 simulator builds: green main 1704155 uses SimulatorRuntime-v24.2.8117.0, whereas 1704232 uses v24.2.91016.19 and its provisioning log ends with Data Migration Failed. This is evidence of a differing native environment, not proof that all 17 failures are caused by this PR. Retry 1704240 is running on the unchanged scoped head; I am not claiming iOS validated yet. |
|
Validated scoped head e9964a9 in unchanged-head retry 1704240: iOS Controls CoreCLR General is green (1479 passed, 0 failed, 14 existing skips; raw log 736). Genuine TRX confirms all 17 previously failing cases Passed. NavigationPage passes in both Windows Controls jobs (16 passed, 0 failed, 3 existing skips each; raw logs 745 packaged and 739 unpackaged), including SettingTitleIconImageSourceDoesntCrash (242 ms and 240 ms). The earlier scoped run 1704232 still failed iOS, as documented above; no further code change was needed for the green retry. Packaged Shell remains red, so this is not a full-CI-green claim. |
|
Correction: build 1704212 failed 17 iOS controls General tests (TabbedPage BarBackgroundTransition, NavigationPage back-button, PageTransitions More tab, ScrollView). I earlier attributed those failures to this PR. The same 17 also fail in #40805 build 1704247, which only changes Windows code, so they are an intermittent iOS cluster that does not come from this PR. It's being investigated separately. This PR's NavigationPage fix is confirmed in build 1704240: NavigationPage passed in Windows controls packaged, and the iOS jobs passed. |
<!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `4b5901591c54bd76752e588ac5582a05707a3207` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 7.5/10 | ↑ PR devicetests [1704250](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704250): iOS controls General 1493 total, 0 failed; log 303 shows iPhone 11 Pro / iOS 27.2 selected.<br>↑ Local simulator runs: 14 scoped tests red → fix green → reverted red → restored green.<br>↓ One green CI run of an intermittent failure; other device-test suites not run locally. | | Diagnosis confidence | 6/10 | ↑ Locally, the iPhone Duo profile reproduces the failures without any predecessor test.<br>↓ main's device step does not log the selected profile, so no CI log shows that failing builds 1704212/1704247 used iPhone Duo. | | Evidence fit | 6/10 | ↑ The same 17-test cluster fails intermittently on unrelated PRs with the main tree, consistent with nondeterministic device selection.<br>↓ Local Duo runs used iOS 27.1 and standard-phone runs iOS 26.0; CI uses iOS 27.2, so this isn't a same-runtime comparison. | <!-- /copilot-assessment --> <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change <!-- Enter description of the fix in this section --> The apparent intermittent iOS General cascade is **simulator-profile drift, not a demonstrated TabbedPage state leak**. The native device-test migration prefers iPhone 11 Pro / iPhone 16 but falls back to any compatible phone on the newest installed runtime. A device-specific runtime supporting only **iPhone Duo** therefore silently changes this standard-phone lane to an unfolded, regular-width navigation environment. The More-tab and native back-button assumptions no longer hold; the tab-bar layer-removal assertion and ScrollView geometry assertion also fail. Select the newest installed runtime **together with a supported standard-phone profile**, retaining the existing iPhone 11 Pro / iPhone 16 preferences. Do not fall back to an arbitrary device profile. Explicit version/major requests remain within their requested version range; when no supported standard-phone profile exists, report a provisioning error instead of substituting another OS. Log and persist the runtime identifier, version, build, and device type in `device.json`. No product code, test assertion, skip, or category exclusion changes. **Coverage boundary:** a device-specific Duo runtime is not a replacement for standard-phone coverage. This does not add foldable coverage; that needs a separately configured lane. For `latest`, the selected standard-phone runtime can be older than an installed Duo-only runtime. #### CI evidence Actual simulator logs in the General job's published `DeviceTests` artifact show: | Build | General job | Device | Runtime | | --- | --- | --- | --- | | [1704247](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704247) | Failed, 17 victims | iPhone Duo / iPhone19,4 | iOS 27.2 / 24B91016s | | [1704240](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704240) | Passed | iPhone 11 Pro / iPhone12,3 | iOS 27.2 / 24B8117 | | [1704155](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704155) | Passed on main | iPhone 11 Pro / iPhone12,3 | iOS 27.2 / 24B8117 | Each has 1,493 `TEST_START` events with different randomized order. In 1704247, the first failure starts at 14:32:39 UTC: `BarBackgroundTransitionRemovesGradientAndRestoresEffect(True)`, with `ArgumentNullException: collection`. The root-replacement tests do not begin until 14:40:12 UTC, so they cannot explain that first failure. The raw test-step log is 749 for 1704247, 736 for 1704240, and 781 for 1704155. The previously reported build 1704212/log 727 was no longer readable; no claims are made about its ordering. Before implementation, searched open and recently merged PRs across all bases for the test names, More-navigation mechanisms, `Start-TestDevice`, device-specific runtime selection, and iPhone Duo. Inspected #40656, #40755, and #40766. The open siblings #40799/#40800/#40801/#40802/#40805/#40796 do not implement this native standard-phone runtime/profile selection correction. #### Local causal validation All results below come from **fresh native MTP TRX**, verified by the existing runner for exact class/method isolation. Only owned iOS simulators were used. | Phase | Profile / runtime | Passed | Failed | | --- | --- | --- | --- | | Original | Duo / iOS 27.1, 24A94232 | 0 | 14 | | Fixed | iPhone 11 Pro / iOS 26.0, 23A343 | 14 | 0 | | Fix reverted exactly to main | Duo / iOS 27.1, 24A94232 | 0 | 14 | | Fix restored | iPhone 11 Pro / iOS 26.0, 23A343 | 14 | 0 | The 14 scoped victims cover all six tab-gradient variants, all six failing More-transition variants, ScrollView, and the base NavigationPage back-button variant. They reproduce **without running any potential leaking predecessor**. Local exception messages match the CI cluster, including `collection`, missing native back button, absent shared-element flight, premature push completion, and navigation timeout. Commands, all from an isolated worktree off `origin/main` at `1344d16421`: ```bash export DOTNET_ROOT=/Users/kubaflo/Projects/copilot-worktrees/maui/kubaflo-catalyst-cascade/.dotnet export PATH="$DOTNET_ROOT:$PATH" # This installed preview SDK packages mlaunch under tools/lib, while its default property points at tools/bin. export MlaunchPath="$DOTNET_ROOT/packs/Microsoft.iOS.Sdk.net12.0_27.1/27.1.12089-net12-p1/tools/lib/mlaunch/mlaunch.app/Contents/MacOS/mlaunch" export RelativeMlaunchPath=packs/Microsoft.iOS.Sdk.net12.0_27.1/27.1.12089-net12-p1/tools/lib/mlaunch/mlaunch.app/Contents/MacOS/mlaunch ``` Preparation — **passed**, zero warnings/errors: ```bash dotnet build Microsoft.Maui.BuildTasks.slnf --disable-build-servers -v:q ``` Causal run command — original used `-iOSVersion 27.1`; fixed/reverted/restored used `-iOSVersion latest`, which selects that same Duo runtime with the original selector. Results are listed in the table above: ```bash pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 \ -Project Controls -Platform ios -iOSVersion latest \ -IncludeClasses 'Microsoft.Maui.DeviceTests.TabbedPageTests,Microsoft.Maui.DeviceTests.TabbedPageTests_TabbedViewHandler,Microsoft.Maui.DeviceTests.TabbedPageNavigationHandlerTests,Microsoft.Maui.DeviceTests.NavigationPageTests,Microsoft.Maui.DeviceTests.PageTransitionsTests,Microsoft.Maui.DeviceTests.ScrollViewTests' \ -IncludeMethods 'BarBackgroundTransitionRemovesGradientAndRestoresEffect,NavigatingBackViaBackButtonFiresNavigatedEvent,MoreTabNavigationsCompleteAfterTheTransition,MoreTabUnanimatedPushIsRecordedForThePop,MoreTabSharedElementFliesFromTheOverflowRoot,TestContentHorizontalOptionsChanged' \ -SkipXcodeVersionCheck -Timeout 00:10:00 -DotnetPath "$DOTNET_ROOT/dotnet" \ -OutputDirectory artifacts/ios-cascade/cluster-restored ``` Final expanded verification includes the three remaining NavigationPage handler variants — **17 passed / 0 failed / 0 skipped**, covering every reported victim: ```bash pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 \ -Project Controls -Platform ios -iOSVersion latest \ -IncludeClasses 'Microsoft.Maui.DeviceTests.TabbedPageTests,Microsoft.Maui.DeviceTests.TabbedPageTests_TabbedViewHandler,Microsoft.Maui.DeviceTests.TabbedPageNavigationHandlerTests,Microsoft.Maui.DeviceTests.NavigationPageTests,Microsoft.Maui.DeviceTests.NavigationPageNavigationHandlerTests,Microsoft.Maui.DeviceTests.NavigationPageTests_TabbedViewHandler,Microsoft.Maui.DeviceTests.NavigationPageTests_FlyoutViewHandler,Microsoft.Maui.DeviceTests.PageTransitionsTests,Microsoft.Maui.DeviceTests.ScrollViewTests' \ -IncludeMethods 'BarBackgroundTransitionRemovesGradientAndRestoresEffect,NavigatingBackViaBackButtonFiresNavigatedEvent,MoreTabNavigationsCompleteAfterTheTransition,MoreTabUnanimatedPushIsRecordedForThePop,MoreTabSharedElementFliesFromTheOverflowRoot,TestContentHorizontalOptionsChanged' \ -SkipXcodeVersionCheck -Timeout 00:10:00 -DotnetPath "$DOTNET_ROOT/dotnet" \ -OutputDirectory artifacts/ios-cascade/full-cluster-final ``` Exact-version guard — **passed**: this real invocation rejects the installed Duo-only 27.1 runtime with the expected provisioning error, exit 1, without creating a simulator: ```bash pwsh -NoProfile .github/skills/run-device-tests/scripts/Start-TestDevice.ps1 \ -Platform ios -ApiVersion 27.1 \ -ResultsDirectory artifacts/ios-cascade/exact-runtime-rejection \ -DeviceDirectory artifacts/ios-cascade/exact-runtime-device ``` PowerShell parser validation and `git diff --check` — **passed**. No pipeline unit/snapshot tests were added. The initial local launch attempt did not run tests because of the preview SDK's missing `tools/bin/mlaunch`; only subsequent runs using the explicit valid launch path are counted. Full repository tests and PR CI have not been run as validation evidence. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> The recurrent iOS Controls General cluster in the linked builds; no unrelated issue-closing reference. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- copilot-assessment:v1 --> ### Agent assessment | Assessment | Evidence | | --- | --- | | Change confidence | Medium-high — ↑ Windows-only product change; 1704239 and 1704247 each passed 92 Shell tests in both Windows modes<br>↑ Final head 1704247 passed 29 Window and 3 WindowOverlay tests per mode, including real drawing and adorner attachment<br>↓ Full CI remains red; iOS General and a Windows Entry mismatch are not dismissed | | Diagnosis confidence | Medium-high — ↑ Build 1704155 log and crash.sequence.log identify SearchHandlerFocusTracksDetachment(True, False)<br>↑ Downloaded native-process-4328.dmp contains 0x80070490 stowed stacks, symbolized using exact Microsoft PDB identities: Win2D CanvasControl.OnLoaded → RegisterEventHandlers → CoreApplication.add_Resuming → GetCurrentView; OnUnloaded → UnregisterEventHandlers → remove_Resuming → GetViewFromTid<br>↓ Stowed records establish the failing native mechanism, not the precise timing of every focus/navigation operation | | Evidence fit | ↑ Empty visual diagnostics overlays instantiate Win2D CanvasControl from Loaded despite Visibility.Collapsed; dump has 14 VisualDiagnosticsOverlay/W2DGraphicsView objects<br>↑ Fix prevents this unnecessary native lifecycle path without changing SearchHandler or NavigationPage<br>↑ Builds 1704239 and 1704247: both Windows Shell categories passed with zero failures/skips; final head also passed the related Window/WindowOverlay categories<br>↓ Two runs strengthen but do not prove elimination of an intermittent crash; broader CI has explicit unmatched failures | Head SHA: `63766cca9b0694b3d6039edd43a34729b8d697b7` <!-- /copilot-assessment --> <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change <!-- Enter description of the fix in this section --> Keep an empty Windows window overlay out of the native visual tree until it has something to draw. The public graphics view remains available, and initialized/populated overlays still attach and draw. Once used, the existing hide/show and teardown behavior remains unchanged. This addresses the Windows Controls Shell host crash observed in [main build 1704155](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704155), also reported in 1704212. The log and sequence identify `SearchHandlerFocusTracksDetachment(replaceSearchHandler: True, disconnectHandler: False)`, but the dump's native stowed stacks point to Win2D's application lifecycle callbacks—not the SearchHandler focus callbacks. Collapsed controls still load, and `WindowHandler.MapContent` initializes a hidden diagnostic overlay for every window. `CoreApplication.GetCurrentView` / `GetViewFromTid` can return ELEMENT_NOT_FOUND while the native view is unavailable. The dump was downloaded and inspected on macOS. `dotnet-dump analyze` explicitly rejects Windows dumps on macOS; LLDB opened it but could not unwind useful native frames. Reading the minidump memory directly recovered the native SE02 stowed exception records, then exact matching Microsoft symbol-server PDBs resolved their addresses. The managed COMException objects contain the same HRESULT but no managed stack trace. The raw dump itself is not claimed as sufficient evidence. The existing AdornerLayerAdded test now requests an actual adorner and waits for its layer to load, instead of requiring an empty layer to be attached. Tests preserve every SearchHandler focus/detachment case and assert the diagnostic overlay stays detached. New Windows overlay cases check empty initialization, first-element drawing, prepopulated initialization and hiding after removal. **Duplicate search:** checked open and recently merged PRs across main, net11, release, candidate and inflight branches for the test, ShellItemHandler, CanvasControl, Win2D and overlay mechanisms. #39779 added the focus coverage; #35079 added Windows focus requests. #40659 is broader diagnostics trimming and switch/default work, not this native attachment fix. #40802 owns NavigationPage continuation deferral and is untouched; #40796 is untouched. **Validation:** - `git diff --check`: passed. - `dotnet format Microsoft.Maui.sln --no-restore --include src/Core/src/WindowOverlay/WindowOverlay.Windows.cs src/Controls/tests/DeviceTests/Elements/Window/WindowOverlayTests.cs src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs --exclude Templates/src --exclude-diagnostics CA1822`: completed with missing-reference workspace warnings; native compilation/formatting coverage is not established. - Windows tests cannot be built or run on this macOS host. Native PR CI validation and the baseline comparison are recorded below. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> No linked issue; root-caused from device-test CI logs and crash artifacts for builds 1704155 and 1704212. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> ### CI progression - **1704237:** canceled before execution; not validation. - **1704239**, initial head `16ba04224f3edf252a38b2a9a552906a724827bf`: Windows packaged and unpackaged **Shell passed**; unpackaged WindowOverlay **3 passed**, including populated rendering and prepopulated initialization. Existing AdornerLayerAdded failed because it assumed empty overlays were already attached; corrected in the latest test-only commit. - Both Windows Controls jobs still crash in `NavigationPage.SettingTitleIconImageSourceDoesntCrash` (owned by #40802). Windows Core ReplacingVirtualViewUpdatesLayoutAndReleasesOldPress has the exact same 0x0 bounds failure as baseline 1704155 (owned by #40800). - iOS Controls General had 17 failures in 1704239 (back-button lookup and page-transition timing); baseline 1704155 was green. This is explicitly **not** a clean cross-platform result; revalidation is pending. All other completed iOS jobs passed; Catalyst Controls was still running at collection time. - **1704242:** Windows compilation exposed a missing explicit bool argument on the IVisualDiagnosticsOverlay.AddAdorner interface call in the updated test. Fixed with `AddAdorner(mainPage, false)`; this run is **not** native validation. The wait now requires the native drawing child itself to be loaded before teardown. ### Final native validation and baseline comparison | Build | Head | Packaged Shell | Unpackaged Shell | | --- | --- | --- | --- | | [1704239](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704239) | Initial product fix `16ba04224f` | 92 passed, 0 failed/skipped | 92 passed, 0 failed/skipped | | [1704247](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704247) | Final `63766cca9b` | 92 passed, 0 failed/skipped | 92 passed, 0 failed/skipped | The product fix is identical across these two runs; subsequent commits only corrected the directly related adorner test. The final merge SHA was `4db1d797fdfcb4a16cd3c3ec7b2c10ba04f2208e`, validating PR head `63766cca9b0694b3d6039edd43a34729b8d697b7`. **Final head:** Window category **29 passed per Windows mode**; WindowOverlay **3 passed per mode**, including populated/prepopulated drawing. Unpackaged logs explicitly record all three SearchHandlerFocusTracksDetachment cases. Evidence: 1704247 logs [736 (packaged)](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704247/logs/736) and [752 (unpackaged)](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704247/logs/752). Both also report successful Shell TRX output. **Evidence strength:** two green Shell runs per mode, exact symbolized crash mechanism and focused regression coverage give materially stronger evidence than a single retry. This is not statistical proof of eliminating every possible intermittent crash. **Broader CI is not all-green.** Against baseline 1704155 (all Apple jobs green), final 1704247 has all five Catalyst jobs and seven of eight iOS jobs green. iOS Controls General has **17 failures**, also seen in 1704239, involving tabbed bar backgrounds, ScrollView layout, overflow page transitions and back-button lookup. These have no changed Apple product path in this Windows-only fix, but remain **unmatched, needing separate investigation**, not silently dismissed as known flakes. Final unpackaged Windows also has an unmatched Entry.UnFocusOnEntryAfterPagePop event-count assertion failure; it passed in 1704239 and baseline 1704155. This is explicitly not a claim of full cross-platform CI cleanliness. The known NavigationPage native crash still occurs in both Windows modes and belongs to #40802. Windows Core's ContentButton 0x0-layout assertion matches baseline 1704155 exactly and belongs to #40800. No changes from either sibling fix were duplicated. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…40814) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `192efb9613b0f7bd215e2df2902f672500667966` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 9/10 | ↑ Windows-only fixture change preserves assertions; bounded native-event waits clean up subscriptions. Windows compilation and both packaging modes passed.<br>↓ Remaining full-pipeline checks are still running. | | Diagnosis confidence | 8/10 | ↑ Matching native PDBs resolve the E_NOINTERFACE stowed stack to the deferred overflow callback; two main crash sequences immediately follow the same overflow test, despite different in-flight tests.<br>↓ No controlled Windows revert/reapply experiment; intermittent failures cannot be ruled out by a small sample. | | Evidence fit | 8/10 | ↑ Raw logs verify 92/0/0 Shell results in both Windows Controls jobs in 1704435, plus packaged 1704388; actual first-run TRX confirms all seven targeted cases.<br>↓ Only one build has verified Shell success in both packaging modes; Catalyst Controls and maui-pr remain pending. | <!-- /copilot-assessment --> <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). This fixes the explicitly requested `main` device-test validation; it does not change servicing branches. For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Keep the Shell overflow fixture's native window alive until WinUI's queued rendering callbacks have run. Before cleanup, wait for `CompositionTarget.Rendering`; then hide the current overflow flyout and wait for its actual `Closed` event; finally wait for rendering again before the surrounding fixture destroys the HWND and disposes the window scope. Every wait is bounded and every event is unsubscribed. No product code, assertions, test categories or test cases are removed or changed. This addresses the fixture-lifetime race rather than catching or suppressing the native exception. The change is confined to `ShellTabBarTests.Windows.cs`, which is excluded from non-Windows test builds. #### Root-cause evidence In [main device-test build 1704308](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704308), Windows controls unpackaged log **650** records: - `17:24:25.439Z`: `Tab With Several ShellContents Is Selected Again After Leaving TabBar Overflow Menu` starts. - `17:24:25.904Z`: its native HWND is destroyed; the crash sequence records that test as passed. - `17:24:25.907Z`: `SearchHandlerFocusTracksDetachment(replaceSearchHandler: True, disconnectHandler: False)` starts. - `17:24:26.099Z`: WinUI reports `System.InvalidCastException: No such interface supported`. - The host exits **57005 / 0xDEAD**, with MTP exit **7** and 39 recovered test results. Although MTP's expected category dump was missing, **`native-process-8400.dmp` was produced**, in artifact `DeviceTests-DeviceTests_net120-26c6211d-5128-515a-41ee-d6f162d0ce5a-1`. Its SHA-256 is `a0fc48a5e78c1e04be8a805f4296707a67fa40cfbd713d5c7b9fdda9124dc321`. The category `crash.sequence.log` has no exception stack. The dump's stowed **0x80004002 / E_NOINTERFACE** backtrace, resolved against its matching Microsoft public PDBs, includes: ```text Microsoft.UI.Xaml.Controls!winrt::check_hresult Microsoft.UI.Xaml.Controls!winrt::impl::call_factory<...FlyoutBase...GetAttachedFlyout...> Microsoft.UI.Xaml.Controls!winrt::Microsoft::UI::Xaml::Controls::Primitives::FlyoutBase::GetAttachedFlyout Microsoft.UI.Xaml.Controls!NavigationViewItem::ShowHideChildren::<lambda>::operator() Microsoft.UI.Xaml.Controls!SharedHelpers::QueueCallbackForCompositionRendering::<lambda>::Invoke Microsoft.UI.Xaml!CEventSourceBase::Raise Microsoft.UI.Xaml!DXamlCore::OnRenderingEvent Microsoft.UI.Xaml!CCoreServices::CallPerFrameCallback ``` The native callback is queued by expanding a nested navigation item. The preceding overflow test invokes the item, observes synchronous Shell selection, and returns without waiting for that callback. Its old window is therefore already destroyed when WinUI runs the deferred flyout lookup during the next test. SearchHandler is the in-flight test, not the operation identified by the originating native stack. **Independent corroboration:** [main build 1704369](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704369), at the PR's base `9c4919b856`, crashed in Windows controls packaged log **808** with `Can Reuse Pages` in flight. Its real crash sequence shows the same overflow test passed at `18:09:54.280Z`, then `Can Reuse Pages` started at `18:09:54.295Z`. The crash moves between later tests, but both sequences immediately follow the same overflow fixture. This is distinct from merged #40805's empty-overlay/Win2D `0x80070490` path and merged #40802's NavigationPage completion callback; neither is modified. The fix in #40359 waits for flyout closure **before reopening** it; this adds the missing rendering/closure barriers **before destroying the overflow fixture**. Open and recently merged PRs were searched across main, net11, candidate, inflight and release branches; no equivalent teardown fix was found. #### Validation - `../kubaflo-catalyst-cascade/.dotnet/dotnet format whitespace --folder --include src/Controls/tests/DeviceTests/Elements/Shell/ShellTabBarTests.Windows.cs --verify-no-changes` — **passed**. - `git diff --check` — **passed** before committing. - Windows tests cannot run on this macOS host; the following results were verified in actual PR CI logs, not inferred from check badges. | Build | Windows Controls | Shell passed/failed/skipped | Raw log | |---|---|---|---| | [1704388](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704388) | Packaged | **92 / 0 / 0** | 747 | | [1704435](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704435) | Unpackaged | **92 / 0 / 0** | 747 | | [1704435](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704435) | Packaged | **92 / 0 / 0** | 754 | Both builds used merge revision `e9a4c5e4975a961d0273c3241ab74b54e7279dfa`, containing the assessed head. Each whole Shell category includes all four overflow tests and all three `SearchHandlerFocusTracksDetachment` variants. The actual 1704388 packaged `Controls-Shell.trx` was also checked and confirms those seven tests passed. 1704388's unpackaged job stalled; the requested Azure rerun automatically superseded/deleted that active build. Its packaged evidence was downloaded and verified before supersession. **No unpackaged success is claimed for 1704388.** One build has verified complete Shell success in both Windows jobs, with an additional independent packaged pass. This is encouraging evidence for an intermittent crash, not proof that it can never recur. **Other platforms:** Raw native execution logs in 1704435 report zero failures for all five Android suites, all completed iOS suites/shards (including Shell), and Catalyst Core, Graphics, Essentials and BlazorWebView. The changed file does not compile for those platforms. Catalyst Controls is still running. The first run's Catalyst Controls reported two failures in SwipeView and CollectionView; these are outside this Windows-only change, but an identical baseline failure was not established, so they are not claimed as verified known flakes. **Remaining checks:** `maui-pr` build [1704389](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704389) and 1704435 Catalyst Controls are still running. No full-pipeline green or merge-readiness claim is made. A second completed build with both Windows Shell jobs passing would strengthen the evidence; another rerun must wait until the current build finishes to avoid Azure superseding it. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> No separate issue filed. Investigated from recurring main CI host crashes in builds 1704308 and 1704369, after #40805. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nt UIKit callbacks (#40828) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `34743c3d66cdd5a00ce98ef5166238e6c13c5a48` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 9/10 | ↑ Both complete Catalyst fixtures passed; ten further full-family repetitions passed; PR CI Catalyst controls is green with 2190 passed and 0 failed; no public API change or new production allocation.<br>↓ Other platform results have not been exhaustively reviewed. | | Diagnosis confidence | 7/10 | ↑ Real synchronous UIKit callbacks deterministically demonstrate the older Start call replacing a newer End marker; the repro fails with both pre-#40817 and merged-main product code.<br>↓ The exact CI Position 1090 case was not reproduced naturally locally; other family failures may have additional causes. | | Evidence fit | 9/10 | ↑ Causal red/green/revert/restore from genuine native TRX, ten complete-family repetitions, and raw green Catalyst controls CI logs on macOS 27 for this head.<br>↓ The exact intermittent 1090 symptom was not naturally reproduced locally; local OS differs from CI. | <!-- /copilot-assessment --> <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change <!-- Enter description of the fix in this section --> Fix shared CollectionView scroll-anchor animation ownership, not individual test delays or assertion tolerances. This is a new branch from `6e6416eece627b26e7ac45a92a3c64427c3ded4b`, after #40817 merged; its request-scoped completion fix is retained unchanged. **Root cause:** `CollectionViewScrollAnchor.ScrollToStart` and `ScrollToEnd` assigned `_edgeAnimation` **after** calling UIKit. UIKit can synchronously raise `Scrolled` or an animation end before returning. If `Scrolled` starts a newer End request, the older Start call resumes and overwrites the newer marker with `(Start, 0)`. Turning anchoring off then transfers the wrong completion correction. Diagnostic output on merged main showed `requestedEnd=True marker=(Start, -0) offset=0`, followed by failure to reach the measured end. **Fix:** Arm the edge/target before calling `SetContentOffset`, and do not write it again afterward. A newer reentrant request—or synchronous completion clearing the marker—therefore survives. Publish the current tracker state rather than an unconditional anchored value. **Regression test:** A private native test view detaches immediately before the native `SetContentOffset`, after the anchor has selected its animated branch. UIKit really jumps and reports callbacks synchronously; no delegate completion is fabricated. The app reattaches and requests End from `Scrolled`, then disables anchoring and grows the last row. The test waits for a real window and the grown native cell before checking the measured end. Both navigation variants run it. The helper exists only to make the window/callback interleaving deterministic; production code gains no test hook. #### Baseline comparison The exact reported case is: `An animated ScrollToStart or ScrollToEnd right after one to the other edge that doesn't animate wins(anchorMode: Start | End, edge: End, headerAndFooter: False)`. Raw Catalyst logs show it ran without failure in both navigation variants in all five baseline builds: | Build | Source | Exact case | Other Catalyst failure | |---|---|---|---| | [1704369](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704369) | main `9c4919b856` | Passed | Last item shrinks | | [1704308](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704308) | main `a16185b807` | Passed | None | | [1704250](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704250) | #40806 | Passed | None | | [1704240](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704240) | #40802 | Passed | ScrollToEnd from Scrolled | | [1704475](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704475) | main `cea39ee6e3` | Passed | Turning AnchorMode off timeout | Logs inspected: 835, 849, 769, 783, and 849 respectively. #40806 changes iOS simulator provisioning; #40802's change is Windows-only. Neither changes the Catalyst scroll-anchor implementation. [1704445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704445), #40817 merge `78e680c543`, is the first observed failure of this exact case in the inspected set: log 784, `Position: 1090`. **Attribution boundary:** The exact 1090 failure did not reproduce naturally locally. Repeated full-fixture runs and width probes (320/800/1200/6650) did reproduce a related native reentrant End failure. The controlled window interleaving then proved this shared marker bug on both pre-#40817 and merged-main code. This establishes a pre-existing ownership defect, **not** a proven introduction of the exact CI symptom by #40817. No per-test assertion was weakened. #### Causal local validation macOS 26.7.3, Xcode 27.2, pinned SDK `12.0.100-alpha.1.26523.103` from the existing fallback SDK directory. The installed Xcode is newer than the workload's requested 27.1, so `-SkipXcodeVersionCheck` was used. All execution was in-process Mac Catalyst; no physical devices or host XCTest UI automation. The following exact command was used with the fix and again with only `CollectionViewScrollAnchor.cs` restored to merged main: ```bash pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 \ -Project Controls -Platform maccatalyst \ -DotnetPath /Users/kubaflo/Projects/copilot-worktrees/maui/kubaflo-catalyst-cascade/.dotnet/dotnet \ -SkipXcodeVersionCheck -Rebuild \ -IncludeClasses Microsoft.Maui.DeviceTests.CollectionViewTests,Microsoft.Maui.DeviceTests.CollectionViewNavigationHandlerTests \ -IncludeMethods TurningAnchorModeOffAfterAReentrantAnimatedScrollToEndKeepsTheEndRequest,AnAnimatedScrollToAnEdgeRightAfterAJumpToTheOtherEdgeWins,ScrollToEndFromScrolledWhileADetachedScrollToStartFinishesReachesTheEnd \ -OutputDirectory artifacts/scroll-anchor/prearmed-fixed -Timeout 00:15:00 ``` - **Baseline red:** Before the fix, the native interleaving failed in both navigation variants. With pre-#40817 versions of `ItemsViewController2.cs` and `GroupableItemsViewController2.cs` from `cea39ee6e3`, the same repro also failed twice, at offset 1080 and distance 340. Both files were restored to merged main afterward. - **Fix green:** 36 passed, 0 failed, including every parameter set of the reported theory and #40817's regression. - **Fix reverted red:** Same command with output directory `artifacts/scroll-anchor/prearmed-reverted`: 34 passed, 2 failed. Only the new regression variants failed, with end distances 210 and 340. - **Restored green:** Both complete fixtures passed after restoring the fix: ```bash pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 \ -Project Controls -Platform maccatalyst \ -DotnetPath /Users/kubaflo/Projects/copilot-worktrees/maui/kubaflo-catalyst-cascade/.dotnet/dotnet \ -SkipXcodeVersionCheck -Rebuild \ -IncludeClasses Microsoft.Maui.DeviceTests.CollectionViewTests,Microsoft.Maui.DeviceTests.CollectionViewNavigationHandlerTests \ -OutputDirectory artifacts/scroll-anchor/prearmed-restored-full -Timeout 00:15:00 ``` **422 passed, 0 failed, 8 existing skips (430 total)**, verified from genuine `testResults.trx`. Additional checks: - `dotnet build Microsoft.Maui.BuildTasks.slnf --nologo -v:q`: passed, 0 warnings/errors. - `dotnet format whitespace Microsoft.Maui.sln --no-restore --exclude Templates/src --include src/Controls/src/Core/Handlers/Items2/iOS/CollectionViewScrollAnchor.cs src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.ScrollAnchor.cs`: passed; workspace-loading warnings. - `git diff --check`: passed. <!-- scroll-anchor-validation:v1 --> **Ten further complete-family repetitions passed on committed revision `34743c3d66cdd5a00ce98ef5166238e6c13c5a48`: 211 passed, 0 failed, 4 existing skips per run; aggregate 2110 passed, 0 failed, 40 skips.** Each run includes the entire scroll-anchor family in `CollectionViewNavigationHandlerTests`, not just the newly added test. All ten fresh TRX files were checked. ```bash for i in $(seq 1 10); do pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 \ -Project Controls -Platform maccatalyst \ -DotnetPath /Users/kubaflo/Projects/copilot-worktrees/maui/kubaflo-catalyst-cascade/.dotnet/dotnet \ -SkipXcodeVersionCheck \ -IncludeClasses Microsoft.Maui.DeviceTests.CollectionViewNavigationHandlerTests \ -OutputDirectory artifacts/scroll-anchor/validated-family-$i -Timeout 00:15:00 done ``` **PR CI Catalyst controls is green:** [build 1704506](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704506), job `Catalyst controls CoreCLR macos27`, completed/succeeded. Raw test-task log **778** reports **2190 passed, 0 failed, 42 skipped (2232 total)**. Both new regression variants appear in that log. The required real-TRX validation step also succeeded. CI tested merge `1f4954e3e5896dfc92b2e2c3380d123ea98a4d4b`, whose parents are main `3507ea53b79eee7d2452c2ba4609b05a98e6b0f4` and this PR head `34743c3d66cdd5a00ce98ef5166238e6c13c5a48`. The newer main changes do not touch the scroll-anchor implementation. **Post-#40817 main comparison:** [1704496](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704496) at `6e6416eece` completed Catalyst tests with **2186 passed, 1 failed, 42 skipped** (raw task log **813**). The entire scroll-anchor family, including the exact 1090 variant, passed. Its only failure was the unrelated PageTransitions test `A root replacement started from the assignment's PropertyChanging animates once its own page lands (UIKit)` (“The queued replacement swapped the root without animating”). That main Catalyst job is therefore **not** called green; no unrelated product code was changed here. <!-- /scroll-anchor-validation --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> No standalone GitHub issue was supplied. Investigates the Catalyst scroll-anchor failures linked above; fixes the reproduced pre-existing marker-ownership race. Related to #40211 and merged #40817. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `8d0bdeb7520eafe7b06555f9279943030ca075e8` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 9.5/10 | ↑ Exact patch-ID match to merged #40802; the original Windows crash test passed in both upstream and net11 packaging modes.<br>↑ 318 net11 portable navigation tests pass on the pushed head, including the inherited non-Windows ordering regression.<br>↓ Full Windows job acceptance still requires the separate runner/validator fix in #41151. | | Diagnosis confidence | 9/10 | ↑ WinUI completes the active navigation task inside `Loaded`, where an inline continuation can update the toolbar icon and close the window before the callback unwinds. Deferring the continuation completes the original crash test in both Windows packaging modes on net11.<br>↓ The native faulting module is unknown. | | Evidence fit | 10/10 | ↑ The net11 and upstream baselines stop in the same test with host exit 57005 and MTP exit 7. Both genuine [net11 backport TRX files](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1706822) now record the exact test as passed. | <!-- /copilot-assessment --> <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change <!-- Enter description of the fix in this section --> Backport #40802 unchanged. In [net11 native CI 1706389, unpackaged runner 1161](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1706389/logs/1161?api-version=7.1) and [PR CI 1706688](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1706688) (runners 1119 and 1139), the Windows Controls host exits 57005 during `SettingTitleIconImageSourceDoesntCrash`, leaving an incomplete TRX. The same signature was captured on the [upstream baseline, runner 760](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704198/logs/760?api-version=7.1). This is separate from the skipped-only WebView validator fix in #41151 and from Appium gallery setup failures. On Windows only, queue the active `NavigationPage` request continuations so a caller cannot run inline in WinUI's `Loaded` callback. The all-pending completion source and non-Windows ordering are unchanged. The backport includes the upstream unit test for non-Windows ordering; it makes no changes to the native crash test, skips, or waits. **Validation** - `./.dotnet/dotnet test --project src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --configuration Release -p:_SkipUpdateBuildNumber=true -p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false --filter-method '*Navigation*' --report-trx --results-directory <dir> --verbosity quiet` — passed, 317 on the base and 318 with this backport before and after the push, including `NonWindowsNavigationCompletionPreservesNativeCallbackOrdering`. This does not execute WinUI. - `./.dotnet/dotnet format whitespace --folder --include src/Controls/src/Core/NavigationPage/NavigationPage.cs src/Controls/tests/Core.UnitTests/NavigationPageLifecycleTests.cs --verify-no-changes --verbosity quiet` and `git diff --check HEAD^ HEAD` — passed. The stable patch ID matches upstream commit `2f147b35e577472c19ace62f1cd1a31515a1497a`. - [Upstream build 1704240](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704240): the [packaged](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704240/logs/745?api-version=7.1) and [unpackaged](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704240/logs/739?api-version=7.1) NavigationPage categories each recorded 16 passed, 3 existing skips, 0 failures. Both genuine TRX files explicitly mark the original test Passed, and the changed files match the tested tree. - [Net11 backport build 1706822](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1706822), merge `c1eca400384377c499c285f7f5627cc69d671e0d`: the packaged and unpackaged NavigationPage artifacts (`52948982` and `52948992`) each record 16 passed, 3 existing skips, and `SettingTitleIconImageSourceDoesntCrash` **Passed**. Each Controls runner recorded 1,077 passed, 33 skipped, and zero failed tests across 55 categories (raw [1115](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1706822/logs/1115?api-version=7.1) and [1121](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1706822/logs/1121?api-version=7.1)). The overall jobs are still red: the old runner leaks the final no-match exit code and the old validators reject the all-skipped WebView TRX (1117/1125). Both are handled by #41151, which was not in this run. No combined Windows job pass is claimed. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Backport of #40802 for the Windows `SettingTitleIconImageSourceDoesntCrash` test-host crash. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…pletion callbacks (backport #40802) (#41239) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `bd031d6cce350ea841aada110490a62d8d4492d6` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 8/10 | ↑ Clean cherry-pick of merged main #40802 (2f147b3), identical to merged net11 port #41156.<br>↑ Local macOS: NavigationPageLifecycleTests 11/11 passed on this head.<br>↓ Windows-only code path not run locally; sr3 Windows devicetests pending on this PR. | | Diagnosis confidence | 8/10 | ↑ sr3 314 build 1707806 unpackaged NavigationPage host exited 57005 during SettingTitleIconImageSourceDoesntCrash, the exact signature fixed by #40802.<br>↓ Original native faulting module still unknown. | | Evidence fit | 8.5/10 | ↑ net11 build 1706822 with #41156: the same test Passed in both packaged and unpackaged NavigationPage TRX (16P/3S each).<br>↓ sr3 recurrence measured once (1707806); packaged leg did not crash in that run. | <!-- /copilot-assessment --> <!-- 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 of Change Backport of #40802 (cherry-pick of 2f147b3) to `candidate/11.0.1xx-sr3`. The same patch is already merged to net11 as #41156. On Windows, WinUI completes NavigationPage navigation inside `Loaded`, where inline callers can immediately close the window. That crashes the test host. The fix resumes NavigationPage outside the native completion callback on Windows only. Other platforms keep their existing callback ordering, which a unit test now covers. **SR3 failure:** In maui-pr-devicetests build [1707806](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1707806), the "Windows controls unpackaged" NavigationPage category crashed with host exit code 57005 while `SettingTitleIconImageSourceDoesntCrash` was running (log 1068). ### Issues Fixed Unblocks sr3 maui-pr-devicetests Windows NavigationPage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
e9964a9acf9cfa240b69eba1155898bc524dcc6b↑ 350 navigation unit tests pass, including the non-Windows ordering regression test.
↑ Build 1704240 validates iOS General and Windows NavigationPage in both packaging modes at this exact head.
↓ The first scoped-head run still had iOS failures; an unchanged-head retry passed, so native environment variability remains relevant.
↑ The Windows-only change retains success of the original crash test in both packaging modes.
↑ Non-Windows callback ordering is restored and unit-tested.
↓ The original Windows native faulting module is unknown; the 17 iOS failures cannot all be causally attributed to deferral, since they also occurred once with this scoped head.
↑ Both Windows NavigationPage categories: 16 passed/0 failed/3 existing skips, and the original test explicitly Passed (242 ms packaged, 240 ms unpackaged).
↓ Build 1704232's first scoped-head iOS result was red; the green validation is the unchanged-head retry 1704240, not that earlier run.
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!
Target Branch
mainnet11, for reviewmain, explicitly requested for the .NET 12 Windows CI failure.For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into
net11; agents must not retarget or merge.Description of Change
On Windows only, create the active
NavigationPagerequest completion source withRunContinuationsAsynchronously. Other platforms retain the original completion source and native callback ordering.On Windows,
StackNavigationManager.OnNavigatedcompletes the request from WinUI'sLoadedcallback. Previously,SetResultcould synchronously run the entire navigation continuation and its caller while that native callback was still on the stack. InSettingTitleIconImageSourceDoesntCrash, this includes updating the toolbar image and immediately closing/destroying the window throughCreateHandlerAndAddToWindow. Queueing continuations lets the native completion callback unwind first.The updated portable unit test uses a manually completed handler and verifies that non-Windows
NavigatedToretains its original synchronous native callback ordering. It fails against this PR's earlier unscoped deferral and passes with the Windows-only correction. The existing Windows device test is unchanged: no skip, delay, image substitution, or reduced coverage.Baseline: build 1704198, Windows Controls packaged log 760, 11:38:15–11:38:38 UTC. The recovered TRX contains one passed test; the sequence starts
SettingTitleIconImageSourceDoesntCrashwithout an end event. The process exits 57005 (0xDEAD), MTP exits 7. The artifact contains no.dmp, andwindows-application-events.jsonis empty. No faulting module or native exception is known. The supplied additional baseline builds are 1704155, 1703964 and 1704185.Duplicate search covered open and recently merged PRs across main, net11, release, candidate and inflight branches for this test, title icons, PageControl, StackNavigationManager, teardown, and navigation continuations. This is not #40795's initial-navigation event guard (already on main), nor #39911's stale image-result guard (also already on main).
Validation (latest revision, configured SDK
12.0.100-alpha.1.26523.103, macOS):Assert.True, actualFalse(1 test), proving the unscoped PR changes non-Windows ordering.--filter-method '*Navigation*': passed, 350/350.dotnet format whitespace --folder --include src/Controls/src/Core/NavigationPage/NavigationPage.cs src/Controls/tests/Core.UnitTests/NavigationPageLifecycleTests.cs --verbosity quiet: passed.git diff --check: passed.Native CI history and regression correction
Build 1704212 tested the previous head
c4da77aa65cbec06d93b41a8c4b0b6ae69f219e6(merge6da2433c9f8cde06366718a44c461b11bc97caf7):SettingTitleIconImageSourceDoesntCrashPassed (148 ms packaged, 189 ms unpackaged). Packaged log 760; unpackaged log 739.Latest-head native validation: build 1704240
Build 1704240 validates head
e9964a9acf9cfa240b69eba1155898bc524dcc6bthrough merge4edb3a18f4e96fe3be0f866b887b506e1a42a221.The genuine iOS
native/testResults.trxconfirms all 17 previously failing cases individually Passed. Both Windowscategories/NavigationPage/Controls-NavigationPage.trxfiles explicitly recordSettingTitleIconImageSourceDoesntCrashPassed (242 ms packaged, 240 ms unpackaged). No native device tests were changed or newly skipped.First-run caveat: build 1704232 tested the same scoped head and still had the same 17 iOS failures (log 736), despite compiling IOS rather than WINDOWS and retaining main's non-Windows code. Compared with green main 1704155, its simulator log records a different iOS 27.2 runtime build (
SimulatorRuntime-v24.2.91016.19versusv24.2.8117.0), and provisioning ends withData Migration Failed. These differences support native environment variability, not a proven root cause of every failure. The subsequent 1704240 run was an unchanged-head retry, not another product fix.The packaged Windows job in 1704240 still fails in the separate Shell category (exit 7); NavigationPage passes. The known Shell/BlazorWebView failures are not fixed or hidden here. This is validation of the requested iOS General and Windows NavigationPage coverage, not a full-CI-green claim.
Issues Fixed
Addresses the Windows Controls
SettingTitleIconImageSourceDoesntCrashCI host crash described above; no separate issue was supplied. Related investigation: #40795, not a replacement or duplicate of its net11 fix.Let AI finish this PR