Manuscript Offprint

arXiv:2610.09159

SpecGuard: Proving a Task Is Broken Before the Agent Cheats

Param Biyani, Krishnamurthy Dvijotham

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

ABSTRACT

As autonomous coding agents get increasingly deployed, the risk that accidental or adversarially injected misspecifications in tasks lead to dangerous agent behavior is critical to address. Prior work has shown that agents given such tasks rarely flag the conflict and instead cheat, editing tests or hard-coding expected outputs, and the actions taken to cheat can cause real damage, such as deleting a security defense to make a corrupted test pass. It remains unclear whether such conflicts can be established with independently verifiable evidence before the agent acts. We present SPECGUARD, which detects and formally certifies these conflicts between task intent and tests. Given only the task description and codebase, SPECGUARD autoformalizes the intended behaviour into a Lean 4 specification. The tests are formalized independently, and the Lean kernel checks whether any implementation could satisfy both formalizations, producing a machine-checked certificate when none can. On conflicted SWE-bench tasks, SPECGUARD detects up to 72.8% of conflicts and formally certifies up to 51.1%, with a nearly five-fold lower conflict miss rate than model-based judgment. SPECGUARD provides a pre-execution safety check that identifies reward-hacking opportunities through formal certification of task-level conflicts, before any agent behavior is observed.

1 INTRODUCTION

Autonomous coding agents increasingly operate inside repositories, test suites, sandboxes, and evaluation harnesses that define whether their work is considered successful. When these signals diverge from the user's intent, agents can exploit the evaluation instead of solving the intended task. Frontier coding agents have been observed modifying evaluators, hard-coding expected outputs, and exploiting weaknesses in task setups (Arx et al., 2025). Related failures have also caused real-world harm, where in a widely reported incident, a deployed coding agent deleted a production database during an explicit code freeze and then misreported its actions (eWeek, 2025). Reward hacking learned during training can further generalize to broader misaligned behavior, including interference with safety mechanisms (MacDiarmid et al., 2025). These

81% GPT-5.6 Sol

cheats

on SWE-Bench

51% SpecGuard formally certifies SWE-Bench cheating

9/22

SpecGuard CLI

formally certifies

real-world conflicts

Figure 1: Headline results for SPECGUARD.

examples motivate a basic question: can we reliably detect when the task itself creates an opportunity for reward hacking before giving it to an agent?

One important case arises when a coding task’s natural-language description and its tests cannot both be satisfied. We call these conflicted tasks. Such conflicts can arise accidentally from incorrect tests, or adversarially when an untrusted contributor modifies the tests or other parts of the evaluation environment (a recent UK AI Security Institute incident involved an agent using fabricated identities to solicit the merge of malicious code into an open-source project (AI Security Institute, 2026)). ImpossibleBench (Zhong et al., 2025) studies this setting by deliberately corrupting tests and observing how coding agents respond. Agents commonly modify tests or hard-code expected outputs rather than report that the task is inconsistent. Figure 2 shows a particularly harmful exam-ple. Under a corrupted test, an agent removed the session-fixation defense that the task explicitly asked it to preserve and reported that all tests passed. More broadly, recent work argues that no single verifier can fully close the gap between coding-agent reward signals and developer intent (Wang et al., 2026). Existing work therefore shows that conflicted tasks can induce reward hacking, but it leaves open whether the conflict itself can be established before any agent behavior is observed. A model can be asked to judge whether a task is inconsistent, but such a verdict still requires trusting the model that produced it. Our goal is instead to produce evidence about task feasibility that can be checked independently.

if session_hash matches a fallback secret:

  • request.session.cycle_key() # security: resets session ID request.session[HASH_SESSION_KEY] = session_auth_hash

Figure 2: An agent’s patch under a mutated test. The agent removed the call that resets the session identifier, which is the session-fixation defense requested by the task, and reported that all tests pass.

We present SPECGUARD, which checks for such conflicts before a coding agent runs. Given the task description and codebase, but without access to the tests, a SpecAgent generates an executable Lean 4 (de Moura & Ullrich, 2021) specification of the intended behavior. A separate TestAgent formalizes the test requirements, and a Certifier connects the two representations. When the generated specification and formalized tests cannot both be satisfied, Lean produces a machine-checked conflict certificate. When a full proof cannot be produced, SPECGUARD can still return execution-checked evidence of disagreement, or return inconclusive when it cannot construct a faithful connection. This gives a spectrum of evidence, from model judgment, to executable disagreement, to a formal certificate that can be checked without trusting the model that generated it. The distinction between detecting and proving a conflict is central to our evaluation.

We evaluate SPECGUARD on conflicted variants of SWE-bench and LiveCodeBench, also with an agentic LLM-judge and a python reference model baseline. With only the corrupted SWE-bench tests available, SPECGUARD detects up to 72.8% of conflicts and formally certifies up to 51.1%. With GPT-5.6 Sol, the conflict miss rate is 8.1%, compared with 39.8% for the LLM judge. A manual audit finds the large majority of certificates faithful (52/60). Providing both the original and corrupted test versions improves detection by 17–25 percentage points across models and raises Sol's certified-conflict rate to 67.0%, showing that cross-representation alignment between independently generated representations is a major source of difficulty. Our formalizability and failure analysis further separates cases that are difficult because the issue does not specify the tested behavior from cases where the current specification, transcription, connector, or harness fails to represent it. Finally, we systematically collect 22 naturally occurring test conflicts from recent GitHub repositories and evaluate the same standalone SPECGUARD CLI intended for use outside our benchmark harness. It produces nine conflict verdicts on these cases, including eight Lean-certified conflicts.

Our contributions are:

• We formulate pre-execution conflict detection as a consistency check between independently generated representations of task intent and test requirements, and introduce SPEC-GUARD, which can produce machine-checked Lean certificates when they disagree.

• We evaluate SPECGUARD across multiple frontier models and evidence levels, showing that it detects up to 72.8% of conflicted SWE-bench tasks and formally certifies up to 51.1%, while substantially reducing conflict misses relative to an agentic LLM judge.

• We analyze when conflict certification succeeds and fails, including the effect of partial formalization, off-issue assertions, fixture dependence, algorithmic complexity, and connector failures.

• A standalone SPECGUARD CLI that successfully runs on 22 naturally occurring conflicts collected from recent GitHub repositories, demonstrating certificate production beyond synthetic benchmark mutations.

References (71)