Abstract
Coding agents are increasingly utilized in test-driven software development, yet the theoretical mechanisms behind their environment-interaction strategies remain underexplored. We provide a probabilistic framework for two dominant paradigms: code selection after generation using the execution environment, and code generation conditioned on environment feedback. First, we formalize several well-established selection heuristics as environment-aware estimators of code correctness. We theoretically prove that estimators based on fuzzy functional similarity add an inductive bias and strictly dominate estimators based on functional equivalence in terms of signal-to-noise ratio. Second, we frame backprompting as an in-context approximation of Thompson sampling. We derive a novel regret bound for reward functions with unobservable components, theoretically explaining why the effectiveness of backprompting is limited by the ambiguity of the informal task description (an irreducible regret). Using three state-of-the-art open weight models, we corroborate these findings across BigCodeBenchHard, LeetCodeDataset, and QiskitHumanEvalSim. Our formalization also suggests how to improve task descriptions effectively, leading to a new benchmark, QiskitHumanEvalSimX.
Introduction
Modern coding agents, such as GitHub Copilot or Claude Code, increasingly rely on test-driven development (TDD) loops to enhance their performance. These agents typically employ two empirical strategies: post-generation selection and iterative backprompting. Post-generation selection involves generating multiple code samples and test suites, executing them, and selecting the candidate that passes the most tests or aligns with peer outputs. Iterative backprompting involves a feedback loop where execution errors are fed back into the Large Language Model (LLM) to refine the code. While these strategies are effective in practice, the theoretical underpinnings explaining their success and fundamental limits have been largely missing. This paper bridges this gap by formalizing these heuristics through the lenses of probability theory and Bayesian optimization.
Theoretical Framework: Selection and Backprompting
The authors analyze the two interaction paradigms using distinct theoretical frameworks.
Post-Generation Selection as Probability Estimation
Selection heuristics, such as CodeT or MBR-EXEC, are formalized as estimators of code correctness. The paper distinguishes between "hard" estimators, which require strict functional equivalence (identical outputs), and "soft" estimators, which utilize fuzzy functional similarity. A key theoretical contribution is the proof that "soft" selection dominates "hard" selection. By grouping code based on fuzzy similarity, agents benefit from an inductive bias that strictly dominates strict equivalence in terms of Signal-to-Noise Ratio (SNR) by a factor of at least $m^2$, where $m$ is the number of test suites.
Backprompting as Thompson Sampling
Iterative backprompting is framed as an in-context approximation of Thompson sampling, a classic Bayesian optimization algorithm. The authors derive a novel regret bound for reward functions containing an unobservable component. This component represents the latent, true algorithm intended by the user, which is often lossily compressed into a natural language prompt.
As shown in Figure 4, the "Informal Specification" is an observable input, but the intended "Algorithm" may contain unobservable nuances. This leads to an "irreducible regret": if the initial prompt is ambiguous, no amount of execution feedback can guarantee convergence to the correct solution.
Experimental Methodology
The theory was validated using three state-of-the-art open-weight models (Qwen3-235B, GPT-OSS-120B, MiniMax-M2.1) across several benchmarks:
- BigCodeBenchHard: 148 difficult tasks requiring complex instructions and external libraries.
- LeetCodeDataset: 228 puzzle-style questions with natural language input-output examples.
- QiskitHumanEvalSim: A subset of quantum computing tasks solvable via simulation.
- QiskitHumanEvalSimX: A new benchmark designed to test the "irreducible regret" theory by reducing task ambiguity through detailed test descriptions and I/O examples.
Key Results
Empirical results across the benchmarks strongly support the theoretical findings.
Performance of Selection Heuristics
Across all models, "soft" variants of selection heuristics consistently outperformed "hard" versions. For instance, on BigCodeBenchHard using Qwen3, Soft CodeT achieved a 35.00% Pass@1, significantly higher than Hard CodeT's 31.22%.
Effectiveness of Backprompting
Backprompting proved highly effective when task ambiguity was low. On the LeetCodeDataset, which inherently includes I/O examples, Qwen3's performance improved from a zero-shot Pass@10 of 28.60% to a Pass@1 of 72.11% after 10 rounds of feedback.
Figure 6 illustrates the performance gains across different datasets. The flatter curves in BigCodeBenchHard (a) compared to LeetCodeDataset (c) highlight how task complexity and ambiguity limit the effectiveness of iterative refinement.
Validating the Ambiguity Theory
To confirm the impact of irreducible regret, the authors compared performance on QiskitHumanEvalSim versus the augmented QiskitHumanEvalSimX. By lowering ambiguity, the accuracy improvement from backprompting jumped from 3.21% to 7.13%, validating that clearer task descriptions allow agents to better utilize environment feedback.
Discussion and Limitations
While powerful, these interaction strategies have limitations. Post-generation selection scales quadratically, $\mathcal{O}(n \times m)$, posing a bottleneck for large-scale tasks. Iterative backprompting is limited by the context window and the quadratic attention complexity of standard Transformers. Furthermore, the effectiveness of these methods is heavily dependent on the model's ability to synthesize valid, discriminative tests. Future work may explore linear-complexity architectures like State-Space Models to support longer interaction loops and more complex software engineering scenarios.
Summary updated