Repository navigation
Description
Problem
PoolResetSetConsistencyTests already enforces the pool ⇄ analyzer relationship in both directions — but only at property granularity:
- cleared in
CleanElement⇒ markedpoolReset: true—Every_Reset_Property_With_Matching_Modifier_Is_Tracked(:117)- marked
poolReset: true⇒ cleared somewhere in the FE-common block —Every_TrappedProperty_Is_Reset_In_CleanElement(:86),Every_TrappedAttachedProperty_Is_Reset_In_CleanElement(:185)
Important
The gap is granularity, not direction. Do not implement this as "add the missing reverse direction" — that test already exists, a new one will pass immediately, and the hole stays open.
At (property × gated receiver) granularity the invariant is one-directional:
exists : "Padding is cleared SOMEWHERE in the FE-common block" -> passes, via the Control|Border|Panel chain
missing : "Padding is cleared for EVERY receiver its gate admits" -> RelativePanel is gated in, never cleared
This is also why the file's other guards cannot catch it: Every_ClearValue_In_CleanElement_Is_Recognized_By_The_Reset_Scan and Attached_Reset_Scan_Sees_Every_Owner_The_Table_Names protect the scan, and a scan that reads the block perfectly still cannot notice a receiver that was never written to.
That asymmetry makes a whole defect class structurally invisible: widen a modifier's gate (or its ApplyModifiers write) to a new receiver type without adding the matching ClearValue. Nothing fails. The analyzer starts telling users the value "is reset on pool return" for a receiver the pool never resets, and the day that receiver is added to PoolableTypes it silently leaks its previous renter's local value — which outranks every Style setter in WinUI's DP precedence order.
This is not hypothetical. It has now appeared three times:
- [Bug] Unsetting a common modifier writes the DP default as a local value instead of ClearValue, permanently overriding Style-provided values #952 — reset present but the wrong shape (assigning a default instead of
ClearValue). - [Bug] ElementPool.CleanElement never releases Panel.Background, or any Control-level Padding/CornerRadius/BorderThickness/BorderBrush/Background/IsEnabled #985 — six modifiers written by
ApplyModifierswith no reset at all onControl/Border/Panel/StackPanel. - Widen panel Padding and CornerRadius modifier gates #1003 + [Bug] ElementPool.CleanElement never releases Panel.Background, or any Control-level Padding/CornerRadius/BorderThickness/BorderBrush/Background/IsEnabled #985 merged (found by trial-merging the two branches, detail on the PR) —
RelativePanelgains write and unset arms inReconciler.csand is added to thePadding/CornerRadiusgates, butElementPool's clear covers onlyGridandStackPanel. The mergedElementPool.cshas zeroRelativePanelmatches. Latent today only becauseRelativePanelisn't inPoolableTypes.
The #985 case additionally shows the cost of the blind spot. During PR #984's development a Control/StackPanel clear block was removed in 14c8aaf4 — this was not a revert of #984, which merged intact. It was a scope narrowing, and that commit's own message says the work was "filed as a follow-up instead"; #985 is that follow-up. The stated reason for removing it was that the block "forced six modifiers from REACTOR_MOD_002 to REACTOR_POOL_001 and invalidated 27 analyzer expectations" — i.e. the existing invariants fired loudly on the marking, which is the expensive half, while the receiver-coverage gap that marking was supposed to describe stayed unmeasured. A receiver-granular invariant would have named that gap directly.
Proposed solution
Add a test alongside the existing ones in tests/Reactor.Tests/AnalyzerTests/PoolResetSetConsistencyTests.cs:
Every_PoolReset_Modifier_Is_Cleared_On_Every_Gated_Receiver
For each ModifierTable entry with poolReset: true, expand its controlGate type list to the concrete receiver types (Control, Border, Panel, Grid, StackPanel, RelativePanel, TextBlock, …) and assert the CleanElement FE-common region contains a ClearValue reaching each one — directly, or via a base type that provably covers it (a Control clear covers every Control subclass; a Panel clear covers Grid/StackPanel/RelativePanel).
Two details worth getting right, because they are what makes it non-vacuous:
- Subsumption must be explicit, not assumed.
if (fe is Control c)genuinely covers allControlsubclasses, butif (fe is StackPanel s)does not coverGrid. The test needs a small "does clear on type X satisfy gate entry Y" relation rather than a name match, or it will either miss real gaps or demand redundant clears. - It must fail if the clear moves out of the scanned region.
ReadCleanElementCommonBlockalready delimits at the firstswitch (<param>); reusing it means the Fix #952: unsetting a common modifier must ClearValue, not write the DP default #984 placement mistake reddens this test too, which is the outcome we want.
Failure message should name the modifier, the gate entry that has no clear, and the file/line of the gate — so the fix is mechanical.
Alternatives considered
- Analyzer-side check instead of a test. Wrong layer:
ModifierTableis the analyzer's own data, and it can't seeElementPool.csat analysis time. - Extend
ModifierUnsetClearValueTests' pin list instead. That file pins an explicit receiver/property list (14 pins today, added in [Bug] ElementPool.CleanElement never releases Panel.Background, or any Control-level Padding/CornerRadius/BorderThickness/BorderBrush/Background/IsEnabled #985). Pins catch deletion of a known clear; they don't catch addition of a new gated receiver, which is precisely this bug. Complementary, not a substitute. - Rely on selftest fixtures. They prove a specific pooled control releases a specific property, which is valuable, but coverage is per-fixture and per-type — the gap only shows up if someone thinks to write the fixture for the new receiver, which is the same omission being guarded against.
- Do nothing, treat it as review discipline. Three occurrences say otherwise, and the merged-tree case was invisible to both PRs' CI: disjoint file sets, clean auto-merge, both green independently.
Additional context
- Source scanning helpers already exist and are line-anchored:
ReadCleanElementCommonBlock,ReadResetProperties,ReadResetAttachedProperties,InstancePropertyOwnersinPoolResetSetConsistencyTests.cs. Note the trap documented there — an unanchored regex let a comment containingswitch (fe)truncate the scanned block and produce 32 misleading failures; both scanners are nowRegexOptions.Multiline-anchored. - Related: [Bug] Unsetting a common modifier writes the DP default as a local value instead of ClearValue, permanently overriding Style-provided values #952 (reset shape), [Bug] ElementPool.CleanElement never releases Panel.Background, or any Control-level Padding/CornerRadius/BorderThickness/BorderBrush/Background/IsEnabled #985 (missing resets), [Bug] ElementPool.CleanElement never releases Control.HorizontalContentAlignment / VerticalContentAlignment #1013 (
HorizontalContentAlignment/VerticalContentAlignmentstill unreset — deliberately deferred, and would be reported by this new invariant once they're marked). - The gate type-group arrays live at the top of
ModifierTable.cs(ControlBorderGridStackRelativeText,ControlBorder,PanelControlBorder, …), which gives the test a single source of truth to enumerate from.
Confirmation
- I have searched existing issues and specs for prior discussion of this idea.
Activity
azchohfi commentedon Jul 31, 2026
Measured evidence for this, from a trial merge of #1015 with #1003 (which widens the
Padding/CornerRadiusgates toGridandRelativePanel).Setup. In the merged tree,
ApplyModifiersgenuinely writesPadding/CornerRadiustoGrid. I deleted theClearValuecalls that release them — they live insidecase WinUI.Panel panel:, i.e. below the type dispatch thatReadCleanElementCommonBlockstops scanning at.PoolResetSetConsistencyTestsaloneThe third row is the control condition: same tree, same build, same filter. Without it, "everything passed" is indistinguishable from a broken harness. It reddens, so the instrument was live for the first two rows too. The only variable is placement relative to the dispatch.
Scope, stated honestly: the selftest tier does catch this case — #1003 ships
Issue950Panel_Pool_NewPropertiesCleared, which goesnot okwhen those clears are removed. So this is a gap in the headless tier, not total blindness. That still matters, because the headless tier is where the pool ⇄ analyzer relationship is supposed to be enforced structurally rather than per-fixture.And the per-fixture coverage is exactly as fragile as you'd expect. The same selftest ends with:
RelativePanelisn't inPoolableTypes, sorecycledRelativeis a freshly constructed object (the adjacent check asserts!ReferenceEquals). Those two properties are unset by construction. Proof rather than argument:ElementPool.cscontains zero occurrences ofRelativePanel— no clear exists anywhere — and the check still reportsok. It passes against no implementation at all.So
RelativePanelreads as covered while having no pool clear, and the day someone adds it toPoolableTypesthe fixture stays green and the leak goes live. A reverse invariant would report it immediately and by name, without anyone having to think to write the fixture.Related, and better than what I proposed above: #1003 adds
ModifierTableIntegrityTests.Every_ControlGate_Matches_The_Types_ApplyModifiers_Writes_To, which enforces the forward direction (gate matches whatApplyModifierswrites) and produces an actionable message:It caught a real mistake in my merge resolution within seconds. The invariant proposed here is the missing third leg of the same triangle —
ApplyModifiers↔ModifierTableis now covered;ModifierTable↔ElementPoolis not. Implementing it next toModifierTableIntegrityTestsrather than inPoolResetSetConsistencyTestsmay be the better home.azchohfi commentedon Jul 31, 2026
Correction to the proposal above — as written it would demand dead code, and would have failed a PR for doing the right thing.
Surfaced while answering #1003 about whether to add a
RelativePanelclear. The answer is no, and the reason invalidates part of the scope I specified.ElementPool.Returnbails beforeCleanElementis ever reached:So
CleanElementonly ever runs on types inPoolableTypes. Two consequences for the proposed invariant:A clear for a gated-but-unpooled receiver can never execute.
RelativePanelis in thePadding/CornerRadiusgates (after Widen panel Padding and CornerRadius modifier gates #1003) but is not poolable, so aRelativePanel.ClearValueinCleanElementwould be unreachable code. The invariant as I wrote it — cleared on every receiver itscontrolGateadmits — would require exactly that, and would flag a correct implementation as a violation.Membership is exact-type, not assignability.
PoolableTypes.Contains(element.GetType())means a subclass ofGridorStackPanelis not pooled either.Corrected scope: the invariant should assert
Everything else in the proposal stands, including the measured evidence in the previous comment — the
GridandStackPanelcases that motivated this are both inPoolableTypes, so they remain in scope and remain uncovered by the headless tier.Two further notes for whoever implements it:
typeof(WinUI.RelativePanel)toPoolableTypeswould immediately bring it into scope and fail until a clear exists. That is precisely the day-two scenario this issue exists to catch, and the corrected form catches it without demanding dead code beforehand.PoolableTypesdirectly rather than hard-coding a receiver list, so the two can't drift.azchohfi commentedon Aug 1, 2026
Ownership settled: PR #1003 will implement this in its post-#1015 union.
#1003 asked whether #1015/#1017 infrastructure should own the dynamic invariant or
whether they should add it. Answer: theirs, and the reason is that the test
cannot fail on #1015's tree.
At #1015's head the border-box gates admit
Control/Border/StackPanel/TextBlock. Every member of that set ∩PoolableTypesis already cleared by theFE-common block in
CleanElementand pinned inCleanElementRequiredClears. Solanding the invariant in #1015 adds an assertion that goes green regardless — it
only starts doing work once the gates widen to
Grid/RelativePanel, which is#1003's change. #1003 also merges last and therefore sees the final state.
Three implementation notes measured while answering
1.
PoolableTypesisprivate, notinternal—src/Reactor/Core/ElementPool.cs:45.InternalsVisibleTo("Reactor.Tests")does notreach it; a runtime read needs
GetField("PoolableTypes", BindingFlags.NonPublic | BindingFlags.Static).This is where the invariant's vacuity lives. If the field is renamed,
GetFieldreturns
null→ empty set → zero poolable gate types → nothing to assert → green.Silent, and in the reassuring direction — the same shape as a
-1sentinel satisfyinga
>comparison. The reflection lookup must throw on null-or-empty rather thanskip. That guard is more load-bearing than the assertion it protects.
Reading it at runtime is headless-safe: the initializer is all
typeof(...)with noWinUI construction, so it does not trip the COMException rule in
AGENTS.md.2. Intersect by assignability, not by gate name. The gate names
Control, butPoolableTypesholds exact runtime types includingButton(:62),TextBox(:63)and
ToggleSwitch(:64). Those are concrete receivers of aControlgate, and noname-based intersection finds them.
CleanElement's FE-common arm isfe is WinUI.Control c, so it does clear them — which is why the redundant per-armIsEnabledclears could be removed in #1015. A name-based intersection would excludeevery poolable
Controlsubtype and shrink the invariant to almost nothing whilestill reading as correct.
3.
RelativePanelis absent fromPoolableTypes(:47–64), so its arm is satisfiedby the non-poolable branch today and flips to requiring a clear the moment anyone adds
it. That is exactly the forward-gate behaviour this issue asks for, and it is the
reason the set must be read at runtime rather than hardcoded.
The mutation that proves it works — and the one that won't
Deleting a clear reddens the static pins (three from #1003, fourteen from #1015), so a
plain delete says nothing about whether the dynamic invariant contributes anything. The
specificity check is to delete the clear and its static pin together — then only the
dynamic invariant should catch it. Green there means the test is decorative.
Same measurement shape that produced the
1 of 26result on #1003's below-dispatchclears: sensitivity is cheap, specificity is the part worth reporting.
If it is written as a source scanner rather than a runtime test, it must use the
anchored region boundary (
switchStart = Regex.Match(..., @"^\s*switch\s*\(..."))introduced in #1015, not the unanchored
IndexOfstill onmain— the lattertruncates the scanned block on any comment containing the dispatch text.
azchohfi commentedon Aug 1, 2026
Correction to my previous comment: ownership moves to #1015, and the reason I gave for
assigning it to #1003 no longer selects #1003.
My comment above says "PR #1003 will implement this in its post-#1015 union." The
coordinator has since fixed the merge order as #1003 first, #1015 second, so #1003
never has a post-#1015 union — it merges into a tree that does not yet contain #1015.
#1015 is the second lander and owns the union, so #1015 owns this.
The reasoning in that comment was sound for the tree it described and stops applying under
the new order. I argued the invariant cannot fail on #1015's tree because #1015's gates
admit only
Control/Border/StackPanel/TextBlock, all of which are alreadycleared. True of #1015 standalone. Under the new order, #1015's tree becomes the
widened tree, so the property that disqualified it is gone.
Measured: the union tree already satisfies the invariant
Before deferring this I computed the full cross-product by hand, because "defer" is only
safe if there is no present-tense gap.
PoolableTypes(src/Reactor/Core/ElementPool.cs:47-64) is 15 exact types: TextBlock,RichTextBlock, StackPanel, Grid, Border, ScrollViewer, Canvas, Viewbox, ProgressBar,
ProgressRing, Image, InfoBadge, Button, TextBox, ToggleSwitch.
Padding— post-union gateControl | Border | Grid | StackPanel | RelativePanel | TextBlock:ControlresetControl.ClearValue(Control.PaddingProperty)BorderresetBorderarmGridresetGridclearStackPanelresetStackclearTextBlockresetTextarmCornerRadius— gateControl | Border | Grid | StackPanel | RelativePanel— resolvesidentically, with StackPanel satisfied by the folded
StackPanel.CornerRadiusclear andTextBlock correctly not admitted.
Every poolable receiver admitted by either widened gate has an above-dispatch clear, and
RelativePanelfalls to the non-poolable branch exactly as designed. So this invariant isfuture-proofing, not a hole-plug — there is no gap open while it is pending, and nothing
degrades by it landing separately.
Why a separate PR rather than inside the union
The union already carries seven items across five files, two of which are silent semantic
reconciliations that merge with no conflict marker. This invariant is a reflection-based
test whose failure mode is fail-open — if
GetFieldreturnsnullthe set is empty andit passes having asserted nothing. That is the shape that most needs proportionate review,
and bundling it behind conflict-resolution review is how a fail-open invariant ships green.
It also needs destructive mutation proof of its own, and running those on a tree that just
changed for unrelated reasons destroys attribution of any failure.
Still valid from the previous comment
The three implementation notes stand unchanged and are not retracted:
PoolableTypesisprivateso reflection must throw on null-or-empty rather than skip; intersection mustbe by
gateType.IsAssignableFrom(poolableExactType)and never by gate name; and a sourcescanner must use the anchored region boundary from #1015, not
main's unanchoredIndexOf.The specificity mutation is refined to move a still-functional clear below the dispatch and
remove its static pin — runtime behaviour stays green, so only an anchored source-scanning
placement check can redden. A plain delete is caught by the static pins and by runtime, and
therefore proves sensitivity without proving this test contributes anything.
One thing to check during implementation rather than assume
RichTextBlockis poolable, is not aTextBlock(it derives fromFrameworkElement),and carries its own
PaddingDP. It is correctly outside the gate today, soApplyModifiersnever writes it — but it is precisely the shape this invariant exists to notice, and it
deserves a deliberate look rather than an assumption.
Canvasis the mirror case: poolable,a
Panel, and has noPaddingat all, so a future widening from the enumeratedGrid/StackPanel/RelativePanelto a barePanelgate should redden.azchohfi commentedon Aug 1, 2026
Verified on current
main(1ed2644e), and this issue is now UNOWNEDThe latent defect described in the body is live on merged
maintoday. Measured, with controls:The arming change is one line. Adding
typeof(WinUI.RelativePanel)toPoolableTypesis aninnocuous-looking enablement that would silently make
Padding/CornerRadiusleak across rent/return forthat type — with no failing test, because the invariant that would catch it is the one this issue exists to
add.
Ownership
Nothing is currently implementing this. Measured:
#1003 — which was expected to pick this up "post-#1015" — merged at 2026-08-01T05:37:12Z (
state=closed merged=true, merge commit1ed2644e). Its branch now readsahead_by=0, so there is no PR left to carrythe work.
This needs a new owner. The spec in the body is intact and is the good one — per (modifier × concrete
poolable receiver admitted by its gate), assignability-resolved, reflection on private
PoolableTypesthrowing on missing/empty (else a rename yields an empty set and every quantifier passes vacuously),
plus a specificity mutation that removes the clear and its static pin so only the new invariant reddens.
And the warning already in the body still applies and is the important part:
No merge is being requested or performed.
azchohfi commentedon Aug 1, 2026
Follow-up from #1015's final audit — two things that materially change how this test should be written, both found after filing.
1. There is a third condition, and the proposal above is missing it
The proposal quantifies over (modifier × gated receiver). That is one condition short. A gated receiver needs a
CleanElementarm only if the property is written by a path that does not self-heal on pool reuse — and Reactor has three write paths with three different obligations:CleanElementarm?OneWay(get, set, dp:)ApplyModifiers).Set(x => ...)escape hatchThe self-healing one is
OneWayClearValuePropEntry.Mount,src/Reactor/Core/V1Protocol/Descriptor/PropEntry.cs:128-141:A rented control carrying the previous renter's local value hits that
else ifand is cleared at mount, so no pool arm is required.A concrete case that looks exactly like the bug and is not one:
RichTextBlockis inPoolableTypes(ElementPool.cs:48), itsPaddingis written (Element.cs:2751-2759, descriptorOneWaywithdp: WinUI.RichTextBlock.PaddingProperty), andCleanElementhas noRichTextBlockarm. That is the #985 shape in every visible respect, and it is correct as-is.It is not reachable through today's gates —
Padding's gate is{Control, Border, Grid, StackPanel, RelativePanel, TextBlock}and does not admitRichTextBlock— so a gate-quantified test is safe today. It stops being safe the moment a descriptor-bound receiver is added to a gate, and the resulting failure would demand a redundantClearValuewhile reading as a genuine leak. Worth encoding the exclusion with its reason rather than discovering it under time pressure.Note this also sharpens the
RelativePanelcase already described above.RelativePanelneeds no arm for a different reason — not inPoolableTypes— and the two reasons are independent. Whichever policy is chosen (clear defensively, or exclude with a reason), the test should distinguish "not poolable" from "self-healing write path", because they fail differently when the world changes: addingRelativePaneltoPoolableTypescreates a real leak, whereas a descriptor-bound property never does.2. The expected set, so the new test has a known-answer case
An implementer has no way today to tell a correct new test from a plausible one. Here is the required set derived from source, independent of any test — (modifier write-chain receivers) ∩ (reachable from
PoolableTypes):PaddingReconciler.cs:3752-3757CornerRadius:3867-3871BorderThickness:3912-3913BorderBrush:3885-3886,:3393-3394Background:3924-3926IsEnabled:3859-3862CleanElementafter #985 contains exactly 17ClearValuecalls — Control 6, Border 5, Panel 1, Grid 2, StackPanel 2, TextBlock 1 — and the two sets agree by membership, per receiver:Compare by membership, not by count.
17 == 17with different members is exactly the failure this issue exists to prevent, and a new test that reports the right total while pairing the wrong receivers would look verified.Chain ordering does not affect this:
Panel,Control,BorderandTextBlockare mutually disjoint WinUI types, so the write chain (Panel-first,:3924) and the clear chain (Control-first,ElementPool.cs:294) partition the same space. Every arm is reachable by at least one concrete poolable type — theControlarm viaButton/TextBox/ScrollViewer/ProgressBar/ProgressRing/ToggleSwitch/InfoBadge, thePanelarm viaCanvasin addition toGrid/StackPanel.Two caveats on that table, stated so it is not over-read:
.Set()writes are unbounded by construction and are [Bug] Pooled Grid never releases BorderThickness/BorderBrush — ElementPool.CleanElement has no border-box clear for concrete panels #1039's subject, not this one.azchohfi commentedon Aug 1, 2026
Ownership resolved — and three pieces of reasoning worth keeping from how it was decided
This issue now has an owner (the
#985/ElementPoolsession), to be implemented as a separate PRagainst a settled
mainrather than folded into a pending union. The premise recorded earlier on thisissue has been independently re-verified at head:
RichTextBlockisRelativePanel's mirror image — poolable but ungated, so nothing writes it today.Canvasis the other mirror: any future widening from the enumerated panels to a barePanelgateshould redden. (Note
RichTextBlockappears 24 times inModifierTable— it is gated for other modifiers.A bare "is it in the table?" check would say yes and be useless.)
1. Why a fail-open invariant must not ride in a conflict resolution
The argument is not about scope. A fail-open guard needs more scrutiny than the code it guards, and
conflict review is the one context where reviewers read for "did the merge preserve both sides?" rather
than "does this assert anything?"
Which is why the destructive probe — rename
PoolableTypesand prove the test THROWS rather than skips —has to run on a settled tree.
2. Measuring whether deferral costs anything, BEFORE deferring
A full cross-product of the 15 poolable types against both post-union gates established that the invariant
passes on the union tree — it is future-proofing, not a hole-plug, and no window opens while it is pending.
3. A corrected position that lived in more places than the conversation
The same session had previously published a comment on this issue assigning the work elsewhere, on
reasoning that was sound under one merge order and stopped applying under another. They went looking for it
rather than waiting to be told, and corrected it with the reasoning made explicit rather than quietly
edited.
Derive the pool-clear obligation from the gate and the poolable set (#…
Correct ElementPool comment claiming gate widening is unguarded (S13)
azchohfi commentedon Aug 1, 2026
Correction to the parenthetical count in my previous comment — and a refinement it exposed
The number was wrong at every basis. I wrote "
RichTextBlockappears 24 times inModifierTable":The conclusion it supported is unaffected and stands —
RichTextBlockis gated for other modifiers, so abare "is it in the table?" check would indeed say yes and be useless.
⭐ But verifying it, my own probe nearly inverted the lesson
I re-checked using the exact quoted literal
"RichTextBlock"— the form that is correct for fixture-registryrows, where a substring match lets a shorter name inherit a longer name's hits. On
mainit returns 0, whichreads as "
RichTextBlockis in no gate at all" — the opposite of the recorded finding, and I was one step fromfiling it as a correction.
It is in two gates, on both refs. The gates name Element types, not control types:
The single quoted
"RichTextBlock"at:317on the #1015 head is thePoolableTypeNameSetmirror, not agate — which is why the count moves 26 → 27 on that branch and not before.
So "always match the exact quoted literal" is incomplete. It needs "…in the vocabulary the file actually
uses" — full names for registry rows,
…Element-suffixed names for modifier gates. Both failures present as awell-formed, plausible answer; the exact-quoted one presents as a confident zero, which is the harder of the
two to doubt because it looks like a clean negative result rather than a broken probe.
Fix ElementPool.CleanElement never releasing Control/Panel-level modi…
azchohfi commentedon Nov 13, 2026
#1015 added this as
Every_Poolable_Gated_Receiver_Is_Released_By_CleanElementinModifierUnsetClearValueTests. It matches receivers by type inheritance instead of by name, and it fails if thePoolableTypesset can't be read or comes back empty, so it can't pass vacuously. Closing.