Jeison Eccel

The Most Dangerous AI Code Is Code That Looks Correct

The previous tests showed that Ministral can understand the main dependency structure of my Spring Boot project when I give it the relevant source.

Now I finally let it write code.

I intentionally choose a small feature:

Add an API endpoint that returns Transactions between two dates.

This isn't supposed to be a difficult architectural problem. The Transaction feature already exists, the project has established patterns, and the model gets a focused slice of the relevant production source.

The question is no longer whether the agent can read my code.

It's whether I can trust what it writes.

Start with a plan

I use a fresh Aider session with the same stack:

Aider 0.86.2
      ↓
Ollama
      ↓
Ministral 3 8B
      ↓
MyFinancesAPI

I load AGENTS.md and the core Transaction files:

TransactionController.java
TransactionService.java
TransactionRepository.java
Transaction.java
TransactionModel.java

Tests stay out of context because this task is specifically about the quality of the first implementation attempt.

Before allowing any edits, I ask Ministral to plan the change:

Do not modify any files yet.

I want to add an API endpoint that returns Transactions between two dates.

Using only the loaded source files and the project instructions:

1. Identify which loaded files need to change.
2. Identify the existing Transaction date field that should be used for the
   range.
3. Explain the Controller → Service → Repository flow you would implement.
4. Identify the request parameters and their Java types based on existing
   project conventions.
5. Identify any existing ownership/user filtering that must be preserved.

Do not invent methods or fields.
Do not propose unrelated refactoring.
Do not modify files.

The plan is surprisingly good.

Ministral identifies TransactionController.java and TransactionService.java as the files that need to change. It correctly finds:

LocalDate date

It proposes LocalDate for startDate and endDate, preserves loggedUser.getUser(), and recognizes the existing repository method:

findByOwnerAndAccountAndDateBetweenOrderByDateAscIndexAsc

The Controller → Service → Repository flow is also correct.

At this point, the model appears to understand the feature.

There is one warning. The existing repository query requires an Account, and Ministral notices this, but later describes Account filtering as optional.

I didn't correct it.

I want to see what the first implementation naturally looks like.

Let the agent write the feature

My implementation prompt keeps the scope deliberately small:

Implement the Transaction date-range endpoint described above.

Requirements:

- Return a list of Transactions between a start date and an end date.
- Follow the existing Transaction Controller → Service → Repository structure.
- Use the existing Transaction date field and existing project date types.
- Preserve the existing logged-in-user/ownership behavior.
- Follow the existing API and naming conventions.
- Make the smallest implementation necessary.
- Do not refactor unrelated code.
- Do not add dependencies.
- Do not modify tests.
- Do not run the application or tests yet.

Modify only the files required for this feature.

The generated controller looks perfectly reasonable:

@GetMapping("/range")
public List<Transaction> getTransactionsByDateRange(
        @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
        @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate
) {
    return service.getTransactionsByDateRange(startDate, endDate);
}

The resulting API is straightforward:

GET /transactions/range

startDate
endDate

Both parameters use ISO-formatted dates, and the controller delegates to the service.

Then I inspect the service.

public List<Transaction> getTransactionsByDateRange(LocalDate startDate, LocalDate endDate) {
    log.info(TYPE + ": Fetching transactions between {} and {}", startDate, endDate);

    return repository.findByOwnerAndAccountOrderByDateAscIndexAsc(loggedUser.getUser(), null)
            .stream()
            .filter(t -> !t.getDate().isBefore(startDate) && !t.getDate().isAfter(endDate))
            .toList();
}

At first glance, this also looks reasonable.

And that's the problem.

The code looks better than it behaves

The method has all the visual signals I would normally expect from a small feature:

  • sensible name;
  • correct parameter types;
  • logging;
  • repository access;
  • ownership filtering;
  • inclusive date filtering;
  • clean Stream usage;
  • no unrelated code.

But there are two important problems hidden inside it.

The first is the date filtering.

