Skip to content

Complete the #1090 selection-write guard; drop the unreproducible hardening - #1097

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 2 commits into
mainfrom
azchohfi-1090-review-followup
Aug 18, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 2 commits into
mainfrom
azchohfi-1090-review-followup

Conversation

@azchohfi

@azchohfi Alexandre Zollinger Chohfi (azchohfi) commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #1091 (merged), addressing findings from a multi-dimensional review of that branch.

Correction (see commit 6fee3d0a). An earlier version of this description claimed a new selftest crashed on the descriptor path, proving it was a live defect. That was wrong. The crash came from a stale binary left by a mutation experiment, and I attributed it to the descriptor change that happened to land next. Section 1 below is corrected. The TemplatedListLifecycle finding is unaffected and remains proven.

1. The fix was incomplete — the typed path was unguarded (high)

#1091 guarded only ListViewHandler and GridViewHandler. The identical suppress-then-write shape lives in the typed/templated list path, which #1091 never touched:

Path Sites Status
TemplatedListLifecycle 6 (Mount/Update x ListView/GridView/FlipView) Proven live defect
TemplatedListViewDescriptor / TemplatedGridViewDescriptor 2 Defensive only — see below

The lifecycle defect is real and pinned. Removing just those 6 guards reddens Issue1090_TypedListView_ControlledIndexUnreachableAfterShrink with ArgumentException: Value does not fall within the expected range — so on the typed path an unreachable index doesn't merely swallow an event, it throws.

The descriptor ports are defensive, not a fix. They are "retained for isolated selftests" (TemplatedListHandler.cs:24) and are not registered on the production path — the TemplatedListHandler decorator replaced the per-kind descriptor registrations. A probe injected into shouldWrite confirms it is never invoked for ListView<T>. The guard stays because the write shape is identical and would be a live defect if those ports were re-registered, but no fixture reaches it. Reviewers who prefer to drop those two lines have a fair case.

2. Removed the BeginSuppressCancelable / EchoSuppressArm hardening

Written for a hypothesis that measurement disproved (an ItemsSource swap preserving a still-valid selection), and it carried a real defect:

CancelIfUnconsumed is watermark-guarded, not identity-guarded. With two overlapping arms on one control, a delayed retraction cancels the wrong token — unsuppressing a genuine engine echo.

Its own XML doc claimed the opposite. The arm-then-observe blocks revert to the plain drift-gated BeginSuppress main used before, and the 12 headless tests modelling the hypothetical branch are deleted.

3. Centralized the rule

IsReachable was duplicated per handler. It is now SelectionWriteGuard.CanLand, used by all write sites, so the typed and untyped families cannot drift.

4. Corrected an unsupported claim in shipped docs

The threading guide asserted that ItemsSource reassignment "preserves the selection silently on some WinUI versions". No in-repo source establishes that — the only support was #1091's own test comments (circular), and every runtime measured (WASDK 2.1 and 2.3.1) resets and fires. Replaced with the rule that is established.

5. Closed the coverage gaps

#1091's mutation check removed both guards at once, so it could not distinguish Mount from Update. Each guard group is now pinned independently:

Mutation Fixture that reddens
ListView Mount guard Issue1090_ListView_IndexPastEndOfShortSource
ListView Update guard Issue1090_ListView_ControlledIndexUnreachableAfterShrink
GridView guards Issue1090_GVEmptyMount + GridView_IndexPastEndOfShortSource
TemplatedListLifecycle guards Issue1090_TypedListView_ControlledIndexUnreachableAfterShrink

New fixtures also cover multi-select empty mount through the OnSelectionChanged snapshot callback, and the GridView past-end case.

Verification

  • 1443 selftest fixtures pass (up from 1440)
  • 13276 unit tests pass
  • Release builds of src/Reactor and the selftest host clean
  • Docs recompiled via mur docs compile --topic threading-and-dispatch

Unrelated flake spotted, not fixed here

