Coding Agents Have a 'Latent Programming Horizon' — New Research Reveals LLMs Predict Edits Before They Happen
A new paper shows that LLM residual streams encode program correctness and can predict future edits up to 25 steps ahead, opening the black box of coding agents.

A team from KTH Royal Institute of Technology has published a paper that digs into what large language models actually know about the code they're generating inside a coding agent. The headline: LLMs don't just react to the current state of a program — they seem to maintain an internal representation of where the code is headed, sometimes 25 steps before the edit is written to disk.
What They Did
The researchers trained logistic regression probes on the residual stream activations of LLMs (two models, two benchmarks) while those models acted as coding agents. The probes decoded whether the current code parsed, passed tests, reduced failing tests, or introduced regressions. The results: AUC up to 0.83 for correctness — meaning the hidden states carry a surprisingly clean signal about program quality.
But the more interesting finding is temporal. Probes trained to predict the outcome of future edits — edits the agent hasn't even made yet — performed above chance up to roughly 25 steps in advance. The authors call this the latent programming horizon. The model's internal representation runs ahead of its own actions.
Why This Matters
Coding agents (like GitHub Copilot, Cursor, or Devin) are black boxes. They take a prompt, run a loop of reasoning-editing-testing, and produce code. We have almost no visibility into whether the model is actually tracking program semantics or just pattern-matching its way through. This paper provides evidence that the model does build a structured internal model of the program — and that this model is predictive, not just reactive.
As a proof of external validity, the probes transferred across benchmarks without retraining. That suggests the latent representations are not benchmark-specific artifacts but general properties of how LLMs encode code during multi-step tasks.
The Catch
The probes are logistic regressions on hidden states — a simple linear readout. That means the signal is there, but it's also noisy. The horizon of 25 steps is an upper bound; performance degrades as you look further ahead. And the paper doesn't show that you can use this horizon to improve agent behavior, just that it exists.
Still, this is a solid piece of mechanistic interpretability work. It opens the door to building coding agents that can introspect their own latent state — maybe even correct course before a bad edit is committed. That would be a real leap forward.
Source: arXiv.org
Discussion
0 Comments
Be the first to start the discussion.