Skip to content

Classify pool-reset ClearValue calls per property, not per owner - #1099

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 5 commits into
mainfrom
alzollin-microsoft-pool-reset-attached-property-classificat
Aug 18, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 5 commits into
mainfrom
alzollin-microsoft-pool-reset-attached-property-classificat

Conversation

@azchohfi

Copy link
Copy Markdown
Collaborator

Fixes #1067.

The defect

PoolResetSetConsistencyTests partitioned the ClearValue calls in ElementPool.CleanElement's FE-common block into instance vs. attached buckets by owner name:

.Where(m => !InstancePropertyOwners.Contains(m.Groups[1].Value))

Owner-level membership cannot express a mixed owner. Grid is in InstancePropertyOwners because Grid.Padding / Grid.CornerRadius are ordinary instance DPs — but Grid.Row, Grid.Column, Grid.RowSpan, Grid.ColumnSpan are genuinely attached. So every Grid.* reset was routed to the instance bucket and never reached Every_Reset_Attached_Property_Is_Classified. No failure, no triage moment.

This is not hypothetical: PanelAttachedHooks.ApplyGridAttached already clears all four attached Grid DPs for pooled reuse, just outside the scanned region. Moving or duplicating one of those lines into CleanElement is exactly the plausible change that would have landed silently.

Product code (ElementPool, ModifierTable, the analyzer) was correct; the defect was in the test's classifier.

The fix

One regex, one predicate, two complementary halves. Both ReadResetProperties and ReadResetAttachedProperties now scan with the same ClearValuePattern and split on a single IsAttachedReset(owner, property), so instance ∪ attached = every recognized clear by construction. InstanceClearValuePattern (the owner alternation) is gone — two views of one owner list is precisely the arrangement that cannot express a mixed owner.

The predicate asks the same question the analyzer asks. A clear is attached when its owner is outside the probe table or the owner type declares the static Owner.SetPROP(DependencyObject, value) setter — literally the call shape PoolResetSetAnalyzer matches inside a .Set(...) lambda. Grid.SetRow exists → Grid.Row is attached. There is no Grid.SetPadding → Grid.Padding stays instance. A future mixed owner needs no edit here.

Reflection is metadata-only — no WinUI object is constructed — following the pattern already proven in ModifierTableIntegrityTests. Owner types are hand-listed as typeof(...) literals to stay IL2057/IL2072-clean (Release build: 0 warnings).

The bias is deliberate and fail-safe. Calling an instance property attached fails loudly and someone triages it; calling an attached property instance is silent — the whole bug. So anything unresolvable resolves to attached: an owner absent from the probe table is attached by default.

The instrument has a positive control. A dead probe (wrong BindingFlags, a projection change) would silently revert to today's owner-keyed behaviour with everything green — a no-match is not a measurement. A 12-row theory pins both directions on the same owner (Grid.Row/Column/RowSpan/ColumnSpan → attached; Grid.Padding, Control.IsEnabled, FrameworkElement.Margin → instance), asserting the owner is in the probe table first so no row can pass vacuously through the unknown-owner short-circuit. A second test asserts each map key equals its OwnerType.Name, so ["Grid"] = … typeof(StackPanel) … cannot pass.

Validation

Mutations inserted into the Grid arm of CleanElement, run with --no-build (this class reads ElementPool.cs as data at runtime):

arm mutation verdict
ARM0 none (baseline) ✅ green — 67 passed (was 54)
ARM1 resetGrid.ClearValue(WinUI.Grid.RowProperty); 🔴 red on Every_Reset_Attached_Property_Is_Classified — was green before this PR
ARM2 resetGrid.ClearValue(WinUI.Canvas.LeftProperty); 🔴 red — unchanged control, path still live for a non-listed owner
ARM3 resetGrid.ClearValue(WinUI.Grid.BorderThicknessProperty); ✅ green — a new instance clear on a mixed owner does not false-positive
ARM4 probe body forced to return false 🔴 red on exactly the 5 attached-expecting probe rows — the instrument is not vacuous