WindowLevel_RuntimeFlip_Topmost failed in 2 of ~5 full-suite runs, including one where nothing of mine was in play. It is order-dependent and unrelated to this diff (nothing here touches windowing), so I left it alone rather than widen scope — worth its own issue.

…dening

Follow-up to #1091 (merged), addressing findings from a multi-dimensional
review of that branch. Every finding below was independently confirmed by a
second model.

1. The fix was incomplete: three more unguarded paths (HIGH)

   #1091 guarded only ListViewHandler and GridViewHandler. The same
   suppress-then-write shape exists in the templated (typed) list path, which
   #1091 never touched:

     - TemplatedListLifecycle: 6 sites (Mount/Update x ListView/GridView/FlipView)
     - TemplatedListViewDescriptor  (spec-047 Phase 3 descriptor variant)
     - TemplatedGridViewDescriptor

   The descriptor pair is worse than a swallowed event: with an unreachable
   index the WinUI setter throws ArgumentException. A new typed selftest
   crashed on it, which is how the path was found.

2. Removed the BeginSuppressCancelable / EchoSuppressArm hardening

   That primitive was written for a hypothesis that measurement disproved (an
   ItemsSource swap preserving a still-valid selection). It also carried a real
   defect: CancelIfUnconsumed is watermark-guarded, not identity-guarded, so
   with two overlapping arms on one control a delayed retraction cancels the
   wrong token -- unsuppressing a genuine engine echo. Its own XML doc claimed
   the opposite. Keeping buggy speculative code for an unobservable branch is
   not a good trade, so the arm-then-observe blocks revert to the plain
   drift-gated BeginSuppress that main used before, and the 12 headless tests
   that modelled the hypothetical branch are deleted.

3. Centralized the rule

   IsReachable was duplicated per handler. It is now
   SelectionWriteGuard.CanLand, used by all 10 write sites, so the typed and
   untyped families cannot drift.

4. Corrected an unsupported claim in shipped docs

   The threading guide asserted that ItemsSource reassignment "preserves the
   selection silently on some WinUI versions". No in-repo source establishes
   that -- the only support was this PR's own test comments, which is circular,
   and every runtime measured (WASDK 2.1 and 2.3.1) resets and fires. Replaced
   with the rule that is actually established: gate on reachability as well as
   drift, and skip the write entirely when it cannot land.

5. Closed the coverage gaps

   #1090's mutation check removed both guards at once, so it could not tell
   Mount from Update. Each guard is now pinned independently:

     ListView Mount guard removed   -> Issue1090_ListView_IndexPastEndOfShortSource
     ListView Update guard removed  -> Issue1090_ListView_ControlledIndexUnreachableAfterShrink
     GridView guards removed        -> Issue1090_GVEmptyMount + GridView_IndexPastEndOfShortSource
     Templated guards removed       -> Issue1090_TypedListView_ControlledIndexUnreachableAfterShrink

   New fixtures also cover multi-select empty mount via the OnSelectionChanged
   snapshot callback, and the GridView past-end case.

Verified: 1443 selftest fixtures pass (up from 1440); 13276 unit tests pass;
Release builds of src/Reactor and the selftest host are clean; docs recompiled
via `mur docs compile --topic threading-and-dispatch`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 32bf22fb-ba60-47d3-a0c6-8f5c0079f10e
@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build metrics

Artifact sizes for 6fee3d0 vs the base branch (24c8414).

Packages (compressed .nupkg)

Artifact base PR Δ
Microsoft.UI.Reactor.nupkg 1.61 MB 1.61 MB -471 B (-0.03%) ≈
Microsoft.UI.Reactor.Advanced.nupkg 487.4 KB 487.4 KB -11 B (0.00%) ≈
Microsoft.UI.Reactor.Devtools.nupkg 278.1 KB 278.1 KB -4 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor

