Skip to content

Commit 3c46b87

Browse files
committed
fix(extractor): revert unsound static-context exemption (Codex P2); keep App-only
Codex flagged the static-context skip as unsound (correctly): a `+=` inside a static member has no `this`, but the handler can still retain a NON-`this` instance — `publisher.Fired += subscriber.OnFired`, or a lambda capturing a parameter — which an outliving source leaks. "No enclosing `this`" does not imply "nothing can be retained". The ProcessHelper case is safe only because its source `process` is a FRESH, non-escaping method-local (`Process.Start(info)`), but there is no sound syntactic rule that admits a factory-fresh local while still excluding an aliased long-lived source (`var src = injectedBus; src.X += ...`) — only `new` proves freshness. A known soundness hole is worse than the FP under the zero-FN mandate, so the static-context exemption (helper + loop skip + StaticContextSubscription.cs + its CI assertions) is reverted in full. ProcessHelper's `process.Exited` subscription stays an honest "possible leak" warning; a proper fresh-source fix is a separate, deliberate change. This leaves PR #81 as the clean, uncontested App fix only: OWN014 region-escape is suppressed for the process-lived WPF `App` singleton. Also handle the alias-qualified base type `global::System.Windows.Application` (AliasQualifiedNameSyntax) in IsProcessLivedApplication, per CodeRabbit — without it `clsIsApp` would miss that declaration shape and re-enable the FP. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rg8kSk1YT14x7A1vo5zgED
1 parent 5179aac commit 3c46b87

3 files changed

Lines changed: 1 addition & 102 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ jobs:
136136
frontend/roslyn/samples/DiCaptiveSample.cs \
137137
frontend/roslyn/samples/SampleTypes.cs \
138138
frontend/roslyn/samples/PipeFieldsSample.cs \
139-
frontend/roslyn/samples/StaticContextSubscription.cs \
140139
frontend/roslyn/samples/AppLifetimeSample.cs \
141140
-o "$RUNNER_TEMP/facts.json"
142141
cat "$RUNNER_TEMP/facts.json"
@@ -285,18 +284,6 @@ jobs:
285284
if echo "$out" | grep -q "CleanStaticEventViewModel"; then
286285
echo "FAIL: an unsubscribed (released) static-event subscription was wrongly reported"; exit 1
287286
fi
288-
# P-004 static-context exemption (mined: ScreenToGif ProcessHelper): a `+=`
289-
# inside a STATIC member has no enclosing `this`, so it cannot leak an
290-
# instance of its type. Both the static-class helper and the static method on
291-
# an instance class subscribe `publisher.Fired` and must stay SILENT, while
292-
# the INSTANCE control (`_bus.Fired += OnFired`) still warns.
293-
echo "$out" | grep -qE "StaticContextSubscription\.cs:[0-9]+: warning: \[OWN001\]" \
294-
|| { echo "FAIL: expected the instance-method subscription (control) to warn"; exit 1; }
295-
echo "$out" | grep -q "_bus.Fired" \
296-
|| { echo "FAIL: expected the injected instance subscription (_bus.Fired) to warn"; exit 1; }
297-
if echo "$out" | grep -q "publisher.Fired"; then
298-
echo "FAIL: a static-context subscription was wrongly reported (should be silent)"; exit 1
299-
fi
300287
# P-004 process-lived-subscriber exemption (mined: ScreenToGif App +
301288
# Translator): the WPF `App` singleton hooking the process-lived
302289
# AppDomain.UnhandledException promotes nothing, so the static-source region

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -189,36 +189,6 @@ static bool IsStaticHandler(ExpressionSyntax right, SemanticModel model) =>
189189
IsHandler(right)
190190
&& model.GetSymbolInfo(right).Symbol is IMethodSymbol { IsStatic: true };
191191

192-
// P-004 static-context exemption: a `+=` lexically inside a STATIC member (or a
193-
// `static class`) has no enclosing `this`, so the handler — a static method group,
194-
// or a lambda that can only close over locals/parameters/statics — retains no
195-
// instance of this type. The "keeps <Type> alive" subscriber-leak is then
196-
// structurally impossible, however long-lived the source. (Found mining
197-
// ScreenToGif: `static ProcessHelper.RestartAsAdmin` does
198-
// `process.Exited += (s, a) => comp.SetResult(...)` — a static helper's method-local
199-
// `Process` and a lambda over locals; nothing instance-scoped to leak. The detector
200-
// had mis-attributed it to an "injected dependency keeping ProcessHelper alive",
201-
// but ProcessHelper is a static class — there is no instance.) The first enclosing
202-
// member / local-function / type decides; lambdas are walked past so the rule keys
203-
// off the real execution frame, not the closure. A static-source region escape
204-
// (OWN014) is likewise impossible with no instance to promote, so this skips both.
205-
static bool IsStaticContext(SyntaxNode node)
206-
{
207-
foreach (var anc in node.Ancestors())
208-
switch (anc)
209-
{
210-
case LocalFunctionStatementSyntax lf:
211-
return lf.Modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword));
212-
case BaseMethodDeclarationSyntax bm:
213-
return bm.Modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword));
214-
case BasePropertyDeclarationSyntax bp:
215-
return bp.Modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword));
216-
case TypeDeclarationSyntax t:
217-
return t.Modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword));
218-
}
219-
return false;
220-
}
221-
222192
// P-004 process-lived-subscriber exemption: the WPF application object (`App`) is a
223193
// process-lived singleton — exactly one instance, created at startup, alive until
224194
// the process exits. Subscribing it to a process-lived static event
@@ -240,6 +210,7 @@ static bool IsProcessLivedApplication(TypeDeclarationSyntax cls)
240210
{
241211
IdentifierNameSyntax id => id.Identifier.Text,
242212
QualifiedNameSyntax q => q.Right.Identifier.Text,
213+
AliasQualifiedNameSyntax aq => aq.Name.Identifier.Text,
243214
_ => null,
244215
};
245216
if (n is "Application")
@@ -1985,12 +1956,6 @@ or ImplicitObjectCreationExpressionSyntax
19851956
if (leftSymbol is IEventSymbol ev)
19861957
{
19871958
var isTimer = IsTimerEvent(a.Left);
1988-
// A subscription in a STATIC context has no enclosing `this`, so no
1989-
// instance of this type can be retained — neither a subscriber leak
1990-
// (OWN001) nor a region escape (OWN014) is possible. (timers excluded:
1991-
// a running timer is dispatcher-rooted regardless of context.)
1992-
if (!isTimer && IsStaticContext(a))
1993-
continue;
19941959
// P-004 lifetime exemptions — skip, not a leak (timers excluded: a
19951960
// running timer is dispatcher-rooted regardless):
19961961
// - self-owned source (`this`, or a field/local the class

‎frontend/roslyn/samples/StaticContextSubscription.cs‎

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)