Skip to content

Commit afeca38

Browse files
committed
P-037 A1.0: port the formal kernel, controls and gates onto post-cutover main; re-measure the current record
Bootstrap only. No production code changes: the port touches no file under frontend/, ownlang/ or rust/, which is verified against the changed-path set rather than asserted. A1's semantics (docs/notes/p037-formal-kernel.md §8.1) has not started. WHAT CAME ACROSS, AND FROM WHERE A0, A0.5 and the control authoring live on claude/p036-capability-bakeoff-fzw74t, which also carries the P-036 comparative bakeoff. That branch is not merged and not cherry-picked: its raw evidence is 846 files of six tools' output over a corpus, none of which A1 reads and all of which would have arrived as unreviewed payload behind a P-037 change. The P-037 assets are ported BY PATH onto a branch cut fresh from main at 63148d0 (the Stage-3 merge, #359). Source tree ce2e6bc; merge base with main 70189a3, which is also the commit the `current` control records name. The work those paths carry: 0355bdd (A0 kernel spike), 96bdac3 (small-width symbolic inputs), 30fc9f0 (tractable solver harnesses), 919a908 (by-value reads at symbolic indices), 6419b33 (collapsed()/today() by value), 9523fac (A0 terminal, 22/22 harnesses proven), 7cf1f93 (A0.5 — the G-T2a/G-T2b split), 7751d1b (the A1 sequencing ruling and the G-V4 controls), ce2e6bc (the owner ruling on no pre-cutover ConsumesParam fix, current/post_a1 expectations, the two-layer checker). Deliberately left behind: docs/evidence/p036-bakeoff/raw/** and custom-codeql/, scripts/p036_bakeoff.py, docs/notes/p036-bakeoff.md, and the 10 corpus cases belonging to P-036 vertical B (enrollment-*, the helper/barrier/throw shapes). 8 of 18 case directories came across. The bakeoff note is still the citation for the SHRINK hand-off, so the three places that cite it now name the branch and ce2e6bc rather than a relative link that would dangle here — the pointer was made honest about where it lives, the claim was not weakened to fit the port. PHASE 0.1 — THE CURRENT RECORD, RE-MEASURED AFTER THE CUTOVER The `current` records were measured at 70189a3, when a bare own-check.sh meant Python. Since Stage 3 the same bare invocation means Rust, so a record whose meaning silently changed under it had to be re-taken before A1 could rest on it. Re-taken, not rewritten: measured_at, current and post_a1 are byte-identical to the source branch, and each expected.json gains an append-only remeasured[] entry (schema p037-control-expectation/2; the checker accepts /1 and /2). Measured on both engines explicitly: all four controls UNCHANGED on both layers, python and rust identical. --post-a1 still fails 4/4 (rc=1), as designed. The Phase-0 STOP condition did not trigger. The engines agreeing is the two-layer design paying out rather than luck — the fabricated `release` is emitted by the Roslyn extractor before either engine sees a fact, which is what §8.2 read off the facts and this now confirms by running both. ADAPTATIONS THE CUTOVER FORCED 1. scripts/p037_controls.py passes --engine explicitly (default rust; python measures the reference; both measures each against the same record and reports agreement). Bare was wrong twice over post-cutover: on a machine with no Rust candidate it exits 2 having measured nothing, and where it does run it silently changes which engine the 70189a3 record is about. `both` agreeing is an observation and is NOT contracted — A1 changes Rust and not Python, so a later divergence there is a finding to classify, not one to paper over. 2. ci.yml's new formal-p037 job keeps toolchain: stable, matching rust-core directly above it. The concrete rustc pin Stage 3 requires is a property of action.yml — the consumer-facing distribution surface — not of this repo's own CI, which is where a moving toolchain is supposed to break us first. tests/test_stage3_surfaces.py reads action.yml for that check: run, green. 3. docs/proposals/README.md: only the P-037 row moved, to say something true in this tree (Stage 3 landed, so the ruling's post-cutover condition is met). The P-036 row is untouched — importing a dangling link into the proposals index to carry P-036 bookkeeping through a P-037 change is not a trade worth making. MEASURED HERE ruff check . All checks passed! mypy (repo config, --strict) Success: no issues found in 54 source files tests/test_stage3_surfaces.py OK — 64 launcher invocations, 24 explicit, rc=0 formal/p037-kernel: cargo fmt --check clean formal/p037-kernel: cargo clippy clean formal/p037-kernel: cargo test 37 passed, 0 failed formal/p037-kernel: 15 fast Kani harnesses 15/15 VERIFICATION:- SUCCESSFUL scripts/p037_controls.py --engine both 4/4 all match scripts/p037_controls.py --post-a1 MISMATCH 4/4, rc=1 (expected until A1) Refs #304, #262. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01376o4syzCem5aQ6NssxwX2
1 parent 63148d0 commit afeca38

39 files changed

Lines changed: 4508 additions & 96 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,64 @@ jobs:
7272
- name: cargo test
7373
run: cargo test
7474

75+
# The P-037 formal kernel (formal/p037-kernel, docs/notes/p037-formal-kernel.md):
76+
# its own workspace root, a member of nothing, wired to nothing — the pure
77+
# guarded-transfer algebra checked twice over the same functions, by plain
78+
# test twins and by Kani proof harnesses. The PR gate is fmt + clippy + the
79+
# twins + the FAST harnesses (value-level laws, the G-A2 floor, the one-step
80+
# lemmas; well under a minute of CBMC in total). The whole-solver harnesses
81+
# take minutes each and run in formal-p037-gate.yml on a schedule / on
82+
# demand — the owner's split after the A0 spike, so the inner loop never
83+
# pays for a proof it does not need on every push.
84+
#
85+
# `toolchain: stable` here is deliberate and matches `rust-core` directly
86+
# above. The pinned rustc that #262 Stage 3 requires is a property of
87+
# action.yml — the CONSUMER-facing distribution surface, where a moving
88+
# toolchain would move what users get — not of this repository's own CI,
89+
# which is where a moving toolchain is supposed to break us first.
90+
formal-p037:
91+
name: formal kernel (fmt + clippy + twins + fast Kani)
92+
runs-on: ubuntu-latest
93+
defaults:
94+
run:
95+
working-directory: formal/p037-kernel
96+
steps:
97+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
98+
- uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master, 2026-07-10
99+
with:
100+
toolchain: stable
101+
components: rustfmt, clippy
102+
- name: cargo fmt --check
103+
run: cargo fmt --check
104+
- name: cargo clippy (the rust/ workspace lints, copied verbatim)
105+
run: cargo clippy --all-targets
106+
- name: cargo test (the exhaustive / randomized twins)
107+
run: cargo test
108+
- name: install Kani (pinned) and its toolchain bundle
109+
run: |
110+
cargo install --locked kani-verifier --version 0.68.0
111+
cargo kani setup
112+
- name: fast Kani harnesses (value-level laws, floor, one-step lemmas)
113+
run: |
114+
set -e
115+
for h in \
116+
k1_transfer_join_laws k1_transfer_order_is_a_partial_order k1_cells_join_laws \
117+
k2_election_join_laws \
118+
k3_reads_and_contributions_are_monotone \
119+
k4_import_is_monotone_and_conflict_propagates \
120+
k5_collapse_monotone_and_join_morphism \
121+
k6_consume_only_through_a_selected_or_unanimous_must \
122+
k7_no_fabricated_consume \
123+
k8_involutions \
124+
k9_residual_bottom_lemma_all_three_groundings \
125+
k10a_step_is_monotone_in_the_state \
126+
k10e_election_step_is_monotone_in_the_state \
127+
k11_one_step_lax_simulation \
128+
k12a_step_keeps_uncond_coordinates_diagonal; do
129+
echo "== $h"
130+
cargo kani --harness "$h"
131+
done
132+
75133
# P-022 step 7b (#261) — the production OwnIR executable's parity replay, on
76134
# BOTH platforms. The Python half of this contract is gated by the `tests`
77135
# matrix above (`tests/test_cli_ownir_fixtures.py` is auto-discovered like
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: formal-p037-gate
2+
3+
# The heavy half of the P-037 formal kernel's proof harnesses
4+
# (formal/p037-kernel): the whole-solver statements — least fixpoint at the
5+
# full 3-coordinate bound, chaotic = Jacobi, the G-T2a lfp form, G-T2b, and
6+
# Uncond-stays-diagonal at the lfp. Minutes of CBMC each, ~15 minutes in all;
7+
# the owner's ruling after the A0 spike keeps them off the PR gate (ci.yml's
8+
# formal-p037 job runs the fast half on every push) and here, nightly and on
9+
# demand. A red run here is a real finding about the kernel or the contract,
10+
# never a flake to re-run: every harness is deterministic.
11+
12+
permissions:
13+
contents: read
14+
15+
on:
16+
schedule:
17+
- cron: "17 3 * * *"
18+
workflow_dispatch:
19+
20+
jobs:
21+
heavy-kani:
22+
name: formal kernel (whole-solver Kani harnesses)
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 90
25+
defaults:
26+
run:
27+
working-directory: formal/p037-kernel
28+
steps:
29+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
30+
- uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master, 2026-07-10
31+
with:
32+
toolchain: stable
33+
- name: install Kani (pinned) and its toolchain bundle
34+
run: |
35+
cargo install --locked kani-verifier --version 0.68.0
36+
cargo kani setup
37+
- name: whole-solver harnesses
38+
run: |
39+
set -e
40+
for h in \
41+
k10b_solve_is_a_fixpoint_below_every_fixpoint \
42+
k10c_chaotic_equals_jacobi_on_small_sccs \
43+
k10e_elect_is_a_fixpoint_below_every_fixpoint \
44+
k10e_chaotic_equals_jacobi_on_small_sccs \
45+
k11_lfp_lax_simulation_against_the_collapsed_system_on_small_sccs \
46+
k11b_legacy_observational_compatibility_on_small_sccs \
47+
k11_lfp_lax_simulation_against_today_post_finalization_on_small_sccs \
48+
k12b_lfp_keeps_uncond_coordinates_diagonal_on_small_sccs; do
49+
echo "== $h"
50+
cargo kani --harness "$h"
51+
done
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// FIXED (synthetic conformance, P-037 §8 row 2). `keep: false` reaches the
2+
// Dispose on the only path -> clean.
3+
using System;
4+
using System.IO;
5+
6+
static class GuardedEarlyReturn
7+
{
8+
static void Close(Stream s, bool keep)
9+
{
10+
if (keep)
11+
return;
12+
s.Dispose();
13+
}
14+
15+
static long Fine(string path)
16+
{
17+
var s = File.OpenRead(path);
18+
long len = s.Length;
19+
Close(s, keep: false);
20+
return len;
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// BUGGY (synthetic conformance, P-037 §8 row 2 — the same guard spelled as an
2+
// early return; the two spellings must converge in a guarded summary).
3+
using System;
4+
using System.IO;
5+
6+
static class GuardedEarlyReturn
7+
{
8+
static void Close(Stream s, bool keep)
9+
{
10+
if (keep)
11+
return;
12+
s.Dispose();
13+
}
14+
15+
static long Leak(string path)
16+
{
17+
var s = File.OpenRead(path);
18+
long len = s.Length;
19+
Close(s, keep: true); // returns before the Dispose -> leak
20+
return len;
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OWN001
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// FIXED (synthetic conformance, P-037 §8 row 1). The caller passes
2+
// `keep: false`, so `Close` disposes the stream on its only path: the
3+
// obligation moves into the helper and the caller must stay silent.
4+
using System;
5+
using System.IO;
6+
7+
static class Guarded
8+
{
9+
static void Close(Stream s, bool keep)
10+
{
11+
if (!keep)
12+
{
13+
s.Dispose();
14+
}
15+
}
16+
17+
static long Fine(string path)
18+
{
19+
var s = File.OpenRead(path);
20+
long len = s.Length;
21+
Close(s, keep: false); // provably disposes -> clean
22+
return len;
23+
}
24+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// BUGGY (synthetic conformance, P-037 §8 row 1 — the SectorTS `Teardown(bool)`
2+
// shape on an IDisposable parameter).
3+
//
4+
// `Close(s, keep)` disposes its parameter ONLY when `keep == false`. The caller
5+
// passes `keep: true`, so the stream is never disposed on any path -> leak.
6+
// A context-insensitive summary can only say "may consume"; the guarded
7+
// summary of P-037 selects the `no` cell at this call site and keeps the
8+
// obligation with the caller.
9+
using System;
10+
using System.IO;
11+
12+
static class Guarded
13+
{
14+
static void Close(Stream s, bool keep)
15+
{
16+
if (!keep)
17+
{
18+
s.Dispose();
19+
}
20+
}
21+
22+
static long Leak(string path)
23+
{
24+
var s = File.OpenRead(path);
25+
long len = s.Length;
26+
Close(s, keep: true); // provably does NOT dispose -> leak
27+
return len;
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OWN001
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// FIXED (synthetic conformance, P-037 §8 row 8). `Outer(s, stop: true)` becomes
2+
// `Inner(s, keep: false)` -> disposed -> clean.
3+
using System;
4+
using System.IO;
5+
6+
static class GuardedNegation
7+
{
8+
static void Inner(Stream s, bool keep)
9+
{
10+
if (!keep)
11+
{
12+
s.Dispose();
13+
}
14+
}
15+
16+
static void Outer(Stream s, bool stop)
17+
{
18+
Inner(s, !stop);
19+
}
20+
21+
static long Fine(string path)
22+
{
23+
var s = File.OpenRead(path);
24+
long len = s.Length;
25+
Outer(s, stop: true);
26+
return len;
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// BUGGY (synthetic conformance, P-037 §8 row 8 — the wrapper NEGATES the flag
2+
// on the edge: `Inner(s, !stop)`; the cells swap).
3+
using System;
4+
using System.IO;
5+
6+
static class GuardedNegation
7+
{
8+
static void Inner(Stream s, bool keep)
9+
{
10+
if (!keep)
11+
{
12+
s.Dispose();
13+
}
14+
}
15+
16+
static void Outer(Stream s, bool stop)
17+
{
18+
Inner(s, !stop); // stop == false => keep == true
19+
}
20+
21+
static long Leak(string path)
22+
{
23+
var s = File.OpenRead(path);
24+
long len = s.Length;
25+
Outer(s, stop: false); // Inner(s, keep: true) never disposes -> leak
26+
return len;
27+
}
28+
}

0 commit comments

Comments
 (0)