Artifact base PR Δ
Reactor.Analyzers.dll 356.0 KB 356.0 KB +0 B (0.00%) ≈
Reactor.dll 2.39 MB 2.39 MB -512 B (-0.02%) ≈
Reactor.Localization.Generator.dll 16.0 KB 16.0 KB +0 B (0.00%) ≈
Reactor.Wrappers.Abstractions.dll 10.5 KB 10.5 KB +0 B (0.00%) ≈
Reactor.Wrappers.Generator.dll 99.5 KB 99.5 KB +0 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor.Advanced

Artifact base PR Δ
Reactor.Advanced.dll 1021.5 KB 1021.5 KB +0 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor.Devtools

Artifact base PR Δ
Microsoft.UI.Reactor.Devtools.dll 777.5 KB 777.5 KB +0 B (0.00%) ≈

No size change beyond the noise floor. ✅

✅ smaller / ⚠️ larger / ≈ within noise. Sizes come from a Release dotnet pack on the CI runner: packages are the compressed .nupkg download size, assemblies the uncompressed DLL inside it.
workflow run.

@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

🧪 Merged coverage

Coverage for 6fee3d0 vs the base branch (24c8414) — unit + selftest merged.

Metric base PR Δ
Line 85.88% 85.85% -0.03 pp ≈
Branch 77.44% (903/1166) 77.44% (903/1166) 0.00 pp ≈

No coverage change beyond the noise floor. ✅

✅ higher / ⚠️ lower / ≈ within noise. Δ is in percentage points; coverage is unit + selftest merged (Debug x64) on the CI runner. Cobertura reports attached to the workflow run as artifacts.

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

This PR completes the Issue #1090 “selection-write reachability” guard across the remaining typed/templated list paths, removes the previously added retractable echo-suppression arm (and its unit tests), and updates the threading guide text to reflect the reachability-based rule rather than a version-dependent ItemsSource-swap claim.

Changes:

  • Introduces SelectionWriteGuard.CanLand() and applies it to all suppressed SelectedIndex write sites across untyped handlers and typed/templated lifecycle + descriptors.
  • Removes BeginSuppressCancelable / EchoSuppressArm from ChangeEchoSuppressor and deletes the associated headless tests.
  • Adds multiple new selftest fixtures to cover the newly-guarded write sites and updates the doc/template wording to match the new guidance.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Reactor.Tests/EchoSuppressArmTests.cs Deletes tests for the removed retractable suppression-arm primitive.
tests/Reactor.AppTests.Host/SelfTest/SelfTestFixtureRegistry.cs Registers new Issue1090 selftest fixtures.
tests/Reactor.AppTests.Host/SelfTest/Fixtures/Issue1090SelectionStrandFixtures.cs Adds new fixtures covering GridView past-end, update-side shrink, multi-select callback path, and typed list shrink scenarios; updates probe commentary.
src/Reactor/Core/V1Protocol/TemplatedListLifecycle.cs Adds reachability gating (SelectionWriteGuard.CanLand) to templated Mount/Update selection writes.
src/Reactor/Core/V1Protocol/SelectionWriteGuard.cs Adds centralized reachability rule helper for selection writes.
src/Reactor/Core/V1Protocol/Handlers/ListViewHandler.cs Switches to centralized reachability guard and drops retractable-suppression arm/observe logic for ItemsSource swaps.
src/Reactor/Core/V1Protocol/Handlers/GridViewHandler.cs Same as ListViewHandler: centralized reachability guard + removal of retractable-suppression logic.
src/Reactor/Core/V1Protocol/Descriptor/Descriptors/TemplatedListViewDescriptor.cs Adds reachability gating to descriptor-based templated ListView/GridView selection writes.
src/Reactor/Core/ChangeEchoSuppressor.cs Removes the retractable suppression-arm primitive.
docs/guide/threading-and-dispatch.md Updates shipped guide text to describe reachability gating rather than version-dependent ItemsSource swap behavior.
docs/_pipeline/templates/threading-and-dispatch.md.dt Updates the source template for the same guide section to match the new guidance.
Suppressed comments (1)

