|
| 1 | +# P-037 Phase B1: the guarded shadow read (pre-registered) |
| 2 | + |
| 3 | +> Status: **PRE-REGISTERED. No Rust code written; stopped for owner review.** |
| 4 | +> |
| 5 | +> This contract is committed before any implementation, so the result is |
| 6 | +> judged against it rather than an impression afterwards. |
| 7 | +> |
| 8 | +> - Governance: `docs/notes/p037-formal-kernel.md` §10.1 (finding classes), |
| 9 | +> §10.4 (proof boundary), §10.6 (R), §10.7 (B0 accepted, A14 gate). |
| 10 | +> - Entry state: B0 PASS, `docs/notes/p037-phase-b-proof-boundary.md` and |
| 11 | +> `formal/p037-kernel/proof-boundary.json`. |
| 12 | +> - Base: `0e2c01a`, the head of #372. Branch: |
| 13 | +> `research/p037-phase-b1-shadow`. |
| 14 | +> |
| 15 | +> Evidence tags as elsewhere: `REPOSITORY FACT`, `MEASURED OBSERVATION`, |
| 16 | +> `INFERENCE`, `OWNER RULING`. |
| 17 | +
|
| 18 | +## 0. Fixed by the owner (OWNER RULING, 2026-09-28, recorded verbatim in meaning) |
| 19 | + |
| 20 | +These are the frame of the contract, not choices it makes. |
| 21 | + |
| 22 | +1. B1 is shadow-only. It changes no MOS, verdict or diagnostic, no |
| 23 | + `ConsumesParam`, and no `own-bridge` behavior. |
| 24 | +2. `own-bridge` is untouched in B1. |
| 25 | +3. The home is a new crate, `own-guarded`. |
| 26 | + - It is the only Rust crate allowed to depend on `p037-kernel`. |
| 27 | + - An executable architecture guard enforces this, because |
| 28 | + `own-diagnostics/tests/dag.rs` sees only workspace-internal edges. |
| 29 | +4. `own-shadow` may depend on `own-guarded` to produce guarded-vs-legacy |
| 30 | + reports. |
| 31 | +5. `own-bridge → own-guarded` is **not** pre-authorized; that edge is phase C. |
| 32 | +6. All 16 B0 entry obligations are B1 acceptance conditions. |
| 33 | +7. A14 remains conditional static-dispatch debt. B1 may **measure** it; B1 may |
| 34 | + not solve it or assume it away. |
| 35 | +8. The first shadow population collects the A14 exposure metrics and the R |
| 36 | + record-absence metrics that the later kill-gates need. |
| 37 | +9. These all degrade to **`NO_GUARDED_EVIDENCE`**, never to a positive |
| 38 | + conclusion: |
| 39 | + - an ambiguous body⋈sidecar join; |
| 40 | + - a missing record or sidecar; |
| 41 | + - an unresolved positive fact; |
| 42 | + - a solver bound failure; |
| 43 | + - unsupported placement. |
| 44 | + |
| 45 | +## A. Question |
| 46 | + |
| 47 | +Can a guarded summary be computed for the real fact surface in shadow, with |
| 48 | +the existing kernel reused rather than re-implemented and every B0 obligation |
| 49 | +discharged by an executable control? That is, reading only A2's sidecar, the |
| 50 | +legacy body and the `functions[]` records. Two things must also hold: |
| 51 | + |
| 52 | +- every place where the facts do not support a guarded conclusion yields |
| 53 | + `NO_GUARDED_EVIDENCE` rather than a guess; |
| 54 | +- every difference against the legacy summary is either one of the three |
| 55 | + declared P-037 classes or explicitly degraded. |
| 56 | + |
| 57 | +If not, **STOP** before phase C. The finding is classified under §10.1, and |
| 58 | +case 5 goes back to the owner. |
| 59 | + |
| 60 | +## B. Necessary conditions (all must hold for PASS) |
| 61 | + |
| 62 | +**N1 — architecture, executable.** |
| 63 | +- `own-guarded` is a workspace member. Its workspace dependencies are |
| 64 | + exactly `own-ir`, and its only non-workspace path dependency is |
| 65 | + `formal/p037-kernel`. |
| 66 | +- `own-shadow` gains `own-guarded`. No other crate gains either. |
| 67 | +- A new guard (a `dag.rs` test reading every `Cargo.toml` under `rust/`, |
| 68 | + mirrored by `scripts/p037_proof_boundary.py`) fails when: |
| 69 | + - any crate other than `own-guarded` names `p037-kernel`; |
| 70 | + - any crate other than `own-shadow` names `own-guarded`; |
| 71 | + - `own-bridge` / `own-cli` / any core crate reaches either, directly or |
| 72 | + transitively. |
| 73 | +- `own-bridge → own-guarded` is absent and asserted absent. |
| 74 | + |
| 75 | +**N2 — zero semantic cut.** `rust/` is an A2 evidence instrument path |
| 76 | +(`scripts/p037_evidence.py`), so adding a crate moves the instrument by |
| 77 | +definition. The A2 snapshot differential therefore refuses to compare across |
| 78 | +B1, and that refusal is correct. The pre-registered evidence instead: |
| 79 | +- **Source-level:** `git diff base..head` touches nothing under `ownlang/`, |
| 80 | + `rust/crates/{own-bridge,own-cli,own-ir,own-lowered,own-analysis,own-cfg,own-syntax,own-diagnostics}/src`, |
| 81 | + `scripts/own-check.sh` or `spec/`. The exceptions are the `dag.rs` guard |
| 82 | + test and `Cargo.toml` / `Cargo.lock` workspace membership. The checker |
| 83 | + enforces the path set. |
| 84 | +- **Binary-level:** the release `own-cli` built at the base and at the head |
| 85 | + with the same toolchain has the **same sha256**. If it does not, the |
| 86 | + fallback is a full MOS/verdict before/after take with the instrument move |
| 87 | + declared. If the harness cannot express that, **STOP**: an |
| 88 | + evidence-infrastructure addition (case 4) comes before B1 can pass. |
| 89 | +- **Extractor-level** (only if the A14 side report of N6 lands in the |
| 90 | + extractor): with the flag absent, the census is byte-identical on both |
| 91 | + engines, and the facts of the 137-file corpus and the repo tree are |
| 92 | + byte-identical to the base. |
| 93 | + |
| 94 | +**N3 — the 16 B0 obligations, each with an executable control in |
| 95 | +`own-guarded`'s tests (or in `own-shadow` for report properties).** |
| 96 | + |
| 97 | +| B0 id | B1 acceptance control | |
| 98 | +|---|---| |
| 99 | +| WF / EWF | a system or coordinate that fails the ported well-formedness predicates is `NO_GUARDED_EVIDENCE`; it is never solved | |
| 100 | +| A2 | Id/Neg only for a resolved callee, at the callee's elected guard ordinal, from `param{source_param}`; an unresolved callee with a param at that position is Opaque | |
| 101 | +| A3 | Uncond seeds only via `Cells::diag`; apply(Uncond) lowers the collapse | |
| 102 | +| A4 / A15 | seeds and masks only through the fail-closed join. The B0 probe shapes (`docs/evidence/p037-b0-probes`) plus `ctor-initializer` are fixtures, each with the pre-registered outcome from B0 §E.6: placeable, or `NO_GUARDED_EVIDENCE` with its reason | |
| 103 | +| A5 | the transform table: `bool_const`/`null_literal`/`object_creation` → ConstPos/ConstNeg (canonical orientation); `param` → Id/Neg under A2; `call_result`/`opaque` → Opaque in the solver | |
| 104 | +| A6 | the driver's step composes `p037_kernel::{read, contribute, Cells::join, import}` (checked: `own-guarded` defines none of the kernel's types or algebra) | |
| 105 | +| A7 | a full sweep by construction, with no schedule parameter; F8 extended to scan `own-guarded` | |
| 106 | +| A8 | application only through `p037_kernel::apply`; F9 scans `own-guarded`; **the K7 witness ported onto the adapter**: a `(must, ⊥)` unselected coordinate built from real facts lowers to plain | |
| 107 | +| A9 / A10 / A11 | a missing record, missing sidecar, unresolved callee or ambiguous join reads as Unknown / `NO_GUARDED_EVIDENCE`, never ⊥. `record-absence-boundary` is a required control: a mutant that reads absence positively turns it red | |
| 108 | +| A12 | the pass bound is `n·HEIGHT+1` per SCC; exceeding it (fault-injected) is `NO_GUARDED_EVIDENCE` for the SCC, never a partial value or a panic | |
| 109 | +| A13 | only `fin()` cells cross an SCC boundary; a two-SCC fixture whose callee has a residual ⊥ cell must not yield `must` at the caller | |
| 110 | +| A14 | every report carries `static_dispatch_conditional: true`; nothing in `own-guarded` reads, upgrades or degrades on dispatch | |
| 111 | + |
| 112 | +**N4 — required-read.** The contradictory-sidecar fixture of A2 flips role |
| 113 | +(§10.3): |
| 114 | +- in B1 it must **change** the guarded shadow result, which proves the |
| 115 | + sidecar is actually read; |
| 116 | +- it must still leave MOS and verdicts unchanged (the inertness script, with a |
| 117 | + guarded layer added). |
| 118 | + |
| 119 | +**N5 — every guarded-vs-legacy difference is classified.** Legacy is |
| 120 | +`own-bridge`'s MOS, read through `own-shadow`. Every coordinate lands in |
| 121 | +exactly one of: |
| 122 | +- `EQUAL`; |
| 123 | +- `SUMMARY_REFINEMENT` (guarded ⊑ legacy after finalization, G-T2a); |
| 124 | +- `LEGACY_HONESTY` (guarded unknown vs legacy may, G-T2b class 3); |
| 125 | +- `APPLICATION_REFINEMENT` (call-site selection differs; the collapse agrees); |
| 126 | +- `NO_GUARDED_EVIDENCE(reason)`; |
| 127 | +- `UNEXPLAINED`. |
| 128 | + |
| 129 | +`UNEXPLAINED > 0` is a KILL (§D). |
| 130 | + |
| 131 | +**N6 — the first shadow population collects the gate metrics.** |
| 132 | +- **A14 exposure** (measurement only; OwnIR is not amended, per §10.7): |
| 133 | + - relevant calls, total; |
| 134 | + - exact calls (static, non-virtual, or a sealed/struct target); |
| 135 | + - virtual / abstract / interface / override dispatch candidates; |
| 136 | + - candidates in a guarded summary chain; |
| 137 | + - candidates whose admissible first-party implementations (in the |
| 138 | + compilation) have **different** guarded summary classes; |
| 139 | + - the subset where the static target yields MUST and some admissible target |
| 140 | + does not (the A14 hard-KILL witness count). |
| 141 | + |
| 142 | + Dispatch class is not in the facts. The measurement therefore comes from a |
| 143 | + **side report** of the extractor: an opt-in flag that writes a separate JSON |
| 144 | + keyed by call site. It is not OwnIR, not read by either engine, and facts |
| 145 | + are byte-identical when it is off (N2). It is an instrument, not a fact, and |
| 146 | + it is reported, not acted upon. |
| 147 | +- **R record-absence:** first-party resolved callees with no `functions[]` |
| 148 | + record, how many guarded paths end there, and the share of otherwise-eligible |
| 149 | + guarded chains that break on R. |
| 150 | +- **Degradation census:** `NO_GUARDED_EVIDENCE` counts by reason (join |
| 151 | + ambiguity per rule clause, missing record, missing sidecar, unresolved, |
| 152 | + bound, malformed, expression form, no body op). |
| 153 | + |
| 154 | +## C. Cheap falsifiers (each demonstrated to fire before the result) |
| 155 | + |
| 156 | +| id | mutation | must happen | |
| 157 | +|---|---|---| |
| 158 | +| G1 | `own-bridge` (or `own-cli`, `own-ir`) gains `own-guarded` or `p037-kernel` | the architecture guard fails | |
| 159 | +| G2 | a second crate gains `p037-kernel` | the architecture guard fails | |
| 160 | +| G3 | `own-guarded` defines its own `join` / `Transfer` / `apply`-like lowering | the reuse guard fails (A6/A8) | |
| 161 | +| G4 | the driver takes a schedule, or `own-guarded` calls `solve_with` / `elect_with` / `lfp_chaotic` | F8 fails | |
| 162 | +| G5 | `own-guarded` lowers/collapses outside `apply` | F9 fails | |
| 163 | +| G6 | the join resolves an ambiguous line (e.g. `Probe.TwoIfs`, `c && F(s)`) to a placement instead of `NO_GUARDED_EVIDENCE` | the A15 fixture test fails | |
| 164 | +| G7 | absence (R, missing sidecar) or an unresolved callee read as ⊥ / no / must | the A9–A11 tests fail, and `record-absence-boundary` goes red | |
| 165 | +| G8 | the ported K7 witness mutated so that application skips `fin` | the adapter-level K7 test fails | |
| 166 | +| G9 | a raw cell exported across an SCC | the A13 two-SCC test fails | |
| 167 | +| G10 | the contradictory sidecar no longer changes the shadow | the N4 required-read test fails | |
| 168 | +| G11 | the report drops `static_dispatch_conditional` or acts on dispatch | the A14 report test fails | |
| 169 | +| G12 | an own-bridge / own-cli source change sneaks in | the N2 path guard fails | |
| 170 | +| G13 | a synthetic guarded-vs-legacy pair outside the three classes | the classifier reports `UNEXPLAINED` (it is not silently bucketed) | |
| 171 | + |
| 172 | +## D. Hard KILL / PASS |
| 173 | + |
| 174 | +**KILL** gives `RESULT: FAIL — B1 BLOCKED`, lists the blockers, fixes no |
| 175 | +semantics here, and triggers when: |
| 176 | + |
| 177 | +1. any MOS, verdict or diagnostic moves (N2 fails); |
| 178 | +2. the architecture guard can be satisfied only by an edge the owner did not |
| 179 | + authorize; |
| 180 | +3. any obligation of N3 has no executable control, or its control is only a |
| 181 | + comment; |
| 182 | +4. any positive guarded conclusion (a selected MUST / NO, or borrow) is |
| 183 | + produced where §0.9 requires `NO_GUARDED_EVIDENCE`; |
| 184 | +5. `UNEXPLAINED > 0` on the population. Each such difference is classified |
| 185 | + under §10.1 before anything else happens; case 5 goes to the owner; |
| 186 | +6. the fail-closed join (A15) cannot be implemented from the A2 facts without |
| 187 | + a sidecar/OwnIR change. That is a case-5 STOP, as B0 §E.3 item 3 foresaw; |
| 188 | +7. A14 is assumed away or acted on; |
| 189 | +8. the kernel is re-implemented rather than reused; |
| 190 | +9. the budget below is exceeded. |
| 191 | + |
| 192 | +**PASS** gives `RESULT: PASS — GUARDED SHADOW READ ESTABLISHED`, and requires |
| 193 | +all of: |
| 194 | +- N1–N6 hold; |
| 195 | +- G1–G13 fire; |
| 196 | +- the first shadow report is committed as evidence (population, commit, |
| 197 | + toolchain), together with the A14 and R metrics; |
| 198 | +- the degradation census, and the classification counts with |
| 199 | + `UNEXPLAINED = 0`. |
| 200 | + |
| 201 | +A PASS authorizes nothing further by itself. The A14 gate and the R value |
| 202 | +gate are separate steps that consume this report. Phase C |
| 203 | +(`own-bridge → own-guarded`, authoritative guarded summaries) needs its own |
| 204 | +authorization. |
| 205 | + |
| 206 | +## E. Population (the first shadow run) |
| 207 | + |
| 208 | +All of it is at one commit and one toolchain. The legacy side is `own-bridge`'s MOS (the Rust production core); Python/Rust parity is already gated by P-022, and B1 does not re-measure it. The population: |
| 209 | +- the repository C# tree (`frontend/`, `audit/`); |
| 210 | +- the committed corpus (the 137 files of `corpus/real-world`, `wpf`, `di`, |
| 211 | + `fixtures`, `p036-bakeoff`); |
| 212 | +- `corpus/p037-shapes` (23 shapes); |
| 213 | +- the P-037 controls `corpus/p036-bakeoff/{guarded-consume-*, gv4-control-*, |
| 214 | + legacy-honesty-*}`; |
| 215 | +- the B0 probes `docs/evidence/p037-b0-probes`. |
| 216 | + |
| 217 | +The report's own schema is versioned (`p037-guarded-shadow/1`). It is |
| 218 | +evidence, not a gate on verdicts. |
| 219 | + |
| 220 | +## F. Budget and stop point |
| 221 | + |
| 222 | +Budget: |
| 223 | +- `own-guarded`: at most ~900 lines of non-test Rust. That covers the join, |
| 224 | + the fact-to-system builder, the dynamic full-sweep driver, application |
| 225 | + through `apply`, and the classifier. |
| 226 | +- `own-shadow`: one report entry point, at most ~200 lines, following owner |
| 227 | + decision R-1: stdin is the facts document, stdout is the report, and it |
| 228 | + takes no path arguments. |
| 229 | +- The extractor side report (A14): at most ~150 lines of C#, opt-in. |
| 230 | +- The architecture and reuse guards, plus fixture tests. |
| 231 | +- No new framework. |
| 232 | + |
| 233 | +Twice the budget is a STOP and a re-plan, not a quiet overrun (the #369 lesson). |
| 234 | + |
| 235 | +Stop point: the PASS/FAIL result, the committed first shadow report, and the |
| 236 | +metrics for the A14 and R gates. **No phase-C wiring, no A14 solution, no R |
| 237 | +experiment, no #368 fix.** |
| 238 | + |
| 239 | +Implementation starts only after the owner has reviewed this contract. |
0 commit comments