When a language model repairs code in a language it has seen little of, such as Verilog, Ada, Fortran or COBOL, each repair round can pull it back toward the languages it knows best. A Verilog fix starts to look like sequential C. An Ada patch picks up Python-style indexing. We call this source reversion. Our hypothesis is that it is a main reason why the loop of generating code, running it, and feeding the errors back stalls after a round or two. Domain adaptation research has a name for the underlying effect: source domain bias, where abundant training data from one domain drowns out the patterns of a sparse target domain. That literature also has a simple remedy. Model the source-specific component explicitly, then keep it from shaping target predictions. This note proposes to carry that remedy into the repair loop at decoding time, when the model chooses each output token.
The proposal has two parts. The first is a measurement: score how "source-like" each repair attempt is, and test whether this score rises across rounds and separates failed repairs from successful ones. The second is a decoding change. At every repair step, the model's next-token scores given the true target-language context are compared with its scores when the same task is framed in the source language. Tokens the source framing favors are pushed down. This works for any target language and needs no hand-written rules, no target-language fine-tuning data, and only logit access to an open model.
Core Claim
The claim has two parts, each testable on its own. The first part is that the plateau in self-debugging on low-resource targets is partly caused by source reversion, and that reversion grows with the number of repair turns. The second part is that removing an explicitly estimated "source-specific" component from the model's token scores during repair turns raises the success rate within $K$ debugging rounds. It should do so more than prompting fixes, resampling from scratch, or retrieval at matched compute.
The first part is motivated by several observations in the literature. CodeTransOcean benchmarks translation across 45 languages. It finds that compiler-feedback self-debugging moves GPT-3.5 from 48.57% to only 52.57% execution success after three rounds, with most of the gain in round one. It does not ask why, and it only executes Python targets. Do Users Write More Insecure Code with AI Assistants? is a user study. It shows that feeding a model its own earlier output back as the prompt reinforces the dominant web-scale patterns rather than correcting them. Conversational Automated Program Repair reports that repair dialogues stop helping after three to four turns. MEIC runs a Verilog debug agent with simulator feedback and rollback. It notes the agent falling into a "new error trap" on dense arithmetic modules, but it never measures whether those errors are software-like constructs.
None of these papers separates source-prior pull from ordinary difficulty. That separation is our first contribution.
Research Program
The mechanism. The method borrows the structure of Frustratingly Easy Domain Adaptation. That paper copies each feature into general, source-specific and target-specific slots, so that source-only behavior is absorbed by its own weights instead of distorting the shared ones. We cannot re-slot a pretrained model's features. We can, however, estimate its source-specific tendency by running it under three contexts.
Let $c_{tgt}$ be the real repair prompt: the task, the current target-language code, and the compiler or simulator error. Let $c_{src}$ be the same prompt with the language set to the dominant source (for example, "write this in Python/C"). Let $c_{0}$ be a language-neutral version with the language name removed. At repair turn $k$, the next token $y_t$ given the previous tokens $y_{<t}$ is chosen from
$$\tilde{s}(y_t) = \log p(y_t \mid c_{tgt}, y_{<t}) - \lambda_k \left[ \log p(y_t \mid c_{src}, y_{<t}) - \log p(y_t \mid c_{0}, y_{<t}) \right].$$
The bracketed term is the source-specific component: how much more the source framing favors a token than the neutral framing does. The weight $\lambda_k$ can differ across turns. To avoid producing garbage, we only consider tokens whose target-context probability is at least a fraction $\alpha$ of the top token's probability. The general idea of contrasting two contexts at decoding time exists outside this file. What is new here is the specific decomposition that mirrors the three slots, its restriction to repair turns, and its use against source bias in execution-feedback loops.
The measurement. We define a span-level source affinity score. It is the log-likelihood of a generated span under $c_{src}$ minus its log-likelihood under $c_{tgt}$. It is computed with a fixed scoring model separate from the generator. We validate it against human annotation of 300 failed repair attempts, labeled as source-reversion errors or other errors. Two examples of reversion errors: blocking assignments inside clocked Verilog blocks, and 0-based loops or Python library names in Ada or Fortran.
If source affinity does not predict the human labels well, the diagnostic claim fails at this stage. In that case we report the annotation study alone.
The testbed. The main new asset is a reversed-direction translate-and-repair benchmark. CodeTransOcean's NicheTrans pairs translate niche languages into popular ones. We reverse them, so the task is Python or C to Fortran, Ada or COBOL. We add execution checking by compiling with open toolchains and comparing the program's output against the Python reference on generated inputs. This fills the gap that the original benchmark only executed Python targets.
For hardware we use the RTLLM generation suite, 30 designs checked for syntax and simulated function. We also use MEIC's 178 labeled RTL bugs, spanning syntax and functional errors. As a control where the source prior should not matter much, we use Python repair on QuixBugs, where the target language is itself high-resource. The method should give roughly zero gain there. A large gain would mean the method is acting as a generic regularizer rather than removing source bias.
Baselines
The naive reference point is plain self-debugging. The same open code model repairs its own output from compiler or simulator errors for $K=3$ rounds with greedy decoding, following the loop in CodeTransOcean. For comparison, that paper's GPT-3.5 result is 48.57% at round zero and 52.57% at round three. This number comes from the niche-to-Python direction. We found no reported result on Lacuna for self-debugging in the Python-to-niche direction, so our own round-zero and round-three numbers set the reference.
The strongest existing system for hardware is MEIC. It combines a Verilog-tuned debug agent, a scorer agent, and rollback to the best previous version when tests regress. It reports a 78% functional-error fix rate with GPT-4, against 66% for plain retrieval or fine-tuning, and 93% on syntax errors. It is the right competitor because it already targets a low-resource language using structure and feedback rather than decoding changes.
We re-implement MEIC's loop around our open model. Our decoding rule is then applied inside that same loop, including rollback, so that decoding is the only thing that varies. Beating it means a statistically significant gain in functional fix rate on the 178 bugs at equal repair rounds, together with a lower source-affinity score on failed attempts. For RTLLM generation, the reference is GPT-4 with self-planning at 19/30 functional passes, as reported in RTLLM. Because we use a smaller open model, the relevant comparison is its own self-planning result with and without contrastive decoding.
A trained baseline is LeDex. It fine-tunes StarCoder-15B on debugging trajectories and reports that the success rate on known-buggy solutions rises from 6.4% to 17.5%. We apply our decoding on top of a LeDex-style model to test whether the two effects add up or whether training already removes the bias.
Compute is matched throughout. Our method uses three forward passes per token. Every baseline therefore gets three times the samples, run as best-of-3 with a compiler filter, so that any win is not bought with extra computation.
Two ablations isolate the key ingredient. The first removes the neutral term, which amounts to plain source subtraction. The second is a wrong-source control: it contrasts against a high-resource language unrelated to the task, such as Java when the source is Python. If gains come from removing the actual source prior, the wrong-source contrast should help clearly less.
Why not just…?
Why not just tell the model the target-language rules in the prompt or feedback? For Verilog this is a real threat. A linter plus a short list of "no blocking assignments in clocked blocks" rules might capture most of the benefit. We run this as a baseline with rules written by a hardware engineer. If it matches our method on RTL, we will say so and narrow the claim to languages without mature rule sets. That is the setting that motivates a rule-free method: CodeTransOcean did not even execute its 37 niche languages. The COBOL and Ada splits settle this question.
Why not just restart from scratch instead of iterating? If reversion comes from feeding the model its own output, as the evidence in Do Users Write More Insecure Code with AI Assistants? and the turn limit in Conversational Automated Program Repair suggest, then independent resampling avoids it for free. We compare against compile-filtered independent samples at matched token budget. If resampling wins, that result itself supports the diagnosis, and the contribution shrinks to the measurement.
Why not just fine-tune on target-language debugging data? For the niche targets, that data mostly does not exist, which is the premise of the low-resource setting. Where it does exist, MEIC's Verilog-tuned agent still shows the "new error trap." The LeDex-plus-decoding experiment tests whether training alone removes reversion.
Why not just retrieve target-language examples? CrossCodeEval finds that models fall short even when given the exact oracle cross-file context. MEIC reports that retrieval reaches only 66% on functional errors. We still include a BM25 retrieval baseline, and a combined retrieval-plus-decoding condition.
Proposed Experiments and Decisive Checks
The first check is diagnostic. On the reversed CodeTransOcean splits and on RTLLM, does source affinity rise from round to round, and are failed round-three attempts significantly more source-like than successful ones, both by the automatic score and by human labels? A flat curve would falsify the premise.
The second check is causal. Does contrastive repair raise success at three rounds over plain self-debugging and over resampling at matched compute on the niche and RTL targets, with the gain concentrated in rounds two and three? And is the gain near zero on Python QuixBugs?
The third check is specificity. The correct-source contrast should beat the wrong-source contrast, and gains should be largest on the problems whose failures were labeled as reversion.
The fourth check examines the tension between rollback and relaxed acceptance raised by ICER. ICER argues that accepting only strictly improving code overfits the visible tests, so it accepts any candidate that passes. We run our decoding under both MEIC-style rollback and ICER-style relaxed acceptance, and report which acceptance policy the debiased model prefers.
We also sweep $\lambda_k$ and the plausibility fraction $\alpha$ on a held-out development split and report sensitivity. The concern that fixed balancing weights fail to transfer, raised in Towards Realizing the Value of Labeled Target Samples, applies here as well.
References
- CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translation
- Do Users Write More Insecure Code with AI Assistants?
- Conversational Automated Program Repair
- MEIC: Re-thinking RTL Debug Automation using LLMs
- Frustratingly Easy Domain Adaptation
- RTLLM: An Open-Source Benchmark for Design RTL Generation with Large Language Model
- LeDex: Training LLMs to Better Self-Debug and Explain Code
- CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completion
- Improving Code Efficiency with Iterative Refinement using LLMs
- Towards Realizing the Value of Labeled Target Samples: A Two-Stage Approach for Semi-Supervised Domain Adaptation