From 451ccef989315571c3f04245634bff3b680af3e1 Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 12 Nov 2026 15:41:14 -0500 Subject: [PATCH 1/2] feat: certify declarative JSON symmetry with exact storage Admit loader-certified declarative models across all exact symmetry strategies and preserve original execution identities. Validate complete model provenance and stored state type before callbacks, route checked products consistently, and authenticate positive report observations. Capture committed declarative diagnostics without exposing failed-attempt writes. Include independent finite oracles, consumer regressions, fresh mutation measurements, and the updated Spec 92 contract and evidence ledger. Approximate declarative support remains gated for L2. Co-authored-by: Codex --- .github/workflows/build.yml | 3 +- README.md | 23 +- .../92-certified-declarative-symmetry.md | 149 +++++++++ docs/plans/declarative-symmetry-contract.md | 11 +- docs/plans/future-work.md | 2 +- docs/plans/post-task10-follow-ups.md | 4 +- .../92-certified-declarative-symmetry.md | 75 +++-- .../93-approximate-declarative-symmetry.md | 8 +- docs/visualizer-e2e.mjs | 25 ++ docs/visualizer-normalize-check.mjs | 31 ++ docs/visualizer.js | 7 +- examples/programs/README.md | 10 + .../samhb/interleave/InterleaveRunner.java | 22 +- .../java/dev/samhb/interleave/TestResult.java | 14 +- .../java/dev/samhb/interleave/cli/Main.java | 16 +- .../dev/samhb/interleave/core/Program.java | 8 + .../samhb/interleave/dpor/DporExplorer.java | 4 +- .../interleave/format/dsl/DslInvariant.java | 39 +++ .../interleave/format/dsl/DslLoader.java | 13 +- .../interleave/format/dsl/DynamicStep.java | 75 +++++ .../format/dsl/SourceInstruction.java | 2 +- .../interleave/format/dsl/SourceSymmetry.java | 52 ++- .../interleave/por/StaticPorExplorer.java | 2 +- .../interleave/report/BenchmarkHarness.java | 16 +- .../interleave/report/BenchmarkResult.java | 12 +- .../report/SoundnessAttestation.java | 73 ++++- .../search/BitstateSymmetryStateStore.java | 3 + .../search/SymmetryDfsExplorer.java | 16 +- .../interleave/search/SymmetryRunContext.java | 10 +- .../interleave/search/SymmetryStateStore.java | 18 +- .../interleave/search/TraceReplayer.java | 40 +++ .../DeclarativeSymmetryRunTest.java | 143 +++++++++ .../dev/samhb/interleave/cli/MainTest.java | 63 ++++ .../DeclarativeSymmetryEligibilityTest.java | 216 +++++++++++++ .../DeclarativeSymmetryAttestationTest.java | 173 ++++++++++ .../DeclarativeSnapshotCaptureTest.java | 55 ++++ .../search/DeclarativeSymmetryOracleTest.java | 296 ++++++++++++++++++ .../dsl/symmetry-committed-failure.json | 10 + 38 files changed, 1625 insertions(+), 114 deletions(-) create mode 100644 docs/measurements/92-certified-declarative-symmetry.md create mode 100644 src/test/java/dev/samhb/interleave/DeclarativeSymmetryRunTest.java create mode 100644 src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java create mode 100644 src/test/java/dev/samhb/interleave/report/DeclarativeSymmetryAttestationTest.java create mode 100644 src/test/java/dev/samhb/interleave/search/DeclarativeSnapshotCaptureTest.java create mode 100644 src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java create mode 100644 src/test/resources/dsl/symmetry-committed-failure.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f6de3f..6ae6864 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,10 +48,11 @@ jobs: cache: gradle - name: Generate and validate fresh source report - run: ./gradlew test --tests dev.samhb.interleave.format.SourceProgramLoaderTest --tests dev.samhb.interleave.format.SourceAssertionTest --tests dev.samhb.interleave.cli.MainTest.cutoffSimplificationProducesDirectTrace --tests dev.samhb.interleave.cli.MainTest.sourceSymmetryCliCountsAndReportIdentity --tests dev.samhb.interleave.cli.MainTest.approximateSymmetryCliReportIdentity --tests dev.samhb.interleave.cli.MainTest.approximateCbsCliArtifacts --tests dev.samhb.interleave.cli.MainTest.approximateDporAndAllStrategyArtifacts --tests dev.samhb.interleave.ApproximateDporRunTest.dporRunnerKeepsApproximationAndActualPartialPaths --tests dev.samhb.interleave.ApproximateCbsIterationTest.ownedSymmetrySupportsCbsAndGlobalResourceAllowance --tests dev.samhb.interleave.ApproximateSymmetryRunTest.runnersRetainPrecisionLimitsAndIsolation --tests dev.samhb.interleave.cli.MainTest.shortestCutoffProducesProofArtifacts --tests dev.samhb.interleave.ResourcePrefixJsonTest --no-daemon + run: ./gradlew test --tests dev.samhb.interleave.format.SourceProgramLoaderTest --tests dev.samhb.interleave.format.SourceAssertionTest --tests dev.samhb.interleave.cli.MainTest.cutoffSimplificationProducesDirectTrace --tests dev.samhb.interleave.cli.MainTest.sourceSymmetryCliCountsAndReportIdentity --tests dev.samhb.interleave.cli.MainTest.approximateSymmetryCliReportIdentity --tests dev.samhb.interleave.cli.MainTest.approximateCbsCliArtifacts --tests dev.samhb.interleave.cli.MainTest.approximateDporAndAllStrategyArtifacts --tests dev.samhb.interleave.ApproximateDporRunTest.dporRunnerKeepsApproximationAndActualPartialPaths --tests dev.samhb.interleave.ApproximateCbsIterationTest.ownedSymmetrySupportsCbsAndGlobalResourceAllowance --tests dev.samhb.interleave.ApproximateSymmetryRunTest.runnersRetainPrecisionLimitsAndIsolation --tests dev.samhb.interleave.cli.MainTest.shortestCutoffProducesProofArtifacts --tests dev.samhb.interleave.ResourcePrefixJsonTest --tests dev.samhb.interleave.cli.MainTest.declarativeSymmetryCliSupportsExactMatrix --tests dev.samhb.interleave.DeclarativeSymmetryRunTest.exactRunsRemainIsolatedAndEmitResourceFixtures --tests dev.samhb.interleave.report.DeclarativeSymmetryAttestationTest.checkedFailureSnapshotsRetainCommittedPrefix --no-daemon - name: Run visualizer test suite env: + DECLARATIVE_SYMMETRY_DIR: build SOURCE_TRACE_JSON: build/source-visualizer.json SOURCE_ASSERTION_JSON: build/source-assertion-visualizer.json SOURCE_SIMPLIFIED_CUTOFF_JSON: build/source-simplified-cutoff.json diff --git a/README.md b/README.md index b31bf81..0dcdb97 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Available bugs: `peterson`, `broken-peterson`, `broken-peterson-v2`, `deadlock`, | `--all` | Run entire corpus | | `--file ` | Load program from JSON file | | `--source ` | Load a bounded concurrent `.ilv` source model | -| `--symmetry` | Opt-in source-thread symmetry; requires `--source --store exact` | +| `--symmetry` | Opt-in checked symmetry: source with exact/bitstate; certified declarative JSON with exact | ### Examples @@ -172,7 +172,8 @@ coverage percentage was produced. The local audit, Javadoc checks, and two local [Spec 75](docs/specs/active/75-thread-symmetry-canonicalization.md) provides thread-orbit keys and reversible owner mappings. [Spec 76](docs/specs/active/76-source-symmetry-exact-search.md) integrates conservative source eligibility and opt-in exact DFS. [Spec 77](docs/specs/active/77-source-symmetry-strategy-composition.md) composes exact -static POR, DPOR and CBS with checked source symmetry. Bitstate composition remains unsupported. +static POR, DPOR and CBS with checked source symmetry. Specs 89–91 add source bitstate composition; +[Spec 92](docs/specs/active/92-certified-declarative-symmetry.md) adds certified declarative exact symmetry. ## Tech stack @@ -469,6 +470,24 @@ snapshot; explicit replay adds intermediate states and separately labeled observ replay never changes the original INCOMPLETE verdict or independently authenticates uploaded JSON. Earlier recorded failures/deadlocks keep selection priority. No shortening or new CLI mode is selected. +B10 L1 enables the existing declarative JSON loader for exact symmetry across DFS, static POR, +DPOR and CBS, including HASHED/ORDERED library backends. For example: + +```bash +./gradlew --max-workers=1 -PpitestThreads=1 run --args="--file examples/programs/semaphore-declarative.json --symmetry --store exact --json" +``` + +Only loader-certified steps and absent/certified shared properties qualify; public constructor +objects, custom callbacks, mixed families and foreign declarations reject. Corresponding ordered +instructions and initial locals must match; owners observing `tid` remain fixed. Existing caps also +apply when trusted objects are reassembled. The semaphore has 8 concrete DFS positions and 5 orbits; +these fixture counts do not promise general speedups. FINAL declarative properties retain conservative +exhaustive reduction fallbacks. JSON keeps its existing error outcomes and original choices. Checked declarative failure snapshots +repeat the last committed values rather than exporting tentative writes; ordinary replay/capture +behavior stays unchanged. JSON does not acquire +source identity, cutoff simplification or authenticated resource prefixes. Approximate declarative +symmetry remains gated for [L2 / Spec 93](docs/specs/active/93-approximate-declarative-symmetry.md). + B9 approximate symmetry is delivered in the [three-phase spec set](docs/plans/approximate-symmetry-contract.md). K1 (DFS/static POR), K2 (CBS) and K3 (DPOR and final all-strategy consumers) are merged in PRs #132–134. B9 is complete. No total-process memory bound or diff --git a/docs/measurements/92-certified-declarative-symmetry.md b/docs/measurements/92-certified-declarative-symmetry.md new file mode 100644 index 0000000..f8ecb94 --- /dev/null +++ b/docs/measurements/92-certified-declarative-symmetry.md @@ -0,0 +1,149 @@ + +# 92 — Certified declarative exact symmetry evidence + +## Status and baseline + +L1 is implemented and locally verified; merge is pending. B10 remains in progress. Declarative +approximate admission is explicitly gated until L2. See [Spec 92](../specs/active/92-certified-declarative-symmetry.md) +and the [set contract](../plans/declarative-symmetry-contract.md). + +The fresh baseline is merged spec PR #135 at `c8ee55373701d0a7f131c752397460a61217aaf4`, measured +in a separate untouched worktree. Its build/strict Javadoc and **1,907 tests** passed without +failures/errors/skips. No B9 measurement is substituted for this baseline. + +## Implementation and independent checks + +| Contract | Evidence and actual boundary | +|---|---| +| Loader trust | Private DslLoader.ValidationPermit authorizes certified steps/properties; public constructors and null permits cannot issue certification. Ordinary constructor execution remains available. | +| Complete admission | All owner/declaration/property bindings checked, including fixed owners. Foreign declarations/callbacks, mixed families and invalid IDs reject; fixed unknown callbacks are rejected before enabledness can execute. | +| Reassembly | Empty/65-step owners reject; 64-step owners admit. Two owners with ten repeated 250-node steps admit at 5,000 nodes; another occurrence or a one-node property rejects. Counts include aliases and property nodes. | +| Independent graphs | Hand-written finite counter/semaphore/split rules enumerate concrete positions; explicit permutations enumerate orbits without production grouping/canonicalization/key helpers. DFS literals: counter 16/5, semaphore 8/5, split increment 13/8, with HASHED/ORDERED orbit-set equality. | +| Typed transitions | All six three-owner permutations and all corresponding action owners check scalar/boolean/array frame transport, guards, ordered effects, short-circuiting, private partial errors and shared-property observations. | +| Exact integration | DFS/static POR/DPOR/CBS across HASHED/ORDERED, direct checked DPOR root-product coverage, FINAL fallback, iterative CBS's real one-preemption failure, store clear/copy and mismatched-run rejection. | +| Positive observations | Actual final step errors with true invariants validate. Disabled/invalid choices, invented errors/violations, trailing actions, earlier property failures and foreign source/cutoff evidence reject. Empty root property failure validates. | +| Isolation/resources | Repeated and simultaneous runners retain counts; root/later state stops and deterministic root deadline preserve interruption identity without JSON source prefixes. | + +The semaphore 8/5 and counter 16/5 counts were also cross-checked outside Java by separate finite +constraint/counting routes during spec authoring. The split graph uses independent operational rules, +not recomputation with the implementation under test. The array/guard check is an equivariance test +over real declarative execution with independently transported frames; it is not a separate general +interpreter or a universal proof for arbitrary callbacks. + +## Verification and consumers + +- Admission, routing, CLI, viewer, attestation and failed-scratch regressions failed before their + fixes and passed afterward. No test was deleted or weakened to pass a production defect. +- Final full build and strict Javadoc: **1,943 tests**, zero failures/errors/skips. +- **218 browser assertions** pass with zero console errors, using fresh existing source artifacts + and declarative exact reports, completed/root/later traces and failed-effect library/CLI payloads. +- Private-member doclint passes for eight certification/attestation/state/capture files using + `-private -Xdoclint:all -Werror`; the ordinary Javadoc task also treats warnings as errors. +- An external Java 26 caller compiled against the actual built jar and Gson passes all four exact + strategies with both backends, non-source identity, approximate rejection, the stored-state type + query and committed failure snapshots `[0, 1, 1]`. +- Workflow YAML parses with Ruby's YAML parser. Local Markdown targets/anchors and `git diff --check` + pass. CI generates fresh report/library artifacts before normalization/browser checks. + +The final source compatibility regression initially used an invalid mixed-case source identifier; +correcting the test fixture preserves the lowercase grammar. Earlier integrated logs retain report +wording/test-wrapper failures and the snapshot red/green evidence. Failed commands are not passes. + +## Mutation measurements + +All runs use one Gradle worker and one PIT minion, the existing operators/test selection, and the +unchanged default mutation threshold. K = KILLED, S = SURVIVED, NC = NO_COVERAGE. Each row below is +an actual run; the scopes and revisions differ deliberately and their denominators are not comparable +as whole-checker percentages. No row has resource, timeout, run-error or other mutation statuses. + +| Scope / point measured | Baseline | Feature | Meaning | +|---|---|---|---| +| Default gate | 455/468 K + 13 S | 455/468 K + 13 S | Final production code; all 468 fingerprints and statuses identical. The subsequent source-only regression adds test coverage without changing production. | +| Broad affected census | 2,247/2,853 K + 177 S + 429 NC | 2,421/3,040 K + 184 S + 435 NC | Feature census precedes the later stored-state and committed-snapshot refinements. This is explicitly a point-in-time wide run. | +| Program / SourceSymmetry / SoundnessAttestation (including record) | 225/227 K + 2 S | 343/344 K + 1 S | Final stored-state guard and strict positive-witness checks. Program 29/29 K; SourceSymmetry 106/107 K; attestation plus record 208/208 K. | +| Source partial visitor, final test refinement | 30/43 K + 13 S | 38/47 K + 9 S | Added source partial-failure regression kills the source/JSON selector and source snapshot-call removals; zero NC. | +| Snapshot producers / TraceReplayer / DynamicStep | 756/833 K + 60 S + 17 NC | 839/914 K + 56 S + 19 NC | Final production and guard-outcome regression, before the additional source partial-failure test below. All 30 new capture-method mutants are killed. | + +Broad affected targets: DynamicStep, DslInvariant, DslLoader, SourceSymmetry, SourceInstruction, +SymmetryRunContext, SymmetryStateStore, BitstateSymmetryStateStore, DporExplorer, StaticPorExplorer, +InterleaveRunner, TestResult, Main, BenchmarkHarness and SoundnessAttestation, including nested types. +The later focused scopes supplement that run; they do not masquerade as another broad final run. +The source visitor refinement adds two kills to the preceding snapshot run (36/47 K + 11 S +for that class); the earlier snapshot total is retained as the actual run, not silently recomputed. +Separate baseline Program and TraceReplayer measurements are **27/27 K** and **202/203 K + 1 S**. + +Broad comparison: 2,209 shared fingerprints, 2,206 unchanged statuses, three changed; 644 baseline-only +and 831 feature-only fingerprints. Focused state/attestation comparison: 82 shared fingerprints with +all statuses unchanged, 145 baseline-only and 262 feature-only. Snapshot comparison: 733 shared, +726 unchanged statuses, seven changed, 100 baseline-only and 181 feature-only. Method rewrites can +reuse instruction indexes for different operations; these matches do not establish semantic lineage +or prove that every new fingerprint is an inherited kill. + +Residuals remain visible in raw XML. The focused SourceSymmetry survivor removes an explicit +`Objects.requireNonNull`; the next dereference still throws NPE. Keep the clear boundary check. +Unused DFS bookkeeping was deleted, not counted as a test kill. Main's broad census **33 K + 370 NC** +reflects child-JVM CLI execution outside PIT's instrumentation coverage; CLI/browser assertions do +not turn NC into kills. DynamicStep's prior uncovered guard-outcome mutation is killed by a literal +error-outcome regression. The snapshot population retains legacy/rewritten survivors and uncovered +paths; they are neither all confirmed bugs nor a claim of general equivalence. + +A custom SharedState adapter reproduced a real trust gap: a later copy could return DynamicState +although the retained initial object was custom. `Program.initialStateType` now exposes the actual +stored class without invoking another copy, allowing rejection before callbacks/dispatch. A separate +fresh-reader pass confirmed this keeps core independent of DSL types. + +## CodeRabbit review and dispositions + +CodeRabbit CLI 0.8.1 completed three actual implementation reviews, not heartbeat-only or skipped +reviews. The initial 32-file review returned three Major, one Minor and four Trivial findings: + +| Finding | Disposition | +|---|---| +| Major: remove certified INCOMPLETE expectation exception | Declined: approved Spec 92 R7 and the set contract require inconclusive handling, matching existing source policy. INCOMPLETE never fulfills an expected VIOLATION or seeds exact agreement. A focused expected-VIOLATION/actual-INCOMPLETE test checks that the label remains INCOMPLETE and Markdown says inconclusive, not matched. | +| Major: verify property provenance/foreign declaration | Already enforced by DslInvariant.symmetryNodes; public-constructor properties and foreign loader declarations reject before grouping. Public-property, absent-permit and foreign-declaration regressions verify those paths. No bypass fix was needed. | +| Major: verify declarative BITSTATE staging/harness restriction | Retained the explicit factory rejection required by L1 R5. Harness.runProgram now documents unsupported declarative BITSTATE; direct/harness/runner/CLI tests verify rejection across strategies. No premature L2 feature is enabled. | +| Minor: exact factory documentation | Corrected source-only summary/property/exception wording. | +| Trivial: browser verdict substring match | Changed new declarative assertions to exact trimmed badge equality. | +| Trivial: explicit CLI strategy identity | Assert the single returned row names the requested strategy. | +| Trivial: finite failing-property oracle | Added exhaustive split-increment final-value reference and concrete enabled failure checks across all four strategies/backends, without equating reduced visit counts to DFS. | +| Trivial: CLI guard reasons | Assert specific phase/store/source-only witness errors, not exit status alone. | + + +The second review completed 35 files with one Major and two Trivial findings. The Major was valid: +legacy snapshot capture could expose failed-attempt scratch values through checked full/partial +runner results and harness reports. The dedicated `TraceReplayer.captureDeclarativeSnapshots` now +validates actual enabled outcomes, records only committed states and repeats the last committed +snapshot for a failed final attempt. All checked JSON producer paths select it; ordinary replay and +source capture retain their existing APIs and semantics. The Trivial findings were patched with a +nonempty completion witness and meaningful false public-constructor property/root provenance tests. + +The third review completed 38 files with one Minor and two Trivial findings. All were patched: +remove contradictory pending-review ledger prose, assert CLI failure-report soundness explicitly, +and assert independently derived true/false property observations during typed permutation checks. +No CLI rerun is used merely to double-check these Minor/Trivial documentation/assertion changes. + +## Raw evidence + +Local artifacts use `/private/tmp/interleave-l1-` as a prefix. These are diagnostic artifacts, not +committed build products: + +- `baseline-build.log`, `baseline-default.xml`, `baseline-affected.xml`, `baseline-program.xml`, + `baseline-replayer.xml`, `baseline-focused.xml`, `baseline-snapshot-scope.xml`. +- `wide-affected.xml`, `final-focused.xml`, `final-snapshot-scope.xml`, `release-default.xml`; + `final-source-visitor.xml` and corresponding `.log` files and `focused-comparison.txt`, `snapshot-comparison.txt`, + `default-comparison.txt` preserve measurement/comparison details. +- `release-source-build.log`, `snapshot-browser.log`, `private-javadoc-final.log`; + `snapshots-red.log`, `snapshots-green.log` and `snapshots-contract.log` retain regression history. +- `coderabbit.ndjson`, `coderabbit-final.ndjson`, `coderabbit-snapshots.ndjson` retain completed + review output and finding severities. This ledger records independent dispositions. + +## Assurance limits + +Admission covers one trusted declarative family, not general Java, typed JSON, arbitrary callbacks +or semantic expression normalization. Generic non-source replay remains unchanged. The dedicated +snapshot API checks state/action execution; strict positive report attestation separately validates +property/terminal observations and provenance. Failed attempts publish no successor. FINAL properties +may conservatively fall back to exhaustive search. Representative visit counts are not general +speedups or counts of all concrete schedules, and no whole-process memory or whole-checker mutation +closure is claimed. Source resource-prefix authentication remains source-only. L2 approximate +support, CI results and merge are pending; none is claimed here. diff --git a/docs/plans/declarative-symmetry-contract.md b/docs/plans/declarative-symmetry-contract.md index 5d326ad..5f3c114 100644 --- a/docs/plans/declarative-symmetry-contract.md +++ b/docs/plans/declarative-symmetry-contract.md @@ -3,7 +3,7 @@ ## Objective and status -**Approved direction; specifications only. B10 is not implemented or complete.** Planning baseline: +**L1 implemented in this change; locally verified; merge pending. L2 planned. B10 remains in progress.** Planning baseline: main `b1c7586fc34542e919b3f82d1dece87ade7dec86`, after B9 / PR #134 merged at `3d5c09e`. Sam selected declarative JSON and the full DFS/static POR/DPOR/CBS exact/approximate matrix. This approval supersedes B9's stop-before-B10 boundary for this selected scope only. @@ -26,6 +26,9 @@ not enable a feature. Implementation PRs update their spec, tests, measurements a package-visible final nested type with a private constructor and a single private loader-held instance, never exposed by an accessor or returned model. Null permits reject before certification. No public certificate injection API or caller-declared observation proof is introduced. +- Program.initialStateType() is a read-only metadata query of the actual stored snapshot class, + invoking no model code. Certification requires DynamicState before another copy/initialization; + a custom state adapter returning DynamicState from deepCopy cannot establish trust. - A checked declarative model contains only certified DynamicStep objects, dense actual owner bindings, DynamicState with matching owner count, and an absent or certified DslInvariant. Every step/property must retain the same StateDecl object as the initial DynamicState. Trusted objects @@ -106,6 +109,12 @@ TestResult precision/incomplete handling, including no-trace and completed-trace exact/INCOMPLETE handling; L2 owns final BITSTATE absence checks. The resourcePrefix authentication branch remains strictly source-only. Ordinary unmarked JSON display behavior remains unchanged. +Checked declarative producers use the dedicated TraceReplayer.captureDeclarativeSnapshots diagnostic +method: replay enabled original choices through TransitionExecutor, capture committed configurations, +and repeat the previous state for a failed last attempt. Full/partial runner and harness paths share +this policy; legacy replay/capture methods stay unchanged. This closes tentative-write leakage without +inventing a committed successor or adding source identity. Captured values are not terminal proof. + Existing source/ordinary report behavior stays intact. L2 broadens BenchmarkResult approximate-PASS normalization to sourceModel OR symmetryReduction, retaining the BITSTATE condition. TestResult retains the precision emission established in L1 without inventing SOURCE identity. diff --git a/docs/plans/future-work.md b/docs/plans/future-work.md index 684c4ba..51e1c55 100644 --- a/docs/plans/future-work.md +++ b/docs/plans/future-work.md @@ -163,7 +163,7 @@ Sam selected #10 as the stopping point: finish it, explicitly report completion, | # | Item | LOE | Spec Needed? | Why | PR grouping / boundary | |---|---|---|---|---|---| -| 10 | Symmetry reduction — complete | High | Spec-set | [Spec 75](../specs/active/75-thread-symmetry-canonicalization.md), [Spec 76](../specs/active/76-source-symmetry-exact-search.md) and [Spec 77](../specs/active/77-source-symmetry-strategy-composition.md) shipped in PRs #117–119. Final composition merged at `d8ad49e`: checked source symmetry for exact DFS, static POR, DPOR and CBS, including iterative CBS and original-identity evidence. | Completed in three coherent stages: canonicalization/mappings; checked exact DFS and evidence; exact POR/DPOR/CBS composition with proof, callers and regressions. K1 / [Spec 89](../specs/active/89-approximate-symmetry-dfs-por.md) adds approximate bitstate composition for explicit DFS/static POR; [Spec 90](../specs/active/90-approximate-symmetry-cbs.md) adds CBS in K2; [Spec 91](../specs/active/91-approximate-symmetry-dpor.md) adds DPOR and all-strategy consumers in K3, completing B9 with PR #134 merged at `3d5c09e`. Arbitrary custom-store composition remains unsupported. [Spec 84](../specs/active/84-certified-symmetry-backends.md) adds a separately selected HASHED/ORDERED library storage choice under post-task-#10 B6. B10 [declarative JSON spec set](declarative-symmetry-contract.md) is selected: Specs 92/93 plan exact then approximate support; implementation has not started. #11/#12 remain excluded. | +| 10 | Symmetry reduction — complete | High | Spec-set | [Spec 75](../specs/active/75-thread-symmetry-canonicalization.md), [Spec 76](../specs/active/76-source-symmetry-exact-search.md) and [Spec 77](../specs/active/77-source-symmetry-strategy-composition.md) shipped in PRs #117–119. Final composition merged at `d8ad49e`: checked source symmetry for exact DFS, static POR, DPOR and CBS, including iterative CBS and original-identity evidence. | Completed in three coherent stages: canonicalization/mappings; checked exact DFS and evidence; exact POR/DPOR/CBS composition with proof, callers and regressions. K1 / [Spec 89](../specs/active/89-approximate-symmetry-dfs-por.md) adds approximate bitstate composition for explicit DFS/static POR; [Spec 90](../specs/active/90-approximate-symmetry-cbs.md) adds CBS in K2; [Spec 91](../specs/active/91-approximate-symmetry-dpor.md) adds DPOR and all-strategy consumers in K3, completing B9 with PR #134 merged at `3d5c09e`. Arbitrary custom-store composition remains unsupported. [Spec 84](../specs/active/84-certified-symmetry-backends.md) adds a separately selected HASHED/ORDERED library storage choice under post-task-#10 B6. B10 [declarative JSON spec set](declarative-symmetry-contract.md) is selected: Specs 92/93 merged in PR #135; L1 exact support is implemented in this change with local verification complete; merge pending, while L2 approximate support remains planned. #11/#12 remain excluded. | | 11 | Relaxed memory models | Very High | Spec-set | Fundamental semantics change — needs formal spec | Stage one selected memory model: state/transition foundations; complete execution and witness support; supported search/reduction integration. Keep each additional memory model separate. Exact PR count follows the semantics/proof scope. | | 12 | Real Java bytecode instrumentation | Very High | Spec-set | Entirely new subsystem with external deps (ASM/Javassist) | Stage supported-bytecode ingestion and rejection rules; execution/lowering with source identities and replay; CLI/library integration and differential corpus verification. Group broader bytecode coverage by supported capability, not individual opcodes. Exact PR count follows the selected Java subset. | diff --git a/docs/plans/post-task10-follow-ups.md b/docs/plans/post-task10-follow-ups.md index 32b3a8b..8e7319a 100644 --- a/docs/plans/post-task10-follow-ups.md +++ b/docs/plans/post-task10-follow-ups.md @@ -51,7 +51,7 @@ execution spec. No implementation is included in this document. | **10 / B7** | Offer a stronger shortest-cutoff witness guarantee | Legacy `--simplify-cutoff` stays deletion-1-minimal. Specs 85/86 add bounded library and opt-in CLI search for shortest length among the supplied witness’s subsequences, with best-found output and explicit proof/work metadata. This does not search every legal schedule or turn INCOMPLETE into PASS. | **L: 1–2 weeks for a bounded, precisely defined mode. High cost/completeness risk.** | Define the search domain and length metric first. Preserve the entire omitted cutoff value and nonterminal/property contract. Add an opt-in exact search with an explicit work budget; report proven shortest length only when every shorter candidate is excluded or the empty lower bound is reached. If stopped early, retain an honest best-found result with `shortestProven` false; it need not be deletion-1-minimal. Test tiny independently enumerated optima and resource stops. | **2 PRs — I1/I2:** I1 bundles bounded library search, immutable proof/work result, authentication, tests and evidence. I2 bundles opt-in CLI proof/work presentation and consumer/schema validation; legacy CLI behavior remains unchanged. | **Spec-set:** optimization domain/optimality plus resource and result semantics. | **I1 merged PR #127 at `fc10c62` — [Spec 85](../specs/active/85-shortest-cutoff-subsequence.md). I2 CLI proof/work presentation and consumer validation completed under [Spec 86](../specs/active/86-shortest-cutoff-cli.md), merged PR #128 at `2f578cf`. B7 is complete.** | [Spec 74 algorithm](../specs/active/74-source-cutoff-witness-simplification.md), [CutoffSimplifier](../../src/main/java/dev/samhb/interleave/minimize/CutoffSimplifier.java), [legacy simplifier tests](../../src/test/java/dev/samhb/interleave/minimize/CutoffSimplifierTest.java), [shortest-subsequence tests](../../src/test/java/dev/samhb/interleave/minimize/ShortestCutoffSubsequenceTest.java). | | **11 / B8** | Capture, replay and present resource-limited prefixes safely | `CutoffSimplifier` accepts reproducible loop/preemption cutoffs and rejects resource-only incomplete results. A host deadline, state limit or memory stop is not automatically an omitted modeled action that replay can reproduce. | **L: 1–2 weeks for a useful bounded prefix feature. High evidence-classification risk.** | Define a separate resource-result contract: authenticate/replay the committed prefix and preserve its external stop classification. Do not fabricate a LOOP_LIMIT/PREEMPTION_BOUND witness, reproduce a wall-clock deadline as model behavior, or label a shorter prefix PASS. Capture the actual interrupted prefix and authenticate its committed execution; expose replay observations separately from the original resource stop. Carry provenance through Java/JSON/viewer validation. Choice A is the complete selected scope; shortening and a new CLI mode remain unselected. | **2 PRs — J1/J2:** actual capture/authenticated replay under Spec 87, then Java JSON/viewer presentation under Spec 88. Publish sequentially; no shortening stages. | **Spec-set:** reproducible prefix versus external stop, simplification and compatibility/reporting. | **Choice A approved — [contract](resource-prefix-contract.md).** J1 capture/replay under [Spec 87](../specs/active/87-resource-prefix-evidence.md) merged in PR #129 at `9abbc4f` (1,852 tests/build/strict Javadoc, 60/60 new-module K and default mutation gate pass). J2 JSON/viewer presentation under [Spec 88](../specs/active/88-resource-prefix-presentation.md) merged in PR #130 at `1db7870` (1,862 tests/build/strict Javadoc, 97/97 resource-module K, unchanged default gate, 135 browser checks). B8 is complete. | [Spec 74 input contract](../specs/active/74-source-cutoff-witness-simplification.md), [trace/minimization contract](../specs/active/16-concurrent-program-parser/06-traces-replay-and-minimization.md), [CutoffSimplifier](../../src/main/java/dev/samhb/interleave/minimize/CutoffSimplifier.java). | | **12 / B9** | Combine symmetry with approximate bitstate storage | Exact symmetry supports all four strategies; approximate DFS/static POR, CBS and DPOR merged in K1/K2/K3. An approximate orbit store can introduce collisions on top of symmetry pruning, while CBS and DPOR retain additional scheduling context. Exact-store absence guarantees cannot simply be reused. | **L–XL: 2–4 weeks across the selected strategies. High assurance/reporting risk.** | Define the approximation contract and complete orbit/context encoding. Preserve CBS cost semantics and DPOR sleep-context requirements, report approximate status explicitly, retain the symmetry marker, and prevent exhaustive-absence claims. Validate collision behavior and independent verdict/witness oracles before enabling each supported strategy. Do not combine this with generic custom-backend support by default. | **3 complete PRs — K1/K2/K3:** shared membership with DFS/static POR and consumers; CBS cost/deepening and consumers; DPOR complete product membership and final all-strategy consumers. | **Spec-set:** approximate storage, strategy applicability and result/attestation guarantees. | **Complete: K1/K2/K3 merged in PRs #132–134; final merge `3d5c09e`.** [B9 spec set](approximate-symmetry-contract.md): all four strategies, library/CLI/reports, one shared CBS Bloom budget and approximate complete DPOR context. Specs 89–91 define sequential K1/K2/K3; no whole-process memory or speed guarantee. | [Spec 77 exclusions](../specs/active/77-source-symmetry-strategy-composition.md), [BitstateStore](../../src/main/java/dev/samhb/interleave/state/BitstateStore.java), [StateStore](../../src/main/java/dev/samhb/interleave/search/StateStore.java). | -| **13 / B10** | Certify declarative JSON symmetry | Selected extension: trusted format: declarative JSON through DslLoader. Current source-only certification, DPOR routing and precision consumers must be extended without admitting typed/registered models or arbitrary callbacks. JSON execution and evidence remain distinct from source. | **XL; high assurance risk. Two coherent implementation phases; re-estimate from each measured base.** | Add loader-held certification and model-wide admission checks; preserve structural grouping, ordered effects/errors and original owners. L1 delivers all exact strategies/backends with consumers and strict positive-witness checks; L2 reuses B9 complete products and one Bloom budget with truthful approximate reports. | **1 spec-only PR, then 2 implementation PRs — L1/L2:** complete exact certification/integration; complete approximate matrix and consumers. | **Spec-set:** [contract](declarative-symmetry-contract.md), [Spec 92](../specs/active/92-certified-declarative-symmetry.md), [Spec 93](../specs/active/93-approximate-declarative-symmetry.md). | **Selected; specs drafted, implementation not started.** All four strategies and exact HASHED/ORDERED plus BITSTATE selected. Publish/review specs first; complete B10 only after L2 merges, then stop before #11/#12 and parked work. | [SourceSymmetry.groups](../../src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java), [Spec 76](../specs/active/76-source-symmetry-exact-search.md), [Spec 77](../specs/active/77-source-symmetry-strategy-composition.md). | +| **13 / B10** | Certify declarative JSON symmetry | Selected extension: trusted format: declarative JSON through DslLoader. Current source-only certification, DPOR routing and precision consumers must be extended without admitting typed/registered models or arbitrary callbacks. JSON execution and evidence remain distinct from source. | **XL; high assurance risk. Two coherent implementation phases; re-estimate from each measured base.** | Add loader-held certification and model-wide admission checks; preserve structural grouping, ordered effects/errors and original owners. L1 delivers all exact strategies/backends with consumers and strict positive-witness checks; L2 reuses B9 complete products and one Bloom budget with truthful approximate reports. | **1 spec-only PR, then 2 implementation PRs — L1/L2:** complete exact certification/integration; complete approximate matrix and consumers. | **Spec-set:** [contract](declarative-symmetry-contract.md), [Spec 92](../specs/active/92-certified-declarative-symmetry.md), [Spec 93](../specs/active/93-approximate-declarative-symmetry.md). | **Specs merged in PR #135 at `c8ee553`; L1 implemented in this change, locally verified; merge pending. L2 planned; B10 remains in progress.** All four strategies and exact HASHED/ORDERED plus BITSTATE selected. Publish/review specs first; complete B10 only after L2 merges, then stop before #11/#12 and parked work. | [SourceSymmetry.groups](../../src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java), [Spec 76](../specs/active/76-source-symmetry-exact-search.md), [Spec 77](../specs/active/77-source-symmetry-strategy-composition.md). | ## Recommended PR sequence and dependencies @@ -139,7 +139,7 @@ and final returns merged in PR #125** at `a0b45b9` under [Spec 83](../specs/acti **B6 / H certified backend selection merged in PR #126** at `7c0072d` under [Spec 84](../specs/active/84-certified-symmetry-backends.md). **B7 / I1 bounded shortest-subsequence library search** merged PR #127 at `fc10c62` under [Spec 85](../specs/active/85-shortest-cutoff-subsequence.md). -I2 CLI proof/work presentation and consumer validation merged PR #128 at `2f578cf` under [Spec 86](../specs/active/86-shortest-cutoff-cli.md); **B7 is complete**. **B8 / J1 capture/replay merged in PR #129 at `9abbc4f`** under [Spec 87](../specs/active/87-resource-prefix-evidence.md); J2 JSON/viewer presentation merged in PR #130 at `1db7870` under [Spec 88](../specs/active/88-resource-prefix-presentation.md); B8 is complete. B9 planning is captured in the [B9 spec set](approximate-symmetry-contract.md), with K1/K2/K3 merged in PRs #132–134 and **B9 complete**. Sam subsequently selected **B10 declarative JSON certification** under the [new spec set](declarative-symmetry-contract.md): Specs 92/93 are drafted, implementation has not started. B10 uses two implementation PRs after the spec-only PR; mark complete after L2 merges and stop. Other B5 capabilities and arbitrary third-party +I2 CLI proof/work presentation and consumer validation merged PR #128 at `2f578cf` under [Spec 86](../specs/active/86-shortest-cutoff-cli.md); **B7 is complete**. **B8 / J1 capture/replay merged in PR #129 at `9abbc4f`** under [Spec 87](../specs/active/87-resource-prefix-evidence.md); J2 JSON/viewer presentation merged in PR #130 at `1db7870` under [Spec 88](../specs/active/88-resource-prefix-presentation.md); B8 is complete. B9 planning is captured in the [B9 spec set](approximate-symmetry-contract.md), with K1/K2/K3 merged in PRs #132–134 and **B9 complete**. Sam subsequently selected **B10 declarative JSON certification** under the [new spec set](declarative-symmetry-contract.md): Specs 92/93 merged in PR #135 at `c8ee553`; L1 exact implementation is in this change, with locally verified; merge pending. L2 remains planned. B10 uses two implementation PRs after the spec-only PR; mark complete after L2 merges and stop. Other B5 capabilities and arbitrary third-party backends remain unselected. This approval does not activate excluded roadmap work or require combining independent capabilities. diff --git a/docs/specs/active/92-certified-declarative-symmetry.md b/docs/specs/active/92-certified-declarative-symmetry.md index f04fa9e..2149c1f 100644 --- a/docs/specs/active/92-certified-declarative-symmetry.md +++ b/docs/specs/active/92-certified-declarative-symmetry.md @@ -7,22 +7,28 @@ Let validated declarative JSON models use checked symmetry through all four exac the existing library and --file CLI/report/viewer paths. Preserve declarative execution and original owner evidence while reusing the existing checked context/key contracts. -**Type: delta. Status: planned; no implementation or new verification run.** Baseline is main -`b1c7586fc34542e919b3f82d1dece87ade7dec86`. The +**Type: delta. Status: implemented; locally verified; merge pending.** Fresh baseline is +merged spec PR #135 at `c8ee55373701d0a7f131c752397460a61217aaf4`. The [B10 set contract](../../plans/declarative-symmetry-contract.md) owns shared terminology, interfaces, oracles and release boundaries. This spec owns L1 only; B10 completes after L2 merges. ## Scope - Module: declarative validation/certification, checked search routing and exact consumers. +- Adds a read-only Program.initialStateType() query in core/Program.java so certification checks + the stored snapshot type before invoking model copy/initialization code. This is metadata only, + not a certificate or execution interface; generic Program behavior remains unchanged. - Modifies `src/main/java/dev/samhb/interleave/format/dsl/{DslLoader,DynamicStep,DslInvariant,SourceSymmetry,SourceInstruction}.java`; SourceInstruction changes are limited to sharing exhaustive expression identity inspection. -- Modifies `src/main/java/dev/samhb/interleave/search/{SymmetryRunContext,SymmetryStateStore,BitstateSymmetryStateStore}.java`, +- Modifies `src/main/java/dev/samhb/interleave/search/{SymmetryRunContext,SymmetryStateStore,BitstateSymmetryStateStore,TraceReplayer}.java`, `src/main/java/dev/samhb/interleave/{InterleaveRunner,TestResult}.java`, `src/main/java/dev/samhb/interleave/{dpor/DporExplorer,por/StaticPorExplorer,cli/Main}.java` and `src/main/java/dev/samhb/interleave/report/{BenchmarkHarness,SoundnessAttestation}.java` for owned routing, API documentation, exact selection, narrow attestation and the L1 approximate guard. - No new public certificate or execution interface is selected. + `search/SymmetryDfsExplorer.java` and `report/BenchmarkResult.java` receive documentation-only + applicability updates; L2 still owns approximate report normalization. + The additive APIs are a read-only stored-type query and dedicated certified declarative snapshot + diagnostics; existing generic replay/execution interfaces retain their behavior. - Adds `src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java`, `src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java` and `src/test/java/dev/samhb/interleave/DeclarativeSymmetryRunTest.java`. Extends relevant existing @@ -60,7 +66,8 @@ larger limits, authenticated uploaded JSON, new dependencies or broad explorer r private-loader-held capability described in the set contract; same-package callers SHALL not mint certification with an absent/forged permit. No public opt-out SHALL exist. 2. **R2 — Certification.** WHEN checked symmetry binds a model, THE SYSTEM SHALL select one trusted - instruction family, validate actual dense owner/declaration/state/property bindings and infer groups + instruction family, verify the actual stored initial snapshot is DynamicState before further + copying/initialization, validate dense owner/declaration/state/property bindings and infer groups from complete ordered structural semantics and typed initial locals. Tid-observing owners SHALL stay fixed; empty eligible groups, foreign/custom/uncertified/mixed objects SHALL reject. Reassembled objects SHALL still satisfy 1–64 steps per owner and total step bounds and the 5,000-node model AST budget, with @@ -82,10 +89,13 @@ larger limits, authenticated uploaded JSON, new dependencies or broad explorer r SYSTEM SHALL attest actual enabled original-owner transitions and recorded outcomes, accepting a final real ASSERTION_FAILED or a false supplied invariant at the observed configuration. It SHALL reject malformed/invented witnesses and execution after an earlier failure/property violation. - Certification/execution errors SHALL produce failed attestation, never a passing fallback. + Source/cutoff evidence attached to a declarative violation SHALL reject rather than authenticate + invented diagnostics. Certification/execution errors SHALL produce failed attestation, never a passing fallback. 7. **R7 — Consumers and precision.** WHEN exact results are exported, THE SYSTEM SHALL retain the symmetry marker, EXACT identity, representative-count meaning, concrete witness categories and - bounded/resource incompleteness while leaving JSON models non-source. Certified declarative + bounded/resource incompleteness while leaving JSON models non-source. Failed-attempt diagnostic + snapshots SHALL repeat the last committed state, with one initial snapshot plus one per attempt; + tentative failed writes SHALL not be exported as a successor. Certified declarative symmetry INCOMPLETE DFS rows SHALL remain inconclusive under harness/attestation expectation checks, with shared certification rather than the VIOLATION-only helper authorizing that exception. All exact consumer paths @@ -173,7 +183,9 @@ budget during certification of a reassembled Program. Count each occurrence and the cap and reuse bounded validated expression metadata/counting; never expand an unbounded alias list or trust loader-time aggregate counts for a newly assembled Program. Shared exhaustive Expr identity inspection may be package-private on SourceInstruction for both callers; no separate expression evaluator is created. -DynamicStep already has straight-line next-PC semantics; do not add SourceStep/control metadata. +Program.initialStateType() returns the actual stored snapshot class without calling deepCopy. +Reject non-DynamicState snapshots before initialConfiguration; a custom copy that returns a trusted +state cannot establish provenance of the stored model. DynamicStep already has straight-line next-PC semantics; do not add SourceStep/control metadata. Use existing CheckedSymmetryStore dispatch for exact DPOR contexts, keeping value-only pruning bypassed. Extend only the source-or-checked predicate around its mapped sleep normalization/lookup. @@ -195,6 +207,14 @@ choices. With no failed action, accept only an actually false property at the la Handle malformed input/execution exceptions as failed checks. Leave generic TraceReplayer and source attestation unchanged, and qualify Markdown claims to match this new narrow check. +TraceReplayer.captureDeclarativeSnapshots is a dedicated diagnostic API for certified non-source +models. It checks model eligibility, enabled original choices and actual outcomes via TransitionExecutor, +then captures only committed configurations. A final failed attempt repeats the preceding immutable +snapshot to retain choice/state alignment; trailing execution after failure rejects. Runner full and +partial conversion and harness snapshot creation select this method only for declarative symmetry. +Ordinary captureSnapshots/replay and source capture stay unchanged. Snapshot capture does not prove +terminal properties or authenticate uploaded JSON; private attestation retains those separate checks. + Update docs/visualizer.js normalization predicates for exact symmetry TestResult payloads to use source-or-symmetry without treating JSON as SOURCE. Handle no selected trace and selected completed trace cases, plus actual INCOMPLETE/resource classification. Keep ordinary unmarked JSON display and @@ -207,18 +227,27 @@ as an exact agreement seed. Preserve existing source exceptions. ## Current State -- [verified] DslLoader bounds/types its ASTs, builds DynamicState/DynamicStep and optional DslInvariant, - and rejects local/tid property observations. DynamicStep effects are ordered and erroring guards - remain enabled to expose ASSERTION_FAILED. -- [verified] DynamicStep/DslInvariant are final with public constructors; class identity alone is - insufficient evidence of loader validation. StateDecl and expression/effect value structures are - immutable; initial arrays are defensively copied. -- [verified] SourceSymmetry rejects JSON. DPOR checked sleep lookup is nested under isSource(); - final-only declarative properties lack final observations and conservatively fall back. -- [verified] Generic non-source replay does not validate enabled choices or terminal violation; - existing attestation can reject a real declarative step failure when the supplied invariant holds. -- [unverified] New certification, all-strategy exact preservation, fixture counts through the Java - implementation and affected mutation populations require L1 implementation/measurement. +- [verified] At merged baseline c8ee553, source-only admission, source-gated DPOR coverage and + source-gated precision prevented the new mode. Red admission/routing/CLI/viewer/attestation + regressions were observed before the corresponding fixes. +- [verified] DslLoader issues the inaccessible ValidationPermit; public constructors remain + uncertified. Groups check every owner/declaration/property and reassembled step/AST bounds. +- [verified] All four exact strategies/backends work through existing interfaces. Checked DPOR + uses normalized mapped products for declarative models; FINAL retains conservative fallback. +- [verified] Private attestation checks enabled actual transitions/terminal observations, rejects + foreign diagnostics and preserves failed-attempt/no-successor behavior. Ordinary report wording + remains unchanged; JSON has no fabricated source identity/resource prefix. +- [verified] Full build, strict Javadoc and 1,943 tests pass with no failures/errors/skips. All 218 + browser checks and an external Java 26 built-jar consumer pass. See the + [L1 ledger](../../measurements/92-certified-declarative-symmetry.md) for scope and provenance. +- [verified] The reproduced custom-copy adapter is rejected by a stored-type metadata guard before + another copy callback. Program.initialStateType exposes only the actual stored snapshot class; + generic initialization and source identity remain unchanged. Its regression failed before the fix + and passes afterward. +- [verified] Default PIT retains all 468 baseline fingerprints/statuses (455 K + 13 S). The broad + affected census and final focused mutation checks are recorded separately in the ledger. Three + actual CodeRabbit reviews completed; independently checked dispositions and patched findings are + recorded there. No L1 merge or B10 completion is claimed; L2 approximate admission stays gated. ## Tests @@ -269,3 +298,9 @@ regressions. Kill meaningful validation/routing/outcome mutants; record remainin The spec-only PR runs documentation/link/structure checks and per-spec CodeRabbit, not Java/PIT/browser feature tests. Implementation runs the complete relevant checks and publishes its measured ledger. Stop after publishing L1 and await Sam's merge update before L2; do not mark B10 complete here. + +## Implementation evidence + +The [L1 ledger](../../measurements/92-certified-declarative-symmetry.md) records fresh baselines, +red/green regressions, independent finite graphs/permutations, consumers and review outcomes. +Spec-authoring reviews are historical evidence; implementation has its own required review gate. diff --git a/docs/specs/active/93-approximate-declarative-symmetry.md b/docs/specs/active/93-approximate-declarative-symmetry.md index 39b8e65..ecf9e2f 100644 --- a/docs/specs/active/93-approximate-declarative-symmetry.md +++ b/docs/specs/active/93-approximate-declarative-symmetry.md @@ -7,7 +7,7 @@ Complete B10 by enabling certified declarative JSON symmetry with approximate bi across DFS, static POR, DPOR and CBS. Reuse B9's complete context encodings and L1's certification, concrete execution and witness checks; expose approximation honestly through every selected consumer. -**Type: delta. Status: planned; depends on unimplemented L1. No new verification run.** +**Type: delta. Status: planned; depends on unmerged L1. No new verification run.** The [B10 set contract](../../plans/declarative-symmetry-contract.md) owns common semantics/oracles; [Spec 92](92-certified-declarative-symmetry.md) owns certification and exact integration. Planning reference is `b1c7586fc34542e919b3f82d1dece87ade7dec86`; the implementation baseline must be the actual @@ -179,8 +179,10 @@ counts or guaranteed discovery of every exact failure. precision unless the selected consumer predicates are broadened without changing source identity. - [verified] Existing generic non-source replay checks recorded execution outcomes but not full enabledness/terminal claims. L1 therefore owns the stricter private symmetry attestation path. -- [unverified] L1 has not been implemented/merged. Its real base SHA, exact evidence, approximate - guard and reusable helper must be verified before beginning L2. +- [verified] L1 is implemented in the Spec 92 change, with an explicit approximate guard and shared + certification/attestation; its merge is pending. +- [unverified] The actual merged L1 SHA and freshly remeasured exact evidence remain prerequisites + for L2; an unmerged L1 worktree is not its implementation baseline. - [unverified] Declarative approximate context coverage, artifact consumers and mutation populations require new implementation measurements; no source fixture score proves them in advance. diff --git a/docs/visualizer-e2e.mjs b/docs/visualizer-e2e.mjs index 472eb62..986c719 100644 --- a/docs/visualizer-e2e.mjs +++ b/docs/visualizer-e2e.mjs @@ -303,6 +303,31 @@ async function runTests() { assert((await page.locator('#verdictBadge').textContent()).includes('PASS'), 'Symmetry report retains the actual PASS verdict'); } + if(process.env.DECLARATIVE_SYMMETRY_DIR){ + const directory=join(projectRoot,process.env.DECLARATIVE_SYMMETRY_DIR); + const report=JSON.parse(readFileSync(join(directory,'declarative-symmetry-exact-report.json'),'utf8')); + const payloads=report.benchmarks.map(row=>[JSON.stringify({...report,benchmarks:[row]}),'PASS']); + for(const [name,verdict] of [['completed','PASS'],['resource-1','INCOMPLETE'],['resource-2','INCOMPLETE']]){ + payloads.push([readFileSync(join(directory,'declarative-symmetry-'+name+'.json'),'utf8'),verdict]); + } + for(const name of ['failure-report','failure-library','failure-cli']){ + const payload=readFileSync(join(directory,'declarative-symmetry-'+name+'.json'),'utf8'); + const raw=JSON.parse(payload); + const trace=raw.benchmarks ? raw.benchmarks[0].failingTrace : raw.failingTraces[0]; + assert(trace.states.at(-1).fields.x===1 && trace.states.every(state=>state.fields.x!==7),'Failed declarative attempt retains committed snapshots'); + payloads.push([payload,'VIOLATION']); + } + for(const [payload,verdict] of payloads){ + await page.locator('#clearBtn').click();await page.locator('#paste').fill(payload); + await page.locator('#loadPaste').click(); + await page.waitForFunction(()=>document.querySelector('#meta')?.textContent.includes('Thread symmetry')); + const meta=await page.locator('#meta').textContent(); + assert(meta.includes('EXACT') && meta.includes('representative visits'),'Declarative producer retains exact representative identity'); + assert((await page.locator('#verdictBadge').textContent()).trim()===verdict,'Declarative producer retains '+verdict); + assert(!(await page.locator('#error').getAttribute('class')).includes('show'),'Declarative producer loads without error'); + } + } + if(process.env.SOURCE_APPROXIMATE_SYMMETRY_JSON){ const payload = readFileSync(join(projectRoot, process.env.SOURCE_APPROXIMATE_SYMMETRY_JSON), 'utf8'); const row = JSON.parse(payload).benchmarks[0]; diff --git a/docs/visualizer-normalize-check.mjs b/docs/visualizer-normalize-check.mjs index ad9c838..03b3e06 100644 --- a/docs/visualizer-normalize-check.mjs +++ b/docs/visualizer-normalize-check.mjs @@ -35,6 +35,37 @@ for (const raw of [ ]) assert.equal(normalize(raw).meta.symmetryReduction, true); assert.equal(normalize({benchmarks:[{verdict:'PASS',symmetryReduction:'true'}]}).meta.symmetryReduction, false); +// Certified declarative exact results retain precision and incomplete status without SOURCE identity. +for(const traces of [[],[{threads:[0],outcome:'COMPLETED'}]]){ + const raw={symmetryReduction:true,storeType:'EXACT',completedTraces:traces,hasViolation:false}; + assert.equal(normalize(raw).meta.verdict,'PASS'); + assert.equal(normalize({...raw,limitExceeded:true}).meta.verdict,'INCOMPLETE'); +} +assert.equal(normalize({symmetryReduction:'true',storeType:'EXACT',completedTraces:[],limitExceeded:true}).meta.verdict,'LIMIT EXCEEDED'); + +if(process.env.DECLARATIVE_SYMMETRY_DIR){ + const directory=process.env.DECLARATIVE_SYMMETRY_DIR; + const report=JSON.parse(read(directory+'/declarative-symmetry-exact-report.json')); + assert.equal(report.benchmarks.length,4); + for(const row of report.benchmarks){ + const value=normalize({...report,benchmarks:[row]}); + assert.equal(value.meta.symmetryReduction,true);assert.equal(value.meta.storeType,'EXACT'); + assert.equal(value.meta.verdict,'PASS');assert.equal(row.programKind,undefined); + } + for(const name of ['failure-report','failure-library','failure-cli']){ + const raw=JSON.parse(read(directory+'/declarative-symmetry-'+name+'.json')); + const value=normalize(raw);assert.equal(value.meta.verdict,'VIOLATION'); + assert.equal(value.trace.states.at(-1).fields.x,1); + assert(value.trace.states.every(state=>state.fields.x!==7)); + } + for(const [name,verdict] of [['completed','PASS'],['resource-1','INCOMPLETE'],['resource-2','INCOMPLETE']]){ + const raw=JSON.parse(read(directory+'/declarative-symmetry-'+name+'.json')); + assert.equal(raw.programKind,undefined);assert.equal(raw.resourcePrefix,undefined); + const value=normalize(raw);assert.equal(value.meta.verdict,verdict); + assert.equal(value.meta.symmetryReduction,true);assert.equal(value.meta.storeType,'EXACT'); + } +} + // Fresh producer artifact verifies the combined symmetry/approximate shape used by browser CI. if(process.env.SOURCE_APPROXIMATE_SYMMETRY_JSON){ const normalized = normalize(JSON.parse(read(process.env.SOURCE_APPROXIMATE_SYMMETRY_JSON))); diff --git a/docs/visualizer.js b/docs/visualizer.js index 203e522..56d5eb3 100644 --- a/docs/visualizer.js +++ b/docs/visualizer.js @@ -248,6 +248,7 @@ function normalize(raw){ return { trace: { threads: [], outcome: entry.verdict || 'PASS', programHash: entry.bug }, meta: { ...runDiagnostics(entry), verdict: entry.verdict, strategy: entry.strategy, storeType: entry.storeType, statesExplored: entry.statesExplored, wallTimeMs: entry.wallTimeMs, heapDeltaBytes: entry.heapDeltaBytes, bug: entry.bug } }; } if(Array.isArray(raw.failingTraces) || Array.isArray(raw.deadlockedTraces) || Array.isArray(raw.completedTraces) || Array.isArray(raw.incompleteTraces)){ + const checkedResult = raw.programKind==='SOURCE' || raw.symmetryReduction===true; const pick = (arr) => arr && arr.length ? arr[0] : null; // Earlier conclusive failures retain priority; otherwise show the actual interrupted position // before modeled cutoffs or completed paths. A completed path cannot establish exhaustive PASS. @@ -262,7 +263,7 @@ function normalize(raw){ tr ||= pick(raw.incompleteTraces) || pick(raw.completedTraces); if(!tr) { const incomplete = raw.limitExceeded === true && !raw.hasViolation; - const verdict = raw.hasViolation ? 'VIOLATION' : incomplete ? (raw.programKind==='SOURCE' ? 'INCOMPLETE' : 'LIMIT EXCEEDED') : (raw.programKind==='SOURCE' ? (raw.storeType==='BITSTATE' ? 'APPROXIMATE_PASS' : raw.storeType==='EXACT' ? 'PASS' : 'UNKNOWN') : 'PASS'); + const verdict = raw.hasViolation ? 'VIOLATION' : incomplete ? (checkedResult ? 'INCOMPLETE' : 'LIMIT EXCEEDED') : (checkedResult ? (raw.storeType==='BITSTATE' ? 'APPROXIMATE_PASS' : raw.storeType==='EXACT' ? 'PASS' : 'UNKNOWN') : 'PASS'); return { trace: { threads: [], outcome: verdict }, meta: { ...runDiagnostics(raw), verdict, strategy: raw.strategy, statesExplored: raw.statesExplored, wallTimeMs: raw.wallTimeMs, heapDeltaBytes: raw.heapDeltaBytes, limitExceeded: raw.limitExceeded === true } }; } const threads = tr.threads || tr.threadIds; @@ -272,8 +273,8 @@ function normalize(raw){ // did) are different states and are never merged: the latter arrives here as tr.outcome. // Rendering a bounded run that proved nothing as PASS is the most misleading thing this // viewer can do, so it must not be reachable. - let outcome = incomplete ? (raw.programKind==='SOURCE' ? 'INCOMPLETE' : 'LIMIT EXCEEDED') : (tr.outcome || (raw.hasViolation ? 'VIOLATION' : 'PASS')); - if(raw.programKind==='SOURCE' && ['PASS','COMPLETED'].includes(outcome) && ['EXACT','BITSTATE'].includes(raw.storeType)) outcome = raw.storeType==='BITSTATE' ? 'APPROXIMATE_PASS' : 'PASS'; + let outcome = incomplete ? (checkedResult ? 'INCOMPLETE' : 'LIMIT EXCEEDED') : (tr.outcome || (raw.hasViolation ? 'VIOLATION' : 'PASS')); + if(checkedResult && ['PASS','COMPLETED'].includes(outcome) && ['EXACT','BITSTATE'].includes(raw.storeType)) outcome = raw.storeType==='BITSTATE' ? 'APPROXIMATE_PASS' : 'PASS'; return { trace: { ...diagnostics(tr, threads, outcome), threads, outcomes: tr.outcomes, outcome, programHash: tr.programHash, states: tr.states }, meta: { ...runDiagnostics(raw), verdict: outcome, strategy: raw.strategy, statesExplored: raw.statesExplored, wallTimeMs: raw.wallTimeMs, heapDeltaBytes: raw.heapDeltaBytes, hasViolation: raw.hasViolation, limitExceeded: raw.limitExceeded === true } }; } throw new Error('Unrecognized shape — expected TraceRecord {threads}, TestResult {failingTraces|incompleteTraces}, or ReportWriter {benchmarks}.'); diff --git a/examples/programs/README.md b/examples/programs/README.md index fa84676..f2486fc 100644 --- a/examples/programs/README.md +++ b/examples/programs/README.md @@ -8,6 +8,16 @@ Curated JSON programs for teaching and verification. Load via `ProgramLoader` or | `bounded-buffer-declarative.json` | declarative `buf[3], head, tail, count, capacity` | `count >= 0 && count <= capacity && count <= 3 && head >= 0 && head < 3 && tail >= 0 && tail < 3` | Producer/consumer over a capacity-3 ring buffer with guarded `count < capacity`/`count > 0` steps — teaches bounded-buffer safety and circular index correctness. | | `semaphore-declarative.json` | declarative `permits` | `permits >= 0` | Binary semaphore with `acquire` (`permits > 0` guard, `permits--`) and `release` (`permits++`) — teaches mutual exclusion via permits. | +## Certified declarative symmetry + +The semaphore supports `--file examples/programs/semaphore-declarative.json --symmetry --store exact`. +Omitting --strategy runs DFS/static POR/DPOR/CBS. Exact DFS visits 5 orbit representatives rather +than 8 concrete positions. Certification requires matching ordered instructions and initial locals; +loader provenance and existing work limits also apply to reassembled models. Typed JSON/custom +callbacks and declarative bitstate symmetry remain unsupported in this phase. JSON retains its +ordinary guards, sequential effects and error outcomes; source-only witness APIs remain separate. +See [Spec 92](../../docs/specs/active/92-certified-declarative-symmetry.md). + ## Readable source models Load `.ilv` files with `--source`; `--file` continues to mean JSON. All strategy and store options diff --git a/src/main/java/dev/samhb/interleave/InterleaveRunner.java b/src/main/java/dev/samhb/interleave/InterleaveRunner.java index 497b3ac..8c468e1 100644 --- a/src/main/java/dev/samhb/interleave/InterleaveRunner.java +++ b/src/main/java/dev/samhb/interleave/InterleaveRunner.java @@ -28,7 +28,7 @@ public final class InterleaveRunner implements Serializable { /** Strategy. */ private final Strategy strategy; - /** Whether checked source-orbit search is selected. */ + /** Whether checked model orbit search is selected. */ private final boolean symmetryReduction; /** Certified exact symmetry storage, immutable and independent of membership. */ private final SymmetryBackend symmetryBackend; @@ -101,7 +101,7 @@ private StateStore newRunStore(Program program) { * @return the test result including states explored, verdict, and traces * @throws IllegalStateException if iterative deepening receives a previously used store instance * @throws IllegalArgumentException if a bitstate store cannot represent the current preemption bound - * or requested symmetry fails source/property eligibility, or a custom factory supplies a symmetry store + * or requested symmetry fails trusted model/property eligibility, or a custom factory supplies a symmetry store * @throws ArithmeticException if the time limit overflows when converted to milliseconds */ public TestResult run(Program program) { @@ -257,7 +257,9 @@ public void onTraceCreated(Trace trace) { if (program != null && (program.isSource() || record.outcome() == TraceOutcome.VIOLATION || record.outcome() == TraceOutcome.DEADLOCK)) { try { - List states = new TraceReplayer().captureSnapshots(program, trace); + var replayer = new TraceReplayer(); + List states = symmetryReduction && !program.isSource() + ? replayer.captureDeclarativeSnapshots(program, trace) : replayer.captureSnapshots(program, trace); record = record.withStates(states); } catch (Exception ignored) { // Diagnostic snapshot enrichment is best-effort @@ -474,7 +476,8 @@ private TestResult convertToTestResult(DfsResult result, Program program, long w case VIOLATION -> { if (program != null && !program.isSource()) { try { - List states = replayer.captureSnapshots(program, trace); + List states = symmetryReduction + ? replayer.captureDeclarativeSnapshots(program, trace) : replayer.captureSnapshots(program, trace); record = record.withStates(states); } catch (Exception ignored) { // Diagnostic snapshot capture is best-effort @@ -485,7 +488,8 @@ record = record.withStates(states); case DEADLOCK -> { if (program != null && !program.isSource()) { try { - List states = replayer.captureSnapshots(program, trace); + List states = symmetryReduction + ? replayer.captureDeclarativeSnapshots(program, trace) : replayer.captureSnapshots(program, trace); record = record.withStates(states); } catch (Exception ignored) { // Diagnostic snapshot capture is best-effort @@ -535,7 +539,7 @@ public Builder() {} /** Strategy. */ private Strategy strategy = Strategy.DFS; - /** Opt-in checked source symmetry; ordinary verification remains unchanged. */ + /** Opt-in checked source/declarative symmetry; ordinary verification remains unchanged. */ private boolean symmetryReduction; /** Selected certified exact backend; membership is allocated only for each run/bound. */ private SymmetryBackend symmetryBackend = SymmetryBackend.HASHED; @@ -578,10 +582,10 @@ public Builder strategy(Strategy strategy) { } /** - * Selects checked source-orbit search, retaining original execution and trace identities. - * Requires a built-in strategy and owned storage, plus source/property eligibility checked at run time. + * Selects checked trusted-model orbit search, retaining original execution and trace identities. + * Requires a built-in strategy and owned storage, plus trusted model/property eligibility checked at run time. * For example, builder().symmetryReduction(true).build().run(sourceProgram) explores orbits. - * @param enabled whether to enable the conservative source symmetry mode + * @param enabled whether to enable conservative source/declarative symmetry * @return this builder */ public Builder symmetryReduction(boolean enabled) { diff --git a/src/main/java/dev/samhb/interleave/TestResult.java b/src/main/java/dev/samhb/interleave/TestResult.java index a236076..e9f82bd 100644 --- a/src/main/java/dev/samhb/interleave/TestResult.java +++ b/src/main/java/dev/samhb/interleave/TestResult.java @@ -15,7 +15,7 @@ * A changed UID deliberately prevents older readers from silently dropping symmetry metadata. */ public final class TestResult implements Serializable { - /** True only for checked source-orbit search results. */ + /** True only for checked model orbit search results. */ private final boolean symmetryReduction; /** Strategy. */ private final Strategy strategy; @@ -35,7 +35,7 @@ public final class TestResult implements Serializable { private final List incompleteTraces; /** Limit exceeded. */ private final boolean limitExceeded; - /** Whether an approximate store participated in this source run. */ + /** Whether an approximate store participated in this known run. */ private final Boolean approximate; /** Source reporting classification. */ private final boolean sourceModel; @@ -81,7 +81,7 @@ public TestResult(Strategy strategy, long statesExplored, long wallTimeMs, long * @param sourceModel whether source reporting rules apply * @param reason resource cause, or null * @param approximate true/false for a known store guarantee, null when unavailable - * @param symmetryReduction whether this result counts checked source representative visits + * @param symmetryReduction whether this result counts checked model representative visits * @param resourcePrefix captured resource path, or null * @throws IllegalArgumentException if the supplied run metadata contradicts a captured prefix */ @@ -146,8 +146,8 @@ public java.util.Optional resourcePrefix() { return java.util.Optional.ofNullable(resourcePrefix); } - /** Returns whether counts refer to checked source-orbit representatives. - * @return true for explicitly selected checked source symmetry + /** Returns whether counts refer to checked model orbit representatives. + * @return true for explicitly selected checked model symmetry */ public boolean symmetryReduction() { return symmetryReduction; } @@ -298,8 +298,8 @@ public String toJson() { sb.append(" \"heapDeltaBytes\": ").append(heapDeltaBytes).append(",\n"); sb.append(" \"hasViolation\": ").append(hasViolation()).append(",\n"); sb.append(" \"limitExceeded\": ").append(limitExceeded).append(",\n"); - if (sourceModel) { - sb.append(" \"programKind\": \"SOURCE\",\n"); + if (sourceModel) sb.append(" \"programKind\": \"SOURCE\",\n"); + if (sourceModel || symmetryReduction) { if (approximate != null) sb.append(" \"storeType\": \"").append(approximate ? "BITSTATE" : "EXACT").append("\",\n"); } if (resourceLimitReason != null) sb.append(" \"resourceLimitReason\": \"").append(resourceLimitReason).append("\",\n"); diff --git a/src/main/java/dev/samhb/interleave/cli/Main.java b/src/main/java/dev/samhb/interleave/cli/Main.java index f8c3120..87bd250 100644 --- a/src/main/java/dev/samhb/interleave/cli/Main.java +++ b/src/main/java/dev/samhb/interleave/cli/Main.java @@ -261,14 +261,24 @@ public static void main(String[] args) { System.exit(1); } - if (symmetryReduction && (all || program == null || !program.program().isSource() + if (symmetryReduction && (all || program == null || (!EXACT.equals(storeFilter) && !"BITSTATE".equals(storeFilter)) || (strategyFilter != null && !"CONTEXT_BOUNDED".equals(strategyFilter) && (iterativeDeepening || maxPreemptionsExplicit)))) { - System.err.println("Error: --symmetry requires --source and an explicit --store exact|bitstate; CBS options require a CBS selection"); + System.err.println("Error: --symmetry requires eligible --source or declarative --file and an explicit --store exact|bitstate; CBS options require a CBS selection"); System.exit(1); } + if (symmetryReduction) { + try { + dev.samhb.interleave.format.dsl.SourceSymmetry.groups(program.program(), program.invariant().orElse(null)); + } catch (IllegalArgumentException e) { + System.err.println("Error: --symmetry requires eligible source or certified declarative input: " + e.getMessage()); + System.exit(1); + return; + } + } + if (simplifyCutoff && shortestCutoffCandidates != null) { System.err.println("Error: --simplify-cutoff and --shortest-cutoff are mutually exclusive"); System.exit(1); @@ -446,7 +456,7 @@ private static void printUsage() { System.out.println("Flags:"); System.out.println(" --shortest-cutoff N Best cutoff subsequence within N candidate checks; JSON includes proof/work metadata"); System.out.println(" --json Output as JSON (default: Markdown)"); - System.out.println(" --symmetry Checked source-thread symmetry; requires --source and explicit --store exact|bitstate"); + System.out.println(" --symmetry Checked source/declarative symmetry; requires explicit store (declarative: exact only)"); System.out.println(" --simplify-cutoff Emit one shorter INCOMPLETE source trace; requires --json --store exact --strategy"); System.out.println(" --store exact|bitstate Filter by store type (default: both)"); System.out.println(" --strategy DFS|STATIC_POR|DPOR|CONTEXT_BOUNDED Filter by strategy (default: all)"); diff --git a/src/main/java/dev/samhb/interleave/core/Program.java b/src/main/java/dev/samhb/interleave/core/Program.java index 2c58173..ad38817 100644 --- a/src/main/java/dev/samhb/interleave/core/Program.java +++ b/src/main/java/dev/samhb/interleave/core/Program.java @@ -64,6 +64,14 @@ public Program(SharedState initialState, List threads, String sourc this.sourceDigest = sourceDigest; } + /** Returns the stored initial snapshot's type without copying or invoking model callbacks. + * Checked integrations can reject unsupported state implementations before initial enabledness. + * The type belongs to the defensive snapshot retained at construction, not the caller's input. + * @return runtime class of the privately stored initial state + * @throws NullPointerException if a broken caller-supplied deepCopy returned null + */ + public Class initialStateType() { return initialState.getClass(); } + /** Returns source fingerprint, or null for a legacy Java/JSON model. * @return source fingerprint, or null for a legacy Java/JSON model */ diff --git a/src/main/java/dev/samhb/interleave/dpor/DporExplorer.java b/src/main/java/dev/samhb/interleave/dpor/DporExplorer.java index d976d2c..65298f8 100644 --- a/src/main/java/dev/samhb/interleave/dpor/DporExplorer.java +++ b/src/main/java/dev/samhb/interleave/dpor/DporExplorer.java @@ -150,9 +150,9 @@ private void dporDfs(Program program, Configuration config, StateVisitor stateVisitor, Set observations, Map> sleepCoverage) { - // Checked symmetry stores are source-only; mapped sleep coverage below decides revisits. + // Checked symmetry uses mapped sleep products for either trusted input family. boolean seen = !(stateStore instanceof CheckedSymmetryStore) && stateStore.isVisited(config); - if (program.isSource()) { + if (program.isSource() || stateStore instanceof CheckedSymmetryStore) { List enabledHere = config.enabledThreadIds(); boolean allSleeping = !enabledHere.isEmpty(); for (int id : enabledHere) { diff --git a/src/main/java/dev/samhb/interleave/format/dsl/DslInvariant.java b/src/main/java/dev/samhb/interleave/format/dsl/DslInvariant.java index b8d701d..3c1660c 100644 --- a/src/main/java/dev/samhb/interleave/format/dsl/DslInvariant.java +++ b/src/main/java/dev/samhb/interleave/format/dsl/DslInvariant.java @@ -6,6 +6,7 @@ import dev.samhb.interleave.search.Invariant; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.HashSet; @@ -36,6 +37,8 @@ public enum When { ALWAYS } + /** Loader provenance; public constructors never issue this trust. */ + private final boolean certified; /** Predicates. */ private final List predicates; /** Decl. */ @@ -74,6 +77,17 @@ public DslInvariant(Expr predicate, StateDecl decl, When when) { * @param when timing */ public DslInvariant(List predicates, StateDecl decl, When when) { + this(predicates, decl, when, false); + } + + /** Freezes predicate semantics and provenance without changing ordinary construction. + * @param predicates validated or caller-supplied predicates + * @param decl immutable declaration + * @param when observation timing, defaulting to final + * @param certified whether the loader authorized construction + */ + private DslInvariant(List predicates, StateDecl decl, When when, boolean certified) { + this.certified = certified; if (predicates == null || predicates.isEmpty() || predicates.size() > 16) { throw new IllegalArgumentException("predicates must have 1..16 entries"); } @@ -90,6 +104,31 @@ public DslInvariant(List predicates, StateDecl decl, When when) { } } + /** Issues a shared-only property after successful loader validation. + * @param permit non-null inaccessible loader capability + * @param predicates validated shared-only boolean predicates in evaluation order + * @param decl validated declaration + * @param when observation timing + * @return immutable certified property + * @throws NullPointerException if the caller lacks the loader permit + */ + static DslInvariant validated(DslLoader.ValidationPermit permit, List predicates, StateDecl decl, When when) { + Objects.requireNonNull(permit, "loader permit"); + return new DslInvariant(predicates, decl, when, true); + } + + /** Checks property provenance/binding and counts its bounded expressions. + * @param expectedDecl declaration shared by all instructions and initial state + * @return AST nodes to include in aggregate model admission + * @throws IllegalArgumentException for untrusted or foreign properties + */ + int symmetryNodes(StateDecl expectedDecl) { + if (!certified || decl != expectedDecl) { + throw new IllegalArgumentException("Symmetry requires a loader-certified shared declarative property for this declaration"); + } + return predicates.stream().mapToInt(Expr::nodeCount).sum(); + } + /** * Checks whether the invariant holds in the given state and configuration. *