During planning, Ministral had already found:

findByOwnerAndAccountAndDateBetweenOrderByDateAscIndexAsc

Instead of using that existing database query, it calls:

findByOwnerAndAccountOrderByDateAscIndexAsc(...)

and filters the dates afterwards in Java.

Conceptually, it generates:

Database
   ↓
Retrieve broader collection
   ↓
Java application
   ↓
Filter by date

when the repository already supports doing the filtering in the database.

This isn't just a style preference. The application can end up retrieving more records than it needs.

But the second problem is worse.

null doesn't mean "ignore this parameter"

Look again at the repository call:

findByOwnerAndAccountOrderByDateAscIndexAsc(loggedUser.getUser(), null)

The repository method explicitly queries by:

Owner AND Account

Passing null as the Account doesn't magically remove Account from that contract.

It can instead produce query behaviour equivalent to looking for transactions where the Account itself is null.

Conceptually:

WHERE owner = ?
  AND account IS NULL

So the code may return the wrong transactions—or none at all.

The interesting part is that Ministral had enough information to see this problem before generating the code.

During planning, it correctly recognized the Account constraint and found the existing DateBetween query. During implementation, it failed to connect those facts into a correct repository call.

The failure wasn't missing context.

It was reasoning.

The diff is almost suspiciously clean

I inspect the repository after the edit.

Only two source files changed:

TransactionController.java
TransactionService.java

Exactly the files Ministral said it would modify.

It didn't touch the repository, entity, API model, tests, shared infrastructure, dependencies, or build configuration.

There was no unnecessary DTO, new abstraction, or unrelated refactor.

Structurally, this is one of the better agent-generated changes I've seen during the experiment.

AreaResult
Correct files✅
Existing architecture✅
Controller endpoint✅
LocalDate handling✅
Ownership awareness✅
Small modification scope✅
Unrelated refactoring✅
Existing date-range query reused❌
Account query semantics❌
First-pass behavioural correctness❌

This is an interesting failure compare to broken syntax.

If the model had generated obviously bad Java, review would be easy.

Instead, it generated code that rewards a quick review.

Everything looks familiar.

Everything is in the right place.

The names make sense.

The diff is small.

And the important defect is hidden in one repository call.

A small Aider lesson too

There is one unrelated but useful observation during the edit.

Aider's whole-edit output initially made it look like part of the existing TransactionService had been deleted.

Direct inspection and git diff showed otherwise. The existing method was still there, and Ministral had simply inserted the new method before it.

So the display looked more destructive than the actual edit.

For me, the practical lesson is simple:

The Git diff is the source of truth for what actually changed.

This is different from my earlier Qwen experiment, where the model really did corrupt the source. Here, the working tree was structurally clean.

The dangerous code isn't always ugly

Before this experiment, I was more concerned about obvious agent failures: invented APIs, broken syntax, unexpected refactoring, corrupted files, or changes outside the requested scope.

Those failures are annoying, but they're visible.

This one is easier to miss.

The generated code is:

small
clean
consistent
architecturally familiar
plausible

and still wrong.

A superficial review could easily turn into:

Controller looks good. Service looks good. Dates are filtered. Ownership is there. Done.

But loggedUser.getUser() being present doesn't mean the repository query is semantically correct. A nice Stream doesn't make in-memory filtering the right approach. Finding the correct repository method during planning doesn't mean the model will actually use it.

The result gives me a useful distinction:

Looks like the project ≠ Behaves like the project

I deliberately didn't fix it yet

I stopped here.

I didn't compile the code or gave it another attempt.

The purpose of this test is specifically to measure the first generated implementation.

And the first attempt told me something important.

Aider + Ollama + Ministral 3 8B can generate a narrow Spring Boot change while respecting the existing architecture and edit scope.

But I can't trust the implementation because it looks clean.

The most dangerous AI code isn't necessarily code that looks obviously wrong. It's code that looks correct enough to stop me from looking closely.