Manuscript Offprint

arXiv:2609.39957

Learning When and How to Intervene: A Hindsight-Distilled Sentinel for Coding Agents

Jiangrui Zhao, Chenglong Li, Meng Zhang, Xiaoting Du

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

ABSTRACT

Coding agents solve repository-level tasks through sequences of actions, where a single erroneous action can misdirect subsequent decisions and increase recovery costs. Existing approaches use execution feedback for recovery or specialized checks to block errors, but deciding before execution whether intervention will benefit eventual task completion remains challenging. To address this challenge, we propose HiSENTINEL, a hindsight-distillation framework that trains lightweight 0.6B and 1.7B sentinels to select pre-execution interventions aimed at improving task completion rather than correcting every imperfect action. A privileged teacher uses recorded execution outcomes as evidence for intervention judgments, which are distilled into a causal student that receives only the pre-action context and proposed action. Beyond identifying whether and when to intervene, the sentinel must also provide actionable feedback that helps the coding agent recover or obtain necessary human input. To support these capabilities, we introduce SWE-INTERVENE, an action-level dataset constructed from software-engineering trajectories that annotates whether an action should be allowed, autonomously redirected, or paused for human assistance, together with corresponding intervention feedback. Across SWE-bench Verified Mini and Ask or Assume, HiSENTINEL consistently improves task completion across Sentinel scales and coding-agent families, with gains of up to 14% and 10%, respectively, while maintaining competitive token consumption. These results demonstrate that lightweight pre-execution intervention can effectively prevent error propagation and improve the reliability of autonomous coding agents.

1 INTRODUCTION

Large language models now power coding agents that solve repository-level software-engineering tasks by navigating codebases, editing files, executing commands, and running tests (Jimenez et al., 2024; Yang et al., 2024; Wang et al., 2025). Because these agents operate through multi-step interaction loops, a poor action can alter the environment, mislead subsequent decisions, and propagate into failed repairs, redundant exploration, or ultimately task failure (Chen et al., 2025; Majgaonkar et al., 2025; Gandhi et al., 2025). Critically, an early mistake may remain latent for several steps and become apparent only after recovery has become difficult or impossible (Zhao et al., 2026c).

Evidence from Terminal-Bench highlights this gap: among 1,184 failed CLI-agent trajectories, half committed their decisive error by step 7 and became unrecoverable around step 12, while the first observable failure appeared only around step 16; prefix monitoring detected just 3.7–8.7% of failures before lock-in (Merrill et al., 2026; Zhao et al., 2026c). Existing process critics review recent steps and provide periodic corrective feedback (Gandhi et al., 2025), while trajectory diagnosis can locate decisive errors after a run (Wang et al., 2026; Zhang et al., 2026c). Yet feedback may arrive after a harmful action has executed, and retrospective diagnosis cannot prevent it. This leaves open how to judge an action when it is first proposed.

∗^{*}Corresponding author.

Figure

Figure 1: Pre-execution intervention for coding agents. The Sentinel evaluates each proposed action before execution and selects ALLOW, REDIRECT, or HARD-PAUSE.

As illustrated in Figure 1, this motivates moving intervention earlier: after the agent proposes an action but before the environment executes it. At this boundary, a Sentinel can prevent a harmful action from changing the environment, rather than attempting to recover from its consequences afterward. We formulate this as a three-way decision among ALLOW, REDIRECT, and HARD-PAUSE: allowing appropriate actions, redirecting errors the agent can correct autonomously, and pausing when progress requires information, authorization, or access available only from a human.

However, moving intervention before execution creates a fundamental information gap. The execution result provides the most direct evidence of whether a proposed action is appropriate, yet this evidence is inherently unavailable at the time of intervention. The Sentinel must therefore anticipate whether an action threatens eventual task completion using only the pre-execution context and the proposed action.

To bridge this gap, we propose HISENTINEL, a hindsight-distilled framework that transfers knowledge available after execution into a model that acts before execution. During training, a privileged teacher observes both the proposed action and its recorded execution result, allowing it to judge the action using evidence of what actually occurred. Its judgments are then distilled into a lightweight causal Sentinel that receives only the pre-execution context and proposed action. At deployment, the Sentinel can therefore intervene without access to future observations while benefiting from supervision informed by execution hindsight.

Beyond deciding whether to intervene, the Sentinel must communicate how the agent should proceed. We therefore optimize feedback generation separately, training the Sentinel to provide concise, evidence-grounded guidance that suggests a minimal correction or requests the specific human input needed to continue.

To train both intervention decisions and feedback, we introduce SWE-INTERVENE, an action-level dataset constructed by selecting decision nodes from natural software-engineering trajectories. Each node preserves the task, complete pre-action context, and exact proposed action, and is annotated as a three-way decision.

We evaluate HISENTINEL at two levels: intervention decisions and feedback quality on frozen in-domain tests and external trajectory-diagnosis benchmarks, and end-to-end performance with coding agents on SWE-BENCH VERIFIED MINI and ASK-OR-ASSUME. We measure task completion, unnecessary interventions, and inference overhead (Hobbhahn, 2025; Edwards & Schuster, 2026).

In summary, our contributions are as follows:

• We formulate real-time intervention at the boundary between action proposal and execution as a three-way decision among ALLOW, REDIRECT, and HARD-PAUSE, targeting eventual task completion rather than merely detecting imperfect actions.

• We introduce SWE-INTERVENE, an action-level dataset for learning when and how to intervene in natural software-engineering trajectories.

• We propose HiSENTINEL, which distills execution hindsight from a privileged teacher into a lightweight pre-execution Sentinel and trains it to generate concise corrective feedback that guides subsequent agent behavior.

References (48)