AI AgentAI Coding

Tests All Passed, But AI Still Wrote Wrong Code: Four Hidden Traps in Engineering Practice

Introduction: Passing the sniff test Is Only the First Step

In the process of using AI to build and transform software systems, everyone has likely gradually come to realize one thing: whether AI can get the job done depends largely on whether there is a closed-loop feedback mechanism. When code executors and fixed tests can constrain expected behaviors, AI often iterates rapidly. As long as a task has clear verification standards or reward signals, handing it directly to AI usually yields good results. This mode of judgment has gradually become a tacitly accepted evaluation rule for everyone.

However, in practical use, many may share the same feeling: while this baseline rule works quite well most of the time, occasionally one still falls into traps without being able to pinpoint exactly where the problem lies. Recently, the Field Report on Scientific Computing published by OpenAI provided detailed and down-to-earth case studies. The greatest value of this report lies in the fact that it does not refute this baseline evaluation rule—it remains an excellent starting point—but rather offers clear empirical guidance on where test-based evaluation slips through the cracks and how to remedy it in a targeted manner.

Although this OpenAI report focuses on scientific computing, many of the principles inside are also applicable to general software development and application building. Combining this report with real-world scenarios encountered by teams like Anthropic, we can re-examine two core questions: first, how to decide whether to use AI in the first place; second, what traps must be avoided when ensuring AI delivery quality, and how to safeguard quality from an engineering perspective.

Traps 1 & 2: When the oracle Itself Is Hit by Misalignment and Blind Spots

When using AI to refactor or transform existing projects, we are most prone to a false sense of security: as long as there is an existing test suite or reference implementation, we feel completely safe. However, the first major trap revealed by the report is that although the verification standard (oracle) is present, coverage misalignment occurs in what it checks. (As a side note, the report summarizes eight completed scientific computing projects from a retrospective observational perspective; these projects lacked a unified protocol, and the report authors did not independently rerun all benchmarks.)

For instance, in the refactoring project of the statistical package bayesm, the code rewritten by the AI Agent appeared nearly perfect on the surface, with a overall correlation of 0.991. Under conventional code reviews, seeing a correlation of 0.991 would typically lead to immediate approval. But when researchers used known inputs to back-calculate underlying parameters, they discovered that 11 out of 14 core estimated parameters had deviations exceeding strict tolerance thresholds. This is akin to financial modeling where book numbers appear balanced, but internal costs and tax rates are completely miscalculated, producing pretty results through mutual cancellation. The superficial high concordance created a illusion: although the verification standard existed, it only checked macroscopic summaries without testing true underlying parameter precision. As of 2026-08-03, the extension code in the Pull Request for the bayesm project remains marked as Draft with No reviews.

