When a language model fixes its own code, it usually writes a short diagnosis of what went wrong and then writes a patch. Everyone assumes the diagnosis steers the patch. But work on "post-hoc rationalization", meaning explanations produced after the fact that do not actually cause the model's output, suggests the assumption may be false. The patch may come straight from the code and the error message, with the diagnosis as decoration. This note proposes a way to test the assumption. We rewrite the diagnosis so that it blames a different line, sample many patches under each version, and use execution to check whether the patches move to follow the new blame. The comparison has to be made against the model's own run-to-run randomness, because a single sample cannot distinguish "the diagnosis mattered" from "the sampler happened to go elsewhere."
This matters because the best evidence on self-repair is sobering. Demystifying GPT Self-Repair for Code Generation found that at equal compute, GPT-4 self-repair beats simply drawing fresh independent samples by only 5–8% on APPS, and weaker models do worse than resampling. It traced much of the problem to feedback quality: GPT-4 fixed 33.3% of failing programs with its own diagnoses but 52.6% with human ones. That result mixes two different failures. A diagnosis can be wrong but faithfully followed, or it can be ignored whatever its quality. The two call for opposite remedies. The first calls for better diagnoses. The second calls for spending the budget on resampling, because a repair step that ignores its diagnosis is just a resample anchored to broken code.
Core Claim
We claim that diagnosis–patch coupling (how much the patch distribution shifts when the diagnosis is changed, beyond sampling noise) can be measured cheaply on executable code. We further claim that it varies by model and by instance in a way that predicts when self-repair beats resampling. Specifically, we predict that the self-repair advantage reported by Olausson et al. is concentrated in instances where coupling is high and the diagnosis is correct. We also predict that reasoning models tuned with reinforcement learning on verifiable rewards will show lower coupling than instruction-tuned coders of similar size. This second prediction extends to code the finding of Measuring the Faithfulness of Thinking Drafts in Large Reasoning Models that such training drives draft-to-answer consistency as low as 19.5% (QwQ on GPQA Diamond). If both predictions hold, a simple rule follows. When coupling is low, stop repairing and resample.
Measuring Coupling Against the Noise Floor
Take a failing program, its test failure, and the model's own diagnosis $d$. We build a counterfactual diagnosis $d'$ that is equally fluent but points at a different plausible fault location. We then draw $N$ patches conditioned on each. Each patch is summarized by its execution-grounded footprint: which lines and functions it edits, and which tests it passes. Call the resulting distributions $P_d$ and $P_{d'}$, and let $\hat P_d$ be a second independent batch under $d$. Coupling is
$$C = \frac{D(P_d, P_{d'}) - D(P_d, \hat P_d)}{D_{\max}},$$
where $D$ is total-variation distance over patch footprints and $D_{\max}$ is the largest possible distance. $C$ is near zero when changing the diagnosis moves patches no more than rerunning the sampler does. The subtracted noise-floor term also absorbs the hardware-level non-determinism that persists even at temperature zero (Towards large language model-based personal agents in the enterprise). We use footprints rather than text similarity, and this is the step that makes the measurement possible. The faithfulness audits in the thinking-drafts paper rely on multiple-choice label swaps, and that paper lists free-form generation as an open problem. Code sidesteps this because edit location and test outcomes are discrete, checkable properties of the output.
Research Program
The work has three stages. The first builds the measurement on BugSourceBench, introduced in Anchored Self-Play for Code Repair. Its bugs have known injected locations in BigCodeBench tasks and come from four origins (human, human-edited model code, Qwen2.5-Coder-7B errors, gpt-oss-20b errors). The known locations let us score each diagnosis as correct or wrong independently of coupling, and they make counterfactual diagnoses easy to construct.
The second stage audits several open-weight models: Qwen2.5-Coder-7B-Instruct, gpt-oss-20b, a DeepSeek-R1 distillation, and QwQ-32B. For each, we place every instance in a two-by-two grid of diagnosis correctness against coupling. We also run the same audit on APPS so the results connect directly to Olausson et al.
The third stage turns coupling into a budget policy. We first estimate coupling cheaply on a few samples per instance. If it falls below a threshold, the remaining budget goes to fresh independent samples. Otherwise it goes to repair. The threshold is tuned on a held-out split.
This work builds on two lines. Thought Anchors supplies the method. It uses resampling to find which reasoning sentences causally steer single-shot math answers, and we reuse that resampling logic. We differ in intervening on the diagnosis in a multi-turn loop where the environment supplies new evidence, and in grounding the outcome in execution rather than answer labels. The thinking-drafts paper and Unveiling Confirmation Bias in Chain-of-Thought Reasoning motivate the prediction that verbalized reasoning is often overridden. When Disagreements Elicit Robustness is a potential contradiction. It shows coding teams route around corrupted facts because code has many solution paths, which could mean low coupling reflects robustness rather than unfaithfulness. Our correctness-by-coupling grid addresses this directly. Robustness would show up as low coupling that helps when the diagnosis is wrong. Rationalization would show up as low coupling that wastes correct diagnoses. Executable Counterfactuals frames debugging as abduction, meaning inference of a hidden cause from observed effects. It supplies the rationale for separating diagnosis from patching, although it studies only isolated synthetic functions.
Baselines
The naive reference point is equal-budget independent resampling from the original prompt, filtered by the tests. Olausson et al. show this is hard to beat: GPT-4 self-repair gains only 5–8% over it on APPS, and weaker models lose to it. Every method we test gets the same total token budget, counted in generated tokens including diagnoses, the same test suites, and the same temperature sweep.
The strongest existing iterative competitor is Olausson-style self-repair, which generates a diagnosis and then a patch. We run it with their repair-tree allocation on APPS and BugSourceBench. Our policy beats it if it matches or exceeds its pass rate at every budget point on held-out instances. It must also recover most of the gap to resampling on the weaker models, where Olausson et al. found self-repair falls below resampling.
For a trained repair method, we report the self-play fixers from Anchored Self-Play as a reference. The file gives only a +7.0 percentage point average gain for anchoring over standard self-play and no absolute fix rate, so we will rerun its released setup rather than quote a number. For aggregation, we include Fine-Grained Self-Consistency from Integrate the Essence and Eliminate the Dross, which merges fragments across samples. It reports 74.5% on HumanEval for GPT-3.5-turbo versus 69.8% for plain sampling.
The ablation that isolates our key ingredient is repair with the diagnosis stripped: the model sees code and traceback only. If this matches full self-repair, the diagnosis is decorative in aggregate. The per-instance coupling analysis then tells us where it is not. A second ablation replaces the diagnosis with the ground-truth fault location. This bounds what a perfectly faithful, perfectly correct diagnosis could deliver, mirroring Olausson et al.'s human-feedback condition.
Why not just…?
Why not just resample and skip diagnoses entirely? For weak models this may be correct, and our design lets it win. Resampling is the policy's fallback, so if coupling is uniformly low, the policy collapses to it. The claim at risk is narrower. We claim a per-instance signal exists that tells a strong model when repair is worth its cost. If the gated policy never beats pure resampling at any budget, that claim fails.
Why not just gate on a simpler signal, like the model's token-level confidence or an LLM judge rating the diagnosis? This is the real threat. We will run both as gates under the same tuning budget. A judge measures plausibility, not causal use. A confident diagnosis that the patch ignores would pass a judge but score low coupling. The grid tells us whether this happens often enough to matter. If confidence gating performs as well as coupling gating, we will report coupling as an explanatory tool rather than a practical one.
Why not just improve diagnosis quality, for example with human-quality feedback or supervised training on explanations? Improving diagnoses helps only if the patch listens to them. The 33.3% versus 52.6% gap in Olausson et al. suggests GPT-4 does listen to good feedback. However, Are Your LLMs Capable of Stable Reasoning? reports that supervised fine-tuning can raise accuracy while degrading stability across samples, and the thinking-drafts paper shows reinforcement-tuned models override their drafts. The ground-truth-diagnosis ablation settles this model by model. A low-coupling model that gains little from the correct fault location cannot be rescued by better diagnoses.
Decisive Checks
Three results would confirm the proposal, and their failure would refute it. First, coupling must sit clearly above the noise floor for at least some models. If it does not, diagnoses are decorative everywhere and the headline is negative but still new. Second, on APPS the self-repair advantage over resampling must concentrate in the high-coupling, correct-diagnosis cell. Third, at equal budget the gated policy must beat both ungated self-repair and pure resampling on BugSourceBench, and must also beat confidence and judge gates.
As a secondary test of the reinforcement-learning prediction, we compare coupling between the reasoning models and the instruction-tuned coders. For external validity, we then run the gated policy inside a single-agent loop on a SWE-bench Lite sample (SWE-bench). There, MAGIS reports 25.33% resolution (MAGIS). We treat that figure as context, not as a like-for-like target, since our loop is simpler.
References
- Demystifying GPT Self-Repair for Code Generation
- Measuring the Faithfulness of Thinking Drafts in Large Reasoning Models
- Towards large language model-based personal agents in the enterprise: Current trends and open problems
- Anchored Self-Play for Code Repair
- Thought Anchors: Which LLM Reasoning Steps Matter?
- Unveiling Confirmation Bias in Chain-of-Thought Reasoning
- When Disagreements Elicit Robustness: Investigating Self-Repair Capabilities under LLM Multi-Agent Disagreements
- Executable Counterfactuals: Improving LLMs' Causal Reasoning Through Code
- Integrate the Essence and Eliminate the Dross: Fine-Grained Self-Consistency for Free-Form Language Generation
- Are Your LLMs Capable of Stable Reasoning?
- SWE-bench: Can Language Models Resolve Real-world Github Issues?
- MAGIS: LLM-Based Multi-Agent Framework for GitHub Issue Resolution