Do LLM Invariant Repairs Actually Read the Counterexample?

When a language model proposes a loop invariant (a logical formula that stays true on every pass through a loop and lets a verifier prove the program safe) and the verifier rejects it, the verifier usually returns a counterexample: a concrete program state showing exactly why the formula fails. Repair loops feed this counterexample back to the model and ask for a fix. This proposal starts from a simple suspicion. We suspect the model often does not use the counterexample at all. Instead it writes a fluent diagnosis that defends or lightly edits its previous guess, which is the post-hoc rationalization pattern documented for chain-of-thought in question answering. If that is true, it would explain an unresolved disagreement in the field. Lemur built a sound multi-turn propose-and-repair calculus. Quokka later argued that such repair is needless complexity, because independent parallel sampling with a two-query check did better.

Invariant synthesis is an unusually clean place to test this suspicion. Whether a repaired invariant "responds to" a counterexample is not a matter of opinion. For a concrete state, we can simply evaluate the new formula and see whether it excludes the bad state or includes the required successor state. No solver call is needed. This gives a causal faithfulness measure for open-ended generation. That fills the gap left by thinking-draft faithfulness audits, which rely on multiple-choice label flips (Measuring the Faithfulness of Thinking Drafts). The same measure also becomes a cheap training signal for making repair behave like repair.

Core Claim

We claim three things. First, current LLM invariant repair is largely insensitive to the counterexample it is given, and this insensitivity, not the lack of feedback, is why multi-turn repair loses to parallel sampling at equal compute. Second, the insensitivity is stronger in models trained with reinforcement learning on verifiable math rewards. Faithfulness studies predict this direction, since they found such training weakens the link between a model's stated reasoning and its answer (Measuring the Faithfulness of Thinking Drafts). Third, a repair step that is trained or constrained to address the counterexample should beat compute-matched Best-of-N on the hard instances, where Quokka reports its gains vanish.

The key object is a check we call counterexample discharge. The verifier can reject an invariant candidate $I$ for three reasons, and each yields its own discharge condition for the repaired candidate $I'$:

$$ \text{initiation: } I'(s_0), \qquad \text{consecution: } \neg I'(s) \lor I'(s'), \qquad \text{safety: } \neg I'(s_e) $$