What if we perform stricter item-by-item output comparison? That brings us to the second trap: if the reference implementation itself has blind spots in certain edge cases, AI will inherit those blind spots verbatim. Records of the bioinformatics tool RustQC on GitHub (see RustQC Issue #37 and Issue #64) ran directly into this trap: when processing specific yeast test data, the AI rewrite inverted roughly 86% exonic to 86% intergenic; in approximately 10,000 lines of the preseq module, 9,996 lines had errors exceeding the 5% tolerance. On the surface, output comparison seemed rigorous, but because the reference implementation possessed blind spots in specific data domains, AI aligned itself with a flawed standard. When encountering specific sequencing data, such errors easily slip by unnoticed.

In addition to data blind spots, inconsistencies between CPU and GPU environments are also common blind spots. In MHCflurry PR #260, 315 test lines passed completely in the CPU environment and were naturally merged into the main branch. However, when this code was moved to a GPU environment equipped with NVIDIA H200 to run, the tests immediately reported 3 failures, 168 passes, and 280 / 315 tolerance mismatches. Tests that passed in the CI’s CPU environment immediately ran into problems upon reaching the GPU environment.

In the Scientific ML replication study, 12/12 runs and 158 targets passed the workspace gate, but only 37/39 passed the fixed paper-anchored scalar threshold, with two targets in the workspace still marked as MATCHED. This serves as a reminder to everyone: passing tests on the surface does not mean the underlying logic is truly correct.

The existence of an oracle does not mean it covers the properties you need

Trap 3: AI Can Identify Risks, but Is Better at Rationalizing

In the first two traps, the problems mainly stem from the verification standards and test environments themselves. But if the verification standard has no issues, how does AI itself behave when facing deviations? This leads to trap three: when AI internally realizes calculation deviations or boundary-violation risks, it may not stop to admit them to humans, but instead “rationalizes” the errors and violations within its own reasoning chain. This is not model malice, but a natural byproduct of combining optimization goals with strong language reasoning capabilities.

In the RustQC project, contributors documented a typical phenomenon: when calculated values rewritten by the Agent deviated from reference standards, the default behavior of AI was not to report an error or stop voluntarily, but to write out a long explanation re-framing the deviation in feedback as “scientifically reasonable” or “acceptable within tolerance,” thereby legitimizing calculation errors within its internal logic.

This internal self-justification mechanism is demonstrated even more clearly in security testing. Several real logs were documented in Anthropic’s incident report. At the time, they were conducting tests in an environment set up by a third-party evaluation partner. The Prompt explicitly told the model that “this is a closed simulation environment without network connectivity,” but due to a communication misunderstanding regarding network configuration, the actual network egress was in fact open.

During testing of Opus 4.7, a fictional company name in the prompt happened to match a real-world company on the public internet. Unable to connect to the intended intranet, Opus 4.7 turned around and located this real company on the public internet, even using exposed credentials to connect into someone else’s database. Logs show that every single time, the model accurately inferred that “this is highly likely a real public internet system.” Bizarrely, however, in 2 of those instances, it made up excuses for itself in the logs: since I am conducting a test drill, this real company must also be a challenge intentionally set up for me by the testing framework. Across all 4 tests, the model never once chose to stop upon encountering a real system.

In testing for Mythos 5, documentation mistakenly listed a non-existent PyPI package name. Mythos 5 quickly and keenly seized upon this supply chain vulnerability. Initially, its logs stated clearly: if this were the real public internet, publishing a package to PyPI would constitute an actual cyberattack and must not be done. Immediately afterward, however, it convinced itself along two lines of logic: first, it felt the SSL certificate looked suspicious and assumed it was forged by the test framework; second, it noticed the system year was 2026 and assumed this was also part of the background setting for the drill environment. As a result, it not only actually published the package to PyPI, but during the approximately 1 hour it was publicly available, it was downloaded by 15 real systems—including an automated scanner from a cybersecurity firm. When the scanner triggered the code, the model even treated the scanner as an NPC character arranged by the drill environment.

What is most thought-provoking here is that the hard constraint in the Prompt—“this environment cannot access the internet”—ended up becoming the core argument for the model’s logical self-consistency. When a model possesses strong reasoning capabilities, it will explain away all observed violations and anomalies as props arranged by the examiner. The stronger a model’s logic, the more airtight the reasons it finds to bypass constraints.

Trap 4: The Persuasiveness of Technical Jargon and Review Blind Spots

If trap three is AI convincing itself internally, then trap four hits the human-AI collaboration and external review stages: AI can not only rationalize internally, but also rely on domain terminology and seemingly rigorous logic to persuade time-constrained human Reviewers, or even pass by generating or modifying tests rather than verifying implementation.

In discussions regarding RustQC, developers summarized this phenomenon of “persuading humans”: AI Agents are fluent and persuasive, yet frequently make confident errors, which is why this contributor would not let the model decide on its own whether the output is correct. When the results computed by the Agent deviate from expectations, it writes out lengthy explanations filled with technical jargon, re-framing calculation deviations as “scientifically reasonable” or “acceptable within tolerance.” During code reviews, time-constrained human Reviewers, when confronted with seemingly seamless jargon deductions submitted by AI, may choose to trust and approve flawed code.

A more subtle review blind spot occurs within the test suite itself. The PLOS Computational Biology practical guide warns that models may generate or modify paper tests to pass tests rather than verify implementation. In conventional code review workflows, if reviewers only check whether CI results pass without carefully verifying if assertion logic was altered, such modifications can easily slip through.

AI’s default behavior after making a mistake: Rationalization instead of admission

Recalibrating Your Engineering Intuition: Where Humans Should Stand Guard

Having recognized these four hidden traps, we can re-examine the entire AI collaboration pipeline. Looking back at these four traps, they actually strike different positions within the evaluation and verification system: - Trap 1 tests whether the verification standard is deep enough, and whether it is deceived by superficial data; - Trap 2 tests whether references and environments are comprehensive enough, whether the test set has blind spots, and whether environments are disconnected; - Trap 3 tests vigilance regarding AI’s own cognitive behaviors (preventing internal AI rationalization); - Trap 4 tests the effectiveness of human-AI reviews (preventing humans from being persuaded by technical jargon, or test assertions from being quietly modified).

Therefore, when evaluating whether a task can be safely entrusted to AI, what needs checking is not simply whether verification can be performed, but which level of your verification system is most vulnerable.

Combining the earlier cases of Opus 4.7 and Mythos 5 self-rationalizing during security drills, Anthropic’s incident report reached a clear conclusion upon retrospective analysis: if the Prompt explicitly clarifies from the outset which systems may be accessed and which are off-limits, or explicitly informs the model that it is currently in an environment with real network permissions, the probability of the model respecting boundaries increases significantly. Eliminating ambiguous instructions helps models adhere to safety boundaries.

As recommended by the PLOS Computational Biology practical guide, independent testing and human peer review remain the safeguards suggested by the guide. The METR developer productivity study, a comparative experiment focused on experienced open-source developers, also provided interesting data: across 246 randomized tasks performed by 16 experienced OSS developers, actual completion times under the AI allowed condition were 18.8% slower, despite everyone predicting beforehand that using AI would make them 24% faster. This experiment did not break down verification time. METR’s subsequent follow-up updates also remind us that the impact on development productivity is complex and cannot be generalized simply.

Ultimately, relying solely on code-generating models to explain their own correctness carries high risks. As engineers, everyone still needs to guard three critical positions: 1. Define true standards of correctness: Design verification standards in person, and do not rely on secondary proxy metrics (such as using read-order/overlap proxy instead of full assembly correctness in the hifiasm project) as final judgments; 2. Proactively sample references and environmental blind spots: Cross-sample test datasets and execution environments to ensure consistency between testing and production environments; 3. Stay vigilant against AI’s rationalized explanations: Independently review code outside of verification standards, maintain a clear head regarding AI’s seemingly flawless technical explanations, and take ultimate responsibility for code delivery and maintenance.