You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rocq mirror of Lean PR #36 (LLM-assisted Tier-3 reconstruction
fallback), plus the load-bearing prerequisite that makes the
fallback actually work cross-bridge: the SDK's `Adapter_llm` and
`Llm_reconstruct` now produce bridge-appropriate prompts /
trace_formats based on `ir.source_system.name`.
**Bridge-aware SDK** (`sdk/lib/adapter_llm.ml`, `llm_reconstruct.ml`):
- New `rocq_ty` / `rocq_term` / `rocq_paren` parallel to the
existing Lean rendering helpers — translate IR's bridge-agnostic
type-ref vocabulary (Int / Real / Prop + arrow chains) to Rocq
Stdlib syntax (Z / R / Prop with ASCII `->`), and render
shell_terms with Rocq's `/\` `\/` `~` connectives, `forall (x :
T), body` quantifiers, ASCII Z-scope arithmetic.
- New `dialect` record bundles per-bridge state (system_prompt,
render_prompt, ty, term, trace_format, cert_format, annotation).
`dialect_of_ir` dispatches on `ir.source_system.name`: "rocq" →
`rocq_dialect`, everything else → `lean_dialect` (safer
LLM-familiar default).
- `Adapter_llm.dispatch` and `Llm_reconstruct.translate` both pick
the dialect upfront — Rocq home systems get Rocq-flavored
prompts asking for Ltac in a fenced ```coq block; minted certs
carry `format = trace_format = "rocq-tactic-script"`.
- `Verifier.verify` extends its Tier-3 dispatch to recognize both
`lean-tactic-script` and `rocq-tactic-script` → both return
`Tier3_replay_deferred { trace_format }` (envelope-only;
soundness deferred to the home kernel's audit-H1 replay gate).
**Closers tightened** (M3.b): Rocq's `close_or_fail` now matches
`Tier3_replay_deferred { trace_format = "rocq-tactic-script" }`
specifically. A `lean-tactic-script` cert reaching the Rocq closer
(misconfigured manifest pointing this bridge at a Lean-flavored
LLM endpoint, or future bug) is a clean user error rather than a
silent parse failure when Ltac tries to chew on Lean syntax.
**Reconstruction fallback** (M3.c, `rocq-bridge/src/pb_rocq_main.ml`):
Mirror of Lean's `closeOrFailPrimary` + `closeOrFail` wrap.
- The existing `close_or_fail` is renamed `close_or_fail_primary`.
- New `replay_reconstructed_script trace_format script` runs the
candidate through `Llm_replay.replay_script` (the same audit-H1
gate from M2) and on success emits a `Feedback.msg_info` line
naming the source trace format — audit trail visible in build
output.
- New `try_llm_reconstruct ir cert?` gates on Tier-3 cert with
`trace_format ≠ rocq-tactic-script`, calls
`Proof_broker.Llm_reconstruct.translate` (direct-linked, no FFI),
returns `Some fallback_tac` or `None`.
- New `close_or_fail` wraps primary in `Proofview.tclORELSE`; on
primary failure invokes `try_llm_reconstruct` lazily (HTTP only
fires when primary actually fails) and routes to the fallback
if a script came back, else re-raises the primary error.
- Audit H1: reconstruction goes through the SAME audit gate as
primary LLM-replay (kernel replay + axiom-footprint subset
check), so the LLM never widens the trust base.
**Test-only tactic** (`g_proof_broker.mlg`): new `llm_reconstruct_test
"<format>" "<script>"` drives `replay_reconstructed_script`
directly with a string literal — exercises the audit-H1 contract
without a live LLM endpoint. Mirror of Lean's evalLlmReconstructTest.
**Tests** (Rocq-side mirror of Lean's `llm_reconstruct_test` block):
- Positive `pb_llm_reconstruct_axiom_free`: clean `intros;
reflexivity` translation closes a Z-equality goal. Allowlisted
`[]`.
- Negative `assert_fails (llm_reconstruct_test ... "idtac")` —
non-closing translation.
- Negative `assert_fails (llm_reconstruct_test ... "@@@ ...")` —
parse failure.
**SDK tests** added bridge-aware coverage: Rocq-flavored
`test_prompt_render_rocq` and `test_mock_endpoint_rocq` for
`Adapter_llm`; `test_prompt_render_rocq` for `Llm_reconstruct`.
Verifies Z translation, Theorem...Proof...Qed scaffold, ```coq
fence, and that the Rocq-flavored cert's verify reason carries
`trace_format = "rocq-tactic-script"`.
Locally verified: SDK + Rocq plugin sources build clean (`dune
build sdk rocq-bridge/src` rc=0). Full SDK suite passes including
the new Rocq tests. Python schema/gate suite green. JSON
allowlist valid. The Rocq theory build path (incl. the new
fallback test and Print Assumptions on `pb_llm_reconstruct_axiom_free`)
needs CI per the same broken-local-rocq-env caveat from M1/M2.
With this, Phase 3 Rocq parity is structurally complete for
deliverables #3 and #4. M4 (polish) carries the
`fragment_of_logic` consolidation (Phase-4 retro carry) plus a
README/delta sync to record the Rocq Phase-3 surface.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments