Inspectable Control for Structure-Preserving Software Regeneration

Controllable partial code regeneration using hierarchical discrete latent representations.

Alexey Gavrilov1Alan-Barsag Gazzaev1Mikhail Mozikov2Ilya Makarov2Sergey Muravyov1

  1. ITMO University, Saint Petersburg, Russian Federation
  2. AXXX, Moscow, Russian Federation

Read the full paper in HTMLSearchable text with formulas, tables, figures, and references.

Author camera-ready manuscript with the final author list and DOI. CC BY 4.0 author manuscript; the ACM DOI page remains the version of record. Posting and reuse terms.

Paper in 30 seconds

Research questionHow can a generative model modify selected parts of a program while preserving chosen elements of its coarse structure?

Problem

AI-assisted code modification often needs one bounded change while selected program structure remains fixed. Regenerating the entire program can disturb unrelated regions, and token-level constraints do not expose a coarse control surface.

Approach

The study encodes 64-token Python functions with a hierarchical VQ-VAE, locks selected coarse discrete codes, and uses masked discrete generation for localized code regeneration in the remaining latent positions.

Main result

Locking four top-level codes raises parse rate from 0.453 to 0.591 while unlocked positions still change at rate 0.936 and conditional samples remain 0.998 unique.

Why it matters

The results show a measurable stability–freedom trade-off for controllable code editing and partial program regeneration. They provide early evidence for an inspectable latent control layer, not proof of semantic equivalence or functional correctness.

Abstract

Software-engineering workflows such as constrained repair, staged refinement, and structure-preserving modification require control over what changes and what remains fixed. Token-level generation is a weak control surface for these operations because it constrains local surface text rather than the coarse structural invariants that software engineering often aims to preserve. We study hierarchical discrete latents as an inspectable intermediate representation for software artifacts: a hierarchical VQ-VAE compresses a 64-token Python function into coarse and fine discrete codes, and masked discrete generation regenerates only selected positions under partial constraints. On 2,000 preprocessed Python functions, locking four top-level codes improves parse rate from 0.453 to 0.591 while preserving substantial change in unlocked positions (edit freedom, 0.936) and near-maximal sample uniqueness (diversity, 0.998). Under fixed coarse context, lower-level refinement is weaker but remains monotonic, supporting a coarse-to-fine reading of the hierarchy. Overall, these results provide early evidence for a practical control layer that supports bounded, structure-preserving software-artifact regeneration above the token level.

Published at Proceedings of the 34th ACM International Conference on the Foundations of Software Engineering

Contribution type Latent-space control method

pp. 1406–1407Companion poster

DOI https://doi.org/10.1145/3803437.3807386

Share this paperShare

Key results

Inspectable Control for Structure-Preserving Software Regeneration key results
SettingParse rateSkeletonSignatureUnlocked change
Input (truncated)0.9940.9940.994
Codec reconstruction0.8570.8480.4930
Unconditional generation0.4530.0800.995
Conditional, prefix k=40.5910.2950.0610.936
Conditional, signature span0.60.3020.063not reported

Key result. Coarse latent locking improves syntactic stability without collapsing change in the editable region; the result demonstrates structural control, not guaranteed functional equivalence.

Dataset
2,000 preprocessed Python functions from a CodeParrot Clean subset
Sample size
2,000 preprocessed Python functions; conditional sample uniqueness is 0.998.
Metrics
Parse rate; Skeleton and signature preservation proxies; Unlocked-position change rate; Sample uniqueness and entropy
Uncertainty
The two-page study reports point estimates without confidence intervals or multi-seed statistical analysis.
Conditions
64-token functions, argmax decoding, 16 top-level codes and 32 lower-level codes; full locking exactly recovers the codec reconstruction.
Download results:

PDF & citation

Cite this paper BibTeX is the recommended format. Every variant below is generated from the same publication record.