ARM1's failure message names the mixed-owner situation explicitly, so the next person reads why Grid is in the probe table and that it is not a reason to reclassify.

  • Full Reactor.Tests: 13289 passed, 0 failed (Release, x64).
  • src/Reactor.Analyzers Release: 0 warnings, 0 errors.
  • Solution build reached 0 Warning(s); 4 NU1301 restore errors on untouched VS-extension / Reactor.Compile.Analyzer.Tests projects are an offline-environment artifact — reproduced on a stashed (clean) tree as a positive control, so they are not from this change. CI has network.

Scope

Test-only behavioural change plus a comment update to ModifierTable.DeliberatelyExcludedAttached (which argued only the exclusion-list hazard, not the owner-list hazard it introduced). No product behaviour, no new diagnostic id, no AnalyzerReleases.Unshipped.md row, no mur check mirror, no docs or API regeneration.

Rejected alternative: the issue's option 2, a test-only KnownAttachedOnGridLikeOwners deny-list. Smaller, but hand-maintained, silent when the next mixed owner appears, and it leaves both scans owner-keyed — the same shape that produced this bug.

Known probe limitation (documented in the helper's remarks rather than papered over): an attached DP with no static setter — the AutomationProperties.DescribedBy collection shape — would still read as instance. No such property exists on the eight listed owners, and it is exactly the shape the Owner.SetPROP(x, v) rule cannot match anyway.

Adjacent, out of scope: #1066 and #1048 are the same family and touch the same two files; expect textual conflicts if they land first.

PoolResetSetConsistencyTests split the ClearValue calls in
ElementPool.CleanElement's FE-common block into instance vs. attached
buckets by owner name. Owner-level membership cannot express a *mixed*
owner: Grid owns instance DPs (Padding, CornerRadius) and genuine
attached DPs (Row, Column, RowSpan, ColumnSpan) at the same time. Since
"Grid" was in InstancePropertyOwners, every Grid.* reset was routed to
the instance bucket, so a genuinely attached Grid.* reset never reached
Every_Reset_Attached_Property_Is_Classified -- no failure, no triage
moment. PanelAttachedHooks.ApplyGridAttached already clears all four
attached Grid DPs for pooled reuse just outside the scanned region, so
this is a plausible edit, not a hypothetical one.

Both scans now share one ClearValue regex and split on one predicate,
so instance union attached is every recognized clear by construction.
The predicate asks the same question PoolResetSetAnalyzer asks: does
the owner declare the static Owner.SetPROP(DependencyObject, value)
setter? Grid.SetRow exists, so Grid.Row is attached; there is no
Grid.SetPadding, so Grid.Padding stays instance. A future mixed owner
needs no edit. Reflection is metadata-only (no WinUI object is
constructed), following ModifierTableIntegrityTests, with owner types
hand-listed as typeof literals to stay IL2057/IL2072-clean.

Unresolvable cases resolve to *attached* on purpose: that direction
fails loudly, while the toward-instance direction is silent -- the bug.

A dead probe would silently restore the old owner-keyed behaviour with
everything green, so a 12-row theory pins both directions on the same
owner, and a second test asserts each map key equals its OwnerType.Name
so a copy-paste typo cannot pass.

Validated by mutating the Grid arm of CleanElement:

  ARM0  baseline                          green (67 passed, was 54)
  ARM1  ClearValue(Grid.RowProperty)      RED  <- was green before
  ARM2  ClearValue(Canvas.LeftProperty)   red  (unchanged control)
  ARM3  ClearValue(Grid.BorderThickness)  green (no false positive)
  ARM4  probe forced to return false      red on the probe theory

Full Reactor.Tests: 13289 passed, 0 failed.

Test-only behaviour change plus a comment update to
ModifierTable.DeliberatelyExcludedAttached; no product behaviour, no
new diagnostic id, no docs or API regeneration.

Fixes #1067

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

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build metrics

Artifact sizes for 571dca3 vs the base branch (d8853b1).

Packages (compressed .nupkg)

Artifact base PR Δ
Microsoft.UI.Reactor.nupkg 1.61 MB 1.61 MB +14 B (0.00%) ≈
Microsoft.UI.Reactor.Advanced.nupkg 487.4 KB 487.5 KB +9 B (0.00%) ≈
Microsoft.UI.Reactor.Devtools.nupkg 278.2 KB 278.2 KB +6 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 +0 B (0.00%) ≈
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 18, 2026 •

Copy link
Copy Markdown
Contributor

🧪 Merged coverage

Coverage for 571dca3 vs the base branch (d8853b1) — unit + selftest merged.

Metric base PR Δ
Line 85.85% 85.85% 0.00 pp ≈
Branch 77.44% (903/1166) 77.36% (902/1166) -0.08 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.

z and others added 2 commits August 17, 2026 21:16
The probe filtered inside a foreach with two `continue` guards, which
code-quality flagged as implicit filtering. The question it answers is
existential, not iterative, so `.Any(...)` states it directly and the
setter name is computed once instead of per candidate method.

Behaviour is identical, and ARM4 re-run against the new form still
reddens exactly the five attached-expecting probe rows, so the control
still proves the probe is live.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
ModifierTableIntegrityTests already reflects over public static two-arg
methods on a WinUI owner, so a reader meeting DeclaresAttachedSetter
reasonably asks why there are now two probes.

They answer different questions. HasStaticTwoArgMethod omits
FlattenHierarchy and checks neither the void return nor that the first
parameter is a DependencyObject -- sufficient for the pure
attached-property holders it runs against (AutomationProperties,
ToolTipService, TitleBar, FlexPanel), where no instance member can
collide. This probe discriminates on mixed owners such as Grid, where a
loose match is precisely the silent misclassification #1067 is about, so
the extra constraints carry the weight.

Reusing the looser helper would reintroduce the bug by another route;
unifying them would tighten a predicate for callers that do not need it.
Comment only -- no behaviour change.

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

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 fixes a blind spot in PoolResetSetConsistencyTests by classifying ElementPool.CleanElement ClearValue(Owner.PropProperty) resets as instance vs. attached per property, not per owner (so mixed owners like Grid are handled correctly). It also updates the related explanation comment in ModifierTable.DeliberatelyExcludedAttached.

Changes:

  • Replace owner-keyed reset partitioning with a single ClearValuePattern plus IsAttachedReset(owner, property) predicate to correctly handle mixed owners (e.g., Grid).
  • Add positive-control tests to ensure the attached-setter probe is live and keyed correctly.
  • Update ModifierTable documentation to reflect the new per-property classification approach.

Reviewed changes

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

File Description
tests/Reactor.Tests/AnalyzerTests/PoolResetSetConsistencyTests.cs Reworks reset scanning to split instance vs. attached by per-property probe; adds probe validation tests and improves failure messaging for mixed owners.
src/Reactor.Analyzers/ModifierTable.cs Updates commentary around DeliberatelyExcludedAttached to align with the revised classification model and hazards.

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

Comment thread src/Reactor.Analyzers/ModifierTable.cs Resolved
Two review points on the probe and its comment.

The probe re-materialized the owner's full public static method list on
every call -- once per ClearValue match per scan, times every test that
rescans, plus each theory row. Hoist it: AttachedSetterProbe now takes
the reflection pass once per owner when the map initializes, keeps the
qualifying setter names in an ordinal set, and returns a closure that is
a set lookup. Classifying a match now costs no reflection.

This is a refactor of the predicate the whole classification rests on,
so it gets the mutation control rather than an assumption that behaviour
was preserved: forcing the lookup name unmatchable still reddens exactly
the five attached-expecting rows of the probe theory (Grid.Row/Column/
RowSpan/ColumnSpan and Control.IsTemplateFocusTarget), and the restored
form is back to 67/67 with the full suite at 13289/0.

Separately, the DeliberatelyExcludedAttached remarks said 'The scan now
classifies per property', which in a file that *is* the analyzer's table
reads as though the analyzer does it. Name the test.

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

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

Suppressed comments (1)

tests/Reactor.Tests/AnalyzerTests/PoolResetSetConsistencyTests.cs:633

  • InstancePropertyOwnerProbes repeats the owner type expression twice per entry (OwnerType and AttachedSetterProbe(typeof(...))). That creates a real foot-gun: a future edit can accidentally mismatch the probe type from the OwnerType (e.g., OwnerType=Grid but probe built from StackPanel), and the existing Every_Instance_Owner_Key_Names_Its_Own_Type test would not catch it because it only validates the key→OwnerType pairing. Consider factoring entry construction so the probe is always derived from the exact OwnerType used in the tuple.
                ["FrameworkElement"] = (
                    typeof(Microsoft.UI.Xaml.FrameworkElement),
                    AttachedSetterProbe(typeof(Microsoft.UI.Xaml.FrameworkElement))),
                ["UIElement"] = (
                    typeof(Microsoft.UI.Xaml.UIElement),

Each map entry named its owner twice -- once for OwnerType, once inside
AttachedSetterProbe(typeof(...)) -- and nothing tied the two together.
Every_Instance_Owner_Key_Names_Its_Own_Type pins the key to OwnerType
and never looks at what the probe actually reads, so a drifted pair
would classify against the wrong type.

That is #1067 restored by a different route: a probe built from a type
without the owner's static setters answers 'instance' for every attached
property on it.

Measured rather than assumed. Building the UIElement entry's probe from
TextBlock leaves all 67 tests green, so the hole is real. It is only
partly covered elsewhere -- Grid and Control have attached-expecting
rows in the probe theory (ARM4 showed those exact five redden when the
probe cannot match), but the remaining six owners carry none, so for
them the mistake is silent.

ProbeFor(Type) takes the type once and returns both halves, which makes
the mismatch inexpressible rather than merely tested for. Full suite
13289/0.

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

Copy link
Copy Markdown
Collaborator Author

Picking up the suppressed comment from the last Copilot pass (no inline thread to reply on) — it was right, and it found a hole the visible comments didn't.

InstancePropertyOwnerProbes repeats the owner type expression twice per entry […] Every_Instance_Owner_Key_Names_Its_Own_Type would not catch it because it only validates the key→OwnerType pairing.

Confirmed by measurement rather than taken on the description. Building the UIElement entry's probe from TextBlock while leaving OwnerType = typeof(UIElement):

Passed!  - Failed: 0, Passed: 67

So the drift really is silent. It is partly covered elsewhere, which is worth stating precisely: Grid and Control do carry attached-expecting rows in the probe theory, and the earlier ARM4 control showed those exact five rows redden whenever the probe cannot find the owner's setters — so a mismatch on those two owners fails. The other six carry no attached-expecting row, and for them nothing fires. A pair like (typeof(Grid), AttachedSetterProbe(typeof(StackPanel))) answers "instance" for every attached Grid property, i.e. #1067 restored by another route.

Fixed in 571dca3 by removing the second mention rather than testing for its absence:

private static (Type OwnerType, Func<string, bool> DeclaresAttachedSetter) ProbeFor(
    [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type)
    => (type, AttachedSetterProbe(type));
["Grid"] = ProbeFor(typeof(Microsoft.UI.Xaml.Controls.Grid)),

The type is named once and both halves derive from it, so the mismatch is inexpressible instead of merely tested for. I deliberately did not also derive the key from type.Name: that would make Every_Instance_Owner_Key_Names_Its_Own_Type a tautology, and the key is a distinct fact — it is the spelling ElementPool.cs uses, which that test exists to pin.

Full suite 13289/0.

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

@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit 2b4385f into main Aug 18, 2026
22 checks passed
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) deleted the alzollin-microsoft-pool-reset-attached-property-classificat branch August 18, 2026 06:30
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

2 participants