|
| 1 | +# N1-F0 — ownership feasibility gate — pre-registration |
| 2 | + |
| 3 | +Written 2026-10-20, 21:51 +05, before any F0 run. Authority: owner decision |
| 4 | +`ACCEPT-N1-COMPETITOR-GATE / GO-N1-OWNERSHIP-FEASIBILITY / NO-PRODUCTION`, on #417. |
| 5 | + |
| 6 | +- **Budget.** 0.25 agent-day for F0-A, F0-B and F0-C together. |
| 7 | +- **Outcome.** One verdict, `PASS-F0` or `KILL-N1`. `PASS-F0` does not authorise production work or a PoC. |
| 8 | +- **Rules of the work.** No production, OwnIR, CI or golden change. No third-party build and no package download (D13). |
| 9 | + |
| 10 | +## F0-A — finish the competitor check |
| 11 | + |
| 12 | +**Run.** The four reproductions of #417 (`n1-competitor-gate-2026-10/repro`, stubs as a separate assembly), under: |
| 13 | + |
| 14 | +| K | CA2000 settings | |
| 15 | +|---|---| |
| 16 | +| A1 | `AllPaths`, `interprocedural_analysis_kind = None` | |
| 17 | +| A2 | `AllPaths`, `NonContextSensitive` | |
| 18 | +| A3 | `AllPaths`, `ContextSensitive` | |
| 19 | +| A4–A6 | A1–A3 plus `dispose_ownership_transfer_at_constructor = true` and `…_at_method_call = true` | |
| 20 | + |
| 21 | +plus K1–K5 of #417 again, so that every configuration uses the new collector. |
| 22 | + |
| 23 | +**Collector.** Every diagnostic whose location is inside the buggy **method** of each pair, from the first line of |
| 24 | +its declaration to its closing brace, not only on the `ACQ` line. A diagnostic is **disposal-related** if its rule |
| 25 | +is one of the following, or its message contains `dispos` (case-insensitive): |
| 26 | + |
| 27 | +- CA2000, CA1001, CA2213, CA2215, CA2216; |
| 28 | +- IDISP001–IDISP026; |
| 29 | +- S2930, S2931, S3966, S4487. |
| 30 | + |
| 31 | +**Verdict per pair.** |
| 32 | + |
| 33 | +- **`CAUGHT`:** at least one disposal-related diagnostic in the buggy method names the leaked resource (its |
| 34 | + acquisition expression or its variable) in any configuration. |
| 35 | +- **`ADJACENT`:** disposal-related diagnostics that name another object. They are listed and do not count. |
| 36 | +- **`MISSED`:** otherwise. |
| 37 | + |
| 38 | +**F0-A kill.** Fewer than 2 pairs `MISSED` → `KILL-N1`. The other parts are then not scored. |
| 39 | + |
| 40 | +## F0-B — ownership oracle |
| 41 | + |
| 42 | +**Oracle (fixed now).** A call result `r` acquired in method `M` of type `T` is **owned by `M`** only when all of |
| 43 | +the following hold: |
| 44 | + |
| 45 | +1. **Hand-over target.** On the success path, `M` hands `r` to one of: |
| 46 | + - (a) an instance field `f` of `T`; |
| 47 | + - (b) an element of a collection field `f` of `T` (indexer store, `Add`, `TryAdd`); |
| 48 | + - (c) a constructor argument of an in-source type `W` whose constructor stores it in a field `g` of `W`, where |
| 49 | + the `W` instance is returned or stored as in (a)/(b). |
| 50 | +2. **The repository itself disposes that target.** The same type (`T`, or `W` for (c)) contains a |
| 51 | + `Dispose`/`DisposeAsync`/`Close`/`CloseAsync` call whose receiver is: |
| 52 | + - `f` or `g`; |
| 53 | + - a local obtained from `f` by `TryRemove(…, out x)`, `Remove(…, out x)`, an indexer read, or `foreach` over |
| 54 | + `f` / `f.Values`; |
| 55 | + - or `using` / `await using` of one of those. |
| 56 | +3. **Not a borrow.** The acquisition call is not in the borrow table: `IServiceProvider.GetService`, |
| 57 | + `GetRequiredService`, `GetServices`, `GetKeyedService*`, `ActivatorUtilities.GetServiceOrCreateInstance`. The |
| 58 | + table only suppresses; it never creates ownership. |
| 59 | + |
| 60 | +Ownership is **never** inferred from the result type being `IDisposable`/`IAsyncDisposable`, from a `Create*` name, |
| 61 | +or from `await`. The result type matters only because rule 2 needs something to dispose. |
| 62 | + |
| 63 | +**Defect, given ownership.** A call that can throw (any invocation or `await`, other than `nameof`/`typeof`) lies |
| 64 | +between the acquisition and the hand-over, and no enclosing `try` disposes `r` on the way out (`catch` or |
| 65 | +`finally` that disposes `r`, or a `published`-style flag guarding a dispose). |
| 66 | + |
| 67 | +**F0-B inputs.** |
| 68 | + |
| 69 | +- **Real code**, as single files from GitHub at the pairs' SHAs, parsed with framework references only: |
| 70 | + - R: rockbot `McpBridgeService.cs` base and fix; |
| 71 | + - B: BareWire `RabbitMqTransportAdapter.cs` base and fix; |
| 72 | + - X: NexusKit `PluginHostBuilder.cs` base and fix, plus `PluginHost.cs` at the same SHAs. |
| 73 | +- **Negative controls** (`controls/OwnershipControls.cs`, written before the first run). Each must be **silent**: |
| 74 | + |
| 75 | +| # | Control | |
| 76 | +|---|---| |
| 77 | +| N1 | DI-resolved: `var s = sp.GetRequiredService<IFoo>(); await X(); _foo = s;` with `T` disposing `_foo` (borrow table) | |
| 78 | +| N2 | borrowed reference: a parameter stored into a field `T` disposes (not acquired by a call) | |
| 79 | +| N3 | shared instance stored in a field `T` never disposes: `var c = Cache.Get(k); await X(); _c = c;` | |
| 80 | +| N4 | caching factory into a dictionary `T` never disposes from | |
| 81 | +| N5 | factory result handed over **before** any throwing call | |
| 82 | +| N6 | the throwing step inside `try`/`catch` that disposes `r` and rethrows (the fixes' shape) | |
| 83 | +| N7 | `published` flag + `finally` disposal (the rockbot fix's shape) | |
| 84 | +| N8 | factory result used and disposed locally with `using` (no hand-over) | |
| 85 | +| N9 | factory result returned to the caller (rule 1 has no return case: silent by design, an inter-procedural case) | |
| 86 | + |
| 87 | +- **Positive samples**, which must be reported: the R, X and B shapes in synthetic form, P-R, P-X and P-B. |
| 88 | + |
| 89 | +**F0-B pass.** All three of: |
| 90 | + |
| 91 | +- the oracle reports the real R, X and B base files at the acquisition, with ownership established by rules 1–2, |
| 92 | + each citing the disposing line it found; |
| 93 | +- it is silent on their fix files; |
| 94 | +- N1–N9 are silent and P-R, P-X and P-B are reported. |
| 95 | + |
| 96 | +Any failure → `KILL-N1`. The oracle must not be changed after the first run on the real files; control files may |
| 97 | +be extended. |
| 98 | + |
| 99 | +The oracle is a throwaway research scan (Roslyn, the same build route as the #416 PoC). It is not an Own.NET |
| 100 | +implementation. |
| 101 | + |
| 102 | +## F0-C — cost |
| 103 | + |
| 104 | +Read the extractor (`frontend/roslyn/OwnSharp.Extractor/Program.cs`) and OwnIR (`ownlang/ownir.py`) and answer |
| 105 | +three questions with file and line references: |
| 106 | + |
| 107 | +1. Can the extractor emit an acquisition for a call result (rather than `new`) using an existing OwnIR fact kind? |
| 108 | +2. Can it emit the hand-over (field, collection or wrapper store) as an existing release/move fact? |
| 109 | +3. Are throw edges between acquisition and hand-over already expressible (the `--body-throw-edges` tier)? |
| 110 | + |
| 111 | +**F0-C kill.** Any of the three needs a new OwnIR fact kind, a version bump, or a new interprocedural pass in the |
| 112 | +core → `KILL-N1`. Needing only extractor-side work (emitting existing facts from new syntax) is acceptable, and |
| 113 | +the estimate is reported. |
| 114 | + |
| 115 | +## Verdict |
| 116 | + |
| 117 | +`PASS-F0` only if F0-A, F0-B and F0-C all pass. Otherwise `KILL-N1`, naming the first failing part. |
0 commit comments