Manuscript Offprint

arXiv:2610.03055

hacktrace: behavior-supervised detection of reward hacking during code generation

Hao Jiang, Xin Li, Annan Wang, Yichi Zhang, Weisi Lin

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

ABSTRACT

A coding agent can earn a passing grade by fixing its code, or by deleting the test that exposes the bug. Detecting such reward hacking requires recognizing attempted shortcuts, including those that fail. We release 173,561 annotated multi-turn coding trajectories from Qwen3-8B and show that supervising shortcut behavior independently of exploit success substantially improves detection. We introduce HACKTRACE, a behavior-supervised monitor that reads the internal states the agent already computes while generating code. Reusing these states enables monitoring before a turn is complete, without additional language-model tokens or passes. Combining this evidence with static features of the final files achieves a mean per-problem AUC of 0.997 with 8 ms of monitoring overhead, improving both accuracy and latency over monitors that run the model again on an honesty question and answer. The same generation states also provide an inexpensive monitoring signal for reinforcement learning. With strong GRPO penalties, HACKTRACE reduces the cheating share of passing solutions from 82–91% to 1–5%, while retaining honest, correct solutions and maintaining high detection accuracy as the policy evolves. Our results show that both the supervision target and the source of monitoring evidence matter for turning accurate detection into a useful training signal.

1 INTRODUCTION

Coding agents use language models to solve programming tasks through repeated interaction with an execution environment: they write code, run tests, and revise their solutions using the resulting feedback. An automated grader evaluates these attempts, and its judgments can serve as rewards for reinforcement learning. Yet coding agents optimized against a grader may learn to pass the grader rather than solve the underlying task. They may rewrite test assertions, hard-code expected outputs, special-case visible inputs, or otherwise exploit gaps between the grader and the intended specification (Skalse et al., 2022; Denison et al., 2024; Baker et al., 2025). Such reward hacking undermines the use of measured reward as evidence of progress and can reinforce undesirable behavior during training.

Detecting reward hacking requires evidence about how an agent arrives at its apparent success. Existing approaches inspect generated code and written reasoning (Baker et al., 2025; Wang et al., 2026), or train classifiers on the internal states computed by the language model (Goldowsky-Dill et al., 2025; Wilhelm et al., 2026). A monitor restricted to externally visible text, however, has limited access to the computation that produced it, may be evaded once it becomes a training signal (§4.4), and, when applied after execution, identifies a shortcut only after it has been carried out. Some monitors run the model again on a question about the agent's honesty and a fixed answer, then inspect the resulting states (self-report probes; Taufeeque et al., 2026). This adds token processing and latency. These costs motivate monitoring shortcut behavior as code is written, with low overhead for repeated use during training.

A second question is what behavior the monitor should learn to recognize. Consider an agent that deletes a failing test instead of repairing its code. If the remaining tests pass, the manipulation appears

∗^{*}Corresponding author.

as a successful exploit; if another test still fails, the same attempted manipulation may receive a negative training label. The distinction reflects whether the shortcut worked, even though the behavior of concern is present in both cases. Supervision based only on successful exploits therefore places unsuccessful attempts outside the detection target. We argue that a reward-hacking monitor should instead learn to recognize attempted shortcut behavior, independently of its success. This distinction is especially consequential when the monitor guides learning: a failed attempt is still behavior that training should discourage.

We introduce HACKTRACE, a behavior-supervised approach to monitoring reward hacking during code generation. To establish the supervision needed for this task, we construct and release a dataset of multi-turn coding interactions, comprising successive code revisions and execution feedback. Its labels distinguish shortcut evidence in the final code and tests from whether the shortcut successfully exploits the grader. This enables a direct comparison between learning to recognize attempts and learning to recognize successful exploits. We compare honest and shortcut behavior on the same programming problem, so that detection cannot rely on differences in how easily tasks can be exploited.

To make this supervision practical, HACKTRACE reads the internal states that the coding agent already computes while generating its response. Lightweight classifiers turn these states into scores for shortcut behavior, allowing an unfinished generation to be monitored without additional questions, language-model tokens, or language-model passes. Once generation is complete, the monitor can combine this evidence with simple features of the resulting code and tests to improve detection accuracy.

The same design allows HACKTRACE to supply a low-cost penalty during reinforcement learning. We integrate the monitor into Group Relative Policy Optimization (GRPO) (Shao et al., 2024), using its score to penalize shortcut behavior. In this setting, the agent changes in response to the monitoring signal itself (Gupta & Jenner, 2025; Taufeeque et al., 2026). A useful monitor must therefore continue to recognize shortcuts as training proceeds, while its penalty preserves the agent's ability to produce correct solutions. We therefore evaluate both sustained detection accuracy and the agent's ability to produce honest, correct solutions.

Our contributions are threefold:

• A dataset and supervision principle for detecting reward hacking. We release 173,561 annotated multi-turn coding trajectories and show the importance of supervising shortcut attempts independently of exploit success. The dataset separates behavioral evidence from execution outcomes, enabling monitors to learn from both successful and unsuccessful attempts.

• Accurate and efficient monitoring during code generation. HACKTRACE-combined achieves the highest detection accuracy among the evaluated monitors requiring no additional language-model pass, reaching 0.997 AUC with 8 ms of monitoring overhead. It exceeds self-report probes in both accuracy and speed, while eliminating their extra token cost. An activation-only variant also supports monitoring before a generation turn is complete.

• Effective monitoring throughout reinforcement learning. As a GRPO penalty, HACKTRACE maintains high detection accuracy as the agent evolves and suppresses cheating without additional monitoring tokens. It yields the lowest cheating share among the compared penalties without calibration or extra passes.

References (66)