Skip to content

Commit 69c79b0

Browse files
authored
Merge pull request #158 from PhysShell/claude/mos-ownership-summary-n3q3j4
docs: record static-class subscriber exemption as a rejected approach
2 parents ede20ce + dace9e8 commit 69c79b0

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎docs/notes/oracle-known-fps.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,48 @@ entry and let the oracle re-confirm clean.
182182
`docs-src/`) are handled per-entry in the baseline rather than by polluting the
183183
generic `_is_test_path` with repo-specific directory names.
184184

185+
## Rejected approaches
186+
187+
### Static-class subscriber exemption (the CsvHelper `ConsoleHost` over-reach)
188+
189+
**Attempted in PR #157, reverted in `488d505` before merge. Do not retry.**
190+
191+
To clear the two CsvHelper `ConsoleHost` FPs (§3, root-cause 3 — a process-lived
192+
host subscribing to a process-lived `AppDomain`/`Console` event), the tempting move
193+
was to add `|| clsIsStatic` next to the existing `clsIsApp` exemption in the
194+
extractor (`Program.cs`, the `if (!isTimer && source == "static" && clsIsApp)`
195+
drop): "the subscriber's containing type is a `static class`, so there's no instance
196+
to leak — drop the OWN014 the same way we drop it for the WPF `App` singleton."
197+
198+
**Why it is unsound.** A `static class` only rules out an instance `this` being
199+
pinned. It says **nothing** about a lambda handler that captures a **local**. When
200+
the source is a static/process-lived event, that captured local is pinned for the
201+
whole process — a genuine leak. The exemption would silently swallow it:
202+
203+
```csharp
204+
static class Foo {
205+
void Attach(VM vm) =>
206+
SystemEvents.UserPreferenceChanged += (_, _) => vm.Refresh(); // pins vm forever
207+
}
208+
```
209+
210+
`clsIsApp` is safe where `clsIsStatic` is not: the WPF `App` singleton *is* the
211+
process-lived object, so promoting its own subscriptions to process lifetime changes
212+
nothing; a static class is just a namespace for methods whose lambdas can still
213+
capture and pin arbitrary shorter-lived state.
214+
215+
**Caught by:** Codex (P2) and CodeRabbit (Major) in review of #157, before merge.
216+
217+
**Why a sound narrowing still wouldn't help here.** A capture-gated version
218+
("exempt only when the handler captures nothing") would be sound — but it would
219+
**not** clear the motivating case: CsvHelper's `ConsoleHost` handlers capture `cts`
220+
and `resetEvent`, so the capture-free guard would (correctly) keep firing. The clear
221+
verdict is "this specific host is process-lived" (the subscriber's own lifetime),
222+
which we have no reliable signal for. So those two findings stay in
223+
`corpus/oracle-fp-baseline.txt` as baselined FPs rather than being suppressed by an
224+
extractor rule. An in-code `ANTI-PATTERN` comment at the exemption site warns against
225+
re-adding `|| clsIsStatic`.
226+
185227
## How the baseline stays honest
186228

187229
- **Matched by name, not line** — `(repo, file-basename, OWN code,

‎frontend/roslyn/OwnSharp.Extractor/Program.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,6 +3325,22 @@ or ImplicitObjectCreationExpressionSyntax
33253325
// process — so the region escape (OWN014) is a false positive. Scoped
33263326
// to NON-timers: a timer is forced to source "static" above, but a
33273327
// never-stopped timer in `App` is still a real leak (CodeRabbit).
3328+
//
3329+
// ANTI-PATTERN — do NOT broaden this to `|| clsIsStatic` (subscriber is
3330+
// a static class). It looks symmetric with `clsIsApp` but is UNSOUND: a
3331+
// static class only rules out an instance `this` being pinned; it does
3332+
// NOTHING about a lambda handler that captures a *local*. A static-source
3333+
// (process-lived) event then pins that captured local for the whole
3334+
// process — a genuine leak this exemption would silently swallow, e.g.
3335+
// static class Foo {
3336+
// void Attach(VM vm) =>
3337+
// SystemEvents.UserPreferenceChanged += (_,_) => vm.Refresh(); // pins vm forever
3338+
// }
3339+
// This was tried in PR #157 and caught pre-merge by Codex (P2) + CodeRabbit
3340+
// (Major); reverted in 488d505. A capture-gated narrowing was considered but
3341+
// would NOT clear the motivating case (CsvHelper ConsoleHost captures cts/
3342+
// resetEvent), so it stays in corpus/oracle-fp-baseline.txt instead. Full
3343+
// write-up: docs/notes/oracle-known-fps.md → "Rejected approaches".
33283344
if (!isTimer && source == "static" && clsIsApp)
33293345
continue;
33303346
var released = unsub.Contains($"{a.Left}|{a.Right}")

0 commit comments

Comments
 (0)