From a3e77130cfac4a3b7dd62e36e5dba0b76f4a7752 Mon Sep 17 00:00:00 2001 From: Levi Neuwirth Date: Thu, 21 May 2026 15:58:07 -0400 Subject: [PATCH] Phase 3 Rocq parity M3: bridge-aware LLM adapter + reconstruction fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 "" "