diff --git a/src/main/java/dev/samhb/interleave/format/dsl/DslLoader.java b/src/main/java/dev/samhb/interleave/format/dsl/DslLoader.java index de95512..ece4a55 100644 --- a/src/main/java/dev/samhb/interleave/format/dsl/DslLoader.java +++ b/src/main/java/dev/samhb/interleave/format/dsl/DslLoader.java @@ -34,6 +34,15 @@ */ public final class DslLoader { + /** Sole capability authorizing objects that passed this loader's validation. */ + private static final ValidationPermit VALIDATION_PERMIT = new ValidationPermit(); + + /** Unforgeable by ordinary same-package callers; never exposed by a loaded object. */ + static final class ValidationPermit { + /** Only the enclosing loader can issue its private capability. */ + private ValidationPermit() {} + } + /** Prevents instantiation of this utility class. */ private DslLoader() {} @@ -218,7 +227,7 @@ public static BenchmarkProgram load(ProgramDefinition def) { throw new RegistryException("Unknown field '" + key + "' at " + path); } } - DynamicStep step = new DynamicStep(i, guard, effects, decl, name); + DynamicStep step = DynamicStep.validated(VALIDATION_PERMIT, i, guard, effects, decl, name); steps.add(step); } threads.add(new ModelThread(i, steps)); @@ -308,7 +317,7 @@ public static BenchmarkProgram load(ProgramDefinition def) { predicates.add(pred); } } - invariant = new DslInvariant(predicates, decl, when); + invariant = DslInvariant.validated(VALIDATION_PERMIT, predicates, decl, when); } Program program = new Program(initial, threads); diff --git a/src/main/java/dev/samhb/interleave/format/dsl/DynamicStep.java b/src/main/java/dev/samhb/interleave/format/dsl/DynamicStep.java index 29b3174..232f2cc 100644 --- a/src/main/java/dev/samhb/interleave/format/dsl/DynamicStep.java +++ b/src/main/java/dev/samhb/interleave/format/dsl/DynamicStep.java @@ -8,12 +8,15 @@ import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; /** * Declarative step with derived reads/writes and sandboxed execution. */ public final class DynamicStep implements Step { + /** Whether loader validation, rather than public construction, issued this instruction. */ + private final boolean certified; /** Owner. */ private final int owner; /** Guard. */ @@ -39,6 +42,19 @@ public final class DynamicStep implements Step { * @param name diagnostic name or null */ public DynamicStep(int owner, Expr guard, List effects, StateDecl decl, String name) { + this(owner, guard, effects, decl, name, false); + } + + /** Constructs immutable semantics and footprints, retaining loader provenance privately. + * @param owner original action owner + * @param guard optional guard + * @param effects ordered effects + * @param decl declaration shared with the initial state + * @param name optional diagnostic label + * @param certified whether the loader capability authorized construction + */ + private DynamicStep(int owner, Expr guard, List effects, StateDecl decl, String name, boolean certified) { + this.certified = certified; this.owner = owner; this.guard = guard; this.effects = List.copyOf(effects); @@ -62,6 +78,65 @@ public DynamicStep(int owner, Expr guard, List effects, StateDecl decl, this.writes = Set.copyOf(w); } + /** Issues trusted semantics only to the loader holding its inaccessible permit. + * @param permit non-null loader-owned capability + * @param owner original owner + * @param guard validated optional boolean guard + * @param effects validated ordered effects + * @param decl validated declaration + * @param name optional diagnostic label + * @return immutable loader-certified instruction + * @throws NullPointerException if the caller lacks the loader permit + */ + static DynamicStep validated(DslLoader.ValidationPermit permit, int owner, Expr guard, + List effects, StateDecl decl, String name) { + Objects.requireNonNull(permit, "loader permit"); + return new DynamicStep(owner, guard, effects, decl, name, true); + } + + /** Returns the declaration for package-owned complete-model certification. + * @return immutable declaration identity, not an authorization capability + */ + StateDecl declaration() { return decl; } + + /** Validates trust and binding before returning complete owner-independent semantics. + * @param expectedOwner actual containing owner + * @param expectedDecl declaration shared by the complete model + * @return ordered shape, or null when any syntax observes tid + * @throws IllegalArgumentException for an uncertified instruction or foreign binding + */ + Object symmetryShape(int expectedOwner, StateDecl expectedDecl) { + if (!certified || owner != expectedOwner || decl != expectedDecl) { + throw new IllegalArgumentException("Symmetry requires loader-certified declarative owner/declaration bindings"); + } + if (SourceInstruction.usesTid(guard)) return null; + for (Effect effect : effects) { + if (SourceInstruction.usesTid(effect.rhs()) + || effect.lhs() instanceof Lhs.ArrayLhs a && SourceInstruction.usesTid(a.index()) + || effect.lhs() instanceof Lhs.LocalArrayLhs a && SourceInstruction.usesTid(a.index())) return null; + } + return new Shape(guard, effects); + } + + /** Counts this already-validated instruction occurrence for reassembled model admission. + * @return bounded AST node count including guard and assignment indices + */ + int symmetryNodes() { + int count = guard == null ? 0 : Expr.nodeCount(guard); + for (Effect effect : effects) { + count += Expr.nodeCount(effect.rhs()); + if (effect.lhs() instanceof Lhs.ArrayLhs a) count += Expr.nodeCount(a.index()); + if (effect.lhs() instanceof Lhs.LocalArrayLhs a) count += Expr.nodeCount(a.index()); + } + return count; + } + + /** Complete straight-line action semantics without diagnostic identity. + * @param guard optional validated guard + * @param effects immutable ordered effects + */ + private record Shape(Expr guard, List effects) {} + /** * Records the memory location an assignment target writes. * diff --git a/src/main/java/dev/samhb/interleave/format/dsl/SourceInstruction.java b/src/main/java/dev/samhb/interleave/format/dsl/SourceInstruction.java index 991bbd9..d1bf816 100644 --- a/src/main/java/dev/samhb/interleave/format/dsl/SourceInstruction.java +++ b/src/main/java/dev/samhb/interleave/format/dsl/SourceInstruction.java @@ -79,7 +79,7 @@ private static SymmetryNode symmetryNode(Node node) { * @param expression typed source expression, or null for an absent guard/effect * @return true if any expression node observes tid */ - private static boolean usesTid(Expr expression) { + static boolean usesTid(Expr expression) { if (expression == null) return false; return switch (expression) { case Expr.TidRef ignored -> true; diff --git a/src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java b/src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java index 257881f..d5522f7 100644 --- a/src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java +++ b/src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java @@ -1,54 +1,74 @@ -/* Conservative structural eligibility for source-thread permutation groups. */ +/** Conservative structural eligibility for trusted source and declarative permutation groups. */ package dev.samhb.interleave.format.dsl; import dev.samhb.interleave.core.*; import dev.samhb.interleave.search.Invariant; import java.util.*; -/** Discovers interchangeable source owners without trusting arbitrary step/property callbacks. */ +/** Discovers interchangeable validated owners without trusting arbitrary step/property callbacks. */ public final class SourceSymmetry { /** Prevents instances of this stateless eligibility utility. */ private SourceSymmetry() {} /** * Derives disjoint groups with identical owner-independent instructions and initial locals. - * Only compiler-built source instructions and absent/compiler-built shared properties qualify. + * Only compiler-built source or loader-certified declarative semantics and shared properties qualify. * Non-grouped owners remain fixed, including owners whose instructions observe their own tid. * The returned partition certifies the supplied immutable program/property pair only. - * @param program source program to validate; callbacks/definitions must remain unchanged - * @param invariant absent or compiler-built source property actually used for the run + * @param program trusted program to validate; callbacks/definitions must remain unchanged + * @param invariant absent or matching trusted shared property actually used for the run * @return immutable groups of at least two owners, ordered by first owner * @throws NullPointerException for a null program * @throws IllegalArgumentException for unsupported semantics, invalid bindings or no valid group */ public static List> groups(Program program, Invariant invariant) { Objects.requireNonNull(program, "program"); - if (!program.isSource() || (invariant != null && !(invariant instanceof SourceProperty))) { - throw new IllegalArgumentException("Symmetry requires compiled source and its shared-state property; custom callbacks are unsupported"); + if (program.initialStateType() != DynamicState.class) { + throw new IllegalArgumentException("Symmetry requires a trusted DynamicState initial snapshot"); + } + boolean source = program.isSource(); + if (invariant != null && (source ? !(invariant instanceof SourceProperty) : !(invariant instanceof DslInvariant))) { + throw new IllegalArgumentException("Symmetry requires a trusted shared-state property; custom callbacks are unsupported"); } if (program.threadCount() > 8) { - throw new IllegalArgumentException("Symmetry requires matching source owner counts from 1 through 8"); + throw new IllegalArgumentException("Symmetry requires matching owner counts from 1 through 8"); } // Check all callbacks and owner bindings before initial enabledness can invoke any step. List> shapes = new ArrayList<>(); + StateDecl declaration = null; + int nodes = 0; for (int owner = 0; owner < program.threadCount(); owner++) { ModelThread thread = program.threads().get(owner); - if (thread.id() != owner) throw new IllegalArgumentException("Symmetry requires dense source owner IDs"); + if (thread.id() != owner) throw new IllegalArgumentException("Symmetry requires dense owner IDs"); + if (!source && (thread.steps().isEmpty() || thread.steps().size() > 64)) { + throw new IllegalArgumentException("Declarative symmetry requires 1 through 64 steps per owner"); + } List instructions = new ArrayList<>(); boolean eligible = true; for (int pc = 0; pc < thread.steps().size(); pc++) { - if (!(thread.steps().get(pc) instanceof SourceInstruction instruction)) { - throw new IllegalArgumentException("Symmetry requires compiler-built source instructions in every owner"); + Step action = thread.steps().get(pc); + Object shape; + if (source && action instanceof SourceInstruction instruction) { + shape = instruction.symmetryShape(owner, pc, thread.steps().size()); + } else if (!source && action instanceof DynamicStep instruction) { + if (declaration == null) declaration = instruction.declaration(); + shape = instruction.symmetryShape(owner, declaration); + nodes += instruction.symmetryNodes(); + if (nodes > 5000) throw new IllegalArgumentException("Declarative symmetry exceeds 5000 AST nodes"); + } else { + throw new IllegalArgumentException("Symmetry requires a single trusted instruction family in every owner"); } - Object shape = instruction.symmetryShape(owner, pc, thread.steps().size()); eligible &= shape != null; instructions.add(shape); } shapes.add(eligible ? List.copyOf(instructions) : null); } - if (!(program.initialConfiguration().state() instanceof DynamicState state) - || state.threadCount() != program.threadCount()) { - throw new IllegalArgumentException("Symmetry requires matching dynamic source-state owner counts"); + if (!source && invariant instanceof DslInvariant property && nodes + property.symmetryNodes(declaration) > 5000) { + throw new IllegalArgumentException("Declarative symmetry exceeds 5000 AST nodes including its property"); + } + DynamicState state = (DynamicState) program.initialConfiguration().state(); + if (state.threadCount() != program.threadCount() || (!source && state.decl() != declaration)) { + throw new IllegalArgumentException("Symmetry requires matching dynamic-state owner/declaration bindings"); } Map> candidates = new LinkedHashMap<>(); for (int owner = 0; owner < program.threadCount(); owner++) { @@ -58,7 +78,7 @@ public static List> groups(Program program, Invariant invariant) { } } List> groups = candidates.values().stream().filter(group -> group.size() > 1).map(List::copyOf).toList(); - if (groups.isEmpty()) throw new IllegalArgumentException("Symmetry found no interchangeable source-thread group"); + if (groups.isEmpty()) throw new IllegalArgumentException("Symmetry found no interchangeable thread group"); return groups; } diff --git a/src/main/java/dev/samhb/interleave/por/StaticPorExplorer.java b/src/main/java/dev/samhb/interleave/por/StaticPorExplorer.java index 04ee5a2..1edb193 100644 --- a/src/main/java/dev/samhb/interleave/por/StaticPorExplorer.java +++ b/src/main/java/dev/samhb/interleave/por/StaticPorExplorer.java @@ -99,7 +99,7 @@ public DfsResult explore(Program program, Invariant invariant, StateStore stateS if (program.isSource() && invariant != null && observations.isEmpty()) { observations = invariant.finalObservedLocations(); } - PropertyPersistentSetComputer propertySets = invariant == null ? (program.isSource() + PropertyPersistentSetComputer propertySets = invariant == null ? (program.isSource() || effectiveStateStore instanceof dev.samhb.interleave.search.CheckedSymmetryStore ? new PropertyPersistentSetComputer(program.threads(), Set.of(), relation) : null) : observations .map(locations -> new PropertyPersistentSetComputer(program.threads(), locations, relation)) diff --git a/src/main/java/dev/samhb/interleave/report/BenchmarkHarness.java b/src/main/java/dev/samhb/interleave/report/BenchmarkHarness.java index 7e5d05a..6fca917 100644 --- a/src/main/java/dev/samhb/interleave/report/BenchmarkHarness.java +++ b/src/main/java/dev/samhb/interleave/report/BenchmarkHarness.java @@ -44,7 +44,7 @@ public final class BenchmarkHarness { private final boolean iterativeDeepening; /** Store filter. */ private final Set storeFilter; - /** Opt-in checked source symmetry, using owned exact or approximate stores. */ + /** Opt-in checked model symmetry, using owned exact or approximate stores. */ private final boolean symmetryReduction; /** Strategy filter. */ private final Set strategyFilter; @@ -96,7 +96,7 @@ public BenchmarkHarness(int bitstateSize, int bitstateK, } /** - * Creates a filtered harness with optional checked source symmetry. + * Creates a filtered harness with optional checked trusted-model symmetry. * Filters are copied at construction. For symmetry, explicitly select EXACT or BITSTATE; * source eligibility is validated per program. * @param bitstateSize approximate-store bit capacity for approximate runs @@ -105,7 +105,7 @@ public BenchmarkHarness(int bitstateSize, int bitstateK, * @param strategyFilter selected strategies; null selects all four built-in strategies * @param maxPreemptions ordinary CBS bound * @param iterativeDeepening CBS increasing-bound mode - * @param symmetryReduction whether to enable checked source-orbit search + * @param symmetryReduction whether to enable checked trusted-model orbit search * @throws IllegalArgumentException for a negative bound or unsupported symmetry selection * @throws NullPointerException if a supplied filter contains null */ @@ -157,6 +157,8 @@ public List runAll() { * filtered by the configured store and strategy filters. * * @param program the benchmark program + * @throws IllegalArgumentException for uncertified symmetry models or declarative BITSTATE + * symmetry before B10 L2; source BITSTATE and declarative exact remain supported * @return list of {@link BenchmarkResult}s */ public List runProgram(BenchmarkProgram program) { @@ -210,7 +212,7 @@ private List runProgramWithStore(BenchmarkProgram program, Inva String dfsVerdict = actualVerdict(dfsResult.result()); String expectedVerdict = program.expectedVerdict(); if (expectedVerdict != null && storeType == StoreType.EXACT && !expectedVerdict.equals(dfsVerdict) - && !(program.program().isSource() && dfsVerdict.equals("INCOMPLETE"))) { + && !((program.program().isSource() || symmetryReduction) && dfsVerdict.equals("INCOMPLETE"))) { throw new IllegalStateException("Expected verdict " + expectedVerdict + " for " + program.name() + " but got " + dfsVerdict); } @@ -258,7 +260,7 @@ private List runProgramWithStore(BenchmarkProgram program, Inva } /** Creates the selected run's store without invoking an unused ordinary factory. - * @param program immutable source model when symmetry is enabled + * @param program immutable trusted model when symmetry is enabled * @param invariant property for this run, or null * @param storeType selected exact or approximate storage * @param ordinaryFactory caller's ordinary storage policy @@ -373,7 +375,9 @@ private BenchmarkResult createResult(String strategy, String bugName, Program pr List states = List.of(); if (failingTrace != null && program != null) { try { - states = new TraceReplayer().captureSnapshots(program, failingTrace); + var replayer = new TraceReplayer(); + states = symmetryReduction && !program.isSource() + ? replayer.captureDeclarativeSnapshots(program, failingTrace) : replayer.captureSnapshots(program, failingTrace); } catch (Exception e) { states = List.of(); } diff --git a/src/main/java/dev/samhb/interleave/report/BenchmarkResult.java b/src/main/java/dev/samhb/interleave/report/BenchmarkResult.java index d710758..a025dbc 100644 --- a/src/main/java/dev/samhb/interleave/report/BenchmarkResult.java +++ b/src/main/java/dev/samhb/interleave/report/BenchmarkResult.java @@ -15,7 +15,7 @@ * Immutable result of a single benchmark run (one strategy + one store type). */ public final class BenchmarkResult { - /** Whether this row counts checked source representative visits. */ + /** Whether this row counts checked model representative visits. */ private final boolean symmetryReduction; /** Strategy. */ private final String strategy; @@ -216,7 +216,7 @@ public BenchmarkResult(String strategy, String bugName, long statesExplored, * @param row immutable benchmark row whose counts and existing failure snapshots are preserved * @param program executed model, or null when no source identity or replay context is available * @param result exploration evidence whose INCOMPLETE traces are retained in encounter order - * @param symmetryReduction whether checked source-orbit search produced this row + * @param symmetryReduction whether checked model orbit search produced this row */ private BenchmarkResult(BenchmarkResult row, Program program, DfsResult result, boolean symmetryReduction) { this.symmetryReduction = symmetryReduction; @@ -252,17 +252,17 @@ public BenchmarkResult withExploration(Program program, DfsResult result) { } /** Attaches actual checked exploration mode alongside the ordinary source evidence. - * @param program executed source model + * @param program executed trusted model * @param result actual concrete representative evidence - * @param symmetryReduction whether checked source-orbit search was selected + * @param symmetryReduction whether checked model orbit search was selected * @return immutable row with mode and evidence preserved */ BenchmarkResult withExploration(Program program, DfsResult result, boolean symmetryReduction) { return new BenchmarkResult(this, program, result, symmetryReduction); } - /** Returns whether this row counts checked source representative visits. - * @return true for explicitly selected checked source symmetry + /** Returns whether this row counts checked model representative visits. + * @return true for explicitly selected checked model symmetry */ public boolean symmetryReduction() { return symmetryReduction; } diff --git a/src/main/java/dev/samhb/interleave/report/SoundnessAttestation.java b/src/main/java/dev/samhb/interleave/report/SoundnessAttestation.java index 59fbe58..3f3271e 100644 --- a/src/main/java/dev/samhb/interleave/report/SoundnessAttestation.java +++ b/src/main/java/dev/samhb/interleave/report/SoundnessAttestation.java @@ -4,6 +4,10 @@ import dev.samhb.interleave.bugs.BenchmarkProgram; import dev.samhb.interleave.core.Configuration; import dev.samhb.interleave.core.Program; +import dev.samhb.interleave.core.StepOutcome; +import dev.samhb.interleave.core.TransitionExecutor; +import dev.samhb.interleave.format.dsl.SourceSymmetry; +import dev.samhb.interleave.search.TraceOutcome; import dev.samhb.interleave.search.Invariant; import dev.samhb.interleave.search.Trace; import dev.samhb.interleave.search.TraceReplayer; @@ -21,7 +25,7 @@ * approximate storage may miss violations. Exact {@code INCOMPLETE} and * {@code APPROXIMATE_PASS} rows never seed or conflict with cross-strategy agreement. * For DFS expectation matching, those labels are accepted as inconclusive only for source - * models; legacy DFS expectation matching retains its strict behavior. + * or certified declarative symmetry models; ordinary legacy DFS expectation matching retains its strict behavior. *
  • Trace replay validation (all results): * For every reported VIOLATION (including bitstate and context-bounded), * requires a failing trace and registered program, then replays the recorded execution. @@ -29,6 +33,9 @@ * authenticates a source runtime error or false statement assertion (whose atomic rollback may leave the invariant true). * Without an invariant, replay checks execution and supplied source step evidence only; * success does not establish a property violation. Replay exceptions propagate to the caller. + * Marked declarative symmetry reports instead validate enabled original transitions and + * the first actual failed action/property observation; malformed/foreign evidence fails the check. + * This private path does not change generic legacy replay or grant source identity to JSON. * This positive replay obligation applies to bounded and approximate reports as well. * */ @@ -65,7 +72,6 @@ public SoundnessAttestation(List results, List dfsVerdicts = new LinkedHashMap<>(); Map correctVerdicts = new LinkedHashMap<>(); // Filter to EXACT results for verdict validation (bitstate is incomplete by design) @@ -82,11 +88,11 @@ private SoundnessCheck checkSoundness() { String expectedVerdict = program.expectedVerdict(); if ("DFS".equals(result.strategy())) { if (expectedVerdict != null && !expectedVerdict.equals(actualVerdict) - && !(program.program().isSource() && isInconclusive(actualVerdict))) { + && !((program.program().isSource() || result.symmetryReduction() + && certifiedDeclarative(program)) && isInconclusive(actualVerdict))) { return SoundnessCheck.failed("DFS verdict mismatch for " + key + ": expected " + expectedVerdict + " but got " + actualVerdict); } - dfsVerdicts.put(key, actualVerdict); } if (expectedVerdict != null && !"VIOLATION".equals(expectedVerdict) @@ -121,6 +127,13 @@ private SoundnessCheck checkSoundness() { } Program programDef = program.program(); + if (result.symmetryReduction() && !programDef.isSource()) { + if (!authenticatesDeclarativeViolation(program, failingTrace)) { + return SoundnessCheck.failed("Invalid declarative symmetry violation for " + result.bugName() + + " under " + result.strategy() + " (" + result.storeType() + ")"); + } + continue; + } TraceReplayer replayer = new TraceReplayer(); Invariant invariant = program.invariant().orElse(null); Configuration replayed = replayer.replay(programDef, failingTrace, invariant); @@ -155,6 +168,50 @@ private static boolean isInconclusive(String verdict) { return "INCOMPLETE".equals(verdict) || "APPROXIMATE_PASS".equals(verdict); } + /** Re-certifies marked declarative metadata before granting an inconclusive exception. + * @param model registered non-source program/property pair, already discriminated by the caller + * @return true only for a complete eligible declarative model + */ + private static boolean certifiedDeclarative(BenchmarkProgram model) { + try { + SourceSymmetry.groups(model.program(), model.invariant().orElse(null)); + return true; + } catch (RuntimeException invalid) { + return false; + } + } + + /** Validates a positive JSON observation using enabled original choices and actual transitions. + * Failed attempts have no successor; generic legacy replay is deliberately unchanged. + * @param model registered program and shared property + * @param trace claimed violation witness + * @return true for a final real step error or the first false property observation + */ + private static boolean authenticatesDeclarativeViolation(BenchmarkProgram model, Trace trace) { + if (trace.outcome() != TraceOutcome.VIOLATION || trace.evidence() != null) return false; + try { + SourceSymmetry.groups(model.program(), model.invariant().orElse(null)); + Configuration config = model.program().initialConfiguration(); + Invariant invariant = model.invariant().orElse(null); + if (invariant != null && !invariant.holds(config.state(), config)) return trace.threadIds().isEmpty(); + // Trace freezes and aligns both lists; consume their corresponding outcomes together. + var outcomes = trace.outcomes().iterator(); + for (int owner : trace.threadIds()) { + if (!config.enabledThreadIds().contains(owner)) return false; + var transition = TransitionExecutor.execute(model.program(), config, owner); + if (transition.outcome() != outcomes.next()) return false; + boolean last = !outcomes.hasNext(); + if (transition.outcome() == StepOutcome.ASSERTION_FAILED) return last; + config = transition.successor(); + if (invariant != null && !invariant.holds(config.state(), config)) return last; + } + return false; + } catch (RuntimeException invalid) { + // A malformed/foreign report is a failed check, never an unchecked positive claim. + return false; + } + } + /** * Returns whether the attestation passed (no soundness failures detected). * @@ -186,11 +243,15 @@ public String formatMarkdown() { sb.append("## Soundness Attestation\n\n"); if (sound) { + boolean declarativeSymmetry = results.stream().anyMatch(row -> row.symmetryReduction() + && programs.containsKey(row.bugName()) && !programs.get(row.bugName()).program().isSource()); sb.append("All checked EXACT DFS verdicts matched their supplied expectations. "); - sb.append("Source DFS results that were INCOMPLETE or APPROXIMATE_PASS were accepted as "); + sb.append(declarativeSymmetry ? "Source or certified declarative symmetry DFS results that were INCOMPLETE or APPROXIMATE_PASS were accepted as " + : "Source DFS results that were INCOMPLETE or APPROXIMATE_PASS were accepted as "); sb.append("inconclusive, not matched verdicts; programs without expectations were not expectation-checked. "); sb.append("Reported VIOLATION traces (including bitstate and context-bounded) passed execution replay. "); - sb.append("Supplied invariants failed at the replayed configuration, or source runtime or assertion failures were authenticated. "); + sb.append(declarativeSymmetry ? "Supplied invariants failed at the observed configuration, or source runtime/assertion failures or actual certified declarative step failures were checked with enabled original choices. " + : "Supplied invariants failed at the replayed configuration, or source runtime or assertion failures were authenticated. "); sb.append("Without an invariant, successful replay does not establish a property violation. "); sb.append("Inconclusive results (INCOMPLETE or APPROXIMATE_PASS) are excluded "); sb.append("from the cross-strategy verdict agreement above, since they assert nothing about "); diff --git a/src/main/java/dev/samhb/interleave/search/BitstateSymmetryStateStore.java b/src/main/java/dev/samhb/interleave/search/BitstateSymmetryStateStore.java index dda32e1..55b962b 100644 --- a/src/main/java/dev/samhb/interleave/search/BitstateSymmetryStateStore.java +++ b/src/main/java/dev/samhb/interleave/search/BitstateSymmetryStateStore.java @@ -66,6 +66,9 @@ public static BitstateSymmetryStateStore forRun(Program program, Invariant invar || (strategy != Strategy.CONTEXT_BOUNDED && maxPreemptions != 0)) { throw new IllegalArgumentException("Positive bits/probes and a nonnegative CBS capacity (zero otherwise) required"); } + if (!Objects.requireNonNull(program, "program").isSource()) { + throw new IllegalArgumentException("Approximate symmetry requires source input until declarative B10 L2 is enabled"); + } return new BitstateSymmetryStateStore(new SymmetryRunContext(program, invariant, strategy), bits, hashFunctions, maxPreemptions, strategy); } diff --git a/src/main/java/dev/samhb/interleave/search/SymmetryDfsExplorer.java b/src/main/java/dev/samhb/interleave/search/SymmetryDfsExplorer.java index 7094a3b..abec803 100644 --- a/src/main/java/dev/samhb/interleave/search/SymmetryDfsExplorer.java +++ b/src/main/java/dev/samhb/interleave/search/SymmetryDfsExplorer.java @@ -1,4 +1,4 @@ -/* Checked exact source-orbit exploration with original-identity execution and witnesses. */ +/* Checked exact model orbit exploration with original-identity execution and witnesses. */ package dev.samhb.interleave.search; import dev.samhb.interleave.core.*; @@ -10,12 +10,12 @@ public final class SymmetryDfsExplorer { public SymmetryDfsExplorer() {} /** - * Explores the source quotient with no state budget or visitor. + * Explores the trusted model quotient with no state budget or visitor. * For example, four identical one-increment owners visit five representatives instead of 16 states. - * @param program immutable compiled source model - * @param invariant null or its compiler-built shared-state property + * @param program immutable source or certified declarative model + * @param invariant null or its matching trusted shared-state property * @return concrete representatives and replayable original-identity traces - * @throws IllegalArgumentException if source symmetry eligibility fails + * @throws IllegalArgumentException if trusted symmetry eligibility fails * @throws NullPointerException for a null program */ public DfsResult explore(Program program, Invariant invariant) { @@ -27,12 +27,12 @@ public DfsResult explore(Program program, Invariant invariant) { * Visitors observe original configurations and must not mutate modeled values. Counts are * representatives, not all concrete states or schedules. Diagnostic witnesses are representative; * source locations, original owners, failure and cutoff evidence are never relabeled. - * @param program immutable compiler-built source model - * @param invariant null or its compiler-built pure shared-state property + * @param program immutable source or certified declarative model + * @param invariant null or its matching trusted pure shared-state property * @param visitor read-only observer, or null; exceptions propagate as in ordinary DFS * @param maxStates representative-state budget; Long.MAX_VALUE means unlimited * @return actual concrete representatives and original witnesses - * @throws IllegalArgumentException for unsupported source/property semantics or no eligible group + * @throws IllegalArgumentException for unsupported model/property semantics or no eligible group * @throws NullPointerException for a null program */ public DfsResult explore(Program program, Invariant invariant, StateVisitor visitor, long maxStates) { diff --git a/src/main/java/dev/samhb/interleave/search/SymmetryRunContext.java b/src/main/java/dev/samhb/interleave/search/SymmetryRunContext.java index 29615ca..fa67a23 100644 --- a/src/main/java/dev/samhb/interleave/search/SymmetryRunContext.java +++ b/src/main/java/dev/samhb/interleave/search/SymmetryRunContext.java @@ -1,4 +1,4 @@ -/** Immutable source certification and owner/action mapping shared by checked symmetry stores. */ +/** Immutable trusted model certification and owner/action mapping shared by checked symmetry stores. */ package dev.samhb.interleave.search; import dev.samhb.interleave.Strategy; @@ -23,12 +23,12 @@ final class SymmetryRunContext { /** Read-only-after-construction first-occurrence indices for DPOR actions. */ private final List> occurrences = new ArrayList<>(); - /** Certifies source groups and retains only immutable run/mapping metadata. - * @param program immutable trusted source program - * @param invariant compiler property, or null + /** Certifies trusted owner groups and retains only immutable run/mapping metadata. + * @param program immutable trusted source or certified declarative program + * @param invariant matching trusted shared property, or null * @param strategy built-in bound algorithm * @throws NullPointerException if program or strategy is null - * @throws IllegalArgumentException if source/property or DPOR alias layout is unsupported + * @throws IllegalArgumentException if trusted model/property or DPOR alias layout is unsupported */ SymmetryRunContext(Program program, Invariant invariant, Strategy strategy) { Objects.requireNonNull(strategy, "strategy"); diff --git a/src/main/java/dev/samhb/interleave/search/SymmetryStateStore.java b/src/main/java/dev/samhb/interleave/search/SymmetryStateStore.java index e35d496..c070694 100644 --- a/src/main/java/dev/samhb/interleave/search/SymmetryStateStore.java +++ b/src/main/java/dev/samhb/interleave/search/SymmetryStateStore.java @@ -1,4 +1,4 @@ -/* Exact source-orbit membership bound to one validated program, property and strategy. */ +/* Exact model orbit membership bound to one validated program, property and strategy. */ package dev.samhb.interleave.search; import dev.samhb.interleave.Strategy; @@ -10,7 +10,7 @@ * Checked per-run orbit store for built-in exact strategies. Execution retains original owners. * Create with {@link #forRun(Program, Invariant, Strategy)}; explorers verify the bound run before * executing callbacks. CBS keys include the mapped last owner; DPOR retains mapped sleep context. - * Membership methods require configurations from the bound source model, whose state must be + * Membership methods require configurations from the bound trusted model, whose state must be * {@link DynamicState}; passing foreign configurations violates the run contract. * This mutable store must not be shared between concurrent explorations. */ @@ -38,13 +38,13 @@ private SymmetryStateStore(SymmetryRunContext context, SymmetryBackend backend) } /** - * Validates source/property eligibility and creates fresh exact orbit membership. + * Validates trusted model/property eligibility and creates fresh exact orbit membership. * For example, pass forRun(program, property, Strategy.DPOR) to a DporExplorer. - * @param program immutable compiled source program - * @param invariant null or a compiler-built shared-state property + * @param program immutable trusted source or certified declarative program + * @param invariant null or its matching compiler-built source or loader-certified shared property * @param strategy built-in strategy to bind * @return fresh store bound to these exact objects and strategy - * @throws IllegalArgumentException for unsupported source semantics or mismatched DPOR alias partitions + * @throws IllegalArgumentException for unsupported model/property bindings or mismatched DPOR alias partitions * @throws NullPointerException for a null program or strategy */ public static SymmetryStateStore forRun(Program program, Invariant invariant, Strategy strategy) { @@ -54,12 +54,12 @@ public static SymmetryStateStore forRun(Program program, Invariant invariant, St /** Validates one run and allocates fresh membership using a certified exact backend. * For example, forRun(program, property, Strategy.DPOR, SymmetryBackend.ORDERED) uses tree storage. * No user store, comparator or factory is admitted; keys/context and eligibility remain checked. - * @param program immutable compiled source program - * @param invariant null or its compiler-built shared-state property + * @param program immutable trusted source or certified declarative program + * @param invariant null or its matching trusted shared-state property * @param strategy built-in strategy to bind * @param backend exact hash-based or naturally ordered membership * @return empty store bound to the exact objects, strategy and backend - * @throws IllegalArgumentException for unsupported source/property semantics or DPOR alias layout + * @throws IllegalArgumentException for unsupported model/property semantics or DPOR alias layout * @throws NullPointerException for a null program, strategy or backend */ public static SymmetryStateStore forRun(Program program, Invariant invariant, Strategy strategy, SymmetryBackend backend) { diff --git a/src/main/java/dev/samhb/interleave/search/TraceReplayer.java b/src/main/java/dev/samhb/interleave/search/TraceReplayer.java index 970a76f..a639c2b 100644 --- a/src/main/java/dev/samhb/interleave/search/TraceReplayer.java +++ b/src/main/java/dev/samhb/interleave/search/TraceReplayer.java @@ -3,6 +3,7 @@ import dev.samhb.interleave.TraceRecord; import dev.samhb.interleave.core.*; +import dev.samhb.interleave.format.dsl.SourceSymmetry; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -104,6 +105,45 @@ public List captureSnapshots(Program program, Trace trace) { return Collections.unmodifiableList(snapshots); } + /** Captures committed configurations for certified declarative symmetry diagnostics. + * Enabled original choices and outcomes are checked; a final failed attempt repeats the last + * committed snapshot, preserving action/state alignment without publishing its tentative writes. + * This captures values, not a property/terminal-verdict proof or authenticated source identity. + * Existing generic replay and snapshot behavior remain available through their original methods. + * @param program non-source model eligible for checked declarative symmetry + * @param trace immutable aligned choices and outcomes to capture + * @return immutable initial/action-boundary snapshots, one more than the attempted choices + * @throws NullPointerException for a null program or trace + * @throws IllegalArgumentException for unsupported model certification or source input + * @throws IllegalScheduleException for a disabled, invalid or terminated owner + * @throws CorruptedTraceException for mismatched outcomes or execution after a failed attempt + */ + public List captureDeclarativeSnapshots(Program program, Trace trace) { + var outcomes = trace.outcomes().iterator(); + if (program.isSource()) throw new IllegalArgumentException("Declarative snapshots require non-source input"); + SourceSymmetry.groups(program, null); + Configuration config = program.initialConfiguration(); + List snapshots = new ArrayList<>(); + snapshots.add(StateSnapshotExtractor.extract(config.state())); + for (int owner : trace.threadIds()) { + if (!config.enabledThreadIds().contains(owner)) { + throw new IllegalScheduleException("Declarative snapshot choice is not enabled: " + owner); + } + var transition = TransitionExecutor.execute(program, config, owner); + if (transition.outcome() != outcomes.next()) { + throw new CorruptedTraceException("Declarative snapshot outcome mismatch"); + } + if (transition.outcome() == StepOutcome.ASSERTION_FAILED) { + if (outcomes.hasNext()) throw new CorruptedTraceException("Execution continues after a failed attempt"); + snapshots.add(snapshots.getLast()); + } else { + config = transition.successor(); + snapshots.add(StateSnapshotExtractor.extract(config.state())); + } + } + return Collections.unmodifiableList(snapshots); + } + /** * Replays a trace record against the given program and returns an enriched trace record * containing state snapshots. diff --git a/src/test/java/dev/samhb/interleave/DeclarativeSymmetryRunTest.java b/src/test/java/dev/samhb/interleave/DeclarativeSymmetryRunTest.java new file mode 100644 index 0000000..694b2ea --- /dev/null +++ b/src/test/java/dev/samhb/interleave/DeclarativeSymmetryRunTest.java @@ -0,0 +1,143 @@ +/** Complete exact declarative strategy support, context routing and result identity. */ +package dev.samhb.interleave; + +import com.google.gson.JsonParser; +import dev.samhb.interleave.bugs.BenchmarkProgram; +import dev.samhb.interleave.dpor.DporExplorer; +import dev.samhb.interleave.format.ProgramLoader; +import dev.samhb.interleave.report.*; +import dev.samhb.interleave.search.*; +import java.nio.file.Path; +import java.util.*; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** Verifies the actual checked store/runner/report seams selected by Spec 92. */ +class DeclarativeSymmetryRunTest { + /** Checked DPOR must register the complete root product, even for non-source models. */ + @Test void checkedDeclarativeDporUsesProductCoverage() { + var model = semaphore(); + var store = SymmetryStateStore.forRun(model.program(), null, Strategy.DPOR); + new DporExplorer().explore(model.program(), null, store, null); + assertTrue(store.sleepCovered(model.program().initialConfiguration(), Set.of())); + } + + /** Exact strategy/backends keep JSON non-source and expose known storage precision. */ + @Test void exactStrategiesRetainIdentityAndResourceClassification() { + var model = semaphore(); + for (var strategy : Strategy.values()) for (var backend : SymmetryBackend.values()) { + var runner = InterleaveRunner.builder().strategy(strategy).symmetryReduction(true) + .symmetryBackend(backend).invariant(model.invariant().orElseThrow()).build(); + var result = runner.run(model.program()); + assertTrue(result.symmetryReduction()); + assertFalse(result.hasViolation()); + var json = JsonParser.parseString(result.toJson()).getAsJsonObject(); + assertEquals("EXACT", json.get("storeType").getAsString()); + assertFalse(json.has("programKind")); + assertFalse(json.has("sourceDigest")); + var limited = InterleaveRunner.builder().strategy(strategy).symmetryReduction(true) + .symmetryBackend(backend).maxStates(1).build().run(model.program()); + assertTrue(limited.limitExceeded()); + assertTrue(limited.resourcePrefix().isEmpty()); + var root = JsonParser.parseString(limited.toJson()).getAsJsonObject(); + assertEquals("EXACT", root.get("storeType").getAsString()); + assertEquals("MAX_STATES", root.get("resourceLimitReason").getAsString()); + } + } + + /** Runner reuse and simultaneous callers own independent exact membership and limits. + * @throws Exception if concurrent verification or artifact writes fail + */ + @Test void exactRunsRemainIsolatedAndEmitResourceFixtures() throws Exception { + var model=semaphore(); + java.nio.file.Files.createDirectories(Path.of("build")); + for(var strategy:Strategy.values()) { + var runner=InterleaveRunner.builder().strategy(strategy).symmetryReduction(true).build(); + long expected=runner.run(model.program()).statesExplored(); + assertEquals(expected,runner.run(model.program()).statesExplored()); + try(var executor=java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor()) { + var ready=new java.util.concurrent.CountDownLatch(2); + var start=new java.util.concurrent.CountDownLatch(1); + java.util.concurrent.Callable run=()->{ready.countDown();start.await();return runner.run(model.program());}; + var a=executor.submit(run);var b=executor.submit(run); + try {assertTrue(ready.await(10,java.util.concurrent.TimeUnit.SECONDS));} finally {start.countDown();} + assertEquals(expected,a.get().statesExplored());assertEquals(expected,b.get().statesExplored()); + } + var deadline=InterleaveRunner.builder().strategy(strategy).symmetryReduction(true) + .maxTime(java.time.Duration.ZERO).build().run(model.program(),()->0L); + assertTrue(deadline.limitExceeded());assertEquals(1,deadline.statesExplored()); + assertEquals("MAX_TIME",JsonParser.parseString(deadline.toJson()).getAsJsonObject().get("resourceLimitReason").getAsString()); + for(int limit:List.of(1,2)) { + var partial=InterleaveRunner.builder().strategy(strategy).symmetryReduction(true).maxStates(limit).build().run(model.program()); + assertTrue(partial.limitExceeded());assertTrue(partial.resourcePrefix().isEmpty()); + assertEquals(limit,partial.statesExplored()); + if(strategy==Strategy.DFS)java.nio.file.Files.writeString(Path.of("build/declarative-symmetry-resource-"+limit+".json"),partial.toJson()); + } + if(strategy==Strategy.DFS)java.nio.file.Files.writeString(Path.of("build/declarative-symmetry-completed.json"),runner.run(model.program()).toJson()); + } + } + + /** Iterative bounded search retains a real failure and checked stores cannot cross bindings. */ + @Test void boundedContextsAndStoreCopiesStayOwned() { + var model=new ProgramLoader().loadFromResource("dsl/lost-update-declarative.json"); + for(var backend:SymmetryBackend.values()) { + var result=InterleaveRunner.builder().strategy(Strategy.CONTEXT_BOUNDED).symmetryReduction(true) + .symmetryBackend(backend).maxPreemptions(2).iterativeDeepening(true) + .invariant(model.invariant().orElseThrow()).build().run(model.program()); + assertTrue(result.hasViolation()); + var rows=new BenchmarkHarness(1024,4,Set.of(StoreType.EXACT),Set.of("CONTEXT_BOUNDED"),2,true,true).runProgram(model); + assertTrue(new SoundnessAttestation(rows,List.of(model)).isSound()); + assertEquals("VIOLATION",rows.getFirst().verdict()); + assertEquals(1,rows.getFirst().preemptionsUsed()); + var store=SymmetryStateStore.forRun(model.program(),model.invariant().orElseThrow(),Strategy.DFS,backend); + var root=model.program().initialConfiguration();store.markVisited(root); + var copy=store.freshCopy();assertFalse(copy.isVisited(root)); + assertTrue(store.isVisited(root));store.clear();assertFalse(store.isVisited(root)); + var other=new ProgramLoader().loadFromResource("dsl/lost-update-declarative.json"); + assertThrows(IllegalArgumentException.class,()->new DfsExplorer().explore(other.program(),other.invariant().orElseThrow(),store,null)); + assertThrows(IllegalArgumentException.class,()->new DporExplorer().explore(model.program(),model.invariant().orElseThrow(),store,null)); + assertThrows(IllegalArgumentException.class,()->new DfsExplorer().explore(model.program(),null,store,null)); + } + } + + /** Source interruptions retain their existing strict snapshots rather than using JSON capture. */ + @Test void sourcePartialFailureSnapshotsRetainSourceCapture() { + var model=new dev.samhb.interleave.format.SourceProgramLoader().load(""" + program sourcepartial { + shared int x = 0; + thread 0 { assert(x == 1); } + thread 1 { assert(x == 1); } + thread 2 { atomic { x = 1; } } + } + """); + var result=InterleaveRunner.builder().symmetryReduction(true).maxStates(2).build().run(model.program()); + assertTrue(result.limitExceeded());assertTrue(result.hasViolation()); + assertFalse(result.failingTraces().isEmpty()); + for(var trace:result.failingTraces()) { + assertEquals(2,trace.states().size()); + assertEquals(0,trace.states().getLast().fields().get("x")); + assertNotNull(trace.evidence().sourceDigest()); + } + } + + /** L1 must not accidentally enable approximate JSON through a direct or owned factory. */ + @Test void approximateDeclarativeSelectionStaysGated() { + var model = semaphore(); + for (var strategy : Strategy.values()) { + assertThrows(IllegalArgumentException.class, () -> BitstateSymmetryStateStore.forRun( + model.program(), null, strategy, 1024, 4, strategy == Strategy.CONTEXT_BOUNDED ? 2 : 0)); + assertThrows(IllegalArgumentException.class, () -> InterleaveRunner.builder().strategy(strategy) + .symmetryReduction(true).symmetryBitstate(1024,4).build().run(model.program())); + var rejected=assertThrows(IllegalArgumentException.class,()->new BenchmarkHarness(1024,4, + Set.of(StoreType.BITSTATE),Set.of(strategy.name()),2,false,true).runProgram(model)); + assertTrue(rejected.getMessage().contains("until declarative B10 L2")); + } + } + + /** Loads the existing bounded semaphore without changing its semantics to fit symmetry. + * @return trusted declarative fixture + */ + private static BenchmarkProgram semaphore() { + return new ProgramLoader().loadFromFile(Path.of("examples/programs/semaphore-declarative.json")); + } +} diff --git a/src/test/java/dev/samhb/interleave/cli/MainTest.java b/src/test/java/dev/samhb/interleave/cli/MainTest.java index d34b341..aee12e3 100644 --- a/src/test/java/dev/samhb/interleave/cli/MainTest.java +++ b/src/test/java/dev/samhb/interleave/cli/MainTest.java @@ -770,6 +770,69 @@ void cutoffSimplificationRejectsInvalidSelections(@org.junit.jupiter.api.io.Temp assertFalse(ineligible.output().contains("Exception in thread")); } + /** Declarative symmetry uses existing file syntax and emits four exact non-source rows. + * @throws Exception if the child JVM or artifact write fails + */ + @Test void declarativeSymmetryCliSupportsExactMatrix() throws Exception { + var result=invokeCli("--file","examples/programs/semaphore-declarative.json","--symmetry","--store","exact","--json"); + assertEquals(0,result.exitCode(),result.output()); + var report=dev.samhb.interleave.testsupport.JsonAssertions.parseObject(result.output()); + assertTrue(report.get("soundness").getAsBoolean()); + var rows=report.getAsJsonArray("benchmarks"); + assertEquals(4,rows.size()); + var strategies=new java.util.HashSet(); + for(var element:rows) { + var row=element.getAsJsonObject(); + assertTrue(row.get("symmetryReduction").getAsBoolean()); + assertEquals("EXACT",row.get("storeType").getAsString()); + assertEquals("PASS",row.get("verdict").getAsString()); + assertFalse(row.has("programKind")); + assertTrue(strategies.add(row.get("strategy").getAsString())); + } + assertEquals(java.util.Set.of("DFS","STATIC_POR","DPOR","CONTEXT_BOUNDED"),strategies); + java.nio.file.Files.createDirectories(java.nio.file.Path.of("build")); + java.nio.file.Files.writeString(java.nio.file.Path.of("build/declarative-symmetry-exact-report.json"),result.output()); + var failed=invokeCli("--file","src/test/resources/dsl/symmetry-committed-failure.json","--symmetry","--store","exact","--strategy","DFS","--json"); + assertEquals(0,failed.exitCode(),failed.output()); + var failedReport=dev.samhb.interleave.testsupport.JsonAssertions.parseObject(failed.output()); + assertTrue(failedReport.get("soundness").getAsBoolean()); + var failedRow=failedReport.getAsJsonArray("benchmarks").get(0).getAsJsonObject(); + assertEquals("VIOLATION",failedRow.get("verdict").getAsString()); + var snapshots=failedRow.getAsJsonObject("failingTrace").getAsJsonArray("states"); + assertFalse(snapshots.isEmpty()); + assertEquals(1,snapshots.get(snapshots.size()-1).getAsJsonObject().getAsJsonObject("fields").get("x").getAsInt()); + java.nio.file.Files.writeString(java.nio.file.Path.of("build/declarative-symmetry-failure-cli.json"),failed.output()); + for(var strategy:strategies) { + var explicit=invokeCli("--file","examples/programs/semaphore-declarative.json","--symmetry","--store","exact","--strategy",strategy,"--json"); + assertEquals(0,explicit.exitCode(),explicit.output()); + var selected=dev.samhb.interleave.testsupport.JsonAssertions.parseObject(explicit.output()).getAsJsonArray("benchmarks"); + assertEquals(1,selected.size()); + assertEquals(strategy,selected.get(0).getAsJsonObject().get("strategy").getAsString()); + } + } + + /** Declarative support does not admit approximation early or source-only witness operations. + * @throws Exception if a child JVM fails to launch + */ + @Test void declarativeSymmetryCliRetainsPhaseAndEvidenceGuards() throws Exception { + for(var args:java.util.List.of( + java.util.List.of("--store","bitstate"),java.util.List.of(), + java.util.List.of("--store","exact","--strategy","DFS","--simplify-cutoff"), + java.util.List.of("--store","exact","--strategy","DFS","--shortest-cutoff","4"))) { + var command=new java.util.ArrayList<>(java.util.List.of("--file","examples/programs/semaphore-declarative.json","--symmetry","--json")); + command.addAll(args); + var result=invokeCli(command.toArray(String[]::new)); + assertEquals(1,result.exitCode(),result.output()); + String reason=args.contains("bitstate") ? "Approximate symmetry requires source input" + : args.contains("--simplify-cutoff") ? "--simplify-cutoff requires --source" + : args.contains("--shortest-cutoff") ? "--shortest-cutoff requires --source" : "explicit --store exact|bitstate"; + assertTrue(result.output().contains(reason),result.output()); + } + var typed=invokeCli("--file","examples/programs/lost-update.json","--symmetry","--store","exact"); + assertEquals(1,typed.exitCode(),typed.output()); + assertTrue(typed.output().contains("--symmetry requires")); + } + /** Runs the actual entry point in a child JVM because validation calls System.exit. * @param arguments CLI arguments * @return exit status and merged output diff --git a/src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java b/src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java new file mode 100644 index 0000000..ae8bd22 --- /dev/null +++ b/src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java @@ -0,0 +1,216 @@ +/** Exercises loader-issued symmetry trust and reassembled declarative admission. */ +package dev.samhb.interleave.format.dsl; + +import com.google.gson.Gson; +import dev.samhb.interleave.bugs.BenchmarkProgram; +import dev.samhb.interleave.core.*; +import dev.samhb.interleave.format.ProgramLoader; +import dev.samhb.interleave.search.DfsExplorer; +import dev.samhb.interleave.search.SymmetryDfsExplorer; +import java.nio.file.Path; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** Checks trusted JSON eligibility through the public loader and checked search. */ +class DeclarativeSymmetryEligibilityTest { + /** The finite semaphore has eight concrete positions and five independently enumerated orbits. */ + @Test void semaphoreMatchesIndependentOrbitCounts() { + var model = new ProgramLoader().loadFromFile(Path.of("examples/programs/semaphore-declarative.json")); + var property = model.invariant().orElseThrow(); + assertEquals(List.of(List.of(0, 1)), SourceSymmetry.groups(model.program(), property)); + assertEquals(8, new DfsExplorer().explore(model.program(), property).statesExplored()); + assertEquals(5, new SymmetryDfsExplorer().explore(model.program(), property).statesExplored()); + assertFalse(model.program().isSource()); + assertNull(model.program().sourceDigest()); + } + + /** Public constructors stay usable for ordinary execution but do not issue trust. */ + @Test void publicConstructionAndMissingLoaderPermitCannotIssueTrust() { + var model = pair(null, List.of("x = x + 1"), null); + var state = (DynamicState) model.program().initialConfiguration().state(); + var effect = new Parser("x = x + 1").parseEffect(); + var steps = List.of(new ModelThread(0, List.of(new DynamicStep(0, null, List.of(effect), state.decl(), "a"))), + new ModelThread(1, List.of(new DynamicStep(1, null, List.of(effect), state.decl(), "b")))); + var untrusted = new Program(state, steps); + assertEquals(4, new DfsExplorer().explore(untrusted).statesExplored()); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(untrusted, null)); + var publicProperty = new DslInvariant(new Expr.BoolLit(true), state.decl()); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(model.program(), publicProperty)); + assertThrows(NullPointerException.class, () -> DynamicStep.validated(null, 0, null, List.of(effect), state.decl(), null)); + assertThrows(NullPointerException.class, () -> DslInvariant.validated(null, + List.of(new Expr.LocalRef("v")), state.decl(), DslInvariant.When.ALWAYS)); + } + + /** Trust is tied to complete owner/declaration bindings, including fixed owners and properties. */ + @Test void reassemblyRejectsForeignBindingsAndCallbacks() { + var a = pair(null, List.of("x = 1"), "true"); + var b = pair(null, List.of("x = 1"), "true"); + var state = (DynamicState) a.program().initialConfiguration().state(); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(a.program(), b.invariant().orElseThrow())); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(a.program(), (s,c) -> true)); + var foreign = new Program(state, List.of(a.program().threads().get(0), b.program().threads().get(1))); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(foreign, null)); + var wrongState = new Program(b.program().initialConfiguration().state(), a.program().threads()); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(wrongState, null)); + var wrongOwner = new Program(state, List.of(a.program().threads().get(0), + new ModelThread(1, a.program().threads().get(0).steps()))); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(wrongOwner, null)); + var wrongId = new Program(state, List.of(a.program().threads().get(0), new ModelThread(7, a.program().threads().get(1).steps()))); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(wrongId, null)); + var wrongCount = new Program(new DynamicState(state.decl(), 3), a.program().threads()); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(wrongCount, null)); + } + + /** Repeated certified occurrences still count against per-owner and aggregate AST bounds. */ + @Test void reassembledModelsRetainAdmissionBounds() { + var model = pair(null, List.of("x = 1"), null); + assertEquals(List.of(List.of(0,1)), SourceSymmetry.groups(repeat(model,64), null)); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(repeat(model,65), null)); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(repeat(model,0), null)); + var declaration=((DynamicState)model.program().initialConfiguration().state()).decl(); + var partialEmpty=new Program(new DynamicState(declaration,3),List.of(model.program().threads().get(0), + model.program().threads().get(1),new ModelThread(2,List.of()))); + assertThrows(IllegalArgumentException.class,()->SourceSymmetry.groups(partialEmpty,null)); + // A balanced sum of 125 leaves has 249 AST nodes; the true guard adds one. + var budget = pair("true", List.of("x = " + sum(125)), "true"); + assertEquals(List.of(List.of(0,1)), SourceSymmetry.groups(repeat(budget,10), null)); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(repeat(budget,11), null)); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(repeat(budget,10), budget.invariant().orElseThrow())); + // Two 2,499-node RHS trees plus a two-node shared property exactly reach the admission cap. + var withProperty=pair(null,List.of("x = "+sum(1250)),"!false"); + assertEquals(List.of(List.of(0,1)),SourceSymmetry.groups(withProperty.program(),withProperty.invariant().orElseThrow())); + // 247 RHS nodes + one guard + three index nodes = 251; twenty occurrences exceed 5,000. + for(String target:List.of("arr[0+0]","local.a[0+0]")) { + var indexed=pair("true",List.of(target+" = "+sum(124)),null); + assertThrows(IllegalArgumentException.class,()->SourceSymmetry.groups(repeat(indexed,10),null)); + } + } + + /** Any nested tid syntax fixes its owner, including short-circuited expressions and array indices. + * @param effect owner-sensitive effect + */ + @ParameterizedTest @ValueSource(strings={"x = tid", "x = arr[tid]", "arr[tid] = 1", "local.a[tid] = 1", "x = local.a[tid]", "x = -tid"}) + void nestedIdentityObservationsDoNotQualify(String effect) { + var model = pair(null,List.of(effect),null); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(model.program(),null)); + } + + /** Grouping preserves structure/order and ignores diagnostic names, not semantic differences. */ + @Test void guardsOrderingAndInitialFramesRemainDistinct() { + var identity = pair("true || tid == 0",List.of("x = 1"),null); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(identity.program(),null)); + var model = pair(null,List.of("x = 1","x = x + 1"),null); + var fixed = model; + var state = (DynamicState) model.program().initialConfiguration().state(); + state.setLocalInt(1,"v",1); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(new Program(state,fixed.program().threads()),null)); + var root = (DynamicState) model.program().initialConfiguration().state(); + root.setLocalBool(1,"b",true); + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(new Program(root,fixed.program().threads()),null)); + var arrays = (DynamicState) model.program().initialConfiguration().state(); + arrays.getLocalArrayRef(1,"a")[0]=1; + assertThrows(IllegalArgumentException.class, () -> SourceSymmetry.groups(new Program(arrays,fixed.program().threads()),null)); + } + + /** A custom stored state cannot establish trust by returning a DynamicState from later copies. */ + @Test void storedStateTypeRejectsCopyAdaptersBeforeAnotherCallback() { + var model=new ProgramLoader().loadFromFile(Path.of("examples/programs/semaphore-declarative.json")); + var copies=new java.util.concurrent.atomic.AtomicInteger(); + SharedState adapter=new SharedState() { + /** {@inheritDoc} */ + public SharedState deepCopy() { + return copies.getAndIncrement()==0 ? this : model.program().initialConfiguration().state(); + } + /** {@inheritDoc} */ + public void encodeTo(java.io.DataOutput out) {throw new AssertionError("untrusted encoder invoked");} + }; + var forged=new Program(adapter,model.program().threads()); + int before=copies.get(); + assertThrows(IllegalArgumentException.class,()->SourceSymmetry.groups(forged,null)); + assertEquals(before,copies.get(),"certification must not invoke another untrusted copy"); + } + + /** Fixed owners remain trusted and cannot smuggle executable callbacks into certification. */ + @Test void fixedOwnerCallbackRejectsBeforeEnabledness() { + var model=pair(null,List.of("x = 1"),null); + var decl=((DynamicState)model.program().initialConfiguration().state()).decl(); + Step callback=new Step() { + /** {@inheritDoc} */ + public java.util.Set reads(){return java.util.Set.of();} + /** {@inheritDoc} */ + public java.util.Set writes(){return java.util.Set.of();} + /** {@inheritDoc} */ + public boolean enabled(SharedState state){throw new AssertionError("untrusted callback invoked");} + /** {@inheritDoc} */ + public StepOutcome execute(SharedState state){throw new AssertionError("untrusted callback executed");} + }; + var threads=new ArrayList<>(model.program().threads());threads.add(new ModelThread(2,List.of(callback))); + var program=new Program(new DynamicState(decl,3),threads); + assertThrows(IllegalArgumentException.class,()->SourceSymmetry.groups(program,null)); + } + + /** Names are diagnostic; ordered semantic differences and owner observations stay significant. */ + @Test void noncontiguousGroupsFixObserversAndDoNotNormalizeSyntax() { + String json=""" + {"format":"declarative","name":"mixed","state":{"fields":[{"name":"x","type":"int","init":0}],"locals":[]}, + "threads":[{"id":0,"steps":[{"name":"first","effects":["x = 1","x = x + 1"]}]}, + {"id":1,"steps":[{"effects":["x = tid"]}]}, + {"id":2,"steps":[{"name":"third","effects":["x = 1","x = x + 1"]}]}]} + """; + var model=new ProgramLoader().load(json); + assertEquals(List.of(List.of(0,2)),SourceSymmetry.groups(model.program(),null)); + var reversed=new ProgramLoader().load(json.replace("\"name\":\"third\",\"effects\":[\"x = 1\",\"x = x + 1\"]", + "\"effects\":[\"x = x + 1\",\"x = 1\"]")); + assertThrows(IllegalArgumentException.class,()->SourceSymmetry.groups(reversed.program(),null)); + var guarded=new ProgramLoader().load(json.replace("\"name\":\"third\"","\"guard\":\"false\"")); + assertThrows(IllegalArgumentException.class,()->SourceSymmetry.groups(guarded.program(),null)); + var source=new dev.samhb.interleave.format.SourceProgramLoader().load( + "program mixed { shared int x = 0; thread 0 { atomic { x = 1; } } thread 1 { atomic { x = 1; } } }"); + var mixed=new Program(source.program().initialConfiguration().state(),source.program().threads()); + assertThrows(IllegalArgumentException.class,()->SourceSymmetry.groups(mixed,null)); + } + + /** Reassembles a bounded number of occurrences without minting new trusted instructions. + * @param model original validated model + * @param count occurrences in each owner + * @return isolated reassembled program + */ + private static Program repeat(BenchmarkProgram model,int count) { + var threads=new ArrayList(); + for(var thread:model.program().threads()) threads.add(new ModelThread(thread.id(),Collections.nCopies(count,thread.steps().getFirst()))); + return new Program(model.program().initialConfiguration().state(),threads); + } + + /** Builds a balanced bounded expression without relying on production AST node counting. + * @param leaves literal leaves + * @return sum expression + */ + private static String sum(int leaves) { + return leaves==1 ? "1" : "("+sum(leaves/2)+"+"+sum(leaves-leaves/2)+")"; + } + + /** Loads a real typed JSON pair with scalar/array locals and optional shared property. + * @param guard optional guard + * @param effects ordered effects + * @param property optional always-timed shared predicate + * @return validated model + */ + private static BenchmarkProgram pair(String guard,List effects,String property) { + var gson=new Gson(); + var action=new java.util.LinkedHashMap(); + action.put("effects",effects); if(guard!=null) action.put("guard",guard); + var json=""" + {"format":"declarative","name":"pair","state":{"fields":[{"name":"x","type":"int","init":0}, + {"name":"arr","type":"int[]","init":[0,0]}],"locals":[{"name":"v","type":"int","init":0}, + {"name":"b","type":"bool","init":false},{"name":"a","type":"int[]","init":[0,0]}]}, + "threads":[{"id":0,"steps":[%s]},{"id":1,"steps":[%s]}]%s} + """.formatted(gson.toJson(action),gson.toJson(action),property==null ? "" : ",\"invariant\":"+gson.toJson(Map.of("when","always","expr",property))); + return new ProgramLoader().load(json); + } +} diff --git a/src/test/java/dev/samhb/interleave/report/DeclarativeSymmetryAttestationTest.java b/src/test/java/dev/samhb/interleave/report/DeclarativeSymmetryAttestationTest.java new file mode 100644 index 0000000..89ca7f2 --- /dev/null +++ b/src/test/java/dev/samhb/interleave/report/DeclarativeSymmetryAttestationTest.java @@ -0,0 +1,173 @@ +/** Positive observations and inconclusive expectations for certified declarative symmetry reports. */ +package dev.samhb.interleave.report; + +import com.google.gson.Gson; +import dev.samhb.interleave.bugs.BenchmarkProgram; +import dev.samhb.interleave.core.*; +import dev.samhb.interleave.format.ProgramLoader; +import dev.samhb.interleave.search.*; +import java.util.*; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** Tests actual reported observations, including forged or disabled execution claims. */ +class DeclarativeSymmetryAttestationTest { + /** Real step errors validate without requiring an unrelated invariant to fail. */ + @Test void actualFinalStepFailureWithTrueInvariantIsValid() { + var model = model(null, List.of("x = 1", "x = x % 0"), "true"); + var rows = new BenchmarkHarness(1024,4,Set.of(StoreType.EXACT),null,2,false,true).runProgram(model); + assertEquals(4, rows.size()); + var attestation = new SoundnessAttestation(rows,List.of(model)); + assertTrue(attestation.isSound(),attestation.failureReason()); + assertTrue(attestation.formatMarkdown().contains("actual certified declarative step failures were checked with enabled original choices")); + assertTrue(rows.stream().allMatch(row -> row.verdict().equals("VIOLATION"))); + var root=model.program().initialConfiguration(); + var scratch=(dev.samhb.interleave.format.dsl.DynamicState) root.state().deepCopy(); + assertEquals(StepOutcome.ASSERTION_FAILED,model.program().threads().getFirst().steps().getFirst().execute(scratch)); + assertEquals(1,scratch.getInt("x"),"ordered effects precede the error in private scratch"); + assertNull(TransitionExecutor.execute(model.program(),root,0).successor()); + assertEquals(0,((dev.samhb.interleave.format.dsl.DynamicState)root.state()).getInt("x")); + } + + /** Failed attempts retain the committed prefix in full, partial and harness diagnostics. + * @throws Exception if producer artifact writes fail + */ + @Test void checkedFailureSnapshotsRetainCommittedPrefix() throws Exception { + var model=new ProgramLoader().loadFromResource("dsl/symmetry-committed-failure.json"); + var rows=new BenchmarkHarness(1024,4,Set.of(StoreType.EXACT),null,2,false,true).runProgram(model); + assertEquals(4,rows.size()); + for(var row:rows) { + assertEquals("VIOLATION",row.verdict()); + assertCommittedFailureStates(row.failingTrace().orElseThrow().length(),row.states()); + } + java.nio.file.Files.createDirectories(java.nio.file.Path.of("build")); + java.nio.file.Files.writeString(java.nio.file.Path.of("build/declarative-symmetry-failure-report.json"),new ReportWriter(rows,List.of(model)).writeJson()); + for(var strategy:dev.samhb.interleave.Strategy.values())for(int limit:List.of(0,3)) { + var result=dev.samhb.interleave.InterleaveRunner.builder().strategy(strategy).symmetryReduction(true) + .maxStates(limit).invariant(model.invariant().orElseThrow()).build().run(model.program()); + assertTrue(result.hasViolation());assertEquals(limit>0,result.limitExceeded()); + assertFalse(result.failingTraces().isEmpty()); + for(var trace:result.failingTraces())assertCommittedFailureStates(trace.threadIds().size(),trace.states()); + if(strategy==dev.samhb.interleave.Strategy.DFS && limit==0)java.nio.file.Files.writeString( + java.nio.file.Path.of("build/declarative-symmetry-failure-library.json"),result.toJson()); + } + var original=rows.getFirst().failingTrace().orElseThrow(); + var legacy=new TraceReplayer().replay(model.program(),original); + assertEquals(7,((dev.samhb.interleave.format.dsl.DynamicState)legacy.state()).getInt("x"),"ordinary legacy replay retains its existing partial-effect behavior"); + } + + /** Checks one immutable state per action boundary, repeating the last committed state on failure. + * @param length attempted choices including the failed last action + * @param states exported state snapshots + */ + private static void assertCommittedFailureStates(int length,List states) { + assertEquals(length+1,states.size()); + assertEquals(0,states.getFirst().fields().get("x")); + assertEquals(1,states.getLast().fields().get("x")); + assertEquals(states.get(states.size()-2),states.getLast()); + assertTrue(states.stream().noneMatch(state->Integer.valueOf(7).equals(state.fields().get("x")))); + } + + /** Legacy replay would execute disabled choices and cannot authenticate a no-property violation. */ + @Test void fabricatedAndTrailingViolationsFailWithoutThrowing() { + var blocked = model("false",List.of("x = x % 0"),null); + assertFalse(attest(blocked,new Trace(List.of(0),List.of(StepOutcome.ASSERTION_FAILED),TraceOutcome.VIOLATION))); + var safe=model(null,List.of("x = 1"),null); + assertFalse(attest(safe,new Trace(List.of(0),List.of(StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + assertFalse(attest(safe,new Trace(List.of(),List.of(),TraceOutcome.VIOLATION))); + assertFalse(attest(safe,new Trace(List.of(9),List.of(StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + assertFalse(attest(safe,new Trace(List.of(-1),List.of(StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + assertFalse(attest(safe,new Trace(List.of(0,0),List.of(StepOutcome.ADVANCED,StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + var failure=model(null,List.of("x = x % 0"),"true"); + assertFalse(attest(failure,new Trace(List.of(0,1),List.of(StepOutcome.ASSERTION_FAILED,StepOutcome.ASSERTION_FAILED),TraceOutcome.VIOLATION))); + assertFalse(attest(failure,new Trace(List.of(0),List.of(StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + var always=model(null,List.of("x = 1"),"x == 0"); + assertTrue(attest(always,new Trace(List.of(0),List.of(StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + assertFalse(attest(always,new Trace(List.of(0,1),List.of(StepOutcome.ADVANCED,StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + var root=model(null,List.of("x = 1"),"false"); + assertTrue(attest(root,new Trace(List.of(),List.of(),TraceOutcome.VIOLATION))); + assertFalse(attest(root,new Trace(List.of(0),List.of(StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + } + + /** A real step error cannot authenticate fabricated source or cutoff diagnostics. */ + @Test void declarativeViolationRejectsForeignEvidence() { + var model=model(null,List.of("x = x % 0"),"true"); + var foreign=new TraceEvidence(null,List.of(),null, + new CutoffEvidence(CutoffEvidence.Reason.PREEMPTION_BOUND,0,0,0,null,null,List.of())); + assertFalse(attest(model,new Trace(List.of(0),List.of(StepOutcome.ASSERTION_FAILED),TraceOutcome.VIOLATION,foreign))); + } + + /** Invalid positive metadata fails closed with an actionable subject/strategy/store diagnostic. */ + @Test void positiveCertificationFailuresKeepConcreteDiagnostics() { + var model=model(null,List.of("x = 1"),null); + var trace=new Trace(List.of(0),List.of(StepOutcome.ADVANCED),TraceOutcome.VIOLATION); + var row=new BenchmarkResult("DPOR",model.name(),1,0,0,"VIOLATION",trace,StoreType.EXACT) + .withExploration(model.program(),new DfsResult(Map.of(),List.of(trace),1),true); + var invalid=new SoundnessAttestation(List.of(row),List.of(model)); + assertFalse(invalid.isSound()); + assertEquals("Invalid declarative symmetry violation for subject under DPOR (EXACT)",invalid.failureReason()); + var state=(dev.samhb.interleave.format.dsl.DynamicState)model.program().initialConfiguration().state(); + var property=new dev.samhb.interleave.format.dsl.DslInvariant(new dev.samhb.interleave.format.dsl.Expr.BoolLit(false),state.decl()); + var untrusted=new BenchmarkProgram(model.name(),model.program(),null,property); + assertFalse(attest(untrusted,new Trace(List.of(),List.of(),TraceOutcome.VIOLATION))); + var callback=new BenchmarkProgram(model.name(),model.program(),null,(value,config)->{throw new AssertionError("uncertified property invoked");}); + assertFalse(attest(callback,trace)); + } + + /** Source symmetry retains its existing qualified attestation prose. */ + @Test void sourceSymmetryRetainsExistingAttestationWording() { + var model=new dev.samhb.interleave.format.SourceProgramLoader().load( + "program source { shared int x = 0; thread 0 { atomic { x = x + 1; } } thread 1 { atomic { x = x + 1; } } invariant final (x == 2); }"); + var rows=new BenchmarkHarness(1024,4,Set.of(StoreType.EXACT),null,2,false,true).runProgram(model); + var attestation=new SoundnessAttestation(rows,List.of(model)); + assertTrue(attestation.isSound(),attestation.failureReason()); + var prose=attestation.formatMarkdown(); + assertTrue(prose.contains("Source DFS results that were INCOMPLETE")); + assertTrue(prose.contains("source runtime or assertion failures were authenticated")); + assertFalse(prose.contains("certified declarative")); + } + + /** A real interrupted DFS is inconclusive, while an untrusted marker grants no exception. */ + @Test void certifiedIncompleteDoesNotBecomeExpectationMismatch() { + var model=model(null,List.of("x = 1"),"true"); + var expected=new BenchmarkProgram(model.name(),model.program(),"PASS",model.invariant().orElseThrow()); + var incomplete=new BenchmarkResult("DFS",model.name(),1,0,0,"INCOMPLETE",null,StoreType.EXACT) + .withExploration(model.program(),new DfsResult(Map.of(),List.of(),1),true); + assertTrue(new SoundnessAttestation(List.of(incomplete),List.of(expected)).isSound()); + var forged=new BenchmarkProgram(expected.name(),expected.program(),"PASS",(s,c)->true); + assertFalse(new SoundnessAttestation(List.of(incomplete),List.of(forged)).isSound()); + var expectedFailure=new BenchmarkProgram(model.name(),model.program(),"VIOLATION",model.invariant().orElseThrow()); + var inconclusive=new SoundnessAttestation(List.of(incomplete),List.of(expectedFailure)); + assertTrue(inconclusive.isSound(),inconclusive.failureReason()); + assertEquals("INCOMPLETE",incomplete.verdict()); + assertTrue(inconclusive.formatMarkdown().contains("inconclusive, not matched verdicts")); + } + + /** Attests a marked non-DFS row so positive-witness checks run independently of expectations. + * @param model registered trusted model + * @param trace claimed positive observation + * @return whether concrete positive validation succeeds + */ + private static boolean attest(BenchmarkProgram model,Trace trace) { + var row=new BenchmarkResult("STATIC_POR",model.name(),1,0,0,"VIOLATION",trace,StoreType.EXACT) + .withExploration(model.program(),new DfsResult(Map.of(),List.of(trace),1),true); + return new SoundnessAttestation(List.of(row),List.of(model)).isSound(); + } + + /** Loads matching actions with an optional shared always predicate. + * @param guard optional guard + * @param effects ordered effects + * @param property optional shared predicate + * @return real loader-validated pair + */ + private static BenchmarkProgram model(String guard,List effects,String property) { + var action=new LinkedHashMap(); + action.put("effects",effects);if(guard!=null)action.put("guard",guard); + var document=new LinkedHashMap(); + document.put("format","declarative");document.put("name","subject"); + document.put("state",Map.of("fields",List.of(Map.of("name","x","type","int","init",0)),"locals",List.of())); + document.put("threads",List.of(Map.of("id",0,"steps",List.of(action)),Map.of("id",1,"steps",List.of(action)))); + if(property!=null)document.put("invariant",Map.of("when","always","expr",property)); + return new ProgramLoader().load(new Gson().toJson(document)); + } +} diff --git a/src/test/java/dev/samhb/interleave/search/DeclarativeSnapshotCaptureTest.java b/src/test/java/dev/samhb/interleave/search/DeclarativeSnapshotCaptureTest.java new file mode 100644 index 0000000..65cc71a --- /dev/null +++ b/src/test/java/dev/samhb/interleave/search/DeclarativeSnapshotCaptureTest.java @@ -0,0 +1,55 @@ +/** Committed-state diagnostics for certified declarative models, independent of legacy replay. */ +package dev.samhb.interleave.search; + +import dev.samhb.interleave.bugs.BenchmarkProgram; +import dev.samhb.interleave.core.*; +import dev.samhb.interleave.format.ProgramLoader; +import dev.samhb.interleave.format.SourceProgramLoader; +import java.util.List; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** Verifies actual enabled transitions and failed-attempt snapshot alignment through the public capturer. */ +class DeclarativeSnapshotCaptureTest { + /** A root prefix, successful action and failed last attempt have literal committed values. */ + @Test void capturesOnlyActualCommittedBoundaries() { + var model=model();var replayer=new TraceReplayer(); + var root=new Trace(List.of(),List.of(),TraceOutcome.INCOMPLETE); + assertEquals(List.of(0),replayer.captureDeclarativeSnapshots(model.program(),root).stream().map(s->s.fields().get("x")).toList()); + var completePrefix=new Trace(List.of(0),List.of(StepOutcome.ADVANCED),TraceOutcome.INCOMPLETE); + assertEquals(List.of(0,1),replayer.captureDeclarativeSnapshots(model.program(),completePrefix).stream().map(s->s.fields().get("x")).toList()); + var failed=new Trace(List.of(0,0),List.of(StepOutcome.ADVANCED,StepOutcome.ASSERTION_FAILED),TraceOutcome.VIOLATION); + var states=replayer.captureDeclarativeSnapshots(model.program(),failed); + assertEquals(List.of(0,1,1),states.stream().map(s->s.fields().get("x")).toList()); + assertThrows(UnsupportedOperationException.class,()->states.clear()); + assertEquals(List.of(0,1,7),replayer.captureSnapshots(model.program(),failed).stream().map(s->s.fields().get("x")).toList()); + } + + /** Unsupported models, disabled owners, mismatched outcomes and trailing attempts reject. */ + @Test void rejectsInvalidModelAndExecutionClaims() { + var model=model();var replayer=new TraceReplayer(); + var first=new Trace(List.of(0),List.of(StepOutcome.ADVANCED),TraceOutcome.INCOMPLETE); + assertThrows(NullPointerException.class,()->replayer.captureDeclarativeSnapshots(null,first)); + assertThrows(NullPointerException.class,()->replayer.captureDeclarativeSnapshots(model.program(),null)); + var source=new SourceProgramLoader().load("program source { shared int x = 0; thread 0 { atomic { x = 1; } } thread 1 { atomic { x = 1; } } }"); + assertThrows(IllegalArgumentException.class,()->replayer.captureDeclarativeSnapshots(source.program(),first)); + var wrongState=new Program(new CounterState(0),model.program().threads()); + assertThrows(IllegalArgumentException.class,()->replayer.captureDeclarativeSnapshots(wrongState,first)); + assertThrows(IllegalScheduleException.class,()->replayer.captureDeclarativeSnapshots(model.program(),new Trace(List.of(-1),List.of(StepOutcome.ADVANCED),TraceOutcome.INCOMPLETE))); + assertThrows(CorruptedTraceException.class,()->replayer.captureDeclarativeSnapshots(model.program(),new Trace(List.of(0),List.of(StepOutcome.ASSERTION_FAILED),TraceOutcome.VIOLATION))); + assertThrows(CorruptedTraceException.class,()->replayer.captureDeclarativeSnapshots(model.program(),new Trace(List.of(0,0,1),List.of(StepOutcome.ADVANCED,StepOutcome.ASSERTION_FAILED,StepOutcome.ADVANCED),TraceOutcome.VIOLATION))); + var disabled=new ProgramLoader().load(""" + {"format":"declarative","name":"disabled","state":{"fields":[{"name":"x","type":"int","init":0}],"locals":[]}, + "threads":[{"id":0,"steps":[{"guard":"false","effects":["x = 1"]}]}, + {"id":1,"steps":[{"guard":"false","effects":["x = 1"]}]}]} + """); + assertThrows(IllegalScheduleException.class,()->replayer.captureDeclarativeSnapshots(disabled.program(),first)); + } + + /** Loads the shared two-action committed-prefix failure fixture. + * @return certified declarative model + */ + private static BenchmarkProgram model() { + return new ProgramLoader().loadFromResource("dsl/symmetry-committed-failure.json"); + } +} diff --git a/src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java b/src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java new file mode 100644 index 0000000..eb0dbf9 --- /dev/null +++ b/src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java @@ -0,0 +1,296 @@ +/** Independent finite transition graphs and explicit owner permutations for declarative symmetry. */ +package dev.samhb.interleave.search; + +import com.google.gson.Gson; +import dev.samhb.interleave.Strategy; +import dev.samhb.interleave.bugs.BenchmarkProgram; +import dev.samhb.interleave.core.*; +import dev.samhb.interleave.format.ProgramLoader; +import dev.samhb.interleave.format.dsl.DynamicState; +import dev.samhb.interleave.format.dsl.SourceSymmetry; +import java.util.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import static org.junit.jupiter.api.Assertions.*; + +/** Expected graph states never use production group discovery, canonicalization or key encoding. */ +class DeclarativeSymmetryOracleTest { + /** Whole finite graphs agree with independent operational rules and explicit permutation classes. + * @param mode reference transition family + * @param owners bounded owner count + * @param concrete literal concrete-state count + * @param quotient literal orbit count + */ + @ParameterizedTest @CsvSource({"counter,4,16,5","semaphore,2,8,5","split,2,13,8"}) + void finiteGraphsMatchIndependentReference(String mode,int owners,int concrete,int quotient) { + var steps=switch(mode) { + case "counter" -> List.of(action(null,List.of("x = x + 1"))); + case "semaphore" -> List.of(action("x > 0",List.of("x = x - 1")),action(null,List.of("x = x + 1"))); + case "split" -> List.of(action(null,List.of("local.r = x")),action(null,List.of("x = local.r + 1"))); + default -> throw new AssertionError(mode); + }; + var model=load(owners,mode.equals("semaphore")?1:0,steps,null); + var expected=reference(mode,owners); + assertEquals(concrete,expected.size()); + var permutations=permutations(owners); + var orbits=new HashSet(); + for(var state:expected)orbits.add(orbit(state,permutations)); + assertEquals(quotient,orbits.size()); + var ordinary=new DfsExplorer().explore(model.program()); + var actual=new HashSet(); + for(var state:ordinary.states().values())actual.add(project(state)); + assertEquals(expected,actual); + for(var backend:SymmetryBackend.values()) { + var store=SymmetryStateStore.forRun(model.program(),null,Strategy.DFS,backend); + var reduced=new DfsExplorer().explore(model.program(),null,store,null); + assertEquals(quotient,reduced.statesExplored()); + var actualOrbits=new HashSet(); + for(var state:reduced.states().values())actualOrbits.add(orbit(project(state),permutations)); + assertEquals(orbits,actualOrbits); + assertFalse(reduced.traces().isEmpty()); + assertTrue(reduced.traces().stream().allMatch(t->t.outcome()==TraceOutcome.COMPLETED)); + for(var trace:reduced.traces())checkConcreteWitness(model,trace); + } + } + + /** Every exact strategy/backend preserves a finite violating final property and concrete witness. */ + @Test void failingFinalPropertyMatchesExhaustiveReferenceAcrossStrategies() { + var steps=List.of(action(null,List.of("local.r = x")),action(null,List.of("x = local.r + 1"))); + var model=load(2,0,steps,"x == 2","final"); + var reference=reference("split",2); + var finals=new HashSet(); + for(var state:reference)if(state.pcs().equals(List.of(2,2)))finals.add(state.x()); + assertEquals(Set.of(1,2),finals); + var property=model.invariant().orElseThrow(); + assertTrue(new DfsExplorer().explore(model.program(),property).traces().stream().anyMatch(t->t.outcome()==TraceOutcome.VIOLATION)); + for(var strategy:Strategy.values())for(var backend:SymmetryBackend.values()) { + var store=SymmetryStateStore.forRun(model.program(),property,strategy,backend); + var result=switch(strategy) { + case DFS -> new DfsExplorer().explore(model.program(),property,store,null); + case STATIC_POR -> new dev.samhb.interleave.por.StaticPorExplorer().explore(model.program(),property,store,null); + case DPOR -> new dev.samhb.interleave.dpor.DporExplorer().explore(model.program(),property,store,null); + case CONTEXT_BOUNDED -> new dev.samhb.interleave.cb.ContextBoundedExplorer().explore(model.program(),property,store,null,2); + }; + var failures=result.traces().stream().filter(t->t.outcome()==TraceOutcome.VIOLATION).toList(); + assertFalse(failures.isEmpty(),strategy+" "+backend); + for(var trace:failures) { + var config=model.program().initialConfiguration(); + for(int i=0;i reference(String mode,int owners) { + var root=new Reference(mode.equals("semaphore")?1:0,Collections.nCopies(owners,0),Collections.nCopies(owners,0)); + var seen=new HashSet();seen.add(root); + var queue=new ArrayDeque();queue.add(root); + while(!queue.isEmpty()) { + var state=queue.removeFirst(); + for(int owner=0;owner(state.locals());var pcs=new ArrayList<>(state.pcs());pcs.set(owner,pc+1); + switch(mode) { + case "counter" -> value++; + case "semaphore" -> value+=pc==0?-1:1; + case "split" -> {if(pc==0)locals.set(owner,value);else value=locals.get(owner)+1;} + default -> throw new AssertionError(mode); + } + var next=new Reference(value,List.copyOf(locals),List.copyOf(pcs)); + if(seen.add(next))queue.add(next); + } + } + return Set.copyOf(seen); + } + + /** Projects actual concrete values without using production keys. + * @param config concrete position + * @return independent finite reference position + */ + private static Reference project(Configuration config) { + var state=(DynamicState)config.state();var locals=new ArrayList(); + for(int owner=0;owner permutations) { + String best=null; + for(var permutation:permutations) { + var frames=new String[permutation.length]; + for(int owner=0;owner permutations(int count) { + var result=new ArrayList();result.add(new int[0]); + for(int size=0;size(); + for(var old:result)for(int slot=0;slot<=size;slot++) { + var value=new int[size+1];System.arraycopy(old,0,value,0,slot);value[slot]=size; + System.arraycopy(old,slot,value,slot+1,size-slot);next.add(value); + } + result=next; + } + return result; + } + + /** Transports scalar/array owner frames explicitly while shared fields stay fixed. + * @param original independent concrete state + * @param permutation original-to-image map + * @return independent permuted state + */ + private static DynamicState permute(DynamicState original,int[] permutation) { + var result=(DynamicState)original.deepCopy(); + for(int owner=0;owner action(String guard,List effects) { + var action=new LinkedHashMap();action.put("effects",effects); + if(guard!=null)action.put("guard",guard);return action; + } + + /** Loads finite matching owner programs with complete typed scalar/array state. + * @param owners count of interchangeable owners + * @param initial shared x + * @param steps ordered actions + * @param property optional always property + * @return validated model + */ + private static BenchmarkProgram load(int owners,int initial,List> steps,String property) { + return load(owners,initial,steps,property,"always"); + } + + /** Loads the selected observation timing without changing predicate or transition semantics. + * @param owners interchangeable owner count + * @param initial shared x + * @param steps ordered actions + * @param property optional shared property + * @param when final or always observation timing + * @return validated bounded model + */ + private static BenchmarkProgram load(int owners,int initial,List> steps,String property,String when) { + var document=new LinkedHashMap();document.put("format","declarative");document.put("name","oracle"); + document.put("state",Map.of("fields",List.of(Map.of("name","x","type","int","init",initial), + Map.of("name","arr","type","int[]","init",List.of(0,0))),"locals",List.of(Map.of("name","r","type","int","init",0), + Map.of("name","b","type","bool","init",false),Map.of("name","a","type","int[]","init",List.of(0,0))))); + var threads=new ArrayList>(); + for(int owner=0;owner effects,StepOutcome outcome,boolean propertyAfterExecution) {} + + /** Independent state for the bounded counter, semaphore and split-increment rules. + * @param x shared integer + * @param locals owner-local scalar registers + * @param pcs whole owner control frames + */ + private record Reference(int x,List locals,List pcs) {} +} diff --git a/src/test/resources/dsl/symmetry-committed-failure.json b/src/test/resources/dsl/symmetry-committed-failure.json new file mode 100644 index 0000000..25fa9fa --- /dev/null +++ b/src/test/resources/dsl/symmetry-committed-failure.json @@ -0,0 +1,10 @@ +{ + "format": "declarative", + "name": "committed-failure", + "state": {"fields": [{"name": "x", "type": "int", "init": 0}], "locals": []}, + "threads": [ + {"id": 0, "steps": [{"effects": ["x = 1"]}, {"effects": ["x = 7", "x = x % 0"]}]}, + {"id": 1, "steps": [{"effects": ["x = 1"]}, {"effects": ["x = 7", "x = x % 0"]}]} + ], + "invariant": {"when": "always", "expr": "true"} +} From b65c1594e845654fd386a3c5d0bd7b1ca3ded306 Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 12 Nov 2026 21:13:58 -0500 Subject: [PATCH 2/2] fix: close declarative symmetry admission gaps Require the declarative discriminator for direct loader calls and retain constructor input type metadata before a custom defensive copy can hide its provenance. Checked symmetry now validates both original input and retained snapshot types without retaining caller state or changing ordinary copying. Add red-green format and first-copy adapter regressions plus independent no-property POR/DPOR terminal-value and witness checks. Update the spec and measurement ledger with integrated validation and focused mutation evidence. Co-authored-by: Codex --- .../92-certified-declarative-symmetry.md | 38 ++++++++++++++-- docs/plans/declarative-symmetry-contract.md | 10 +++-- .../92-certified-declarative-symmetry.md | 23 +++++----- .../dev/samhb/interleave/core/Program.java | 10 +++++ .../interleave/format/dsl/DslLoader.java | 2 + .../interleave/format/dsl/SourceSymmetry.java | 4 +- .../DeclarativeSymmetryEligibilityTest.java | 45 +++++++++++++++++++ .../search/DeclarativeSymmetryOracleTest.java | 24 ++++++++++ 8 files changed, 137 insertions(+), 19 deletions(-) diff --git a/docs/measurements/92-certified-declarative-symmetry.md b/docs/measurements/92-certified-declarative-symmetry.md index f8ecb94..47ee75a 100644 --- a/docs/measurements/92-certified-declarative-symmetry.md +++ b/docs/measurements/92-certified-declarative-symmetry.md @@ -34,7 +34,7 @@ interpreter or a universal proof for arbitrary callbacks. - Admission, routing, CLI, viewer, attestation and failed-scratch regressions failed before their fixes and passed afterward. No test was deleted or weakened to pass a production defect. -- Final full build and strict Javadoc: **1,943 tests**, zero failures/errors/skips. +- Final full build and strict Javadoc: **1,948 tests**, zero failures/errors/skips. - **218 browser assertions** pass with zero console errors, using fresh existing source artifacts and declarative exact reports, completed/root/later traces and failed-effect library/CLI payloads. - Private-member doclint passes for eight certification/attestation/state/capture files using @@ -49,8 +49,9 @@ The final source compatibility regression initially used an invalid mixed-case s correcting the test fixture preserves the lowercase grammar. Earlier integrated logs retain report wording/test-wrapper failures and the snapshot red/green evidence. Failed commands are not passes. -## Mutation measurements +## Initial L1 mutation measurements +The following measurements precede the PR feedback refinement recorded below. All runs use one Gradle worker and one PIT minion, the existing operators/test selection, and the unchanged default mutation threshold. K = KILLED, S = SURVIVED, NC = NO_COVERAGE. Each row below is an actual run; the scopes and revisions differ deliberately and their denominators are not comparable @@ -58,7 +59,7 @@ as whole-checker percentages. No row has resource, timeout, run-error or other m | Scope / point measured | Baseline | Feature | Meaning | |---|---|---|---| -| Default gate | 455/468 K + 13 S | 455/468 K + 13 S | Final production code; all 468 fingerprints and statuses identical. The subsequent source-only regression adds test coverage without changing production. | +| Default gate | 455/468 K + 13 S | 455/468 K + 13 S | Pre-feedback production code; all 468 fingerprints and statuses identical. The subsequent source-only regression adds test coverage without changing production. | | Broad affected census | 2,247/2,853 K + 177 S + 429 NC | 2,421/3,040 K + 184 S + 435 NC | Feature census precedes the later stored-state and committed-snapshot refinements. This is explicitly a point-in-time wide run. | | Program / SourceSymmetry / SoundnessAttestation (including record) | 225/227 K + 2 S | 343/344 K + 1 S | Final stored-state guard and strict positive-witness checks. Program 29/29 K; SourceSymmetry 106/107 K; attestation plus record 208/208 K. | | Source partial visitor, final test refinement | 30/43 K + 13 S | 38/47 K + 9 S | Added source partial-failure regression kills the source/JSON selector and source snapshot-call removals; zero NC. | @@ -137,6 +138,37 @@ committed build products: - `coderabbit.ndjson`, `coderabbit-final.ndjson`, `coderabbit-snapshots.ndjson` retain completed review output and finding severities. This ledger records independent dispositions. +## PR #136 feedback refinement + +All three posted findings were independently validated and patched: + +| Severity / finding | Fix and regression | +|---|---| +| Minor: direct DslLoader calls bypassed the format discriminator | Require exactly `declarative` before validation/certification. Direct calls with `typed`, empty or missing format all failed the new regression before the fix; explicit declarative definitions still certify. | +| Major: a custom first-copy adapter could retain a trusted-looking snapshot | Record only the constructor input class in Program before deepCopy and expose `initialStateInputType()`. Require both input and stored classes to be DynamicState. A retained-snapshot adapter demonstrates post-construction root mutation and now rejects without another adapter callback; ordinary Program copying remains unchanged. The regression failed before the fix. | +| Trivial: missing no-property POR oracle | Checked static POR and DPOR, both exact backends, retain terminal x values `{1, 2}` from the independent split graph. Every completion witness checks actual enabled choices/outcomes and termination. This test passed before the admission fixes; it strengthens coverage rather than claiming another production defect. | + +Post-feedback `build javadoc` passes **1,948 tests**, zero failures/errors/skips. All **218 browser +assertions** pass on regenerated artifacts, and the external built-jar consumer passes including the +new original-input type query. A focused CodeRabbit review of all seven feedback files completed +with **zero findings**. It was required for the Major correctness-sensitive provenance fix, not a +repeat check of minor/trivial feedback. Raw artifacts use `/private/tmp/interleave-pr136-feedback-`: +`red.log`, `build.log`, `browser.log`, `coderabbit.ndjson`, and the focused `pitest.log`/`pitest.xml`. +The post-feedback focused census passes **602/712 K + 89 S + 21 NC**, with zero resource/run-error +or other statuses: Program **31/31 K**, SourceSymmetry **108/109 K + 1 S**, DslLoader **463/572 K ++ 88 S + 21 NC**. All mutations on the new discriminator guard and original-input type check are +killed. The sole SourceSymmetry survivor remains the explicit null-check removal whose next +dereference still throws. Loader residuals remain in the raw XML; this patch makes no general +equivalence or whole-loader closure claim. The comparison uses the previously recorded disjoint +per-class populations (594/705 K + 90 S + 21 NC), not a newly measured full PR-head baseline. Of 273 +matching instruction fingerprints, 272 retain status and one changes; 432 old and 439 new identities +mostly reflect shifted instruction indexes. Do not infer semantic mutant lineage from reused indexes. +Comparison artifacts: `baseline.xml`, `comparison.txt` under the same feedback prefix. + +The previous broad/default measurements above retain their original scope and revision. The +default gate was not repeated for this narrow feedback patch; the three changed production classes +receive a focused census in addition to the full integrated build and consumer checks. + ## Assurance limits Admission covers one trusted declarative family, not general Java, typed JSON, arbitrary callbacks diff --git a/docs/plans/declarative-symmetry-contract.md b/docs/plans/declarative-symmetry-contract.md index 5f3c114..fe1e9af 100644 --- a/docs/plans/declarative-symmetry-contract.md +++ b/docs/plans/declarative-symmetry-contract.md @@ -19,16 +19,18 @@ not enable a feature. Implementation PRs update their spec, tests, measurements ## Selected model family and trust - **Certified declarative instruction/property:** immutable typed objects issued by DslLoader only - after its existing parsing, typing, AST/work bounds and shared-only property checks succeed. + after its explicit format discriminator, parsing, typing, AST/work bounds and shared-only property checks succeed. Certification is private immutable state, not a public flag, filename, JSON assertion or class test. - Existing public DynamicStep/DslInvariant constructors retain ordinary behavior but issue no certification. Package-private validated factories require a non-null DslLoader.ValidationPermit: a package-visible final nested type with a private constructor and a single private loader-held instance, never exposed by an accessor or returned model. Null permits reject before certification. No public certificate injection API or caller-declared observation proof is introduced. -- Program.initialStateType() is a read-only metadata query of the actual stored snapshot class, - invoking no model code. Certification requires DynamicState before another copy/initialization; - a custom state adapter returning DynamicState from deepCopy cannot establish trust. +- Program.initialStateType() and Program.initialStateInputType() are read-only metadata queries + of the retained snapshot and original constructor input classes, invoking no model code and + retaining no input object. Certification requires both types to be DynamicState before another + copy/initialization; adapters returning DynamicState on their first or later deepCopy cannot + establish trust. Ordinary Program construction/copy semantics remain unchanged. - A checked declarative model contains only certified DynamicStep objects, dense actual owner bindings, DynamicState with matching owner count, and an absent or certified DslInvariant. Every step/property must retain the same StateDecl object as the initial DynamicState. Trusted objects diff --git a/docs/specs/active/92-certified-declarative-symmetry.md b/docs/specs/active/92-certified-declarative-symmetry.md index 2149c1f..6810679 100644 --- a/docs/specs/active/92-certified-declarative-symmetry.md +++ b/docs/specs/active/92-certified-declarative-symmetry.md @@ -15,8 +15,9 @@ oracles and release boundaries. This spec owns L1 only; B10 completes after L2 m ## Scope - Module: declarative validation/certification, checked search routing and exact consumers. -- Adds a read-only Program.initialStateType() query in core/Program.java so certification checks - the stored snapshot type before invoking model copy/initialization code. This is metadata only, +- Adds read-only Program.initialStateType()/initialStateInputType() queries in core/Program.java + so certification checks both snapshot and original constructor input types before invoking + further model copy/initialization code. This is metadata only, not a certificate or execution interface; generic Program behavior remains unchanged. - Modifies `src/main/java/dev/samhb/interleave/format/dsl/{DslLoader,DynamicStep,DslInvariant,SourceSymmetry,SourceInstruction}.java`; SourceInstruction changes are limited to sharing exhaustive expression identity inspection. @@ -183,9 +184,11 @@ budget during certification of a reassembled Program. Count each occurrence and the cap and reuse bounded validated expression metadata/counting; never expand an unbounded alias list or trust loader-time aggregate counts for a newly assembled Program. Shared exhaustive Expr identity inspection may be package-private on SourceInstruction for both callers; no separate expression evaluator is created. -Program.initialStateType() returns the actual stored snapshot class without calling deepCopy. -Reject non-DynamicState snapshots before initialConfiguration; a custom copy that returns a trusted -state cannot establish provenance of the stored model. DynamicStep already has straight-line next-PC semantics; do not add SourceStep/control metadata. +Program.initialStateType() returns the actual stored snapshot class; initialStateInputType() +records the original constructor input class before its first deepCopy, without retaining that +input object. Require both types to be DynamicState before initialConfiguration; first-copy or +later-copy adapters cannot establish trust. DslLoader.load also requires the explicit declarative +discriminator for direct callers before it issues certified instructions. DynamicStep already has straight-line next-PC semantics; do not add SourceStep/control metadata. Use existing CheckedSymmetryStore dispatch for exact DPOR contexts, keeping value-only pruning bypassed. Extend only the source-or-checked predicate around its mapped sleep normalization/lookup. @@ -237,13 +240,13 @@ as an exact agreement seed. Preserve existing source exceptions. - [verified] Private attestation checks enabled actual transitions/terminal observations, rejects foreign diagnostics and preserves failed-attempt/no-successor behavior. Ordinary report wording remains unchanged; JSON has no fabricated source identity/resource prefix. -- [verified] Full build, strict Javadoc and 1,943 tests pass with no failures/errors/skips. All 218 +- [verified] Full build, strict Javadoc and 1,948 tests pass with no failures/errors/skips. All 218 browser checks and an external Java 26 built-jar consumer pass. See the [L1 ledger](../../measurements/92-certified-declarative-symmetry.md) for scope and provenance. -- [verified] The reproduced custom-copy adapter is rejected by a stored-type metadata guard before - another copy callback. Program.initialStateType exposes only the actual stored snapshot class; - generic initialization and source identity remain unchanged. Its regression failed before the fix - and passes afterward. +- [verified] First-copy and later-copy adapters reject before another copy callback. Read-only + Program type metadata covers both the original constructor input and stored snapshot; generic + initialization and source identity remain unchanged. Direct DslLoader calls also reject missing, + empty or non-declarative formats before issuing trust. Both gaps have observed red/green regressions. - [verified] Default PIT retains all 468 baseline fingerprints/statuses (455 K + 13 S). The broad affected census and final focused mutation checks are recorded separately in the ledger. Three actual CodeRabbit reviews completed; independently checked dispositions and patched findings are diff --git a/src/main/java/dev/samhb/interleave/core/Program.java b/src/main/java/dev/samhb/interleave/core/Program.java index ad38817..e916648 100644 --- a/src/main/java/dev/samhb/interleave/core/Program.java +++ b/src/main/java/dev/samhb/interleave/core/Program.java @@ -14,6 +14,8 @@ public final class Program { /** Initial state. */ private final SharedState initialState; + /** Runtime type supplied before any caller-defined defensive copy executes. */ + private final Class initialStateInputType; /** Threads. */ private final List threads; /** Exact source fingerprint, absent for legacy models. */ @@ -52,6 +54,7 @@ public Program(SharedState initialState, List threads) { public Program(SharedState initialState, List threads, String sourceDigest) { if (initialState == null) throw new IllegalArgumentException("initialState must not be null"); if (threads == null || threads.isEmpty()) throw new IllegalArgumentException("threads must not be empty"); + this.initialStateInputType = initialState.getClass(); this.initialState = initialState.deepCopy(); this.threads = List.copyOf(threads); if (sourceDigest != null && !sourceDigest.matches("[0-9a-f]{64}")) { @@ -72,6 +75,13 @@ public Program(SharedState initialState, List threads, String sourc */ public Class initialStateType() { return initialState.getClass(); } + /** Returns the constructor input's type without retaining or invoking that input object. + * Checked integrations can reject custom adapters even when their first copy returns a trusted type. + * This complements {@link #initialStateType()}, which describes the retained snapshot. + * @return runtime class of the original non-null constructor argument + */ + public Class initialStateInputType() { return initialStateInputType; } + /** Returns source fingerprint, or null for a legacy Java/JSON model. * @return source fingerprint, or null for a legacy Java/JSON model */ diff --git a/src/main/java/dev/samhb/interleave/format/dsl/DslLoader.java b/src/main/java/dev/samhb/interleave/format/dsl/DslLoader.java index ece4a55..3586fcd 100644 --- a/src/main/java/dev/samhb/interleave/format/dsl/DslLoader.java +++ b/src/main/java/dev/samhb/interleave/format/dsl/DslLoader.java @@ -54,6 +54,8 @@ private DslLoader() {} * @throws RegistryException on validation error */ public static BenchmarkProgram load(ProgramDefinition def) { + // Certification must include the discriminator even when callers bypass ProgramLoader. + if (!"declarative".equals(def.format())) throw new RegistryException("format must be declarative"); // Defensive top-level validation (also done in ProgramLoader, but DslLoader is public) if (def.name() == null || def.name().isBlank()) throw new RegistryException("Program name is required"); if (def.threads() == null || def.threads().isEmpty()) throw new RegistryException("At least one thread is required"); diff --git a/src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java b/src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java index d5522f7..efb0441 100644 --- a/src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java +++ b/src/main/java/dev/samhb/interleave/format/dsl/SourceSymmetry.java @@ -23,8 +23,8 @@ private SourceSymmetry() {} */ public static List> groups(Program program, Invariant invariant) { Objects.requireNonNull(program, "program"); - if (program.initialStateType() != DynamicState.class) { - throw new IllegalArgumentException("Symmetry requires a trusted DynamicState initial snapshot"); + if (program.initialStateInputType() != DynamicState.class || program.initialStateType() != DynamicState.class) { + throw new IllegalArgumentException("Symmetry requires a trusted DynamicState input and initial snapshot"); } boolean source = program.isSource(); if (invariant != null && (source ? !(invariant instanceof SourceProperty) : !(invariant instanceof DslInvariant))) { diff --git a/src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java b/src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java index ae8bd22..1158284 100644 --- a/src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java +++ b/src/test/java/dev/samhb/interleave/format/dsl/DeclarativeSymmetryEligibilityTest.java @@ -14,6 +14,7 @@ import java.util.Map; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -136,6 +137,50 @@ public SharedState deepCopy() { assertEquals(before,copies.get(),"certification must not invoke another untrusted copy"); } + /** Input provenance cannot be laundered through an adapter's first defensive copy. */ + @Test void firstCopyAdapterCannotIssueTrustedStateProvenance() { + var model=pair(null,List.of("x = 1"),null); + var retained=(DynamicState)model.program().initialConfiguration().state(); + var copies=new java.util.concurrent.atomic.AtomicInteger(); + SharedState adapter=new SharedState() { + /** {@inheritDoc} */ + public SharedState deepCopy() {copies.incrementAndGet();return retained;} + /** {@inheritDoc} */ + public void encodeTo(java.io.DataOutput out) {throw new AssertionError("untrusted encoder invoked");} + }; + var forged=new Program(adapter,model.program().threads()); + assertEquals(DynamicState.class,forged.initialStateType()); + assertEquals(adapter.getClass(),forged.initialStateInputType()); + // The adapter retains the snapshot; post-construction writes can change this program's root. + retained.setInt("x",7); + assertEquals(7,((DynamicState)forged.initialConfiguration().state()).getInt("x")); + int before=copies.get(); + assertThrows(IllegalArgumentException.class,()->SourceSymmetry.groups(forged,null)); + assertEquals(before,copies.get(),"certification must reject without another adapter callback"); + // Ordinary construction/copy semantics stay usable; checked admission owns the restriction. + var trusted=new Program(retained,model.program().threads()); + assertEquals(DynamicState.class,trusted.initialStateInputType()); + assertEquals(List.of(List.of(0,1)),SourceSymmetry.groups(trusted,null)); + } + + /** Direct callers must supply the declarative discriminator before the loader can issue trust. + * @param format unsupported or missing format + * @throws java.io.IOException if the checked-in fixture cannot be read + */ + @ParameterizedTest @NullAndEmptySource @ValueSource(strings="typed") + void directLoaderRejectsOtherFormatsBeforeCertification(String format) throws java.io.IOException { + var json=com.google.gson.JsonParser.parseString(java.nio.file.Files.readString( + Path.of("examples/programs/semaphore-declarative.json"))).getAsJsonObject(); + if(format==null)json.remove("format");else json.addProperty("format",format); + var definition=new Gson().fromJson(json,dev.samhb.interleave.format.model.ProgramDefinition.class); + var rejected=assertThrows(dev.samhb.interleave.format.registry.RegistryException.class, + ()->DslLoader.load(definition)); + assertTrue(rejected.getMessage().contains("format")); + json.addProperty("format","declarative"); + var valid=DslLoader.load(new Gson().fromJson(json,dev.samhb.interleave.format.model.ProgramDefinition.class)); + assertEquals(List.of(List.of(0,1)),SourceSymmetry.groups(valid.program(),valid.invariant().orElseThrow())); + } + /** Fixed owners remain trusted and cannot smuggle executable callbacks into certification. */ @Test void fixedOwnerCallbackRejectsBeforeEnabledness() { var model=pair(null,List.of("x = 1"),null); diff --git a/src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java b/src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java index eb0dbf9..e05adab 100644 --- a/src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java +++ b/src/test/java/dev/samhb/interleave/search/DeclarativeSymmetryOracleTest.java @@ -54,6 +54,30 @@ void finiteGraphsMatchIndependentReference(String mode,int owners,int concrete,i } } + /** Checked reductions without a property preserve both independently reachable split outcomes. */ + @Test void noPropertyPorPreservesIndependentTerminalValues() { + var model=load(2,0,List.of(action(null,List.of("local.r = x")), + action(null,List.of("x = local.r + 1"))),null); + var expected=new HashSet(); + for(var state:reference("split",2))if(state.pcs().equals(List.of(2,2)))expected.add(state.x()); + assertEquals(Set.of(1,2),expected); + for(var strategy:List.of(Strategy.STATIC_POR,Strategy.DPOR))for(var backend:SymmetryBackend.values()) { + var store=SymmetryStateStore.forRun(model.program(),null,strategy,backend); + var result=strategy==Strategy.STATIC_POR + ? new dev.samhb.interleave.por.StaticPorExplorer().explore(model.program(),null,store,null) + : new dev.samhb.interleave.dpor.DporExplorer().explore(model.program(),null,store,null); + var observed=new HashSet(); + assertFalse(result.traces().isEmpty()); + for(var trace:result.traces()) { + assertEquals(TraceOutcome.COMPLETED,trace.outcome()); + checkConcreteWitness(model,trace); + var terminal=new TraceReplayer().replay(model.program(),trace); + observed.add(((DynamicState)terminal.state()).getInt("x")); + } + assertEquals(expected,observed,strategy+" "+backend); + } + } + /** Every exact strategy/backend preserves a finite violating final property and concrete witness. */ @Test void failingFinalPropertyMatchesExhaustiveReferenceAcrossStrategies() { var steps=List.of(action(null,List.of("local.r = x")),action(null,List.of("x = local.r + 1")));