src/Reactor/Core/V1Protocol/Descriptor/Descriptors/TemplatedListViewDescriptor.cs:104

  • Same as the ListView descriptor: shouldWrite calls el.GetSelectedIndex() multiple times. Store it in a local once and reuse for the reachability + sign checks.
        .OneWayConditional(
            get:         static el => el.GetSelectedIndex(),
            set:         static (ctrl, v) => { if (v >= 0) ctrl.SelectedIndex = v; },
            shouldWrite: static el => el.GetSelectedIndex() >= 0
                                      && SelectionWriteGuard.CanLand(el.GetSelectedIndex(), el.ItemCount));

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…rationale

Review comment: `shouldWrite` called `el.GetSelectedIndex()` twice, which is
redundant and could disagree with itself if that ever normalizes. Capture it
once in a block-bodied lambda. Both descriptor sites.

Also corrects the comment on those two sites, which overstated what I had
established. TemplatedListViewDescriptor / TemplatedGridViewDescriptor are
"retained for isolated selftests" (TemplatedListHandler.cs) and are NOT
registered on the production path -- the TemplatedListHandler decorator
replaced the per-kind descriptor registrations. A probe injected into
shouldWrite confirms it is never invoked for ListView<T>.

I had claimed a new selftest crashed on this path. That was wrong: the crash
came from a stale binary left by an earlier mutation experiment that had
removed the TemplatedListLifecycle guards, and I attributed it to the
descriptor change that happened to land next. The guard stays for consistency
across the family -- the write shape is identical and would be a live defect
if those ports were ever re-registered -- but it is defensive, not a fix for
anything a fixture reaches.

The TemplatedListLifecycle finding is unaffected and remains proven: removing
just those 6 guards still reddens
Issue1090_TypedListView_ControlledIndexUnreachableAfterShrink with the
ArgumentException, re-verified after this change.

Selftests 1443/1443.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 32bf22fb-ba60-47d3-a0c6-8f5c0079f10e

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 11 out of 11 changed files in this pull request and generated no new comments.

@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit d8853b1 into main Aug 18, 2026
22 checks passed
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) deleted the azchohfi-1090-review-followup branch August 18, 2026 02:51
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Sep 1, 2026
Audits every PR merged since v0.1.0-preview.13 (56 commits) for changelog
coverage, then cuts the release section per docs/contributing/release-runbook.md.

Only 9 of those PRs updated CHANGELOG.md. Nine user-facing changes were missing
an entry and are added here:

  Added   - declarative window icon: icon: on ReactorApp.Run plus
            Run(WindowSpec, ...) overloads (#1145, issue #1143)
  Changed - dotnet new reactorapp resolves the latest Windows App SDK (#1096)
  Fixed   - connected animations never played across a replaced subtree (#1124)
          - a controlled SelectedIndex WinUI cannot honor stranded an echo
            token and ate the next real selection (issue #1090, #1091, #1097)
          - legacy text-node TreeView rendered empty under NativeAOT (#1108)
          - devtools DP lookups found nothing, since CsWinRT projects
            DependencyProperty statics as properties (issue #1109)
          - the exe-icon fallback was dead code, and WindowIcon.FromResource
            silently applied a default icon in packaged apps (issue #1143)
          - an installed mur was frozen at first bootstrap, and mur check
            shipped without Roslyn (#1130)
          - mur loc/docs help printed the non-existent "duct" command (#1129)
          - a scaffolded project would not launch in Visual Studio 26 (#1084)

The three behaviour fixes were checked against v0.1.0-preview.13 rather than
assumed: the AOT skip for ControlUpdate_Collections, the
_pendingConnectedAnimationStarts list, and the drift-only SelectedIndex gates
all exist at the tag, so each shipped broken and none qualifies for the
introduced-and-fixed-in-window exemption.

Deliberately omitted: dependency bumps, docs-only and CI/test-infra work, and
#1099/#1102, whose product code was already correct (the defect was in a test
classifier and a text matcher respectively).

Bumps ReactorPublicVersion to 0.1.0-preview.14 and recompiles the guide, which
substitutes {{reactorVersion}} across 8 pages, satisfying the docs freshness gate.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants