ArghDA M1: Backend abstraction — make the engine prover-parametric#32
Merged
Merged
Conversation
The keystone refactor of the "Flying Logic for provers/solvers" epic.
Every Agda-baked seam now lives behind an object-safe `Backend` trait, so
the four-state workspace, DAG builder, content-hash invalidation and the
cycle-safe reachability walk are backend-neutral. Agda is the first (v0.1
reference) impl; adding Idris2/Lean4/Z3/CVC5/… now means an impl, not a
rewrite.
Behaviour is unchanged — this is the promised pure refactor with the test
suite as the oracle: the 64 pre-existing tests (50 lib + 14 integration)
all stay green, +2 new Agda-backend tests = 66 passing. clippy -D warnings,
fmt and the SPDX gate are clean; the `dag` JSON output is byte-compatible
and `check` still runs a real Agda typecheck.
New `src/prover/`:
- `Backend` trait: name/kind/extensions/safe_mode/check_file +
module_name_of/module_to_path/direct_imports/discover_roots/lint_rules.
- `BackendKind { Assistant, Solver }` — the two interaction models.
- `Verdict { Proven, Refuted, Unknown, Admitted, Postulated, Error,
Unavailable }` — the common verdict both models map into; only Proven is
green, Admitted/Postulated are amber.
- `Outcome` — superset of the old AgdaOutcome (raw process facts + kind +
verdict).
- `src/agda.rs` -> `src/prover/agda.rs` (Agda impl; owns the shell-out,
delegates parsing to `graph::` free fns and the lint pack to `lint::`).
Verdict is exit-code-only (0 -> Proven, ran-nonzero -> Error, absent ->
Unavailable) — arghda never claims a result Agda did not return;
Admitted/Postulated stay lint-derived, not manufactured from a green exit.
- `graph::build` and `dag::build` gain a `&dyn Backend` parameter and use
the backend's extension filter + import parsing; the reachability walk
and its cycle-termination regression are untouched.
- `main.rs` scan/check/dag/resolve_roots_and_rules route through the
backend; the `check` JSON key `agda` -> `backend` (now carries kind +
verdict).
- STATE.a2ml records M1 = 100%.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012MpYSh6Wy8YMBH2E3qVyT7
hyperpolymath
marked this pull request as ready for review
July 1, 2026 07:25
hyperpolymath
added a commit
that referenced
this pull request
Jul 1, 2026
…tion (#33) ## What & why The **headline capability** of the "Flying Logic for provers/solvers" epic, built on the M1 `Backend` trait (merged #32). A new `src/reason/` layer *wraps* (does not replace) the DAG: the `DagDocument` is embedded verbatim, and on top go a per-node `Verdict`, `And`/`Or` edge juncts, and a memoised, cycle-safe, **demote-only** propagation fold. ## The honesty invariant (enforced end-to-end) A node's effective verdict can only be **lowered** by its dependencies, never manufactured: - **lint-clean + no typecheck = `Unknown`**, never green. Only a real prover exit-0 makes `Proven`. - Only `Proven` is green; `Admitted`/`Postulated` are amber. - Because the fold is demote-only over `And` import edges, **structural amber infects downstream** — anything that transitively imports a `postulate` (or `missing-safe` / escape-hatch) module is itself capped. Visible *before any prover runs*. - `Or` groups are forgiving (one green route keeps a goal up). Import cycles degrade to `Error` and terminate. Staleness (closure-hash-changed `Proven` → `Unknown`) is applied pre-fold so it propagates. `wired` marks the CRT-root-reachable cone. ## Changes - `src/reason/mod.rs`: `Junct`, `ReasonNode` (`self_verdict`/`effective`/`verdict_evidence`/`soundness`/`wired`), `ReasonEdge`, `ReasonDocument` (`version:"0.1"`, embedded `dag`, `crt_roots`); the rank/demote/promote lattice; lint→verdict caps; the propagation fold. - `arghda reason <path> [--check]`: `--check` runs the backend per node for **real** exit-code verdicts; default is structure+lint-derived (all `unknown` on a clean tree, honestly). - `STATE.a2ml` records M3 = 100%. ## Verified (ran, not inferred) - `cargo test` → **81 passing, 0 failed** (61 lib + 20 integration; +9 reason unit tests covering demote / downstream-amber-infection / Or-forgiveness / cycle-termination / wiring / clean-but-unchecked→Unknown, +6 reason integration). - `cargo clippy -D warnings` clean · `cargo fmt --check` clean · `check-spdx.sh` OK. - **Dogfood** — `arghda reason tests/fixtures/wellformed --check` ran real `agda` typechecks → the whole cone `proven` + `wired`. ### A bug dogfooding caught (and I fixed) The first `--check` dogfood showed **every node `wired=false`** with `crt_roots=['tests.fixtures.wellformed.All']`. The CLI's `discover_roots` yields include-root-*relative* paths, which a stray `include_root.join` double-prefixed — so the CRT-root ids never matched the node ids. The unit/integration tests missed it because they passed *absolute* roots (where the join is a silent no-op). Fixed to match the orphan-module rule's convention (paths go straight to `module_name_of`), plus a regression test that exercises the `discover_roots` path. Re-dogfooded green. ## Next (all unblocked by the stable trait) M4 Idris2 · M5 SMT (Z3/CVC5) · M2 Cubical-Agda · M3 follow-on (feed real verdicts + staleness from a workspace `proven/` state so `reason` lights the cone without `--check`). --- _Generated by [Claude Code](https://claude.ai/code/session_012MpYSh6Wy8YMBH2E3qVyT7)_ Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The keystone of the "Flying Logic for provers/solvers" epic. Every Agda-baked seam now lives behind an object-safe
Backendtrait, so the four-state workspace, DAG builder, content-hash invalidation and the cycle-safe reachability walk become backend-neutral. Agda is the first (v0.1 reference) impl; adding Idris2 / Lean4 / Z3 / CVC5 / Coq / Isabelle / Mizar is now an impl, not a rewrite.Follow-on from M0 (toolchain provisioning, merged as #31). #31 being merged, this is a fresh PR on the same working branch.
This is a pure refactor — the test suite is the oracle
Behaviour is unchanged, ground-truthed by running the tools (not inferred):
cargo test— the 64 pre-existing tests (50 lib + 14 integration) all stay green; +2 new Agda-backend tests = 66 passing, 0 failed.cargo clippy --all-targets --all-features -- -D warnings— clean.cargo fmt --check— clean.scripts/check-spdx.sh .—SPDX licence invariant: OK.arghda dag tests/fixtures/wellformedemits byte-compatible JSON (version: "0.1", same nodes/edges);arghda check …/All.agdaran a real Agda typecheck →proven-eligible(agda is present from ArghDA → Flying Logic for provers/solvers: M0 (toolchain provisioning + doctor) #31's provisioning).Changes
New
src/prover/:Backendtrait —name/kind/extensions/safe_mode/check_file+ the import-graph trio (module_name_of/module_to_path/direct_imports) +discover_roots+lint_rules.BackendKind { Assistant, Solver }— the two interaction models (typecheck-a-file vs SMT query).Verdict { Proven, Refuted, Unknown, Admitted, Postulated, Error, Unavailable }— the common verdict both models map into. OnlyProvenis green;Admitted/Postulatedare amber.Outcome— superset of the oldAgdaOutcome(raw process facts +kind+verdict).Refactor:
src/agda.rs→src/prover/agda.rs.Agdais the first impl: owns theagdashell-out, delegates parsing tograph::free fns and the lint pack tolint::. Verdict is exit-code-only (0 →Proven, ran-nonzero →Error, absent →Unavailable) — arghda never claims a result Agda did not return;Admitted/Postulatedstay lint-derived, never manufactured from a green exit.graph::buildanddag::buildtake&dyn Backendand use the backend's extension filter + import parsing. The cycle-safe reachability walk and itstransitive_imports_terminates_on_a_cycleregression are untouched — cycle safety is inherited free by every backend.main.rsscan/check/dag/resolve_roots_and_rulesroute through the backend; thecheckJSON keyagda→backend(now carrieskind+verdict).STATE.a2mlrecords M1 = 100%;.gitignoreignores*.agdai.Honesty note (owner directive + AGENTIC.a2ml)
The
Backendmodule is the boundary where "never report a verdict the tool did not emit" is enforced:check_filederives its verdict from the actual exit code and degrades toUnavailablewhen the binary is absent.Next (trait now stable → parallelisable)
M3 reasoning-graph (
src/reason), M4 Idris2, M5 SMT (Z3/CVC5), M2 Cubical-Agda.Generated by Claude Code