In the initiation case, $s_0$ is a reachable entry state that $I$ wrongly excludes, and $I'$ must include it. In the consecution case, $(s, s')$ is a single loop iteration where $I(s)$ holds but $I(s')$ fails, and $I'$ must either exclude $s$ or include $s'$. In the safety case, $s_e$ is an exit state where $I$ holds but the assertion fails, and $I'$ must exclude it. The discharge rate is the fraction of repairs that satisfy the condition for the counterexample actually shown. Each check is a single formula evaluation on a concrete state.

Research Program

The first stage is diagnostic. We will reimplement a Lemur-style repair oracle over UAutomizer and ESBMC and record every failed candidate, its counterexample, the model's stated diagnosis, and the repair. On each repair turn we will apply three interventions.

The first intervention swaps the counterexample for a different valid one. We obtain this by asking the solver for a second counterexample that is blocked from matching the first. A faithful repair should discharge the new counterexample rather than the original.

The second intervention replaces the counterexample with an irrelevant state from another program. A faithful repair's output should change. A rationalizing one will look the same.

The third intervention edits the model's own verbalized diagnosis mid-generation and lets it continue, for example changing "fails because x can be odd" to "fails because y exceeds n". This is the draft-to-answer intervention from Measuring the Faithfulness of Thinking Drafts, moved into a setting where compliance can be checked mechanically.

From these we compute three quantities: the discharge rate, a swap-sensitivity gap (discharge of the shown counterexample minus discharge of the unshown one), and an anchoring score (syntactic distance of $I'$ to the previous $I$ versus to fresh samples). We also estimate how often confident first guesses produce short, defensive diagnoses, following the entropy-based confirmation-bias analysis of Unveiling Confirmation Bias in Chain-of-Thought Reasoning.

The second stage tests where insensitivity comes from and how it interacts with cross-domain training. We will hold the model family fixed and compare three variants. One is a Qwen-class base or instruction model. The second is the same model after math reinforcement learning, using a released checkpoint such as Satori, whose self-reflection tokens are claimed to transfer to code reasoning. The third is the base model plus a math-derived reasoning vector. The transfer literature (CPL, Satori, reasoning vectors) reports that math training helps one-shot code tasks. None of it tests formal invariants or feedback-driven repair. This stage asks whether math training improves the first guess while worsening the model's responsiveness to external feedback. That combination would be a concrete, measurable form of the paradox that verifiable-reward training raises accuracy while lowering faithfulness.

The third stage is the intervention. We will train a Qwen3-8B-class model, the scale used by WONDA, on repair turns. Preference pairs come from the discharge check. Among sampled repairs for the same counterexample, those that discharge it and are not trivially weak are preferred over those that do not. We also add swap-contrast pairs, in which the preferred repair for counterexample A is dispreferred when the model is shown counterexample B. This is the logic of FRIT, which uses causal intervention to build preference pairs for Direct Preference Optimization (DPO, a method that trains a model to prefer one output over another). Here, though, the intervention target is a verifier artifact rather than a reasoning step, and the label comes from formula evaluation rather than from a distractor judgment. We will track discharge on held-out programs throughout training, because FRIT warns that faithfulness can drift during preference training.

Baselines

The naive reference point is the plain verifier. We run UAutomizer alone under the same timeout, which tells us what any LLM assistance adds.

The strongest existing method is Quokka's parallel prove-then-use pipeline with Best-of-8 sampling (Quokka). It generates candidates independently and checks each in parallel for inductiveness and for usefulness in proving the assertion. It is the strongest competitor because its authors explicitly show it beats multi-turn repair. On the 866-instance benchmark, it reports that under a 60-second timeout it solved 21 instances the base verifier could not. It also reports a 1.2x speedup on 81 instances and a 2.0x speedup on 51 instances with GPT-5.2, and that Best-of-8 gave a 22% improvement in accelerated instances. We will run it with the same backbone model as our method, the same verifier version and timeout, and a matched budget of total verifier calls and generated tokens per instance. A repair trajectory of k turns is therefore compared against Best-of-k, not Best-of-8. Beating it means solving strictly more instances, or accelerating more, at equal budget on the subset Quokka's authors call hard (over 500 seconds of solver effort), without losing on the easy subset.

The second strong baseline is Lemur's repair calculus (Lemur), run with the same model and budget. With GPT-4 it reports 107/133 on Code2Inv and 25/47 on the SV-COMP 2023 hard set. We will report its discharge rate alongside our own. We also include a WONDA-style fine-tuned model (Not All Invariants Are Equal), trained on curated one-shot invariants, both alone and inside a repair loop. This separates "better first guesses" from "better repairs". The file contains no single headline solved-count for WONDA; it reports relative gains, such as roughly doubled correctness for Qwen3-4B and 8B.

The key ablations isolate the discharge signal. The first trains on generic repair supervision, preferring repairs that eventually verify, without any counterexample-specific pairs. The second keeps our pairs but removes the swap-contrast half. If the first ablation matches the full method, the counterexample-grounding ingredient is not doing the work.

Why not just…?

Why not just use Best-of-N with a bigger N? This is the main threat, and the headline comparison is built around it. Quokka's own analysis says Best-of-N stalls on hard programs because of verifier timeouts and resource contention when many verifiers run in parallel. It also attributes 18% of failures to trivial invariants, which more independent samples will keep producing. A repair step that provably discharges each counterexample adds information that independent samples lack. If compute-matched Best-of-N still wins on the hard subset after our training, we will report that repair adds nothing beyond diversity and drop the method claim.

Why not just drop the conversation history and restart with only the counterexample? If anchoring on the previous guess is the cause, a memoryless prompt that shows the program and the counterexample, but not the prior candidate or diagnosis, might fix it for free. This is a real alternative, and we will run it as a baseline under the same budget. Our diagnostic makes a prediction here. If the model ignores the counterexample even when it is the only new content, memoryless restart will behave like Best-of-N. If memoryless restart recovers discharge, the fix is a prompting change, and our contribution narrows to the diagnosis.

Why not just accumulate counterexamples and filter candidates, as learning-based invariant synthesis does? Horn-ICE (Horn-ICE Learning) treats counterexamples as a growing set of positive, negative, and implication constraints. Discarding sampled candidates that violate any stored counterexample is cheap and needs no training. We will include this Best-of-N-plus-filter variant. It rejects bad candidates but cannot make the model propose ones that pass. So if the model's proposals rarely discharge counterexamples, the filter mostly empties the pool. The measured pass rate of the filter tells us which regime holds.

Why not just fine-tune on curated in-domain invariants? WONDA shows curation lets small models match much larger ones. But its training data exists only where UAutomizer already succeeds, and its authors note that it exposes no intermediate reasoning or verifier feedback. Our WONDA-in-a-loop baseline tests whether stronger first guesses make repair unnecessary. If so, discharge-trained repair should show no extra gain on top of it.

Proposed Experiments

We evaluate on three benchmarks: Code2Inv (133 programs), the SV-COMP 2023 hard set of 47 programs from Lemur, and the 866-instance Quokka/InvBench suite, which we stratify by baseline solver time. Training programs come from the 3,589-program Quokka synthetic set. All benchmark programs are held out, with near-duplicates removed.

Four checks decide the outcome. The first tests the existence of the problem. If untrained models show a swap-sensitivity gap near zero, repairs discharge the shown counterexample no more often than an unshown one, and that supports the rationalization hypothesis. A large gap would refute it and redirect the explanation for the repair plateau toward model capability.

The second tests the transfer interaction. Math-reinforcement-learning variants should show higher first-guess correctness but a smaller swap-sensitivity gap than their base models on the same programs. The reverse would contradict the predicted link between verifiable-reward training and feedback-ignoring.

The third tests the method. Discharge-trained repair should beat compute-matched Quokka Best-of-N, memoryless restart, and counterexample filtering on solved instances in the over-500-second stratum and on the SV-COMP hard set, measured against Lemur's 25/47. Its trivial-invariant rate should also fall below Quokka's reported 18%.

The fourth tests mechanism. Across models and checkpoints, per-instance gains should track the discharge rate. Otherwise the improvement comes from something other than responding to the counterexample. We will report this rank correlation alongside the ablations, because it is what ties the faithfulness measurement to verification outcomes.