arXiv:2610.25300cs.LGOct 2026

Manuscript Offprint

arXiv:2610.25300

Learning When to Abort in Transformer Planning: A Mechanistic Study

Shi Feng, Qimin Zhong, Siwei Wang, Yifei Shen, Shang-Hua Teng, Hao Liao, Wei Chen

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Planning does not by itself imply the ability to recognise errors, but recognising errors can improve planning capacity. In this paper, we study this phenomenon in Transformer planning. To analyze the inner mechanism, we follow the approach of Wang et al. (2024) and abstract planning as path-finding in graphs. In this setting, we train the model to detect the error of invalid transitions, i.e., after the model generates a next node that is not adjacent with the current node, the model should then generate a special abort token ×. For expressiveness, we construct a Transformer with feed-forward width O(∣V∣)O(|V|) for any fixed graph with node set V. It can detect all possible invalid transitions, and select a valid next node if the prefix is valid. We then propose a worst-case lower bound on feed-forward width, which makes the detector's linear width near-optimal up to logarithmic factors. In trained models, we demonstrate that invalid-transition detection increases previous-node attention, and most of the valid–invalid separation locates in the feed-forward network's output. This accords with our theoretical insights. Finally, we use this error detection to improve the model's performance: at inference, generating the abort token × will directly cause an external procedure to discard the attempt and restart from the original prompt. Experiments show that error detection combined with retry improves model's planning reliability on graphs, Countdown, and mazes.

1 INTRODUCTION

Planning involves choosing a sequence of steps that leads from an initial state to a goal, and is ubiquitous in daily life. In recent years, Transformer-based large language models (LLMs) are increasingly used for tasks requiring such multi-step planning, including mathematics and coding. Understanding how these models plan, and improving their planning capacity therefore becomes more and more important. In this paper, we study how learning to recognise invalid planning steps (or invalid transitions), could improve language-model planning. Traditional training on correct planning trajectories teaches a model which steps to take, but does not explicitly teach how to recognise invalid steps. In fact, planning ability does not need to bring failure recognition: a model may be able to find valid solutions yet fail to recognise that a problematic input contains invalid steps.

In human planning, however, failure recognition is also thought to play an important role in planning ability (Alexander & Brown, 2010; Fu et al., 2023).

Can a Transformer-based language model learn to detect invalid planning steps, what could be the underlying mechanism of this learning process, and how can this improve the model's performance?

We conduct a mechanistic study on this problem, based on the path planning setup of ALPINE (Wang et al., 2024). In ALPINE, the planning task is abstracted as looking for valid paths in a fixed graph. The graph is not supplied as an input, hence the model must learn the graph's structure from the training paths and find valid paths for unseen pairs. As for invalid planning steps, we focus on invalid transition, which is a step in the generated path from some node u to node v that has no corresponding edge in the underlying graph. To enable the Transformer to detect invalid transitions, we generate

∗^{*}Corresponding author: Wei Chen, weic@microsoft.com.

new training data containing valid path prefixes followed by an invalid transition, and then followed by a special abort token ×. Only the abort token is supervised on these generated data, so that the Transformer could learn to flag invalid transitions without being trained to produce them. Intuitively, this is analogous to adding wrong planning steps and masking them in a planning task for the model to learn from mistakes.

Graph path-finding lets us distinguish two computations. Selecting the next node uses the current node’s outgoing edges and reachability to the target; detecting an invalid transition instead requires relating the previous node to the current one.

Learning from search traces and error markers can improve planning (Gandhi et al., 2024; Lehnert et al., 2024; Huang et al., 2025; Yang et al., 2026). Our focus is the mechanism: what computation invalid-transition detection requires, and whether abort supervision induces it in trained models. Theoretically, Proposition 1 of Section 4.1 shows that an additive score of the previous and current nodes with a threshold cannot detect arbitrary invalid transitions. In Section 4.2, we construct a one-layer Transformer that combines next-node selection with invalid-transition detection using the non-linear feed-forward layer with width linear in the number of nodes. The lower bound in Section 4.3 makes the detector's linear width near-optimal up to logarithmic factors within the specified class of ReLU detectors. Empirically, Section 5 connects the abort decision to previous-node information and feed-forward network (FFN) processing in real trained Transformers. Attention measurements show whether the model looks back, interventions test whether previous-node information controls the abort decision, and direct logit attribution measures the FFN's contribution to the abort signal. A fitted additive-logit alternative retains substantial detection error on the same supervised prefixes (Appendix B.2). These findings are consistent with the computational dependencies identified by the theory.

We then ask whether the learned signal improves planning. At inference, a harness, an external procedure surrounding the model, discards an attempt when × is emitted and restarts from the original prompt. Experiments on random graphs, Countdown and mazes show that this procedure improves planning reliability (Section 6). Unlike verifier-ranked best-of-N sampling (Cobbe et al., 2021; Lightman et al., 2024), it does not require a fixed set of complete candidates or a separate correctness verifier: the model supplies the signal for restarting an attempt.

Our contributions are threefold: a simple training method that turns local errors into abort supervision; a mechanistic account of invalid-transition detection, combining a one-layer Transformer construction, a capacity lower bound and experiments on trained models; and an inference-time restart harness that uses the learned signal to improve planning across tasks and models.