Open PDF
@inproceedings{Gavrilov2026InspectableControl,
  title      = {Inspectable Control for Structure-Preserving Software Regeneration},
  author     = {Gavrilov, Alexey and Gazzaev, Alan-Barsag and Mozikov, Mikhail and Makarov, Ilya and Muravyov, Sergey},
  booktitle  = {Proceedings of the 34th ACM International Conference on the Foundations of Software Engineering},
  publisher  = {ACM},
  year       = {2026},
  pages      = {1406--1407},
  doi        = {10.1145/3803437.3807386},
  url        = {https://doi.org/10.1145/3803437.3807386},
  isbn       = {979-8-4007-2636-1},
}
Download .bib
Citation files:

APA textIEEE textRISCSL-JSONSchema.org JSON-LDOAI-DC XMLOpenAIRE v4 XMLMODS XMLJATS 1.4 metadata XMLFull-text JATS 1.4 XMLRDF TurtleLink Set (JSON)Link Set (HTTP)RO-Crate

DOI:https://doi.org/10.1145/3803437.3807386

Full guide

Full research guide

Method

The method compresses a short Python function into two levels of discrete codes, freezes selected coarse positions, and regenerates the remaining positions before decoding back to code.

  1. Encode

    Compress a 64-token Python function into 16 top-level codes and 32 lower-level codes with a hierarchical VQ-VAE.

  2. Lock

    Choose coarse code positions that represent structure to preserve, such as a prefix covering the function-signature span.

  3. Regenerate

    Run masked discrete generation only over unlocked positions and decode the completed hierarchy back to source code.

  4. Inspect

    Measure parse rate, structural proxies, change in unlocked positions, and sample uniqueness before accepting a regeneration.

Selected coarse program codes remain fixed while masked fine discrete codes are regenerated and decoded into a modified Python function.
Hierarchical discrete latent code editing preserves selected coarse program structure while regenerating fine codes in the editable region.Source: Author-created explanatory diagram based on the published method and results..Reuse terms: CC BY 4.0.Suggested attribution: Gavrilov et al. (2026), Inspectable Control for Structure-Preserving Software Regeneration. Download SVG.

Key idea

Control is applied to a learned representation above tokens: coarse latent positions define explicit places where structure can be frozen while nearby implementation details remain editable.

Difference from nearby approaches

Prompt-level or token-level constraints operate on surface text. The proposed interface exposes coarse and fine discrete control points and measures the resulting stability–freedom trade-off.

What is new

The work introduces and evaluates an inspectable hierarchical latent control layer for bounded software-artifact regeneration.

Questions this paper helps answer

Open a question for a concise answer grounded in the paper. Detailed evidence boundaries are listed in Limitations.

  1. How can AI edit code without rewriting everything?

    The paper studies partial code regeneration above the token level. A hierarchical VQ-VAE maps a short Python function to coarse and fine discrete codes; selected coarse positions are locked, and masked discrete generation changes only the remaining latent positions before decoding. This provides an explicit preservation boundary instead of regenerating the whole function.

  2. What methods preserve program structure during code generation?

    This work tests hierarchical discrete latent control. Coarse latent positions can be fixed while unlocked positions are regenerated, after which parse rate and structural proxies are measured. The evidence concerns probabilistic structural stability on short Python functions; it does not establish exact AST preservation, semantic equivalence, or functional correctness.

  3. Can hierarchical discrete latents provide localized control over code?

    In the reported 2,000-function experiment, locking four top-level codes increased parse rate from 0.453 to 0.591. At the same time, 0.936 of unlocked positions changed and conditional samples were 0.998 unique. These results are early evidence that coarse latent constraints can preserve some structure without eliminating local edit freedom or sample diversity.

  4. How can code generation balance structural stability and diversity?

    The paper evaluates stability and freedom together rather than optimizing only validity. Coarse-code locking raises syntactic validity while unlocked-position change remains high and conditional samples remain almost entirely unique. The result demonstrates a measurable stability-freedom trade-off under the tested configuration, not a universal optimum.

  5. How does this work relate to LLM-assisted code editing?

    The tested model is a hierarchical VQ-VAE with masked discrete generation, not a large language model. The control problem is nevertheless relevant to LLM-assisted editing because unnecessary changes outside a requested region are a practical concern. The paper contributes a complementary latent-space mechanism and evaluation framing, not an LLM editing benchmark.

Comparison with nearby approaches

Inspectable Control for Structure-Preserving Software Regeneration factual comparison with nearby approaches
CapabilityToken-level controlHierarchical latent control
Freeze coarse structureLimitedNative coarse-code locking
Partial regenerationFragile surface constraintsMasked resampling of selected codes
Inspectable control pointsNo explicit intermediate layerCoarse and fine discrete positions
Evidence in this paperNot evaluated as a complete baselineSyntactic stability and edit-freedom diagnostics

The table describes interfaces and the study's measured evidence; it does not claim functional correctness or universal superiority.

Relevance & scope

The paper is most relevant to work that needs explicit control over what an AI-assisted code transformation may change and which parts of a program should remain stable.

  1. Controllable and structure-preserving code generation

  2. Localized program repair and bounded refactoring

  3. Hierarchical discrete representations for source code

  4. Masked discrete generation for source code

  5. Latent control for software artifacts

See limitations and evidence boundaries

Limitations

  • The study is limited to short Python functions truncated to 64 tokens.
  • Evaluation uses argmax decoding and syntactic or structural proxies rather than tests of functional equivalence.
  • Exact signature preservation remains weak.
  • Lower-level control is weaker than top-level control.
  • Latent positions are not yet aligned to semantic regions such as AST spans, signatures, or control-flow structure.
  • The results do not establish correctness for practical repair, refactoring, or repository-level changes.

References cited by the paper

These entries correspond to the numbered References section in the paper PDF.

  1. Ali Razavi, Aaron van den Oord, Oriol Vinyals. . Generating Diverse High-Fidelity Images with VQ-VAE-2. Advances in Neural Information Processing Systems.
  2. Jacob Austin, Daniel D. Johnson, Jonathan Ho, Daniel Tarlow, Rianne van den Berg. . Structured Denoising Diffusion Models in Discrete State-Spaces. Advances in Neural Information Processing Systems.
  3. Subham Sekhar Sahoo, Marianne Arriola, Yair Schiff, Aaron Gokaslan, Edgar Marroquin, Justin T Chiu, Alexander Rush, Volodymyr Kuleshov. . Simple and Effective Masked Diffusion Language Models. Advances in Neural Information Processing Systems.
  4. Shraddha Barke, Michael B. James, Nadia Polikarpova. . Grounded Copilot: How Programmers Interact with Code-Generating Models. Proceedings of the ACM on Programming Languages.
  5. Fengji Zhang, Bei Chen, Yue Zhang, Jacky Keung, Jin Liu, Daoguang Zan, Yi Mao, Jian-Guang Lou, Weizhu Chen. . RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generation. Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing.

Resources & reproducibility

Publisher
ACM
Publication resources
The public manuscript, results tables, explanatory figure, and citation files are available here. Implementation code and checkpoints are not publicly released.

Data statement

Source
A preprocessed subset of CodeParrot Clean containing 2,000 Python functions.
License
No dataset files are redistributed by this site; reuse remains subject to the upstream CodeParrot dataset and source-code licenses.
Preprocessing
Python functions are tokenized and truncated or padded to 64 tokens before hierarchical encoding.
Split
The poster reports a 2,000-function evaluation set; an immutable train/validation split manifest is not included in the public paper.
Format
Python source functions, GPT-style token sequences, top-level code sequences of length 16, and lower-level sequences of length 32.
Version / checksum
A dataset checksum and immutable snapshot identifier are not reported in the two-page paper.
Acquisition
A public acquisition script is not released with the publication page.
Use limits
The sample is not representative of repository-scale software, multiple programming languages, or behaviorally verified repair tasks.

Versions

  1. Published versionACM FSE Companion, 2026
  2. Open repository recordZenodo record indexed by OpenAIRE
  3. Author resourcesPoster and slide deck
  4. Bibliographic recordDBLP
  5. Open scholarly recordOpenAlex
  6. Citation graph recordSemantic Scholar
  7. Author-shared full textResearchGate
  8. Plain-language summaryKudos

The published DOI is the primary bibliographic identifier. This page remains the single canonical project URL across versions.