Hydra: Efficient, Correct Code Generation via Checkpoint-and-Rollback Support

Alexander Du, Jianjun Ou, Danyang Zhuo, Matthew Lentz
5/14/2026
cs.SEcs.AIcs.PL

No confident code implementation found for this paper.

Abstract

Large language models are increasingly used for code generation, but many generated programs fail to compile, a prerequisite for further correctness checks such as unit tests. Existing solutions for repairing static errors are costly in both latency and token consumption.

Show full abstract

Post-hoc repair delays error detection until generation completes and commonly regenerates large regions of previously valid code. Constrained semantic decoding checks after each token, incurring per-token overhead while limiting repair to the current token even when the root cause lies earlier. We present Hydra, a system for efficient recovery from static errors during code generation. Hydra allows checking to proceed asynchronously with generation, avoiding checker overhead when the generated code is semantically correct. In addition, it provides checkpoint-and-rollback support for targeted repair, avoiding regeneration and rechecking of valid prefixes. We retrofit the Clang C/C++ compiler to support Hydra with modest modifications. Paired with a token-efficient repair strategy, Hydra reduces latency by up to 71% and token consumption by up to 70% relative to post-hoc repair on C/C++ code generation tasks that encounter static errors.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{du2026hydra,
  title  = {Hydra: Efficient, Correct Code Generation via Checkpoint-and-Rollback Support},
  author = {Alexander Du and Jianjun Ou and Danyang Zhuo and Matthew Lentz},
  year   = {2026},
  eprint = {2605.15238},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2605.15238v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2605.15238.svg)](https://codeofpaper.com/paper/2605.15238)

Discussion