Can the Agent Fix Its Own Bad Design When Requirements Change?
The previous experiment ended with code that looked good but wasn't.
Ministral created a clean Transaction date-range endpoint, but the service passed null to an Account-specific repository query and filtered dates in Java even though the repository already supported date-range filtering.
I deliberately left that implementation untouched.
Now the requirement changes:
The endpoint must require an Account ID and return only Transactions belonging to that Account within the requested date range.
I didn't tell the agent to fix its previous mistakes.
The bad implementation simply becomes the starting point.
This gives me a different question:
Can the agent understand a changed requirement, improve existing code, and avoid breaking something else in the process?
Start by inspecting the existing code
I keep the same focused Transaction context from the previous experiment and ask Ministral to plan before editing:
Do not modify any files yet.
The existing Transaction date-range endpoint now needs to be changed.
New requirement:
The endpoint must require an Account ID in addition to startDate and endDate,
and return only Transactions belonging to that Account within the requested
date range.
Using the currently loaded source:
1. Explain what is wrong or insufficient in the current implementation for
this new requirement.
2. Identify exactly which files need to change.
3. Explain how the Account ID should flow from Controller → Service →
Repository using existing project patterns.
4. Identify existing methods or dependencies that can be reused.
5. Identify any ownership checks that must remain preserved.
Do not modify files yet.
Do not invent new abstractions or repository methods if existing code can
support the requirement.
Do not propose unrelated refactoring.
This time, Ministral immediately notices both problems from the previous test.
It recognizes that this is wrong:
repository.findByOwnerAndAccountOrderByDateAscIndexAsc(loggedUser.getUser(), null)
and that retrieving a broader collection before filtering dates in Java is unnecessary.
It also found the repository method it ignored last time:
findByOwnerAndAccountAndDateBetweenOrderByDateAscIndexAsc
The model selects only:
TransactionController.java
TransactionService.java
and preserves loggedUser.getUser() for ownership.
So far, this is encouraging.
The model isn't blindly modifying its previous solution. It recognizes that the new requirement changes how the data should flow.
One detail is still unresolved
There is a problem in the plan.
Ministral says the service should pass the Account ID to the repository.
But the repository doesn't accept a String.
It expects:
List<Transaction> findByOwnerAndAccountAndDateBetweenOrderByDateAscIndexAsc(
User owner,
Account account,
LocalDate start,
LocalDate end
);
I asked a focused follow-up without giving it the answer.
Ministral correctly finds the existing AccountService dependency and resolves the conversion:
Account account = accountService.getById(accountId);
Now the flow makes sense:
accountId
↓
AccountService.getById(accountId)
↓
Account
↓
Repository(
logged user,
account,
start date,
end date
)
There is still one ambiguity.
Ministral can't decide whether accountId should enter the controller as:
@PathVariable
or:
@RequestParam
I ask it to determine the convention from the loaded source.
It still didn't make a definite choice.
I stop asking.
At some point, continuing to clarify every uncertainty stops measuring the model and starts coaching it toward my implementation.
Let it modify the existing code
The implementation prompt explicitly requires database-level date filtering, but I didn't tell Ministral exactly how to wire the Account into the controller.
The generated service is a major improvement:
public List<Transaction> getTransactionsByDateRange(
LocalDate startDate,
LocalDate endDate,
String accountId
) {
log.info(
TYPE + ": Fetching transactions between {} and {} for account {}",
startDate,
endDate,
accountId
);
Account account = accountService.getById(accountId);
return repository.findByOwnerAndAccountAndDateBetweenOrderByDateAscIndexAsc(
loggedUser.getUser(),
account,
startDate,
endDate
);
}
Comparing this with previous result:
null Account
+
broader database query
+
Java Stream date filtering
now produces:
accountId
↓
AccountService
↓
Account
↓
Owner + Account + DateBetween
↓
Database filtering
The two main semantic problems from the previous implementation are gone.
Ministral correctly reused the existing AccountService, preserved ownership, used the existing repository method, and moved date filtering back where it belongs.
The service is much better.
Then I look at the controller.
It fixes one problem and creates another
The generated controller includes:
@GetMapping("/range")
public List<Transaction> getTransactionsByDateRange(
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
@PathVariable String accountId
) {
return service.getTransactionsByDateRange(
startDate,
endDate,
accountId
);
}
There is an obvious mismatch once I look closely.
The method expects:
@PathVariable String accountId
but the route is still:
@GetMapping("/range")
There is no {accountId} in the path.
If accountId is a path variable, the route needs something conceptually like:
@GetMapping("/{accountId}/range")
Alternatively, /range could remain unchanged and accountId could be a request parameter.
Either approach could have been made internally consistent.
The model made neither one.
More interestingly, this wasn't a surprise that appeared only during code generation. The uncertainty was visible during planning.
Ministral repeatedly hesitated between @PathVariable and @RequestParam, then generated code without actually resolving the decision.
Unresolved planning ambiguity
↓
Implementation
↓
Real code defect
This is a useful results.
A weak point in the plan became a weak point in the code.
Correct files don't guarantee a clean edit
At the file level, Ministral remains disciplined.
Only these files changed:
TransactionController.java
TransactionService.java
No repository changes. No new DTO. No dependencies. No test modifications. No unrelated runtime logic.
But the Git diff reveals something else.
Ministral removed several comments from an unrelated existing service method. None of the changes were required.
They don't break the application, but my prompt explicitly said:
Make the smallest change necessary.
Do not refactor unrelated code.
So another distinction appears:
Correct file scope ≠ Correct edit scope
The agent knew which files to touch.
It still changed things inside those files that it had no reason to change.
Better doesn't mean correct
The agent can improve existing code.
It didn't just rewrite the same bad solution. It understood the new Account requirement, found an existing dependency, converted the ID into the correct entity, reused the correct repository query, and eliminated the unnecessary in-memory filtering.
But fixing the larger design didn't make the implementation correct as a whole.
The defect moved.
Repository/domain reasoning failure
↓
Changed requirement
↓
Repository/domain reasoning improved
+
Spring MVC wiring failure
A code review can't stop at:
This is much better than before.
It still has to ask:
Does the entire change actually work?
This is where I STOP the local experiment
This was originally supposed to lead into more tests: compilation, test generation, failure diagnosis, and another correction loop.
I stop here instead.
The problem is the amount of supervision required to trust the result.
I have to catch incorrect repository semantics.
Then the model fixes those semantics but leaves me with broken Spring MVC wiring and unrelated source changes.
Even on a small feature, I still need to inspect the plan, resolve ambiguities, read the generated code carefully, inspect the Git diff, and eventually compile and test everything before I can trust it.
At this point, the local model isn't removing enough work.
The failure isn't that the local model can't write code. It can. The problem is that I can't trust it enough to delegate repetitive coding work.
This doesn't make this a failed experiment.
I started with a question: how much of agentic coding can I learn without paying for models or new hardware?
By this point, I've learned enough to know where the limits of this particular setup are.
The next question is no longer how to make Ministral write one more Spring Boot method.
It's whether the same agentic workflow becomes meaningfully more useful when the local model is no longer the main constraint.