- The paper reveals that code correctness is linearly decodable from pre-generation hidden states, achieving a robust AUC over 0.91 after prompt-length residualization.
- The authors employ linear probing and per-dimension residualization to accurately control for confounds, ensuring that the correctness signal is not merely a length artifact.
- The geometric analysis of repair deltas indicates that repair signals are context-dependent, cautioning against naive interpretations of self-repair mechanisms in LLMs.
Code Correctness Signals in LLM Hidden States: Pre-Generation Probing and Repair Geometry
Overview
This paper systematically investigates the decodability of code correctness from internal representations of Qwen3-4B-Instruct-2507, specifically focusing on two questions: (1) whether correctness is linearly decodable from the pre-generation, prompt-final hidden state, and (2) whether there is a contrastive geometric direction in hidden-state space corresponding to successful repair when the model self-edits failed code outputs. The study centers its analyses on LiveCodeBench, leveraging 444 tasks and rigorous cross-validation and confound control via residualization. The methodology and results have direct implications for mechanistic interpretability and the diagnosis of internal reasoning in large autoregressive models.
Methodological Framework
A 36-layer, 4B-parameter decoder-only transformer (Qwen3-4B-Instruct-2507) is used, with focus placed on hidden states from upper transformer blocks (layers 29–36). The dataset is LiveCodeBench, which supports task-level binary evaluation (pass/fail) based on unit tests. The pipeline for interpretability is based on linear probing: a linear classifier is trained on extracted hidden states to predict code correctness. To explicitly control for potential confounds, each hidden state dimension can be residualized against covariates, most prominently input prompt length for the pre-generation probe.
For analysis of the repair process, deltas between hidden states before and after attempted self-repair are considered, with a contrastive direction constructed by group means between successful and failed repair attempts. Covariates specific to the repair context (change in prompt length, previous code output length, failure type) are also examined and, where necessary, regressed out before assessing the existence of a meaningful geometric direction.
Pre-Generation Code Correctness Decodability
The primary finding is that code correctness is, to a considerable extent, linearly decodable from the model’s final prompt-token hidden state prior to any autoregressive decoding. The performance of the linear probe over 50 random splits achieves a mean AUC of 0.931±0.008 (layer 29), which remains robust (0.911±0.010) after stringent residualization against prompt length. Nonlinear baselines trained on prompt length alone reach only 0.754±0.014, confirming the probe accesses information not attributable to a trivial length artifact.
Modal layer selection, determined by nested cross-validation, consistently prefers the shallow end of the upper block range (layers 29–30). This indicates maximal accessibility of correctness information in those layers, aligning with prior literature showing greater linear decodability of semantic features at intermediate transformer depths. Notably, the integrity of the evaluation is preserved via strict separation of task splits and nested validation to avoid selection bias.
Implications: The prompt-final hidden state encodes a substantial signal as to whether the model will ultimately produce correct code, independent of superficial properties like prompt length. This supports the hypothesis that, for code generation tasks, substantial “reasoning” about correctness occurs before output is generated, and that pre-generation representations can be systematically interrogated for alignment errors and failure prediction.
Repair Dynamics and Geometric Analysis
The second analysis focuses on the hidden-state shift when the model repairs failed code outputs. For 236 cleaned 0→1 transitions, the mean difference vector (success minus failure) in delta space is highly statistically significant in both magnitude (norm exceeded all shuffled-label nulls) and geometric stability (split-half cosine $0.767$, null mean ≈0).
However, this raw signal is not sufficient evidence for an isolable repair-relevant feature. All observable repair-context covariates—change in prompt length, prior code length, failure type—differ systematically between successful and failed repairs (p<0.001 for all). Conditional residualization, regressing out these covariates, collapses both the magnitude and geometric coherence of the direction; after residualization, neither norm nor split-half stability of the direction are significant. This demonstrates that the contrastive direction is a correlate of repair context and not a standalone representation of “repair comprehension.”
At later repair transitions (1→2 and beyond), data limitations prevent further meaningful geometric analysis. Pass rates sharply decrease and the number of successes is insufficient for statistical testing, reflecting the diminishing returns of iterative self-repair within the model (Arimbur, 12 Apr 2026).
Implications: Geometric signatures of success in repair deltas are confounded by features of the repair prompt, and do not survive removal of direct context correlates. This cautions against naively interpreting contrastive hidden-state differences as evidence of genuine mechanistic representations, absent rigorous conditional analysis. The finding further quantifies the limitations of current LLM self-repair mechanisms.
Methodological Contributions and Limitations
The paper’s primary technical contribution is the application of per-dimension residualization as a diagnostic confound-control across both pre-generation and repair analyses. This method demonstrates capability to both uphold claims (pre-generation correctness probe is robust) and overturn them (repair direction is not context-invariant). The transparent reporting of negative results, as well as empirical analysis of covariate redundancy effects, adds to the methodological rigor.
Limitations include exclusive focus on a single model (Qwen3-4B-Instruct-2507), restriction to the uppermost hidden layers (with the caveat that lower layers could in principle show stronger effects), and data starvation for multi-step repair transitions. Adapting the approach to a broader set of models and larger datasets remains an open avenue for future work.
Theoretical and Practical Implications
- Interpretability and Transparency: The persistent pre-generation signal strengthens the case for mechanistic interpretability approaches examining representations before generation. Probing pre-generation states could inform alignment diagnostics and early error detection tools.
- Repair and Self-Editing: The negative result for geometric repair comprehension restricts interpretation claims for current representation engineering techniques in post-hoc repair. Automated identification of causally-meaningful subspaces must rigorously control for contextual confounds.
- Evaluation Protocols: The study underscores the necessity of leakage-free, stratified, and cross-validated pipelines in representation probing to avoid overfitting and misattribution of learned signals.
Future Directions
Replication across multiple architectures and scales, expansion to multi-step repair dynamics, and integration with mechanistic analysis of attention and MLP subspaces represent natural extensions. Systematic accumulation and curation of code generation benchmarks with detailed error logging and repair context annotation will enable further advances in the field.
Conclusion
Through probing and geometric analysis, this paper demonstrates that LLM hidden states can linearly encode code correctness pre-generation, robustly beyond prompt length artifacts. In contrast, post-hoc geometric directions in the repair process do not isolate context-invariant repair features after explicit confound removal. The results highlight both the potential and limits of linear interpretability for program synthesis tasks, providing a nuanced methodological framework for future analysis of LLM internal computations (2606.14530).