Repository navigation
fix(a11y): marshal UseAnnounce.Announce to the UI thread (#130) - #614
Merged
Alexandre Zollinger Chohfi (azchohfi) merged 2 commits intoJun 22, 2026
Merged
Alexandre Zollinger Chohfi (azchohfi) merged 2 commits into
Alexandre Zollinger Chohfi (azchohfi) merged 2 commits into
Conversation
AnnounceHandle.Announce called WinUI XAML APIs (FrameworkElementAutomationPeer.FromElement, RaiseNotificationEvent, TextBlock.Text) that throw RPC_E_WRONG_THREAD (0x8001010E) when invoked off the UI thread. Announcing from a Task.Run continuation silently ate the caller's Task. Capture the DispatcherQueue in SetTextBlock (runs on the UI thread during reconciler mount) and, in Announce, marshal via TryEnqueue when called cross-thread. The UI-thread fast path is a single HasThreadAccess bool check. Existing announce body extracted into AnnounceCore. Adds a selftest fixture that announces from a background thread and asserts no crash. Closes #130 Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
requested a review
from Chris Anderson (codemonkeychris)
as a code owner
June 19, 2026 18:36
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a cross-thread footgun in UseAnnounce by marshalling AnnounceHandle.Announce(...) onto the UI thread (via a captured DispatcherQueue) to avoid WinUI RPC_E_WRONG_THREAD failures, and adds a selftest to validate the behavior.
Changes:
- Capture the UI
DispatcherQueueduring live-region mount and marshal announcement work when called off-thread. - Extract the announce body into
AnnounceCore(...)and add a UI-thread fast path (HasThreadAccesscheck). - Add/register a new selftest fixture that calls
Announce(...)from aTask.Runcontinuation to assert it no longer throws synchronously.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Reactor/Hooks/UseAnnounce.cs |
Captures DispatcherQueue and marshals Announce() back to the UI thread; refactors announce logic into AnnounceCore. |
tests/Reactor.AppTests.Host/SelfTest/Fixtures/CoverageBoostFixtures.cs |
Adds a cross-thread selftest fixture exercising UseAnnounce from a background thread. |
tests/Reactor.AppTests.Host/SelfTest/SelfTestFixtureRegistry.cs |
Registers the new CovBoost_UseAnnounceCrossThread fixture in discovery + factory switch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Apply PR #614 review findings: - M1: gate Announce readiness on the captured DispatcherQueue (not _textBlock) and mark both fields volatile, so an off-thread caller can never observe a wired text block with a stale/null dispatcher and run AnnounceCore off-thread. - M2: cross-thread selftest now proves delivery on the UI thread via a FIFO sentinel enqueued after the off-thread Announce. - M3: UseAnnounce fast-path fixture renders announce.Region so AnnounceCore's UI-thread path is exercised. - M4: regenerate docs/guide/focus-and-input-internals.md from the updated announce-live-region snippet. - L1: document the Announce threading contract in XML docs. - L2: add CHANGELOG ### Fixed entry for #130. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
deleted the
azchohfi-marshal-useannounce-ui-thread
branch
June 22, 2026 17:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AnnounceHandle.Announce(message, assertive)calls WinUI XAML APIs —FrameworkElementAutomationPeer.FromElement,RaiseNotificationEvent, andTextBlock.Text— all of which throwRPC_E_WRONG_THREAD(0x8001010E) when invoked off the UI thread.This is a footgun for the obvious calling pattern: announcing when a long-running operation finishes from a
Task.Runcontinuation. The failure mode is an unobserved Task exception, which surfaces to the user as "the feature does nothing" with no actionable diagnostic.Fix
DispatcherQueueinSetTextBlock, which runs on the UI thread during reconciler mount — no chicken-and-egg.Announce, marshal the work viaDispatcherQueue.TryEnqueuewhen called off-thread; the UI-thread fast path is a singleHasThreadAccessbool check.AnnounceCore(message, assertive).This mirrors how
Observable<T>handles cross-thread subscribers.Tests
CovBoost_UseAnnounceCrossThreadthat mounts a component, callsAnnouncefrom aTask.Runcontinuation, and asserts no exception is thrown (before the fix this threw synchronously on the background thread).dotnet build Reactor.slnxsucceeds.dotnet test tests/Reactor.Tests— 9431 passed, 0 failed.CovBoost_UseAnnounce*all pass.Closes #130